From cd2812e30e52e4a44d3fe492860997049d7c7607 Mon Sep 17 00:00:00 2001 From: Lan Liang Date: Sun, 17 Mar 2024 15:13:25 +0000 Subject: [PATCH] Delete the labels of uid. Signed-off-by: Lan Liang --- pkg/apis/policy/v1alpha1/well_known_constants.go | 6 ------ pkg/apis/work/v1alpha2/well_known_constants.go | 9 --------- pkg/controllers/binding/common.go | 4 ---- pkg/detector/detector.go | 15 --------------- pkg/util/helper/work.go | 2 -- pkg/util/label.go | 2 -- 6 files changed, 38 deletions(-) diff --git a/pkg/apis/policy/v1alpha1/well_known_constants.go b/pkg/apis/policy/v1alpha1/well_known_constants.go index 940e69375..bd7b55409 100644 --- a/pkg/apis/policy/v1alpha1/well_known_constants.go +++ b/pkg/apis/policy/v1alpha1/well_known_constants.go @@ -31,18 +31,12 @@ const ( // In backup scenarios, when applying the backup resource manifest in a new cluster, the UUID may change. ClusterPropagationPolicyPermanentIDLabel = "clusterpropagationpolicy.karmada.io/permanent-id" - // PropagationPolicyUIDLabel is the uid of PropagationPolicy object. - PropagationPolicyUIDLabel = "propagationpolicy.karmada.io/uid" - // PropagationPolicyNamespaceAnnotation is added to objects to specify associated PropagationPolicy namespace. PropagationPolicyNamespaceAnnotation = "propagationpolicy.karmada.io/namespace" // PropagationPolicyNameAnnotation is added to objects to specify associated PropagationPolicy name. PropagationPolicyNameAnnotation = "propagationpolicy.karmada.io/name" - // ClusterPropagationPolicyUIDLabel is the uid of ClusterPropagationPolicy object. - ClusterPropagationPolicyUIDLabel = "clusterpropagationpolicy.karmada.io/uid" - // ClusterPropagationPolicyAnnotation is added to objects to specify associated ClusterPropagationPolicy name. ClusterPropagationPolicyAnnotation = "clusterpropagationpolicy.karmada.io/name" diff --git a/pkg/apis/work/v1alpha2/well_known_constants.go b/pkg/apis/work/v1alpha2/well_known_constants.go index c09e14004..eda0610ad 100644 --- a/pkg/apis/work/v1alpha2/well_known_constants.go +++ b/pkg/apis/work/v1alpha2/well_known_constants.go @@ -34,21 +34,12 @@ const ( // WorkPermanentIDLabel is the ID of Work object. WorkPermanentIDLabel = "work.karmada.io/permanent-id" - // ResourceBindingUIDLabel is the UID of ResourceBinding object. - ResourceBindingUIDLabel = "resourcebinding.karmada.io/uid" - - // ClusterResourceBindingUIDLabel is the uid of ClusterResourceBinding object. - ClusterResourceBindingUIDLabel = "clusterresourcebinding.karmada.io/uid" - // WorkNamespaceAnnotation is added to objects to specify associated Work's namespace. WorkNamespaceAnnotation = "work.karmada.io/namespace" // WorkNameAnnotation is added to objects to specify associated Work's name. WorkNameAnnotation = "work.karmada.io/name" - // WorkUIDLabel is the uid of Work object. - WorkUIDLabel = "work.karmada.io/uid" - // ResourceBindingReferenceKey is the key of ResourceBinding object. // It is usually a unique hash value of ResourceBinding object's namespace and name, intended to be added to the Work object. // It will be used to retrieve all Works objects that derived from a specific ResourceBinding object. diff --git a/pkg/controllers/binding/common.go b/pkg/controllers/binding/common.go index a6bc134e1..1a390ced4 100644 --- a/pkg/controllers/binding/common.go +++ b/pkg/controllers/binding/common.go @@ -159,8 +159,6 @@ func mergeLabel(workload *unstructured.Unstructured, workNamespace string, bindi util.MergeLabel(workload, workv1alpha1.WorkNameLabel, names.GenerateWorkName(workload.GetKind(), workload.GetName(), workload.GetNamespace())) util.MergeLabel(workload, util.ManagedByKarmadaLabel, util.ManagedByKarmadaLabelValue) if scope == apiextensionsv1.NamespaceScoped { - util.RemoveLabels(workload, workv1alpha2.ResourceBindingUIDLabel) - bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ResourceBindingPermanentIDLabel) util.MergeLabel(workload, workv1alpha2.ResourceBindingReferenceKey, names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName())) util.MergeLabel(workload, workv1alpha2.ResourceBindingPermanentIDLabel, bindingID) @@ -168,8 +166,6 @@ func mergeLabel(workload *unstructured.Unstructured, workNamespace string, bindi workLabel[workv1alpha2.ResourceBindingReferenceKey] = names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName()) workLabel[workv1alpha2.ResourceBindingPermanentIDLabel] = bindingID } else { - util.RemoveLabels(workload, workv1alpha2.ClusterResourceBindingUIDLabel) - bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ClusterResourceBindingPermanentIDLabel) util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingReferenceKey, names.GenerateBindingReferenceKey("", binding.GetName())) util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingPermanentIDLabel, bindingID) diff --git a/pkg/detector/detector.go b/pkg/detector/detector.go index bf40b7a16..346449917 100644 --- a/pkg/detector/detector.go +++ b/pkg/detector/detector.go @@ -477,9 +477,6 @@ func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, object "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") } - // TODO: Delete following two lines in release-1.9 - delete(bindingCopy.Labels, workv1alpha2.ResourceBindingUIDLabel) - delete(bindingCopy.Labels, policyv1alpha1.PropagationPolicyUIDLabel) if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" { bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()}) @@ -579,9 +576,6 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") } - // TODO: Delete following two lines in release-1.9 - delete(bindingCopy.Labels, workv1alpha2.ResourceBindingUIDLabel) - delete(bindingCopy.Labels, policyv1alpha1.ClusterPropagationPolicyUIDLabel) if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" { bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()}) @@ -634,9 +628,6 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") } - // TODO: delete following two lines in release-1.9 - delete(bindingCopy.Labels, workv1alpha2.ClusterResourceBindingUIDLabel) - delete(bindingCopy.Labels, policyv1alpha1.ClusterPropagationPolicyUIDLabel) if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ClusterResourceBindingPermanentIDLabel) == "" { bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, map[string]string{workv1alpha2.ClusterResourceBindingPermanentIDLabel: uuid.New().String()}) @@ -740,8 +731,6 @@ func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructure } } - // Delete following line when release-1.9 - delete(objLabels, policyv1alpha1.PropagationPolicyUIDLabel) objLabels[policyv1alpha1.PropagationPolicyNamespaceLabel] = policy.Namespace objLabels[policyv1alpha1.PropagationPolicyNameLabel] = policy.Name objLabels[policyv1alpha1.PropagationPolicyPermanentIDLabel] = policyID @@ -787,10 +776,6 @@ func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unst } objectCopy := object.DeepCopy() - // TODO: delete following 3 lines in release-1.9 - labels := objectCopy.GetLabels() - delete(labels, policyv1alpha1.ClusterPropagationPolicyUIDLabel) - objectCopy.SetLabels(labels) util.MergeLabel(objectCopy, policyv1alpha1.ClusterPropagationPolicyLabel, policy.Name) util.MergeLabel(objectCopy, policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, policyID) diff --git a/pkg/util/helper/work.go b/pkg/util/helper/work.go index 06d50aa0c..52ec85288 100644 --- a/pkg/util/helper/work.go +++ b/pkg/util/helper/work.go @@ -76,8 +76,6 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour return fmt.Errorf("work %s/%s is being deleted", runtimeObject.GetNamespace(), runtimeObject.GetName()) } - // TODO: Delete following one line in release-1.9 - delete(runtimeObject.Labels, workv1alpha2.WorkUIDLabel) runtimeObject.Spec = work.Spec runtimeObject.Labels = work.Labels runtimeObject.Annotations = work.Annotations diff --git a/pkg/util/label.go b/pkg/util/label.go index a0f78db47..d0f619c9b 100644 --- a/pkg/util/label.go +++ b/pkg/util/label.go @@ -59,8 +59,6 @@ func RetainLabels(desired *unstructured.Unstructured, observed *unstructured.Uns } labels[key] = value } - // TODO: Delete following one line in release-1.9 - delete(labels, workv1alpha2.WorkUIDLabel) if len(labels) > 0 { desired.SetLabels(labels) }