Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func createNamespaceAndDeployFunction() TestNamespace {
out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(ns))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
DeferCleanup(func() {
_, _ = utils.RunFunc("delete", "--path", repoDir, "--namespace", ns)
})

// Push updated func.yaml back to repo
err = utils.CommitAndPush(repoDir, "Update func.yaml after deploy", "func.yaml")
Expand Down
76 changes: 37 additions & 39 deletions test/e2e/func_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func createSSHFunctionAndExpectReady(
err = k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

Eventually(functionBecomesReady(function.Name, functionNamespace)).Should(Succeed())
return function.Name
}
Expand Down Expand Up @@ -216,13 +220,6 @@ var _ = Describe("Operator", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should mark the function as ready", func() {
Expand All @@ -242,6 +239,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed())
Expand Down Expand Up @@ -296,13 +297,6 @@ var _ = Describe("Operator", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should mark the function as ready", func() {
Expand All @@ -323,6 +317,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed())
Expand Down Expand Up @@ -356,12 +354,7 @@ var _ = Describe("Operator", func() {
})

AfterEach(func() {
// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
logFailedTestDetails(functionName, functionNamespace)
})

It("should mark the function as not ready", func() {
Expand All @@ -381,6 +374,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionNotDeployed(functionName, functionNamespace), 2*time.Minute).Should(Succeed())
Expand Down Expand Up @@ -435,13 +432,6 @@ var _ = Describe("Operator", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

Context("using token authentication", func() {
Expand Down Expand Up @@ -481,6 +471,10 @@ var _ = Describe("Operator", func() {
err = k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed())
Expand All @@ -504,6 +498,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionNotReadyWithAuthError(functionName, functionNamespace), 2*time.Minute).Should(Succeed())
Expand Down Expand Up @@ -548,6 +546,10 @@ var _ = Describe("Operator", func() {
err = k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed())
Expand All @@ -571,6 +573,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionNotReadyWithAuthError(functionName, functionNamespace), 2*time.Minute).Should(Succeed())
Expand Down Expand Up @@ -636,12 +642,6 @@ var _ = Describe("Operator", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should mark the function as ready with SSH key auth", func() {
Expand Down Expand Up @@ -714,12 +714,6 @@ var _ = Describe("Operator", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should mark the function as ready when SSH key authSecretRef is provided", func() {
Expand All @@ -743,6 +737,10 @@ var _ = Describe("Operator", func() {
err := k8sClient.Create(ctx, function)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", function.Name, "--namespace", function.Namespace)
})

functionName = function.Name

Eventually(functionNotReadyWithAuthError(functionName, functionNamespace), 2*time.Minute).Should(Succeed())
Expand Down
26 changes: 12 additions & 14 deletions test/e2e/func_middleware_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ var _ = Describe("Middleware Update", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should update the middleware and mark the function as ready", func() {
Expand Down Expand Up @@ -188,6 +181,10 @@ var _ = Describe("Middleware Update", func() {
err = k8sClient.Create(ctx, fn)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", fn.Name, "--namespace", fn.Namespace)
})

functionName = fn.Name

Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed())
Expand Down Expand Up @@ -335,13 +332,6 @@ var _ = Describe("Middleware Update", func() {

AfterEach(func() {
logFailedTestDetails(functionName, functionNamespace)

// Cleanup function resource
if functionName != "" {
cmd := exec.Command("kubectl", "delete", "function", functionName, "-n", functionNamespace, "--ignore-not-found")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
}
})

It("should reconcile functions without explicit autoUpdateMiddleware when ConfigMap changes", func() {
Expand Down Expand Up @@ -379,6 +369,11 @@ var _ = Describe("Middleware Update", func() {

err = k8sClient.Create(ctx, fn)
Expect(err).NotTo(HaveOccurred())

utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", fn.Name, "--namespace", fn.Namespace)
})

functionName = fn.Name

By("Waiting for Function to become ready with middleware updates disabled")
Expand Down Expand Up @@ -492,6 +487,9 @@ var _ = Describe("Middleware Update", func() {

err = k8sClient.Create(ctx, fn)
Expect(err).NotTo(HaveOccurred())
utils.DeferCleanupOnSuccess(func() {
_, _ = utils.RunCmd("kubectl", "delete", "function", fn.Name, "--namespace", fn.Namespace)
})
functionName = fn.Name

By("Waiting for Function to become ready")
Expand Down
6 changes: 6 additions & 0 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func Run(cmd *exec.Cmd) (string, error) {
return string(output), nil
}

func RunCmd(cmd string, args ...string) (string, error) {
c := exec.Command(cmd, args...)

return Run(c)
}

// GetNonEmptyLines converts given command output string into individual objects
// according to line breakers, and ignores the empty elements in it.
func GetNonEmptyLines(output string) []string {
Expand Down
Loading