Skip to content

Commit 14554b7

Browse files
authored
fix: split service account from ExpectApplied (#190)
* split service account from ExpectApplied * change polling time * align function naming * check namespace object instead of pod
1 parent e515037 commit 14554b7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/expectations/expectations.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ func ExpectNotFound(ctx context.Context, c client.Client, objects ...client.Obje
102102
func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Object) {
103103
GinkgoHelper()
104104
for _, object := range objects {
105-
// If the object is a pod, ensure the default service account exists to avoid flaky tests
106-
// https://github.com/kubernetes/kubernetes/issues/66689
107-
if pod, ok := object.(*v1.Pod); ok {
108-
Eventually(func(g Gomega) {
109-
g.Expect(c.Get(ctx, apitypes.NamespacedName{Namespace: pod.Namespace, Name: "default"}, &v1.ServiceAccount{})).Error().NotTo(HaveOccurred())
110-
}).WithTimeout(1 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
111-
}
112-
113105
deletionTimestampSet := !object.GetDeletionTimestamp().IsZero()
114106
current := object.DeepCopyObject().(client.Object)
115107
statusCopy := object.DeepCopyObject().(client.Object) // Snapshot the status, since create/update may override
@@ -135,6 +127,14 @@ func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Objec
135127
}
136128
}, "2s", "400ms").Should(Succeed())
137129

130+
// If the object is a namespace, ensure the default service account exists to avoid flaky tests
131+
// https://github.com/kubernetes/kubernetes/issues/66689
132+
if namespace, ok := object.(*v1.Namespace); ok {
133+
Eventually(func(g Gomega) {
134+
g.Expect(c.Get(ctx, apitypes.NamespacedName{Namespace: namespace.Name, Name: "default"}, &v1.ServiceAccount{})).Error().NotTo(HaveOccurred())
135+
}).WithTimeout(1 * time.Minute).WithPolling(1 * time.Second).Should(Succeed())
136+
}
137+
138138
// Re-get the object to grab the updated spec and status
139139
Expect(c.Get(ctx, client.ObjectKeyFromObject(object), object)).To(Succeed())
140140

0 commit comments

Comments
 (0)