-
Notifications
You must be signed in to change notification settings - Fork 917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict the cluster sync mode for the unjoin and unregister command #6081
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import ( | |
"k8s.io/klog/v2" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" | ||
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned" | ||
"github.com/karmada-io/karmada/pkg/util" | ||
"github.com/karmada-io/karmada/pkg/util/names" | ||
|
@@ -95,6 +96,19 @@ func DeleteClusterObject(controlPlaneKubeClient kubeclient.Interface, controlPla | |
return err | ||
} | ||
|
||
// GetClusterSyncMode return the sync mode of the member cluster. | ||
func GetClusterSyncMode(controlPlaneKarmadaClient karmadaclientset.Interface, clusterName string) (clusterv1alpha1.ClusterSyncMode, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, this function doesn't feel very necessary, and inconvenient to test |
||
target, err := controlPlaneKarmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), clusterName, metav1.GetOptions{}) | ||
if apierrors.IsNotFound(err) { | ||
return clusterv1alpha1.Push, fmt.Errorf("no cluster object %s found in karmada control Plane", clusterName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it better for sycnmode to return an empty string when the returned err is not null? The first is that it's easier to read and understand, and the second is that the handler of the mode function is improperly handled. |
||
} | ||
if err != nil { | ||
klog.Errorf("Failed to get cluster object. cluster name: %s, error: %v", clusterName, err) | ||
return clusterv1alpha1.Push, err | ||
} | ||
return target.Spec.SyncMode, nil | ||
} | ||
|
||
// removeWorkFinalizer removes the finalizer of works in the executionSpace. | ||
func removeWorkFinalizer(executionSpaceName string, controlPlaneKarmadaClient karmadaclientset.Interface) error { | ||
list, err := controlPlaneKarmadaClient.WorkV1alpha1().Works(executionSpaceName).List(context.TODO(), metav1.ListOptions{}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is delete changed to get because a query is added?