Skip to content

Commit

Permalink
add e2e
Browse files Browse the repository at this point in the history
Signed-off-by: zhzhuang-zju <[email protected]>
  • Loading branch information
zhzhuang-zju committed Jan 19, 2024
1 parent 349f021 commit 6ac3601
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
31 changes: 10 additions & 21 deletions test/e2e/clusterpropagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
})
})
})
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/coverage_docs/clusterpropagationpolicy_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/coverage_docs/propagationpolicy_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
10 changes: 10 additions & 0 deletions test/e2e/framework/clusterpropagationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 4 additions & 12 deletions test/e2e/propagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
})
})
})
Expand Down

0 comments on commit 6ac3601

Please sign in to comment.