Merge pull request #1766 from duanmengkk/feature_globalResource
fixed a bug where not-namespaced resource could not be promoted
This commit is contained in:
commit
0f2bd7c02b
|
@ -256,13 +256,39 @@ func promote(controlPlaneRestConfig *rest.Config, obj *unstructured.Unstructured
|
|||
|
||||
controlPlaneDynamicClient := dynamic.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
|
||||
karmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
|
||||
if len(obj.GetNamespace()) == 0 {
|
||||
_, err := controlPlaneDynamicClient.Resource(gvr).Get(context.TODO(), opts.name, metav1.GetOptions{})
|
||||
if err == nil {
|
||||
fmt.Printf("Resource %q(%s) already exist in karmada control plane, you can edit PropagationPolicy and OverridePolicy to propagate it\n",
|
||||
gvr, opts.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !apierrors.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to get resource %q(%s) in control plane: %v", gvr, opts.name, err)
|
||||
}
|
||||
|
||||
_, err = controlPlaneDynamicClient.Resource(gvr).Create(context.TODO(), obj, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create resource %q(%s) in control plane: %v", gvr, opts.name, err)
|
||||
}
|
||||
|
||||
err = createOrUpdateClusterPropagationPolicy(karmadaClient, gvr, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Resource %q(%s) is promoted successfully\n", gvr, opts.name)
|
||||
} else {
|
||||
_, err := controlPlaneDynamicClient.Resource(gvr).Namespace(opts.Namespace).Get(context.TODO(), opts.name, metav1.GetOptions{})
|
||||
if err == nil {
|
||||
fmt.Printf("Resource %q(%s/%s) already exist in karmada control plane, you can edit PropagationPolicy and OverridePolicy to propagate it\n",
|
||||
gvr, opts.Namespace, opts.name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if !apierrors.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to get resource %q(%s/%s) in control plane: %v", gvr, opts.Namespace, opts.name, err)
|
||||
}
|
||||
|
@ -272,19 +298,13 @@ func promote(controlPlaneRestConfig *rest.Config, obj *unstructured.Unstructured
|
|||
return fmt.Errorf("failed to create resource %q(%s/%s) in control plane: %v", gvr, opts.Namespace, opts.name, err)
|
||||
}
|
||||
|
||||
karmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
|
||||
if len(obj.GetNamespace()) == 0 {
|
||||
err = createOrUpdateClusterPropagationPolicy(karmadaClient, gvr, opts)
|
||||
} else {
|
||||
err = createOrUpdatePropagationPolicy(karmadaClient, gvr, opts)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Resource %q(%s/%s) is promoted successfully\n", gvr, opts.Namespace, opts.name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue