add deploymentStatus collection testing (#255)

Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
Zhen Chang 2021-04-06 11:50:36 +08:00 committed by GitHub
parent c4acba97aa
commit 350adfcccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 12 deletions

View File

@ -22,18 +22,6 @@ import (
"github.com/karmada-io/karmada/test/helper"
)
const (
deploymentNamePrefix = "deploy-"
serviceNamePrefix = "service-"
podNamePrefix = "pod-"
crdNamePrefix = "cr-"
updateDeploymentReplicas = 6
updateServicePort = 81
updatePodImage = "nginx:latest"
updateCRnamespace = "e2e-test"
)
// BasicPropagation focus on basic propagation functionality testing.
var _ = ginkgo.Describe("[BasicPropagation] basic propagation testing", func() {
ginkgo.Context("Deployment propagation testing", func() {

110
test/e2e/resource_test.go Normal file
View File

@ -0,0 +1,110 @@
package e2e
import (
"context"
"encoding/json"
"fmt"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"github.com/karmada-io/karmada/test/helper"
)
var _ = ginkgo.Describe("[resource-status collection] resource status collection testing", func() {
ginkgo.Context("DeploymentStatus collection testing", func() {
policyNamespace := testNamespace
policyName := deploymentNamePrefix + rand.String(RandomStrLength)
deploymentNamespace := testNamespace
deploymentName := policyName
deployment := helper.NewDeployment(deploymentNamespace, deploymentName)
policy := helper.NewPolicyWithSingleDeployment(policyNamespace, policyName, deployment, clusterNames)
ginkgo.BeforeEach(func() {
ginkgo.By(fmt.Sprintf("creating policy(%s/%s)", policyNamespace, policyName), func() {
_, err := karmadaClient.PolicyV1alpha1().PropagationPolicies(policyNamespace).Create(context.TODO(), policy, metav1.CreateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
})
ginkgo.AfterEach(func() {
ginkgo.By(fmt.Sprintf("removing policy(%s/%s)", policyNamespace, policyName), func() {
err := karmadaClient.PolicyV1alpha1().PropagationPolicies(policyNamespace).Delete(context.TODO(), policyName, metav1.DeleteOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
})
ginkgo.It("deployment status collection testing", func() {
ginkgo.By(fmt.Sprintf("creating deployment(%s/%s)", deploymentNamespace, deploymentName), func() {
_, err := kubeClient.AppsV1().Deployments(testNamespace).Create(context.TODO(), deployment, metav1.CreateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("check whether the deployment status can be correctly collected", func() {
wantedReplicas := *deployment.Spec.Replicas * int32(len(clusters))
klog.Infof("Waiting for deployment(%s/%s) collecting correctly status", deploymentNamespace, deploymentName)
err := wait.Poll(pollInterval, pollTimeout, func() (done bool, err error) {
currentDeployment, err := kubeClient.AppsV1().Deployments(testNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
if currentDeployment.Status.ReadyReplicas == wantedReplicas &&
currentDeployment.Status.AvailableReplicas == wantedReplicas &&
currentDeployment.Status.UpdatedReplicas == wantedReplicas &&
currentDeployment.Status.Replicas == wantedReplicas {
return true, nil
}
return false, nil
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("updating deployment replicas", func() {
patch := map[string]interface{}{
"spec": map[string]interface{}{
"replicas": pointer.Int32Ptr(updateDeploymentReplicas),
},
}
bytes, err := json.Marshal(patch)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
_, err = kubeClient.AppsV1().Deployments(deploymentNamespace).Patch(context.TODO(), deploymentName, types.StrategicMergePatchType, bytes, metav1.PatchOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("check if deployment status has been update whit new collection", func() {
wantedReplicas := updateDeploymentReplicas * int32(len(clusters))
klog.Infof("Waiting for deployment(%s/%s) collecting correctly status", deploymentNamespace, deploymentName)
err := wait.Poll(pollInterval, pollTimeout, func() (done bool, err error) {
currentDeployment, err := kubeClient.AppsV1().Deployments(testNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
if currentDeployment.Status.ReadyReplicas == wantedReplicas &&
currentDeployment.Status.AvailableReplicas == wantedReplicas &&
currentDeployment.Status.UpdatedReplicas == wantedReplicas &&
currentDeployment.Status.Replicas == wantedReplicas {
return true, nil
}
return false, nil
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By(fmt.Sprintf("removing deployment(%s/%s)", deploymentNamespace, deploymentName), func() {
err := kubeClient.AppsV1().Deployments(testNamespace).Delete(context.TODO(), deploymentName, metav1.DeleteOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
})
})
})

View File

@ -45,6 +45,18 @@ const (
RandomStrLength = 3
)
const (
deploymentNamePrefix = "deploy-"
serviceNamePrefix = "service-"
podNamePrefix = "pod-"
crdNamePrefix = "cr-"
updateDeploymentReplicas = 6
updateServicePort = 81
updatePodImage = "nginx:latest"
updateCRnamespace = "e2e-test"
)
var (
kubeconfig string
restConfig *rest.Config