Merge pull request #1633 from XiShanYongYe-Chang/work-status-grab

Add ReflectStatus ResourceInterperter interface to grab workload status
This commit is contained in:
karmada-bot 2022-04-25 17:37:12 +08:00 committed by GitHub
commit f4ddd15b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 403 additions and 19 deletions

View File

@ -192,7 +192,8 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
ConcurrentWorkSyncs: opts.ConcurrentWorkSyncs,
RateLimiterOptions: opts.RateLimiterOpts,
},
StopChan: stopChan,
StopChan: stopChan,
ResourceInterpreter: resourceInterpreter,
}
if err := controllers.StartControllers(controllerContext, controllersDisabledByDefault); err != nil {
@ -261,6 +262,7 @@ func startWorkStatusController(ctx controllerscontext.Context) (bool, error) {
ClusterCacheSyncTimeout: ctx.Opts.ClusterCacheSyncTimeout,
ConcurrentWorkStatusSyncs: ctx.Opts.ConcurrentWorkSyncs,
RateLimiterOptions: ctx.Opts.RateLimiterOptions,
ResourceInterpreter: ctx.ResourceInterpreter,
}
workStatusController.RunWorkQueue()
if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil {

View File

@ -318,6 +318,7 @@ func startWorkStatusController(ctx controllerscontext.Context) (enabled bool, er
ClusterCacheSyncTimeout: opts.ClusterCacheSyncTimeout,
ConcurrentWorkStatusSyncs: opts.ConcurrentWorkSyncs,
RateLimiterOptions: ctx.Opts.RateLimiterOptions,
ResourceInterpreter: ctx.ResourceInterpreter,
}
workStatusController.RunWorkQueue()
if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil {

View File

@ -21,6 +21,7 @@ import (
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
"github.com/karmada-io/karmada/pkg/resourceinterpreter"
"github.com/karmada-io/karmada/pkg/sharedcli/ratelimiterflag"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
@ -50,6 +51,7 @@ type WorkStatusController struct {
ClusterClientSetFunc func(clusterName string, client client.Client) (*util.DynamicClusterClient, error)
ClusterCacheSyncTimeout metav1.Duration
RateLimiterOptions ratelimiterflag.Options
ResourceInterpreter resourceinterpreter.ResourceInterpreter
}
// Reconcile performs a full reconciliation for the object referred to by the Request.
@ -275,10 +277,10 @@ func (c *WorkStatusController) recreateResourceIfNeeded(work *workv1alpha1.Work,
// reflectStatus grabs cluster object's running status then updates to its owner object(Work).
func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj *unstructured.Unstructured) error {
statusMap, _, err := unstructured.NestedMap(clusterObj.Object, "status")
statusRaw, err := c.ResourceInterpreter.ReflectStatus(clusterObj)
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName(), err)
return err
klog.Errorf("Failed to reflect status for object(%s/%s/%s) with resourceInterpreter.",
clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName(), err)
}
identifier, err := c.buildStatusIdentifier(work, clusterObj)
@ -288,29 +290,27 @@ func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj
manifestStatus := workv1alpha1.ManifestStatus{
Identifier: *identifier,
Status: statusRaw,
}
if statusMap != nil {
rawExtension, err := helper.BuildStatusRawExtension(statusMap)
if err != nil {
return err
}
manifestStatus.Status = rawExtension
}
workCopy := work.DeepCopy()
return retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
work.Status.ManifestStatuses = c.mergeStatus(work.Status.ManifestStatuses, manifestStatus)
updateErr := c.Status().Update(context.TODO(), work)
manifestStatuses := c.mergeStatus(workCopy.Status.ManifestStatuses, manifestStatus)
if reflect.DeepEqual(workCopy.Status.ManifestStatuses, manifestStatuses) {
return nil
}
workCopy.Status.ManifestStatuses = manifestStatuses
updateErr := c.Status().Update(context.TODO(), workCopy)
if updateErr == nil {
return nil
}
updated := &workv1alpha1.Work{}
if err = c.Get(context.TODO(), client.ObjectKey{Namespace: work.Namespace, Name: work.Name}, updated); err == nil {
if err = c.Get(context.TODO(), client.ObjectKey{Namespace: workCopy.Namespace, Name: workCopy.Name}, updated); err == nil {
//make a copy, so we don't mutate the shared cache
work = updated.DeepCopy()
workCopy = updated.DeepCopy()
} else {
klog.Errorf("failed to get updated work %s/%s: %v", work.Namespace, work.Name, err)
klog.Errorf("failed to get updated work %s/%s: %v", workCopy.Namespace, workCopy.Name, err)
}
return updateErr
})

View File

@ -10,6 +10,7 @@ import (
jsonpatch "github.com/evanphx/json-patch/v5"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
webhookutil "k8s.io/apiserver/pkg/util/webhook"
"k8s.io/klog/v2"
@ -293,3 +294,18 @@ func (e *CustomizedInterpreter) GetDependencies(ctx context.Context, attributes
return response.Dependencies, matched, nil
}
// ReflectStatus returns the status of the object.
// return matched value to indicate whether there is a matching hook.
func (e *CustomizedInterpreter) ReflectStatus(ctx context.Context, attributes *webhook.RequestAttributes) (status *runtime.RawExtension, matched bool, err error) {
var response *webhook.ResponseAttributes
response, matched, err = e.interpret(ctx, attributes)
if err != nil {
return
}
if !matched {
return
}
return &response.RawStatus, matched, nil
}

View File

@ -112,6 +112,9 @@ func verifyResourceInterpreterContext(operation configv1alpha1.InterpreterOperat
}
return res, nil
case configv1alpha1.InterpreterOperationInterpretStatus:
if response.RawStatus == nil {
return nil, fmt.Errorf("webhook returned nill response.rawStatus")
}
res.RawStatus = *response.RawStatus
return res, nil
case configv1alpha1.InterpreterOperationInterpretHealthy:

View File

@ -4,6 +4,7 @@ import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
@ -19,6 +20,7 @@ type DefaultInterpreter struct {
retentionHandlers map[schema.GroupVersionKind]retentionInterpreter
aggregateStatusHandlers map[schema.GroupVersionKind]aggregateStatusInterpreter
dependenciesHandlers map[schema.GroupVersionKind]dependenciesInterpreter
reflectStatusHandlers map[schema.GroupVersionKind]reflectStatusInterpreter
}
// NewDefaultInterpreter return a new DefaultInterpreter.
@ -29,6 +31,7 @@ func NewDefaultInterpreter() *DefaultInterpreter {
retentionHandlers: getAllDefaultRetentionInterpreter(),
aggregateStatusHandlers: getAllDefaultAggregateStatusInterpreter(),
dependenciesHandlers: getAllDefaultDependenciesInterpreter(),
reflectStatusHandlers: getAllDefaultReflectStatusInterpreter(),
}
}
@ -55,6 +58,9 @@ func (e *DefaultInterpreter) HookEnabled(kind schema.GroupVersionKind, operation
if _, exist := e.dependenciesHandlers[kind]; exist {
return true
}
case configv1alpha1.InterpreterOperationInterpretStatus:
return true
// TODO(RainbowMango): more cases should be added here
}
@ -106,3 +112,14 @@ func (e *DefaultInterpreter) GetDependencies(object *unstructured.Unstructured)
}
return handler(object)
}
// ReflectStatus returns the status of the object.
func (e *DefaultInterpreter) ReflectStatus(object *unstructured.Unstructured) (status *runtime.RawExtension, err error) {
handler, exist := e.reflectStatusHandlers[object.GroupVersionKind()]
if exist {
return handler(object)
}
// for resource types that don't have a build-in handler, try to collect the whole status from '.status' filed.
return reflectWholeStatus(object)
}

