Skip to content

Commit

Permalink
ci/e2e: add operator uninstall test
Browse files Browse the repository at this point in the history
Check that Elemental Operator can be delete and reinstall after.
Also check that non-elemental resources can still be deleted/created.

Signed-off-by: Loic Devulder <ldevulder@suse.com>
  • Loading branch information
ldevulder committed Mar 22, 2023
1 parent 0b8a97d commit f6760a5
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/master-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ jobs:
- name: List installed nodes
if: inputs.test_type == 'cli'
run: sudo virsh list
- name: Uninstall Elemental Operator
if: inputs.test_type == 'cli'
run: cd tests && make e2e-uninstall-operator
- name: Store logs
if: always()
env:
Expand Down
14 changes: 8 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ generate-readme:
@./scripts/generate-readme > README.md

# E2E tests
e2e-install-rancher: deps
ginkgo --label-filter install -r -v ./e2e
e2e-bootstrap-node: deps
ginkgo --timeout $(GINKGO_TIMEOUT)s --label-filter bootstrap -r -v ./e2e
e2e-configure-rancher: deps
ginkgo --label-filter configure -r -v ./e2e
e2e-get-logs: deps
ginkgo --label-filter logs -r -v ./e2e
e2e-install-rancher: deps
ginkgo --label-filter install -r -v ./e2e
e2e-ui-rancher: deps
ginkgo --label-filter ui -r -v ./e2e
e2e-bootstrap-node: deps
ginkgo --timeout $(GINKGO_TIMEOUT)s --label-filter bootstrap -r -v ./e2e
e2e-uninstall-operator:
ginkgo --label-filter uninstall-operator -r -v ./e2e
e2e-upgrade-node: deps
ginkgo --label-filter upgrade -r -v ./e2e
start-cypress-tests:
@./scripts/start-cypress-tests
e2e-get-logs: deps
ginkgo --label-filter logs -r -v ./e2e
105 changes: 105 additions & 0 deletions tests/e2e/uninstall-operator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright © 2022 - 2023 SUSE LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e_test

import (
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher/elemental/tests/e2e/helpers/misc"
)

func testClusterAvailability(ns, cluster string) {
Eventually(func() string {
out, _ := kubectl.Run("get", "cluster",
"--namespace", ns, cluster,
"-o", "jsonpath={.metadata.name}")
return out
}, misc.SetTimeout(3*time.Minute), 5*time.Second).Should(Equal(clusterName))
}

var _ = Describe("E2E - Uninstall Elemental Operator", Label("uninstall-operator"), func() {
// Create kubectl context
// Default timeout is too small, so New() cannot be used
k := &kubectl.Kubectl{
Namespace: "",
PollTimeout: misc.SetTimeout(300 * time.Second),
PollInterval: 500 * time.Millisecond,
}

It("Uninstall Elemental Operator", func() {
By("Testing cluster availability BEFORE operator uninstallation", func() {
testClusterAvailability(clusterNS, clusterName)
})

By("Uninstalling Operator via Helm", func() {
err := kubectl.RunHelmBinaryWithCustomErr(
"--namespace", "cattle-system-elemental",
"uninstall", "elemental-operator",
)
Expect(err).To(Not(HaveOccurred()))
})

By("Testing cluster availability AFTER operator uninstallation", func() {
testClusterAvailability(clusterNS, clusterName)
})

By("Deleting cluster", func() {
_, err := kubectl.Run("delete", "cluster",
"--namespace", clusterNS, clusterName)
Expect(err).To(Not(HaveOccurred()))
})

By("Testing cluster unavailability", func() {
out, err := kubectl.Run("get", "cluster",
"--namespace", clusterNS, clusterName,
"-o", "jsonpath={.metadata.name}")
Expect(err).To(HaveOccurred())
Expect(out).To(BeNil())
})
})

It("Re-install Elemental Operator", func() {
By("Installing Operator via Helm", func() {
operatorChart := "oci://registry.opensuse.org/isv/rancher/elemental/dev/charts/rancher/elemental-operator-chart"
err := kubectl.RunHelmBinaryWithCustomErr("upgrade", "--install", "elemental-operator",
operatorChart,
"--namespace", "cattle-elemental-system",
"--create-namespace",
)
Expect(err).To(Not(HaveOccurred()))

k.WaitForNamespaceWithPod("cattle-elemental-system", "app=elemental-operator")
Expect(err).To(Not(HaveOccurred()))

// Check elemental-operator image
operatorImage, err := misc.GetOperatorImage()
Expect(err).To(Not(HaveOccurred()))
GinkgoWriter.Printf("Operator Image:\n%s\n", operatorImage)
})

By("Re-creating the cluster", func() {
// NOTE: we can re-use clusterYaml as it has already been configured correctly
err := kubectl.Apply(clusterNS, clusterYaml)
Expect(err).To(Not(HaveOccurred()))
})

By("Testing cluster availability", func() {
testClusterAvailability(clusterNS, clusterName)
})
})
})

0 comments on commit f6760a5

Please sign in to comment.