feat(crd): add update custom resource status
This commit is contained in:
33
internal/crd/convert.go
Normal file
33
internal/crd/convert.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package crd
|
||||
|
||||
import (
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
func convertToUnstructured(obj v1alpha1.FlinkJob) (*unstructured.Unstructured, error) {
|
||||
// Convert the structured object to an unstructured map
|
||||
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert to unstructured: %v", err)
|
||||
}
|
||||
|
||||
// Create an Unstructured object from the map
|
||||
unstructuredObj := &unstructured.Unstructured{
|
||||
Object: unstructuredMap,
|
||||
}
|
||||
|
||||
return unstructuredObj, nil
|
||||
}
|
||||
|
||||
func convertFromUnstructured(in *unstructured.Unstructured) (*v1alpha1.FlinkJob, error) {
|
||||
job := &v1alpha1.FlinkJob{}
|
||||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(in.Object, job)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
return job, nil
|
||||
}
|
||||
Reference in New Issue
Block a user