View File

@ -0,0 +1,199 @@
package defaultinterpreter
import (
"fmt"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
)
type reflectStatusInterpreter func(object *unstructured.Unstructured) (*runtime.RawExtension, error)
func getAllDefaultReflectStatusInterpreter() map[schema.GroupVersionKind]reflectStatusInterpreter {
s := make(map[schema.GroupVersionKind]reflectStatusInterpreter)
s[appsv1.SchemeGroupVersion.WithKind(util.DeploymentKind)] = reflectDeploymentStatus
s[corev1.SchemeGroupVersion.WithKind(util.ServiceKind)] = reflectServiceStatus
s[extensionsv1beta1.SchemeGroupVersion.WithKind(util.IngressKind)] = reflectIngressStatus
s[batchv1.SchemeGroupVersion.WithKind(util.JobKind)] = reflectJobStatus
s[appsv1.SchemeGroupVersion.WithKind(util.DaemonSetKind)] = reflectDaemonSetStatus
s[appsv1.SchemeGroupVersion.WithKind(util.StatefulSetKind)] = reflectStatefulSetStatus
return s
}
func reflectDeploymentStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if !exist {
klog.Errorf("Failed to grab status from %s(%s/%s) which should have status field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
deploymentStatus, err := helper.ConvertToDeploymentStatus(statusMap)
if err != nil {
return nil, fmt.Errorf("failed to convert DeploymentStatus from map[string]interface{}: %v", err)
}
grabStatus := appsv1.DeploymentStatus{
Replicas: deploymentStatus.Replicas,
UpdatedReplicas: deploymentStatus.UpdatedReplicas,
ReadyReplicas: deploymentStatus.ReadyReplicas,
AvailableReplicas: deploymentStatus.AvailableReplicas,
UnavailableReplicas: deploymentStatus.UnavailableReplicas,
}
return helper.BuildStatusRawExtension(grabStatus)
}
func reflectServiceStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
serviceType, exist, err := unstructured.NestedString(object.Object, "spec", "type")
if err != nil {
klog.Errorf("Failed to get spec.type field from %s(%s/%s)")
}
if !exist {
klog.Errorf("Failed to get spec.type from %s(%s/%s) which should have spec.type field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
if serviceType != string(corev1.ServiceTypeLoadBalancer) {
return nil, nil
}
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if !exist {
klog.Errorf("Failed to grab status from %s(%s/%s) which should have status field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
serviceStatus, err := helper.ConvertToServiceStatus(statusMap)
if err != nil {
return nil, fmt.Errorf("failed to convert ServiceStatus from map[string]interface{}: %v", err)
}
grabStatus := corev1.ServiceStatus{
LoadBalancer: serviceStatus.LoadBalancer,
}
return helper.BuildStatusRawExtension(grabStatus)
}
func reflectIngressStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
return reflectWholeStatus(object)
}
func reflectJobStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if !exist {
klog.Errorf("Failed to grab status from %s(%s/%s) which should have status field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
jobStatus, err := helper.ConvertToJobStatus(statusMap)
if err != nil {
return nil, fmt.Errorf("failed to convert JobStatus from map[string]interface{}: %v", err)
}
grabStatus := batchv1.JobStatus{
Active: jobStatus.Active,
Succeeded: jobStatus.Succeeded,
Failed: jobStatus.Failed,
Conditions: jobStatus.Conditions,
StartTime: jobStatus.StartTime,
CompletionTime: jobStatus.CompletionTime,
}
return helper.BuildStatusRawExtension(grabStatus)
}
func reflectDaemonSetStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if !exist {
klog.Errorf("Failed to grab status from %s(%s/%s) which should have status field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
daemonSetStatus, err := helper.ConvertToDaemonSetStatus(statusMap)
if err != nil {
return nil, fmt.Errorf("failed to convert DaemonSetStatus from map[string]interface{}: %v", err)
}
grabStatus := appsv1.DaemonSetStatus{
CurrentNumberScheduled: daemonSetStatus.CurrentNumberScheduled,
DesiredNumberScheduled: daemonSetStatus.DesiredNumberScheduled,
NumberAvailable: daemonSetStatus.NumberAvailable,
NumberMisscheduled: daemonSetStatus.NumberMisscheduled,
NumberReady: daemonSetStatus.NumberReady,
UpdatedNumberScheduled: daemonSetStatus.UpdatedNumberScheduled,
NumberUnavailable: daemonSetStatus.NumberUnavailable,
}
return helper.BuildStatusRawExtension(grabStatus)
}
func reflectStatefulSetStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if !exist {
klog.Errorf("Failed to grab status from %s(%s/%s) which should have status field.",
object.GetKind(), object.GetNamespace(), object.GetName())
return nil, nil
}
statefulSetStatus, err := helper.ConvertToStatefulSetStatus(statusMap)
if err != nil {
return nil, fmt.Errorf("failed to convert StatefulSetStatus from map[string]interface{}: %v", err)
}
grabStatus := appsv1.StatefulSetStatus{
AvailableReplicas: statefulSetStatus.AvailableReplicas,
CurrentReplicas: statefulSetStatus.CurrentReplicas,
ReadyReplicas: statefulSetStatus.ReadyReplicas,
Replicas: statefulSetStatus.Replicas,
UpdatedReplicas: statefulSetStatus.UpdatedReplicas,
}
return helper.BuildStatusRawExtension(grabStatus)
}
func reflectWholeStatus(object *unstructured.Unstructured) (*runtime.RawExtension, error) {
statusMap, exist, err := unstructured.NestedMap(object.Object, "status")
if err != nil {
klog.Errorf("Failed to get status field from %s(%s/%s), error: %v",
object.GetKind(), object.GetNamespace(), object.GetName(), err)
return nil, err
}
if exist {
return helper.BuildStatusRawExtension(statusMap)
}
return nil, nil
}

View File

@ -0,0 +1,72 @@
package defaultinterpreter
import (
"reflect"
"testing"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/karmada-io/karmada/pkg/util/helper"
)
func Test_getEntireStatus(t *testing.T) {
testMap := map[string]interface{}{"key": "value"}
wantRawExtension, _ := helper.BuildStatusRawExtension(testMap)
type args struct {
object *unstructured.Unstructured
}
tests := []struct {
name string
args args
want *runtime.RawExtension
wantErr bool
}{
{
"object doesn't have status",
args{
&unstructured.Unstructured{
Object: map[string]interface{}{},
},
},
nil,
false,
},
{
"object have wrong format status",
args{
&unstructured.Unstructured{
Object: map[string]interface{}{
"status": "a string",
},
},
},
nil,
true,
},
{
"object have correct format status",
args{
&unstructured.Unstructured{
Object: map[string]interface{}{
"status": testMap,
},
},
},
wantRawExtension,
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := reflectWholeStatus(tt.args.object)
if (err != nil) != tt.wantErr {
t.Errorf("reflectWholeStatus() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("reflectWholeStatus() got = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -4,6 +4,7 @@ import (
"context"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
@ -37,6 +38,10 @@ type ResourceInterpreter interface {
// GetDependencies returns the dependent resources of the given object.
GetDependencies(object *unstructured.Unstructured) (dependencies []configv1alpha1.DependentObjectReference, err error)
// ReflectStatus returns the status of the object.
ReflectStatus(object *unstructured.Unstructured) (status *runtime.RawExtension, err error)
// other common method
}
@ -174,3 +179,22 @@ func (i *customResourceInterpreterImpl) GetDependencies(object *unstructured.Uns
dependencies, err = i.defaultInterpreter.GetDependencies(object)
return
}
// ReflectStatus returns the status of the object.
func (i *customResourceInterpreterImpl) ReflectStatus(object *unstructured.Unstructured) (status *runtime.RawExtension, err error) {
klog.V(4).Info("Begin to grab status for object: %v %s/%s.", object.GroupVersionKind(), object.GetNamespace(), object.GetName())
status, hookEnabled, err := i.customizedInterpreter.ReflectStatus(context.TODO(), &webhook.RequestAttributes{
Operation: configv1alpha1.InterpreterOperationInterpretStatus,
Object: object,
})
if err != nil {
return
}
if hookEnabled {
return
}
status, err = i.defaultInterpreter.ReflectStatus(object)
return
}

View File

@ -85,6 +85,16 @@ func ConvertToDeployment(obj *unstructured.Unstructured) (*appsv1.Deployment, er
return typedObj, nil
}
// ConvertToDeploymentStatus converts a DeploymentStatus object from unstructured to typed.
func ConvertToDeploymentStatus(obj map[string]interface{}) (*appsv1.DeploymentStatus, error) {
typedObj := &appsv1.DeploymentStatus{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj, typedObj); err != nil {
return nil, err
}
return typedObj, nil
}
// ConvertToDaemonSet converts a DaemonSet object from unstructured to typed.
func ConvertToDaemonSet(obj *unstructured.Unstructured) (*appsv1.DaemonSet, error) {
typedObj := &appsv1.DaemonSet{}
@ -95,6 +105,16 @@ func ConvertToDaemonSet(obj *unstructured.Unstructured) (*appsv1.DaemonSet, erro
return typedObj, nil
}
// ConvertToDaemonSetStatus converts a DaemonSetStatus object from unstructured to typed.
func ConvertToDaemonSetStatus(obj map[string]interface{}) (*appsv1.DaemonSetStatus, error) {
typedObj := &appsv1.DaemonSetStatus{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj, typedObj); err != nil {
return nil, err
}
return typedObj, nil
}
// ConvertToStatefulSet converts a StatefulSet object from unstructured to typed.
func ConvertToStatefulSet(obj *unstructured.Unstructured) (*appsv1.StatefulSet, error) {
typedObj := &appsv1.StatefulSet{}
@ -105,6 +125,16 @@ func ConvertToStatefulSet(obj *unstructured.Unstructured) (*appsv1.StatefulSet,
return typedObj, nil
}
// ConvertToStatefulSetStatus converts a StatefulSetStatus object from unstructured to typed.
func ConvertToStatefulSetStatus(obj map[string]interface{}) (*appsv1.StatefulSetStatus, error) {
typedObj := &appsv1.StatefulSetStatus{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj, typedObj); err != nil {
return nil, err
}
return typedObj, nil
}
// ConvertToJob converts a Job object from unstructured to typed.
func ConvertToJob(obj *unstructured.Unstructured) (*batchv1.Job, error) {
typedObj := &batchv1.Job{}
@ -115,6 +145,16 @@ func ConvertToJob(obj *unstructured.Unstructured) (*batchv1.Job, error) {
return typedObj, nil
}
// ConvertToJobStatus converts a JobStatus from unstructured to typed.
func ConvertToJobStatus(obj map[string]interface{}) (*batchv1.JobStatus, error) {
typedObj := &batchv1.JobStatus{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj, typedObj); err != nil {
return nil, err
}
return typedObj, nil
}
// ConvertToEndpointSlice converts a EndpointSlice object from unstructured to typed.
func ConvertToEndpointSlice(obj *unstructured.Unstructured) (*discoveryv1.EndpointSlice, error) {
typedObj := &discoveryv1.EndpointSlice{}
@ -145,7 +185,17 @@ func ConvertToService(obj *unstructured.Unstructured) (*corev1.Service, error) {
return typedObj, nil
}
// ConvertToIngress converts a Service object from unstructured to typed.
// ConvertToServiceStatus converts a ServiceStatus object from unstructured to typed.
func ConvertToServiceStatus(obj map[string]interface{}) (*corev1.ServiceStatus, error) {
typedObj := &corev1.ServiceStatus{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj, typedObj); err != nil {
return nil, err
}
return typedObj, nil
}
// ConvertToIngress converts an Ingress object from unstructured to typed.
func ConvertToIngress(obj *unstructured.Unstructured) (*extensionsv1beta1.Ingress, error) {
typedObj := &extensionsv1beta1.Ingress{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), typedObj); err != nil {

View File

@ -283,7 +283,7 @@ func IsWorkContains(workStatus *workv1alpha1.WorkStatus, targetResource schema.G
}
// BuildStatusRawExtension builds raw JSON by a status map.
func BuildStatusRawExtension(status map[string]interface{}) (*runtime.RawExtension, error) {
func BuildStatusRawExtension(status interface{}) (*runtime.RawExtension, error) {
statusJSON, err := json.Marshal(status)
if err != nil {
klog.Errorf("Failed to marshal status. Error: %v.", statusJSON)