From d20e47c55eec3841b207916a79fd2d6657af74ae Mon Sep 17 00:00:00 2001 From: zhzhuang-zju Date: Tue, 8 Oct 2024 10:12:31 +0800 Subject: [PATCH] rename marks.go to claim.go Signed-off-by: zhzhuang-zju --- pkg/detector/{marks.go => claim.go} | 32 +++++++++---------- pkg/detector/{marks_test.go => claim_test.go} | 16 +++++----- pkg/detector/detector.go | 22 ++++++------- pkg/detector/policy.go | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) rename pkg/detector/{marks.go => claim.go} (61%) rename pkg/detector/{marks_test.go => claim_test.go} (92%) diff --git a/pkg/detector/marks.go b/pkg/detector/claim.go similarity index 61% rename from pkg/detector/marks.go rename to pkg/detector/claim.go index b329851ba550..f5715bbf98ba 100644 --- a/pkg/detector/marks.go +++ b/pkg/detector/claim.go @@ -24,23 +24,23 @@ import ( ) var ( - propagationPolicyMarkedLabels = []string{ + propagationPolicyClaimLabels = []string{ policyv1alpha1.PropagationPolicyPermanentIDLabel, } - propagationPolicyMarkedAnnotations = []string{ + propagationPolicyClaimAnnotations = []string{ policyv1alpha1.PropagationPolicyNamespaceAnnotation, policyv1alpha1.PropagationPolicyNameAnnotation, } - clusterPropagationPolicyMarkedLabels = []string{ + clusterPropagationPolicyClaimLabels = []string{ policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, } - clusterPropagationPolicyMarkedAnnotations = []string{ + clusterPropagationPolicyClaimAnnotations = []string{ policyv1alpha1.ClusterPropagationPolicyAnnotation, } ) -// AddPolicyMarks adds PropagationPolicy marks, such as labels and annotations -func AddPolicyMarks(obj metav1.Object, policyID string, policyMeta metav1.ObjectMeta) { +// AddPPClaimMetadata adds PropagationPolicy claim metadata, such as labels and annotations +func AddPPClaimMetadata(obj metav1.Object, policyID string, policyMeta metav1.ObjectMeta) { util.MergeLabel(obj, policyv1alpha1.PropagationPolicyPermanentIDLabel, policyID) objectAnnotations := obj.GetAnnotations() @@ -52,8 +52,8 @@ func AddPolicyMarks(obj metav1.Object, policyID string, policyMeta metav1.Object obj.SetAnnotations(objectAnnotations) } -// AddClusterPolicyMarks adds ClusterPropagationPolicy marks, such as labels and annotations -func AddClusterPolicyMarks(obj metav1.Object, policyID string, policyMeta metav1.ObjectMeta) { +// AddCPPClaimMetadata adds ClusterPropagationPolicy claim metadata, such as labels and annotations +func AddCPPClaimMetadata(obj metav1.Object, policyID string, policyMeta metav1.ObjectMeta) { util.MergeLabel(obj, policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel, policyID) objectAnnotations := obj.GetAnnotations() @@ -64,14 +64,14 @@ func AddClusterPolicyMarks(obj metav1.Object, policyID string, policyMeta metav1 obj.SetAnnotations(objectAnnotations) } -// CleanupPolicyMarks removes PropagationPolicy marks, such as labels and annotations -func CleanupPolicyMarks(obj metav1.Object) { - util.RemoveLabels(obj, propagationPolicyMarkedLabels...) - util.RemoveAnnotations(obj, propagationPolicyMarkedAnnotations...) +// CleanupPPClaimMetadata removes PropagationPolicy claim metadata, such as labels and annotations +func CleanupPPClaimMetadata(obj metav1.Object) { + util.RemoveLabels(obj, propagationPolicyClaimLabels...) + util.RemoveAnnotations(obj, propagationPolicyClaimAnnotations...) } -// CleanupClusterPolicyMarks removes ClusterPropagationPolicy marks, such as labels and annotations -func CleanupClusterPolicyMarks(obj metav1.Object) { - util.RemoveLabels(obj, clusterPropagationPolicyMarkedLabels...) - util.RemoveAnnotations(obj, clusterPropagationPolicyMarkedAnnotations...) +// CleanupCPPClaimMetadata removes ClusterPropagationPolicy claim metadata, such as labels and annotations +func CleanupCPPClaimMetadata(obj metav1.Object) { + util.RemoveLabels(obj, clusterPropagationPolicyClaimLabels...) + util.RemoveAnnotations(obj, clusterPropagationPolicyClaimAnnotations...) } diff --git a/pkg/detector/marks_test.go b/pkg/detector/claim_test.go similarity index 92% rename from pkg/detector/marks_test.go rename to pkg/detector/claim_test.go index cb1e7f9b6898..fa7443921059 100644 --- a/pkg/detector/marks_test.go +++ b/pkg/detector/claim_test.go @@ -35,7 +35,7 @@ func Test_AddPolicyMarks(t *testing.T) { result metav1.Object }{ { - name: "add policy marks", + name: "add policy claim metadata", policyID: "f2507cgb-f3f3-4a4b-b289-5691a4fef979", policyMeta: metav1.ObjectMeta{Name: "pp-example", Namespace: "test"}, obj: &unstructured.Unstructured{ @@ -57,7 +57,7 @@ func Test_AddPolicyMarks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AddPolicyMarks(tt.obj, tt.policyID, tt.policyMeta) + AddPPClaimMetadata(tt.obj, tt.policyID, tt.policyMeta) assert.Equal(t, tt.obj, tt.result) }) } @@ -72,7 +72,7 @@ func Test_AddClusterPolicyMarks(t *testing.T) { result metav1.Object }{ { - name: "add cluster policy marks", + name: "add cluster policy claim metadata", policyID: "f2507cgb-f3f3-4a4b-b289-5691a4fef979", policyMeta: metav1.ObjectMeta{Name: "cpp-example"}, obj: &unstructured.Unstructured{ @@ -94,7 +94,7 @@ func Test_AddClusterPolicyMarks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AddClusterPolicyMarks(tt.obj, tt.policyID, tt.policyMeta) + AddCPPClaimMetadata(tt.obj, tt.policyID, tt.policyMeta) assert.Equal(t, tt.obj, tt.result) }) } @@ -107,7 +107,7 @@ func Test_CleanupPolicyMarks(t *testing.T) { result metav1.Object }{ { - name: "clean up policy marks", + name: "clean up policy claim metadata", obj: &unstructured.Unstructured{ Object: map[string]interface{}{ "metadata": map[string]interface{}{ @@ -128,7 +128,7 @@ func Test_CleanupPolicyMarks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - CleanupPolicyMarks(tt.obj) + CleanupPPClaimMetadata(tt.obj) assert.Equal(t, tt.obj, tt.result) }) } @@ -141,7 +141,7 @@ func Test_CleanupClusterPolicyMarks(t *testing.T) { result metav1.Object }{ { - name: "clean up policy marks", + name: "clean up policy claim metadata", obj: &unstructured.Unstructured{ Object: map[string]interface{}{ "metadata": map[string]interface{}{ @@ -162,7 +162,7 @@ func Test_CleanupClusterPolicyMarks(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - CleanupClusterPolicyMarks(tt.obj) + CleanupCPPClaimMetadata(tt.obj) assert.Equal(t, tt.obj, tt.result) }) } diff --git a/pkg/detector/detector.go b/pkg/detector/detector.go index 60b61d13feb0..8e9ac463042a 100644 --- a/pkg/detector/detector.go +++ b/pkg/detector/detector.go @@ -448,7 +448,7 @@ func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, object return nil } - binding, err := d.BuildResourceBinding(object, &policy.Spec, policyID, policy.ObjectMeta, AddPolicyMarks) + binding, err := d.BuildResourceBinding(object, &policy.Spec, policyID, policy.ObjectMeta, AddPPClaimMetadata) if err != nil { klog.Errorf("Failed to build resourceBinding for object: %s. error: %v", objectKey, err) return err @@ -536,7 +536,7 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, // For namespace-scoped resources, which namespace is not empty, building `ResourceBinding`. // For cluster-scoped resources, which namespace is empty, building `ClusterResourceBinding`. if object.GetNamespace() != "" { - binding, err := d.BuildResourceBinding(object, &policy.Spec, policyID, policy.ObjectMeta, AddClusterPolicyMarks) + binding, err := d.BuildResourceBinding(object, &policy.Spec, policyID, policy.ObjectMeta, AddCPPClaimMetadata) if err != nil { klog.Errorf("Failed to build resourceBinding for object: %s. error: %v", objectKey, err) return err @@ -683,7 +683,7 @@ func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructure } objectCopy := object.DeepCopy() - AddPolicyMarks(objectCopy, policyID, policy.ObjectMeta) + AddPPClaimMetadata(objectCopy, policyID, policy.ObjectMeta) return policyID, d.Client.Update(context.TODO(), objectCopy) } @@ -698,7 +698,7 @@ func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unst } objectCopy := object.DeepCopy() - AddClusterPolicyMarks(objectCopy, policyID, policy.ObjectMeta) + AddCPPClaimMetadata(objectCopy, policyID, policy.ObjectMeta) return policyID, d.Client.Update(context.TODO(), objectCopy) } @@ -776,7 +776,7 @@ func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unst }, } - AddClusterPolicyMarks(binding, policyID, policyMeta) + AddCPPClaimMetadata(binding, policyID, policyMeta) if d.ResourceInterpreter.HookEnabled(object.GroupVersionKind(), configv1alpha1.InterpreterOperationInterpretReplica) { replicas, replicaRequirements, err := d.ResourceInterpreter.GetReplicas(object) @@ -1062,7 +1062,7 @@ func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyID string) erro // Must remove the marks, such as labels and annotations, from the resource template ahead of ResourceBinding, // otherwise might lose the chance to do that in a retry loop (in particular, the marks was successfully removed // from ResourceBinding, but resource template not), since the ResourceBinding will not be listed again. - if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupPolicyMarks); err != nil { + if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from resource(%s-%s/%s) when propagationPolicy removed, error: %v", binding.Spec.Resource.Kind, binding.Spec.Resource.Namespace, binding.Spec.Resource.Name, err) errs = append(errs, err) @@ -1071,7 +1071,7 @@ func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyID string) erro } // Clean up the marks from the reference binding so that the karmada scheduler won't reschedule the binding. - if err := d.CleanupResourceBindingMarks(&rbs.Items[index], CleanupPolicyMarks); err != nil { + if err := d.CleanupResourceBindingMarks(&rbs.Items[index], CleanupPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from resource binding(%s/%s) when propagationPolicy removed, error: %v", binding.Namespace, binding.Name, err) errs = append(errs, err) @@ -1102,7 +1102,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyID strin // ClusterResourceBinding, otherwise might lose the chance to do that in a retry loop (in particular, the // marks was successfully removed from ClusterResourceBinding, but resource template not), since the // ClusterResourceBinding will not be listed again. - if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupClusterPolicyMarks); err != nil { + if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupCPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from resource(%s-%s) when clusterPropagationPolicy removed, error: %v", binding.Spec.Resource.Kind, binding.Spec.Resource.Name, err) // Skip cleaning up policy labels and annotations from ClusterResourceBinding, give a chance to do that in a retry loop. @@ -1110,7 +1110,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyID strin } // Clean up the marks from the reference binding so that the Karmada scheduler won't reschedule the binding. - if err := d.CleanupClusterResourceBindingMarks(&crbs.Items[index], CleanupClusterPolicyMarks); err != nil { + if err := d.CleanupClusterResourceBindingMarks(&crbs.Items[index], CleanupCPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from clusterResourceBinding(%s) when clusterPropagationPolicy removed, error: %v", binding.Name, err) errs = append(errs, err) @@ -1128,7 +1128,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyID strin // Must remove the marks, such as labels and annotations, from the resource template ahead of ResourceBinding, // otherwise might lose the chance to do that in a retry loop (in particular, the label was successfully // removed from ResourceBinding, but resource template not), since the ResourceBinding will not be listed again. - if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupClusterPolicyMarks); err != nil { + if err := d.CleanupResourceTemplateMarks(binding.Spec.Resource, CleanupCPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from resource(%s-%s/%s) when clusterPropagationPolicy removed, error: %v", binding.Spec.Resource.Kind, binding.Spec.Resource.Namespace, binding.Spec.Resource.Name, err) errs = append(errs, err) @@ -1137,7 +1137,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyID strin } // Clean up the marks from the reference binding so that the Karmada scheduler won't reschedule the binding. - if err := d.CleanupResourceBindingMarks(&rbs.Items[index], CleanupClusterPolicyMarks); err != nil { + if err := d.CleanupResourceBindingMarks(&rbs.Items[index], CleanupCPPClaimMetadata); err != nil { klog.Errorf("Failed to clean up marks from resourceBinding(%s/%s) when clusterPropagationPolicy removed, error: %v", binding.Namespace, binding.Name, err) errs = append(errs, err) diff --git a/pkg/detector/policy.go b/pkg/detector/policy.go index 31a3003e1571..3d93c4611d78 100644 --- a/pkg/detector/policy.go +++ b/pkg/detector/policy.go @@ -345,6 +345,6 @@ func excludeClusterPolicy(obj metav1.Object) (hasClaimedClusterPolicy bool) { if _, ok := obj.GetLabels()[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel]; !ok { return false } - CleanupClusterPolicyMarks(obj) + CleanupCPPClaimMetadata(obj) return true }