Delete the labels of uid.

Signed-off-by: Lan Liang <gcslyp@gmail.com>
This commit is contained in:
Lan Liang 2024-03-17 15:13:25 +00:00
parent aa89947194
commit cd2812e30e
6 changed files with 0 additions and 38 deletions

View File

@ -31,18 +31,12 @@ const (
// In backup scenarios, when applying the backup resource manifest in a new cluster, the UUID may change. // In backup scenarios, when applying the backup resource manifest in a new cluster, the UUID may change.
ClusterPropagationPolicyPermanentIDLabel = "clusterpropagationpolicy.karmada.io/permanent-id" 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 is added to objects to specify associated PropagationPolicy namespace.
PropagationPolicyNamespaceAnnotation = "propagationpolicy.karmada.io/namespace" PropagationPolicyNamespaceAnnotation = "propagationpolicy.karmada.io/namespace"
// PropagationPolicyNameAnnotation is added to objects to specify associated PropagationPolicy name. // PropagationPolicyNameAnnotation is added to objects to specify associated PropagationPolicy name.
PropagationPolicyNameAnnotation = "propagationpolicy.karmada.io/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 is added to objects to specify associated ClusterPropagationPolicy name.
ClusterPropagationPolicyAnnotation = "clusterpropagationpolicy.karmada.io/name" ClusterPropagationPolicyAnnotation = "clusterpropagationpolicy.karmada.io/name"

View File

@ -34,21 +34,12 @@ const (
// WorkPermanentIDLabel is the ID of Work object. // WorkPermanentIDLabel is the ID of Work object.
WorkPermanentIDLabel = "work.karmada.io/permanent-id" 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 is added to objects to specify associated Work's namespace.
WorkNamespaceAnnotation = "work.karmada.io/namespace" WorkNamespaceAnnotation = "work.karmada.io/namespace"
// WorkNameAnnotation is added to objects to specify associated Work's name. // WorkNameAnnotation is added to objects to specify associated Work's name.
WorkNameAnnotation = "work.karmada.io/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. // 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 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. // It will be used to retrieve all Works objects that derived from a specific ResourceBinding object.

View File

@ -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, workv1alpha1.WorkNameLabel, names.GenerateWorkName(workload.GetKind(), workload.GetName(), workload.GetNamespace()))
util.MergeLabel(workload, util.ManagedByKarmadaLabel, util.ManagedByKarmadaLabelValue) util.MergeLabel(workload, util.ManagedByKarmadaLabel, util.ManagedByKarmadaLabelValue)
if scope == apiextensionsv1.NamespaceScoped { if scope == apiextensionsv1.NamespaceScoped {
util.RemoveLabels(workload, workv1alpha2.ResourceBindingUIDLabel)
bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ResourceBindingPermanentIDLabel) bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ResourceBindingPermanentIDLabel)
util.MergeLabel(workload, workv1alpha2.ResourceBindingReferenceKey, names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName())) util.MergeLabel(workload, workv1alpha2.ResourceBindingReferenceKey, names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName()))
util.MergeLabel(workload, workv1alpha2.ResourceBindingPermanentIDLabel, bindingID) 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.ResourceBindingReferenceKey] = names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName())
workLabel[workv1alpha2.ResourceBindingPermanentIDLabel] = bindingID workLabel[workv1alpha2.ResourceBindingPermanentIDLabel] = bindingID
} else { } else {
util.RemoveLabels(workload, workv1alpha2.ClusterResourceBindingUIDLabel)
bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ClusterResourceBindingPermanentIDLabel) bindingID := util.GetLabelValue(binding.GetLabels(), workv1alpha2.ClusterResourceBindingPermanentIDLabel)
util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingReferenceKey, names.GenerateBindingReferenceKey("", binding.GetName())) util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingReferenceKey, names.GenerateBindingReferenceKey("", binding.GetName()))
util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingPermanentIDLabel, bindingID) util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingPermanentIDLabel, bindingID)

View File

@ -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") "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) == "" { if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()}) 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") "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) == "" { if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()}) 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") "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) == "" { if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ClusterResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ClusterResourceBindingPermanentIDLabel: uuid.New().String()}) 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.PropagationPolicyNamespaceLabel] = policy.Namespace
objLabels[policyv1alpha1.PropagationPolicyNameLabel] = policy.Name objLabels[policyv1alpha1.PropagationPolicyNameLabel] = policy.Name
objLabels[policyv1alpha1.PropagationPolicyPermanentIDLabel] = policyID objLabels[policyv1alpha1.PropagationPolicyPermanentIDLabel] = policyID
@ -787,10 +776,6 @@ func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unst
} }
objectCopy := object.DeepCopy() 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.ClusterPropagationPolicyLabel, policy.Name)
util.MergeLabel(objectCopy, policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, policyID) util.MergeLabel(objectCopy, policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, policyID)

View File

@ -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()) 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.Spec = work.Spec
runtimeObject.Labels = work.Labels runtimeObject.Labels = work.Labels
runtimeObject.Annotations = work.Annotations runtimeObject.Annotations = work.Annotations

View File

@ -59,8 +59,6 @@ func RetainLabels(desired *unstructured.Unstructured, observed *unstructured.Uns
} }
labels[key] = value labels[key] = value
} }
// TODO: Delete following one line in release-1.9
delete(labels, workv1alpha2.WorkUIDLabel)
if len(labels) > 0 { if len(labels) > 0 {
desired.SetLabels(labels) desired.SetLabels(labels)
} }