Skip to content

Commit

Permalink
Merge pull request #2133 from AllenZMC/fix_panic
Browse files Browse the repository at this point in the history
`karmada-controller-manager`/`karmada-agent` : fixed panic issue when dumps error infos.
  • Loading branch information
karmada-bot committed Jul 6, 2022
2 parents b26dae6 + 6fbaa0d commit 4ea4787
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/helper/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4ea4787

Please sign in to comment.