Skip to content

Commit 2cb5e6d

Browse files
committed
E2E: Extract waiting for CNI DaemonSet to be ready
This is repetitive and verbose, extracting this makes the tests easier to read and maintain. Signed-off-by: Mike Kolesnik <[email protected]>
1 parent 3509277 commit 2cb5e6d

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

tests/e2e/multicluster/multicluster_multiprimary_test.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,8 @@ values:
106106
})
107107

108108
It("deploys istio-cni-node", func(ctx SpecContext) {
109-
Eventually(func() bool {
110-
daemonset := &appsv1.DaemonSet{}
111-
if err := clPrimary.Get(ctx, kube.Key("istio-cni-node", istioCniNamespace), daemonset); err != nil {
112-
return false
113-
}
114-
return daemonset.Status.NumberAvailable == daemonset.Status.CurrentNumberScheduled
115-
}).Should(BeTrue(), "CNI DaemonSet Pods are not Available on Cluster #1")
116-
Success("CNI DaemonSet is deployed in the namespace and Running on Cluster #1")
117-
118-
Eventually(func() bool {
119-
daemonset := &appsv1.DaemonSet{}
120-
if err := clRemote.Get(ctx, kube.Key("istio-cni-node", istioCniNamespace), daemonset); err != nil {
121-
return false
122-
}
123-
return daemonset.Status.NumberAvailable == daemonset.Status.CurrentNumberScheduled
124-
}).Should(BeTrue(), "IstioCNI DaemonSet Pods are not Available on Cluster #2")
125-
Success("IstioCNI DaemonSet is deployed in the namespace and Running on Cluster #2")
109+
common.AwaitCniDaemonSet(ctx, k1, clPrimary)
110+
common.AwaitCniDaemonSet(ctx, k2, clRemote)
126111
})
127112
})
128113

tests/e2e/multicluster/multicluster_primaryremote_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,7 @@ values:
111111
})
112112

113113
It("deploys istio-cni-node", func(ctx SpecContext) {
114-
Eventually(func() bool {
115-
daemonset := &appsv1.DaemonSet{}
116-
if err := clPrimary.Get(ctx, kube.Key("istio-cni-node", istioCniNamespace), daemonset); err != nil {
117-
return false
118-
}
119-
return daemonset.Status.NumberAvailable == daemonset.Status.CurrentNumberScheduled
120-
}).Should(BeTrue(), "IstioCNI DaemonSet Pods are not Available on Primary Cluster")
121-
Success("IstioCNI DaemonSet is deployed in the namespace and Running on Primary Cluster")
114+
common.AwaitCniDaemonSet(ctx, k1, clPrimary)
122115
})
123116
})
124117

tests/e2e/util/common/checks.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ func CheckPodsReady(ctx context.Context, cl client.Client, namespace string) err
8383
func CheckSamplePodsReady(ctx context.Context, cl client.Client) error {
8484
return CheckPodsReady(ctx, cl, sampleNamespace)
8585
}
86+
87+
// AwaitCniDaemonSet to be deployed and reach the scheduled number of pods.
88+
func AwaitCniDaemonSet(ctx context.Context, k kubectl.Kubectl, cl client.Client) {
89+
key := kube.Key("istio-cni-node", istioCniNamespace)
90+
Eventually(func() bool {
91+
daemonset := &appsv1.DaemonSet{}
92+
if err := cl.Get(ctx, key, daemonset); err != nil {
93+
return false
94+
}
95+
return daemonset.Status.NumberAvailable == daemonset.Status.CurrentNumberScheduled
96+
}).Should(BeTrue(), fmt.Sprintf("DaemonSet '%s' is not Available in the '%s' namespace on %s cluster", key.Name, key.Namespace, k.ClusterName))
97+
Success(fmt.Sprintf("DaemonSet '%s' is deployed and running in the '%s' namespace on %s cluster", key.Name, key.Namespace, k.ClusterName))
98+
}

0 commit comments

Comments
 (0)