diff --git a/test/e2e/clusterpropagationpolicy_test.go b/test/e2e/clusterpropagationpolicy_test.go index ff595e36e553..2c6a1e5ee399 100644 --- a/test/e2e/clusterpropagationpolicy_test.go +++ b/test/e2e/clusterpropagationpolicy_test.go @@ -34,6 +34,7 @@ import ( policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" + "github.com/karmada-io/karmada/pkg/detector" "github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/test/e2e/framework" testhelper "github.com/karmada-io/karmada/test/helper" @@ -650,8 +651,8 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { // Delete when delete a clusterPropagationPolicy, and no more clusterPropagationPolicy matches the object, something like // labels should be cleaned. -var _ = ginkgo.Describe("[Delete] clusterPropagation testing", func() { - ginkgo.Context("delete clusterPropagation and remove the labels from the resource template and reference binding", func() { +var _ = ginkgo.Describe("[Delete] ClusterPropagation testing", func() { + ginkgo.Context("delete ClusterPropagation and remove the labels and annotations from the resource template and reference binding", func() { var policy *policyv1alpha1.ClusterPropagationPolicy var deployment *appsv1.Deployment var targetMember string @@ -695,26 +696,20 @@ var _ = ginkgo.Describe("[Delete] clusterPropagation testing", func() { }, pollTimeout, pollInterval).Should(gomega.Equal(true)) }) - ginkgo.It("delete ClusterPropagationPolicy and check whether labels are deleted correctly", func() { + ginkgo.It("delete ClusterPropagationPolicy and check whether labels and annotations are deleted correctly", func() { framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name) framework.WaitDeploymentFitWith(kubeClient, deployment.Namespace, deployment.Name, func(dep *appsv1.Deployment) bool { - if dep.Labels == nil { - return true - } - return dep.Labels[policyv1alpha1.ClusterPropagationPolicyLabel] == "" && dep.Labels[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel] == "" + return !(framework.MapContainKeys(dep.GetLabels(), detector.ClusterPropagationPolicyRefLabels) || framework.MapContainKeys(dep.GetAnnotations(), detector.ClusterPropagationPolicyRefAnnotations)) }) resourceBindingName := names.GenerateBindingName(deployment.Kind, deployment.Name) framework.WaitResourceBindingFitWith(karmadaClient, deployment.Namespace, resourceBindingName, func(resourceBinding *workv1alpha2.ResourceBinding) bool { - if resourceBinding.Labels == nil { - return true - } - return resourceBinding.Labels[policyv1alpha1.ClusterPropagationPolicyLabel] == "" && resourceBinding.Labels[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel] == "" + return !(framework.MapContainKeys(resourceBinding.GetLabels(), detector.ClusterPropagationPolicyRefLabels) || framework.MapContainKeys(resourceBinding.GetAnnotations(), detector.ClusterPropagationPolicyRefAnnotations)) }) }) }) - ginkgo.Context("delete clusterPropagation and remove the labels from the resource template and reference clusterBinding", func() { + ginkgo.Context("delete ClusterPropagation and remove the labels and annotations from the resource template and reference clusterBinding", func() { var crdGroup string var randStr string var crdSpecNames apiextensionsv1.CustomResourceDefinitionNames @@ -765,21 +760,15 @@ var _ = ginkgo.Describe("[Delete] clusterPropagation testing", func() { }, pollTimeout, pollInterval).Should(gomega.Equal(true)) }) - ginkgo.It("delete ClusterPropagationPolicy and check whether labels are deleted correctly", func() { + ginkgo.It("delete ClusterPropagationPolicy and check whether labels and annotations are deleted correctly", func() { framework.RemoveClusterPropagationPolicy(karmadaClient, crdPolicy.Name) framework.WaitCRDFitWith(dynamicClient, crd.Name, func(crd *apiextensionsv1.CustomResourceDefinition) bool { - if crd.Labels == nil { - return true - } - return crd.Labels[policyv1alpha1.ClusterPropagationPolicyLabel] == "" && crd.Labels[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel] == "" + return !(framework.MapContainKeys(crd.GetLabels(), detector.ClusterPropagationPolicyRefLabels) || framework.MapContainKeys(crd.GetAnnotations(), detector.ClusterPropagationPolicyRefAnnotations)) }) resourceBindingName := names.GenerateBindingName(crd.Kind, crd.Name) framework.WaitClusterResourceBindingFitWith(karmadaClient, resourceBindingName, func(crb *workv1alpha2.ClusterResourceBinding) bool { - if crb.Labels == nil { - return true - } - return crb.Labels[policyv1alpha1.ClusterPropagationPolicyLabel] == "" && crb.Labels[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel] == "" + return !(framework.MapContainKeys(crb.GetLabels(), detector.ClusterPropagationPolicyRefLabels) || framework.MapContainKeys(crb.GetAnnotations(), detector.ClusterPropagationPolicyRefAnnotations)) }) }) }) diff --git a/test/e2e/coverage_docs/clusterpropagationpolicy_test.md b/test/e2e/coverage_docs/clusterpropagationpolicy_test.md index 685db9c14928..561d4be39872 100644 --- a/test/e2e/coverage_docs/clusterpropagationpolicy_test.md +++ b/test/e2e/coverage_docs/clusterpropagationpolicy_test.md @@ -24,11 +24,11 @@ | Test the high explicit/low priority/implicit priority propagation for deployment | high explicit/low priority/implicit priority ClusterPropagationPolicy propagation testing | [Configure PropagationPolicy/ClusterPropagationPolicy priority](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#configure-propagationpolicyclusterpropagationpolicy-priority) | | Test the same explicit priority propagation for deployment | same explicit priority ClusterPropagationPolicy propagation testing | [Choose from same-priority PropagationPolicies](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#choose-from-same-priority-propagationpolicies) | -#### Delete clusterPropagation testing -| Test Case | E2E Describe Text | Comments | -|-----------------------------------------------------|-------------------------------------------------------------------------------------------------|------------| -| Test delete clusterpropagationpolicy for deployment | delete ClusterPropagationPolicy and check whether labels are deleted correctly(namespace scope) | | -| Test delete clusterpropagationpolicy for CRD | delete ClusterPropagationPolicy and check whether labels are deleted correctly(cluster scope) | | +#### Delete ClusterPropagation testing +| Test Case | E2E Describe Text | Comments | +|-----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|------------| +| Test delete ClusterPropagationPolicy for deployment | delete ClusterPropagationPolicy and check whether labels and annotations are deleted correctly(namespace scope) | | +| Test delete ClusterPropagationPolicy for CRD | delete ClusterPropagationPolicy and check whether labels and annotations are deleted correctly(cluster scope) | | #### TODO 1. May need add the test case when the [deployment updates](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#update-deployment). diff --git a/test/e2e/coverage_docs/propagationpolicy_test.md b/test/e2e/coverage_docs/propagationpolicy_test.md index 39ae8b184a93..da51f8592eec 100644 --- a/test/e2e/coverage_docs/propagationpolicy_test.md +++ b/test/e2e/coverage_docs/propagationpolicy_test.md @@ -25,12 +25,12 @@ | Test the same explicit priority propagation for deployment | same explicit priority PropagationPolicy propagation testing | [Choose from same-priority PropagationPolicies](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#choose-from-same-priority-propagationpolicies) | #### Advanced propagation testing -| Test Case | E2E Describe Text | Comments | -|--------------------------------------------------------------------------|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------| -| Test add resourceSelector of the propagationPolicy for the deployment | add resourceSelectors item | [Update propagationPolicy](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#update-propagationpolicy) | -| Test update resourceSelector of the propagationPolicy for the deployment | update resourceSelectors item | | -| Test update propagateDeps of the propagationPolicy for the deployment | update policy propagateDeps | | -| Test update placement of the propagationPolicy for the deployment | update policy placement | | -| Test delete propagationpolicy for deployment | delete the propagationPolicy and check whether labels are deleted correctly | | -| Test modify the old propagationPolicy to unbind and create a new one | modify the old propagationPolicy to unbind and create a new one | | -| Test delete the old propagationPolicy to unbind and create a new one | delete the old propagationPolicy to unbind and create a new one | | +| Test Case | E2E Describe Text | Comments | +|--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------| +| Test add resourceSelector of the propagationPolicy for the deployment | add resourceSelectors item | [Update propagationPolicy](https://karmada.io/docs/next/userguide/scheduling/resource-propagating#update-propagationpolicy) | +| Test update resourceSelector of the propagationPolicy for the deployment | update resourceSelectors item | | +| Test update propagateDeps of the propagationPolicy for the deployment | update policy propagateDeps | | +| Test update placement of the propagationPolicy for the deployment | update policy placement | | +| Test delete propagationpolicy for deployment | delete the propagationPolicy and check whether labels and annotations are deleted correctly | | +| Test modify the old propagationPolicy to unbind and create a new one | modify the old propagationPolicy to unbind and create a new one | | +| Test delete the old propagationPolicy to unbind and create a new one | delete the old propagationPolicy to unbind and create a new one | | diff --git a/test/e2e/framework/clusterpropagationpolicy.go b/test/e2e/framework/clusterpropagationpolicy.go index 5676c58302ca..0c86878b82ed 100644 --- a/test/e2e/framework/clusterpropagationpolicy.go +++ b/test/e2e/framework/clusterpropagationpolicy.go @@ -80,3 +80,13 @@ func UpdateClusterPropagationPolicy(client karmada.Interface, name string, resou gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) }) } + +// MapContainKeys used to determine if the map contains any item from the string array. +func MapContainKeys(m map[string]string, keys []string) bool { + for _, key := range keys { + if _, ok := m[key]; ok { + return true + } + } + return false +} diff --git a/test/e2e/propagationpolicy_test.go b/test/e2e/propagationpolicy_test.go index 0697d10e0b4f..6a82307ffc41 100644 --- a/test/e2e/propagationpolicy_test.go +++ b/test/e2e/propagationpolicy_test.go @@ -42,6 +42,7 @@ import ( policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" + "github.com/karmada-io/karmada/pkg/detector" "github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/test/e2e/framework" testhelper "github.com/karmada-io/karmada/test/helper" @@ -1096,24 +1097,15 @@ var _ = ginkgo.Describe("[AdvancedPropagation] propagation testing", func() { }, pollTimeout, pollInterval).Should(gomega.Equal(true)) }) - ginkgo.It("delete the propagationPolicy and check whether labels are deleted correctly", func() { + ginkgo.It("delete the propagationPolicy and check whether labels and annotations are deleted correctly", func() { framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name) framework.WaitDeploymentFitWith(kubeClient, deployment.Namespace, deployment.Name, func(dep *appsv1.Deployment) bool { - if dep.Labels == nil { - return true - } - return dep.Labels[policyv1alpha1.PropagationPolicyPermanentIDLabel] == "" && dep.Labels[policyv1alpha1.PropagationPolicyNameLabel] == "" && - dep.Labels[policyv1alpha1.PropagationPolicyNamespaceLabel] == "" - + return !(framework.MapContainKeys(dep.GetLabels(), detector.PropagationPolicyRefLabels) || framework.MapContainKeys(dep.GetAnnotations(), detector.PropagationPolicyRefAnnotations)) }) resourceBindingName := names.GenerateBindingName(deployment.Kind, deployment.Name) framework.WaitResourceBindingFitWith(karmadaClient, deployment.Namespace, resourceBindingName, func(resourceBinding *workv1alpha2.ResourceBinding) bool { - if resourceBinding.Labels == nil { - return true - } - return resourceBinding.Labels[policyv1alpha1.PropagationPolicyPermanentIDLabel] == "" && resourceBinding.Labels[policyv1alpha1.PropagationPolicyNameLabel] == "" && - resourceBinding.Labels[policyv1alpha1.PropagationPolicyNamespaceLabel] == "" + return !(framework.MapContainKeys(resourceBinding.GetLabels(), detector.PropagationPolicyRefLabels) || framework.MapContainKeys(resourceBinding.GetAnnotations(), detector.PropagationPolicyRefAnnotations)) }) }) })