Skip to content

Commit 8b0cff1

Browse files
authored
Merge pull request #2795 from camilamacedo86/test-e2e-with-images
🌱 (deploy-image/v1-alpha) - e2e test checking if the pods are running
2 parents 39e4f60 + a864fbf commit 8b0cff1

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

test/e2e/deployimage/plugin_cluster_test.go

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ var _ = Describe("kubebuilder", func() {
120120
By("uncomment kustomize files to ensure that pods are restricted")
121121
uncommentPodStandards(kbc)
122122

123-
Run(kbc, "memcached:1.4.36-alpine")
123+
Run(kbc)
124124
})
125125

126126
It("should generate a runnable project with deploy-image/v1-alpha without options ", func() {
@@ -162,13 +162,13 @@ var _ = Describe("kubebuilder", func() {
162162
By("uncomment kustomize files to ensure that pods are restricted")
163163
uncommentPodStandards(kbc)
164164

165-
Run(kbc, "busybox:1.28")
165+
Run(kbc)
166166
})
167167
})
168168
})
169169

170170
// Run runs a set of e2e tests for a scaffolded project defined by a TestContext.
171-
func Run(kbc *utils.TestContext, imageCR string) {
171+
func Run(kbc *utils.TestContext) {
172172
var controllerPodName string
173173
var err error
174174

@@ -249,42 +249,19 @@ func Run(kbc *utils.TestContext, imageCR string) {
249249
return err
250250
}, time.Minute, time.Second).Should(Succeed())
251251

252-
By("applying the CRD Editor Role")
253-
crdEditorRole := filepath.Join("config", "rbac",
254-
fmt.Sprintf("%s_editor_role.yaml", strings.ToLower(kbc.Kind)))
255-
EventuallyWithOffset(1, func() error {
256-
_, err = kbc.Kubectl.Apply(true, "-f", crdEditorRole)
257-
return err
258-
}, time.Minute, time.Second).Should(Succeed())
259-
260-
By("applying the CRD Viewer Role")
261-
crdViewerRole := filepath.Join("config", "rbac", fmt.Sprintf("%s_viewer_role.yaml", strings.ToLower(kbc.Kind)))
262-
EventuallyWithOffset(1, func() error {
263-
_, err = kbc.Kubectl.Apply(true, "-f", crdViewerRole)
264-
return err
265-
}, time.Minute, time.Second).Should(Succeed())
266-
267-
//TODO: We need to understand why it is not passing in the prow but is passing locally
268-
// By("validating that pod(s) status.phase=Running")
269-
// var podsOutput string
270-
// getPods := func() error {
271-
// podsOutput, err = kbc.Kubectl.Get(true, "pods", "-o",
272-
// "jsonpath={range .items[*]}{.metadata.name},{.status.phase} {end}")
273-
// if err == nil && strings.TrimSpace(podsOutput) == "" {
274-
// err = errors.New("empty pod output, continue")
275-
// }
276-
277-
// return err
278-
// }
279-
// Eventually(getPods, 5*time.Minute, time.Second).Should(Succeed())
280-
// podSlice := strings.Split(strings.TrimSpace(podsOutput), " ")
281-
// Expect(len(podSlice)).To(BeNumerically(">", 0))
282-
// for _, pod := range podSlice {
283-
// // make sure any pod that contains the substring "memcached" is in the running state
284-
// if strings.Contains(pod, fmt.Sprintf("%s-sample", strings.ToLower(kbc.Kind))) {
285-
// Expect(pod).To(ContainSubstring(",Running"))
286-
// }
287-
// }
252+
By("validating that pod(s) status.phase=Running")
253+
getMemcachedPodStatus := func() error {
254+
status, err := kbc.Kubectl.Get(true, "pods", "-l",
255+
fmt.Sprintf("type=%s", strings.ToLower(kbc.Kind)),
256+
"-o", "jsonpath={.items[*].status}",
257+
)
258+
ExpectWithOffset(2, err).NotTo(HaveOccurred())
259+
if !strings.Contains(status, "\"phase\":\"Running\"") {
260+
return err
261+
}
262+
return nil
263+
}
264+
EventuallyWithOffset(1, getMemcachedPodStatus, time.Minute, time.Second).Should(Succeed())
288265
}
289266

290267
func uncommentPodStandards(kbc *utils.TestContext) {

0 commit comments

Comments
 (0)