Skip to content

Commit 4ea4787

Browse files
authored
Merge pull request #2133 from AllenZMC/fix_panic
`karmada-controller-manager`/`karmada-agent` : fixed panic issue when dumps error infos.
2 parents b26dae6 + 6fbaa0d commit 4ea4787

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/resourceinterpreter/customizedinterpreter/configmanager/manager.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"sort"
66
"sync/atomic"
77

8-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
98
"k8s.io/apimachinery/pkg/labels"
10-
"k8s.io/apimachinery/pkg/runtime"
119
"k8s.io/apimachinery/pkg/runtime/schema"
1210
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1311
"k8s.io/client-go/tools/cache"
@@ -89,15 +87,16 @@ func (m *interpreterConfigManager) updateConfiguration() {
8987

9088
configs := make([]*configv1alpha1.ResourceInterpreterWebhookConfiguration, 0)
9189
for _, c := range configurations {
92-
unstructuredConfig, err := runtime.DefaultUnstructuredConverter.ToUnstructured(c)
90+
unstructuredConfig, err := helper.ToUnstructured(c)
9391
if err != nil {
9492
klog.Errorf("Failed to transform ResourceInterpreterWebhookConfiguration: %w", err)
9593
return
9694
}
9795

98-
config, err := helper.ConvertToResourceExploringWebhookConfiguration(&unstructured.Unstructured{Object: unstructuredConfig})
96+
config, err := helper.ConvertToResourceExploringWebhookConfiguration(unstructuredConfig)
9997
if err != nil {
100-
klog.Errorf("Failed to convert object(%s), err", config.GroupVersionKind().String(), err)
98+
gvk := unstructuredConfig.GroupVersionKind().String()
99+
klog.Errorf("Failed to convert object(%s), err: %v", gvk, err)
101100
return
102101
}
103102
configs = append(configs, config)

pkg/util/helper/unstructured.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ func ApplyReplica(workload *unstructured.Unstructured, desireReplica int64, fiel
148148
}
149149
return nil
150150
}
151+
152+
// ToUnstructured converts a typed object to an unstructured object.
153+
func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error) {
154+
uncastObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
155+
if err != nil {
156+
return nil, err
157+
}
158+
return &unstructured.Unstructured{Object: uncastObj}, nil
159+
}

0 commit comments

Comments
 (0)