diff --git a/pkg/resourceinterpreter/customizedinterpreter/configmanager/manager.go b/pkg/resourceinterpreter/customizedinterpreter/configmanager/manager.go index fe300019719f..a11d5935168c 100644 --- a/pkg/resourceinterpreter/customizedinterpreter/configmanager/manager.go +++ b/pkg/resourceinterpreter/customizedinterpreter/configmanager/manager.go @@ -5,9 +5,7 @@ import ( "sort" "sync/atomic" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/cache" @@ -89,15 +87,16 @@ func (m *interpreterConfigManager) updateConfiguration() { configs := make([]*configv1alpha1.ResourceInterpreterWebhookConfiguration, 0) for _, c := range configurations { - unstructuredConfig, err := runtime.DefaultUnstructuredConverter.ToUnstructured(c) + unstructuredConfig, err := helper.ToUnstructured(c) if err != nil { klog.Errorf("Failed to transform ResourceInterpreterWebhookConfiguration: %w", err) return } - config, err := helper.ConvertToResourceExploringWebhookConfiguration(&unstructured.Unstructured{Object: unstructuredConfig}) + config, err := helper.ConvertToResourceExploringWebhookConfiguration(unstructuredConfig) if err != nil { - klog.Errorf("Failed to convert object(%s), err", config.GroupVersionKind().String(), err) + gvk := unstructuredConfig.GroupVersionKind().String() + klog.Errorf("Failed to convert object(%s), err: %v", gvk, err) return } configs = append(configs, config) diff --git a/pkg/util/helper/unstructured.go b/pkg/util/helper/unstructured.go index 5785acbdaad9..8a50461e90cb 100644 --- a/pkg/util/helper/unstructured.go +++ b/pkg/util/helper/unstructured.go @@ -148,3 +148,12 @@ func ApplyReplica(workload *unstructured.Unstructured, desireReplica int64, fiel } return nil } + +// ToUnstructured converts a typed object to an unstructured object. +func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error) { + uncastObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) + if err != nil { + return nil, err + } + return &unstructured.Unstructured{Object: uncastObj}, nil +}