Skip to content

Commit

Permalink
add e2e test for scheduled condition
Browse files Browse the repository at this point in the history
Signed-off-by: dddddai <[email protected]>
  • Loading branch information
dddddai committed Oct 16, 2021
1 parent 5fb94c4 commit edd1fd2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/e2e/failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ var _ = ginkgo.Describe("failover testing", func() {
fmt.Printf("reschedule in %d target cluster\n", totalNum)
})

ginkgo.By("check if the scheduled condition is true", func() {
rb, err := getResourceBinding(deployment)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return meta.IsStatusConditionTrue(rb.Status.Conditions, workv1alpha2.Scheduled), nil
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("recover not ready cluster", func() {
for _, disabledCluster := range disabledClusters {
fmt.Printf("cluster %s is waiting for recovering\n", disabledCluster.Name)
Expand Down
41 changes: 41 additions & 0 deletions test/e2e/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/onsi/gomega"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -92,6 +93,15 @@ var _ = ginkgo.Describe("propagation with label and group constraints testing",
gomega.Expect(len(targetClusterNames) == minGroups).ShouldNot(gomega.BeFalse())
})

ginkgo.By("check if the scheduled condition is true", func() {
rb, err := getResourceBinding(deployment)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return meta.IsStatusConditionTrue(rb.Status.Conditions, workv1alpha2.Scheduled), nil
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("check if deployment present on right clusters", func() {
for _, targetClusterName := range targetClusterNames {
clusterClient := getClusterClient(targetClusterName)
Expand Down Expand Up @@ -266,6 +276,15 @@ var _ = ginkgo.Describe("propagation with label and group constraints testing",
fmt.Printf("target clusters in cluster resource binding are %s\n", targetClusterNames)
})

ginkgo.By("check if the scheduled condition is true", func() {
crb, err := getClusterResourceBinding(crd)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
return meta.IsStatusConditionTrue(crb.Status.Conditions, workv1alpha2.Scheduled), nil
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("check if crd present on right clusters", func() {
for _, targetClusterName := range targetClusterNames {
clusterDynamicClient := getClusterDynamicClient(targetClusterName)
Expand Down Expand Up @@ -864,3 +883,25 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
})
})
})

// get the resource binding associated with the workload
func getResourceBinding(workload interface{}) (*workv1alpha2.ResourceBinding, error) {
uncastObj, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(workload)
obj := unstructured.Unstructured{Object: uncastObj}
bindingName := names.GenerateBindingName(obj.GetKind(), obj.GetName())
binding := &workv1alpha2.ResourceBinding{}

err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Namespace: obj.GetNamespace(), Name: bindingName}, binding)
return binding, err
}

// get the cluster resource binding associated with the workload
func getClusterResourceBinding(workload interface{}) (*workv1alpha2.ClusterResourceBinding, error) {
uncastObj, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(workload)
obj := unstructured.Unstructured{Object: uncastObj}
bindingName := names.GenerateBindingName(obj.GetKind(), obj.GetName())
binding := &workv1alpha2.ClusterResourceBinding{}

err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Name: bindingName}, binding)
return binding, err
}

0 comments on commit edd1fd2

Please sign in to comment.