Skip to content

Commit

Permalink
Merge pull request #4949 from whitewindmills/policyid-webhook
Browse files Browse the repository at this point in the history
cleanup dead code of generating PropagationPolicy permanent id
  • Loading branch information
karmada-bot committed May 20, 2024
2 parents b401112 + bfc0f6f commit 3314771
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions pkg/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,26 +720,9 @@ func (d *ResourceDetector) GetUnstructuredObject(objectKey keys.ClusterWideKey)
return unstructuredObj, nil
}

func (d *ResourceDetector) getPropagationPolicyID(policy *policyv1alpha1.PropagationPolicy) (string, error) {
id := util.GetLabelValue(policy.GetLabels(), policyv1alpha1.PropagationPolicyPermanentIDLabel)
if id == "" {
id = uuid.New().String()
policy.Labels = util.DedupeAndMergeLabels(policy.Labels, map[string]string{policyv1alpha1.PropagationPolicyPermanentIDLabel: id})
if err := d.Client.Update(context.TODO(), policy); err != nil {
return id, err
}
}

return id, nil
}

// ClaimPolicyForObject set policy identifier which the object associated with.
func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructured, policy *policyv1alpha1.PropagationPolicy) (string, error) {
policyID, err := d.getPropagationPolicyID(policy)
if err != nil {
klog.Errorf("Get PropagationPolicy(%s/%s) ID error:%v", policy.Namespace, policy.Name, err)
return "", err
}
policyID := policy.Labels[policyv1alpha1.PropagationPolicyPermanentIDLabel]

objLabels := object.GetLabels()
if objLabels == nil {
Expand Down Expand Up @@ -770,26 +753,9 @@ func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructure
return policyID, d.Client.Update(context.TODO(), objectCopy)
}

func (d *ResourceDetector) getClusterPropagationPolicyID(policy *policyv1alpha1.ClusterPropagationPolicy) (string, error) {
id := util.GetLabelValue(policy.GetLabels(), policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel)
if id == "" {
id = uuid.New().String()
policy.Labels = util.DedupeAndMergeLabels(policy.Labels, map[string]string{policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel: id})
if err := d.Client.Update(context.TODO(), policy); err != nil {
return "", err
}
}

return id, nil
}

// ClaimClusterPolicyForObject set cluster identifier which the object associated with
func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unstructured, policy *policyv1alpha1.ClusterPropagationPolicy) (string, error) {
policyID, err := d.getClusterPropagationPolicyID(policy)
if err != nil {
klog.Errorf("Get ClusterPropagationPolicy(%s) ID error:%v", policy.Name, err)
return "", err
}
policyID := policy.Labels[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel]

claimedID := util.GetLabelValue(object.GetLabels(), policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel)
// object has been claimed, don't need to claim again
Expand Down

0 comments on commit 3314771

Please sign in to comment.