diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index fb1a8b54d..cdb521e3f 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -1,92 +1,13 @@ name: e2e tests -on: - pull_request: +on: workflow_dispatch +# This workflow is still not working on Github Actions. +# pull_request: concurrency: group: e2e-tests=full-${{ github.head_ref || github.ref }}-${{ github.repository }} cancel-in-progress: true jobs: - prepare-build: - name: Wait for the PR project to build - runs-on: ubuntu-latest - outputs: - chart_name: ${{ steps.chart.outputs.chart_name }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Wait for OBS crds chart - uses: "./.github/actions/wait-commit-status" - with: - repository: ${{ github.repository }} - commit: ${{ github.event.pull_request.head.sha }} - context: "OBS: elemental-operator-crds-helm - charts/x86_64" - status: "success" - interval: 60 - retries: 10 - - name: Wait for OBS operator chart - uses: "./.github/actions/wait-commit-status" - with: - repository: ${{ github.repository }} - commit: ${{ github.event.pull_request.head.sha }} - context: "OBS: elemental-operator-helm - charts/x86_64" - status: "success" - interval: 60 - retries: 10 - - name: Wait for OBS elemental-operator package - uses: "./.github/actions/wait-commit-status" - with: - repository: ${{ github.repository }} - commit: ${{ github.event.pull_request.head.sha }} - context: "OBS: elemental-operator - standard/x86_64" - status: "success" - interval: 60 - retries: 30 - - name: Wait for OBS seedimage-builder build - uses: "./.github/actions/wait-commit-status" - with: - repository: ${{ github.repository }} - commit: ${{ github.event.pull_request.head.sha }} - context: "OBS: seedimage-builder - containers/x86_64" - status: "success" - interval: 60 - retries: 30 - - name: Wait for OBS operator-image build - uses: "./.github/actions/wait-commit-status" - with: - repository: ${{ github.repository }} - commit: ${{ github.event.pull_request.head.sha }} - context: "OBS: operator-image - containers/x86_64" - status: "success" - interval: 60 - retries: 30 - - name: Pull chart for PR - env: - PR_NUMBER: ${{ github.event.number }} - OPERATOR_CHART: rancher/elemental-operator-chart - CRDS_CHART: rancher/elemental-operator-crds-chart - run: | - set -x - B_REPO=registry.opensuse.org/isv/rancher/elemental/pr/rancher/elemental-operator/pr-${PR_NUMBER}/charts - mkdir -p build - helm pull -d build oci://${B_REPO}/${CRDS_CHART} - helm pull -d build oci://${B_REPO}/${OPERATOR_CHART} - - name: Set chart output - id: chart - run: | - set -x - FILE=$(find . -type f -name "elemental-operator-chart-[1-9]*.tgz" -print) - CHART=$(basename $FILE) - echo "chart_name=$CHART" >> $GITHUB_OUTPUT - - name: Upload chart - uses: actions/upload-artifact@v4 - with: - name: chart - path: build/*.tgz - overwrite: true - e2e-tests: continue-on-error: true strategy: @@ -96,41 +17,27 @@ jobs: replicas: ["1"] rancherVersion : ["2.8.5"] runs-on: ubuntu-latest - needs: prepare-build name: k8s ${{ matrix.kubernetes }} - Rancher ${{ matrix.rancherVersion }} - ${{ matrix.replicas }} replicas env: - CHART: ${{ github.workspace }}/build/${{ needs.prepare-build.outputs.chart_name }} OPERATOR_REPLICAS: ${{ matrix.replicas }} RANCHER_VERSION: ${{ matrix.rancherVersion }} + KUBE_VERSION: ${{ matrix.kubernetes }} NGINX_VERSION: controller-v1.9.1 CERT_MANAGER_VERSION: v1.13.1 - SYSTEM_UPGRADE_CONTROLLER_VERSION: v0.13.1 + SYSTEM_UPGRADE_CONTROLLER_VERSION: v0.13.4 steps: - - uses: actions/checkout@v4 - - name: Download chart - uses: actions/download-artifact@v4 - with: - name: chart - path: build - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-test-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-test-go-${{ hashFiles('**/go.sum') }} - - name: Install kind - uses: helm/kind-action@v1 + - name: Checkout code + uses: actions/checkout@v4 with: - cluster_name: operator-e2e - node_image: kindest/node:${{ matrix.kubernetes }} + fetch-depth: 0 - name: e2e tests - run: make e2e-tests + run: LOCAL_BUILD=true make e2e-tests + - name: Upload chart + uses: actions/upload-artifact@v4 + with: + name: chart + path: build/*.tgz + overwrite: true - name: Archive artifacts if: always() uses: actions/upload-artifact@v4 diff --git a/Makefile b/Makefile index 364e52d18..a114307a5 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,10 @@ KUSTOMIZE_VER := v5.3.0 KUSTOMIZE := $(ABS_TOOLS_DIR)/kustomize-$(KUSTOMIZE_VER) KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5 +MOCKGEN_PKG := go.uber.org/mock/mockgen +MOCKGEN_VER := v0.4.0 +MOCKGEN := $(ABS_TOOLS_DIR)/mockgen-$(MOCKGEN_VER) + $(CONTROLLER_GEN): GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) controller-gen $(CONTROLLER_GEN_VER) @@ -70,6 +74,9 @@ $(SETUP_ENVTEST): $(KUSTOMIZE): CGO_ENABLED=0 GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) kustomize $(KUSTOMIZE_VER) +$(MOCKGEN): + GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) mockgen $(MOCKGEN_VER) + .PHONY: build build: operator register support @@ -172,7 +179,7 @@ unit-tests: $(SETUP_ENVTEST) $(GINKGO) airgap-script-test: scripts/elemental-airgap-test.sh -e2e-tests: $(GINKGO) +e2e-tests: $(GINKGO) build-docker-operator build-docker-seedimage-builder chart setup-kind kubectl cluster-info --context kind-$(CLUSTER_NAME) kubectl label nodes --all --overwrite ingress-ready=true kubectl label nodes --all --overwrite node-role.kubernetes.io/master= @@ -181,6 +188,8 @@ e2e-tests: $(GINKGO) export CHART=$(CHART) && \ export BRIDGE_IP="172.18.0.1" && \ export CONFIG_PATH=$(E2E_CONF_FILE) && \ + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} && \ + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} && \ cd $(ROOT_DIR)/tests && $(GINKGO) -r -v ./e2e # Only setups the kind cluster @@ -193,7 +202,7 @@ setup-kind: # and run a test that does nothing but installs everything for # the elemental operator (nginx, rancher, operator, etc..) as part of the BeforeSuite # So you end up with a clean cluster in which nothing has run -setup-full-cluster: build-docker-operator build-docker-seedimage-builder chart setup-kind +setup-full-cluster: $(GINKGO) build-docker-operator build-docker-seedimage-builder chart setup-kind @export EXTERNAL_IP=$$(kubectl get nodes -o jsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}') && \ export BRIDGE_IP="172.18.0.1" && \ export CHART=$(CHART) && \ @@ -238,12 +247,20 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g output:webhook:dir=./config/webhook \ webhook +.PHONY: generate-mocks +generate-mocks: $(MOCKGEN) + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/client.go -package=mocks github.com/rancher/elemental-operator/pkg/register Client + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/state.go -package=mocks github.com/rancher/elemental-operator/pkg/register StateHandler + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/install/mocks/install.go -package=mocks github.com/rancher/elemental-operator/pkg/install Installer + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/elementalcli/mocks/elementalcli.go -package=mocks github.com/rancher/elemental-operator/pkg/elementalcli Runner + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/network/mocks/network.go -package=mocks github.com/rancher/elemental-operator/pkg/network Configurator + $(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/util/mocks/command_runner.go -package=mocks github.com/rancher/elemental-operator/pkg/util CommandRunner + .PHONY: generate-go -generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator +generate-go: generate-mocks $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator $(CONTROLLER_GEN) \ object:headerFile=$(ROOT)scripts/boilerplate.go.txt \ paths=./api/... - ./scripts/generate_mocks.sh build-crds: $(KUSTOMIZE) $(KUSTOMIZE) build config/crd > .obs/chartfile/elemental-operator-crds-helm/templates/crds.yaml diff --git a/go.mod b/go.mod index eba0d90c5..87f63a88a 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/jaypipes/ghw v0.12.0 github.com/onsi/ginkgo/v2 v2.17.0 github.com/onsi/gomega v1.32.0 - github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240227152220-1b9250417c8d + github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240926104948-8ac88aebed21 github.com/rancher-sandbox/go-tpm v0.0.0-20230111102523-ee25b94d1912 github.com/rancher/fleet/pkg/apis v0.10.0-rc.4 github.com/rancher/lasso v0.0.0-20240123150939-7055397d6dfa diff --git a/go.sum b/go.sum index 7d4c5f77b..59eb2ef2f 100644 --- a/go.sum +++ b/go.sum @@ -725,8 +725,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/pseudomuto/protoc-gen-doc v1.4.1/go.mod h1:exDTOVwqpp30eV/EDPFLZy3Pwr2sn6hBC1WIYH/UbIg= github.com/pseudomuto/protoc-gen-doc v1.5.0/go.mod h1:exDTOVwqpp30eV/EDPFLZy3Pwr2sn6hBC1WIYH/UbIg= github.com/pseudomuto/protokit v0.2.0/go.mod h1:2PdH30hxVHsup8KpBTOXTBeMVhJZVio3Q8ViKSAXT0Q= -github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240227152220-1b9250417c8d h1:uWhUciLoSxKDYdW87Ir4BeQQdv7OzeZ74GO+R3gSSDM= -github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240227152220-1b9250417c8d/go.mod h1:Ex+a/ng4u2BvcGQdQjTHI48h88bQ6k2a7q8rnvU0XbQ= +github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240926104948-8ac88aebed21 h1:HiCx5MUE8Y3o9K+YV8fMPPbzqSm7r6klDQ8erJbIw9E= +github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240926104948-8ac88aebed21/go.mod h1:Ex+a/ng4u2BvcGQdQjTHI48h88bQ6k2a7q8rnvU0XbQ= github.com/rancher-sandbox/go-tpm v0.0.0-20230111102523-ee25b94d1912 h1:XcxZmGLOTk+9QCUJl/hCwMeOzkaA+nFY2Z04inD3wtc= github.com/rancher-sandbox/go-tpm v0.0.0-20230111102523-ee25b94d1912/go.mod h1:knpgv9J5TouY2g4C3AqhDn7x8kCcyIUUjFFxgPolJys= github.com/rancher/aks-operator v1.3.0-rc5 h1:4yiTDMmPVZbp+Uy8WQprwElJ6R8yKA0aZema5VDMQo4= diff --git a/pkg/elementalcli/mocks/elementalcli.go b/pkg/elementalcli/mocks/elementalcli.go index e9d0d5e07..0b40aa25f 100644 --- a/pkg/elementalcli/mocks/elementalcli.go +++ b/pkg/elementalcli/mocks/elementalcli.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/elementalcli/mocks/elementalcli.go -package=mocks github.com/rancher/elemental-operator/pkg/elementalcli Runner +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/elementalcli/mocks/elementalcli.go -package=mocks github.com/rancher/elemental-operator/pkg/elementalcli Runner // // Package mocks is a generated GoMock package. diff --git a/pkg/install/mocks/install.go b/pkg/install/mocks/install.go index e1e97c7a4..40aa7a39e 100644 --- a/pkg/install/mocks/install.go +++ b/pkg/install/mocks/install.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/install/mocks/install.go -package=mocks github.com/rancher/elemental-operator/pkg/install Installer +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/install/mocks/install.go -package=mocks github.com/rancher/elemental-operator/pkg/install Installer // // Package mocks is a generated GoMock package. diff --git a/pkg/network/mocks/network.go b/pkg/network/mocks/network.go index 9ec2119d0..d8aa97eb0 100644 --- a/pkg/network/mocks/network.go +++ b/pkg/network/mocks/network.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/network/mocks/network.go -package=mocks github.com/rancher/elemental-operator/pkg/network Configurator +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/network/mocks/network.go -package=mocks github.com/rancher/elemental-operator/pkg/network Configurator // // Package mocks is a generated GoMock package. diff --git a/pkg/register/mocks/client.go b/pkg/register/mocks/client.go index 719cd1575..4d7e893f0 100644 --- a/pkg/register/mocks/client.go +++ b/pkg/register/mocks/client.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/client.go -package=mocks github.com/rancher/elemental-operator/pkg/register Client +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/client.go -package=mocks github.com/rancher/elemental-operator/pkg/register Client // // Package mocks is a generated GoMock package. diff --git a/pkg/register/mocks/state.go b/pkg/register/mocks/state.go index 9c490a017..8c98f6ff3 100644 --- a/pkg/register/mocks/state.go +++ b/pkg/register/mocks/state.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/state.go -package=mocks github.com/rancher/elemental-operator/pkg/register StateHandler +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/state.go -package=mocks github.com/rancher/elemental-operator/pkg/register StateHandler // // Package mocks is a generated GoMock package. diff --git a/pkg/util/mocks/command_runner.go b/pkg/util/mocks/command_runner.go index 473bd37b2..7ea9c3042 100644 --- a/pkg/util/mocks/command_runner.go +++ b/pkg/util/mocks/command_runner.go @@ -21,7 +21,7 @@ // // Generated by this command: // -// mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/util/mocks/command_runner.go -package=mocks github.com/rancher/elemental-operator/pkg/util CommandRunner +// mockgen-v0.4.0 -copyright_file=scripts/boilerplate.go.txt -destination=pkg/util/mocks/command_runner.go -package=mocks github.com/rancher/elemental-operator/pkg/util CommandRunner // // Package mocks is a generated GoMock package. diff --git a/scripts/generate_mocks.sh b/scripts/generate_mocks.sh deleted file mode 100755 index 18a8400f3..000000000 --- a/scripts/generate_mocks.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -go install go.uber.org/mock/mockgen@v0.4.0 - -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/client.go -package=mocks github.com/rancher/elemental-operator/pkg/register Client -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/state.go -package=mocks github.com/rancher/elemental-operator/pkg/register StateHandler -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/install/mocks/install.go -package=mocks github.com/rancher/elemental-operator/pkg/install Installer -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/elementalcli/mocks/elementalcli.go -package=mocks github.com/rancher/elemental-operator/pkg/elementalcli Runner -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/network/mocks/network.go -package=mocks github.com/rancher/elemental-operator/pkg/network Configurator -mockgen -copyright_file=scripts/boilerplate.go.txt -destination=pkg/util/mocks/command_runner.go -package=mocks github.com/rancher/elemental-operator/pkg/util CommandRunner diff --git a/tests/e2e/config/config.go b/tests/e2e/config/config.go index e63c70b3f..d9a1d4d3f 100644 --- a/tests/e2e/config/config.go +++ b/tests/e2e/config/config.go @@ -48,6 +48,7 @@ type E2EConfig struct { SystemUpgradeControllerVersion string `yaml:"systemUpgradeControllerVersion"` SystemUpgradeControllerURL string `yaml:"systemUpgradeControllerURL"` + SystemUpgradeControllerCRDsURL string `yaml:"systemUpgradeControllerCRDsURL"` } // ReadE2EConfig read config from yaml and substitute variables using envsubst. @@ -139,6 +140,10 @@ func ReadE2EConfig(configPath string) (*E2EConfig, error) { //nolint:gocyclo config.SystemUpgradeControllerVersion = sysUpgradeControllerURL } + if sysUpgradeControllerCRDsURL := os.Getenv("SYSTEM_UPGRADE_CONTROLLER_CRDS_URL"); sysUpgradeControllerCRDsURL != "" { + config.SystemUpgradeControllerCRDsURL = sysUpgradeControllerCRDsURL + } + if err := substituteVersions(config); err != nil { return nil, err } @@ -179,5 +184,13 @@ func substituteVersions(config *E2EConfig) error { } config.SystemUpgradeControllerURL = sysUpgradeControllerURL + sysUpgradeControllerCRDsURL, err := envsubst.Eval(config.SystemUpgradeControllerCRDsURL, func(_ string) string { + return config.SystemUpgradeControllerVersion + }) + if err != nil { + return fmt.Errorf("failed to substiture system upgrade controller url: %w", err) + } + config.SystemUpgradeControllerCRDsURL = sysUpgradeControllerCRDsURL + return nil } diff --git a/tests/e2e/config/config.yaml b/tests/e2e/config/config.yaml index 4b6fd3730..2ae6a0e47 100644 --- a/tests/e2e/config/config.yaml +++ b/tests/e2e/config/config.yaml @@ -15,5 +15,6 @@ certManagerChartURL: https://charts.jetstack.io/charts/cert-manager-${CERT_MANAG rancherVersion: 2.8.2 rancherChartURL: https://releases.rancher.com/server-charts/latest/rancher-${RANCHER_VERSION}.tgz -systemUpgradeControllerVersion: v0.13.2 +systemUpgradeControllerVersion: v0.13.4 systemUpgradeControllerURL: https://github.com/rancher/system-upgrade-controller/releases/download/${SYSTEM_UPGRADE_CONTROLLER_VERSION}/system-upgrade-controller.yaml +systemUpgradeControllerCRDsURL: https://github.com/rancher/system-upgrade-controller/releases/download/${SYSTEM_UPGRADE_CONTROLLER_VERSION}/crd.yaml diff --git a/tests/e2e/downgrade_test.go b/tests/e2e/downgrade_test.go index b93f66117..30ef5f7d3 100644 --- a/tests/e2e/downgrade_test.go +++ b/tests/e2e/downgrade_test.go @@ -31,7 +31,7 @@ import ( const stableCRDSChart = "oci://registry.suse.com/rancher/elemental-operator-crds-chart" const stableChart = "oci://registry.suse.com/rancher/elemental-operator-chart" -var _ = Describe("Elemental Operator downgrade/upgrade test", func() { +var _ = Describe("Elemental Operator downgrade/upgrade test", Ordered, func() { var k *kubectl.Kubectl var downgradeCfg config.E2EConfig var channelName string diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 6d3a0c5ac..e74d305d7 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -162,7 +162,7 @@ var _ = BeforeSuite(func() { } By("Deploying elemental-operator chart dependencies", func() { - By("installing nginx", func() { + By("installing nginx: "+e2eCfg.NginxVersion, func() { if isAlreadyInstalled(nginxNamespace) { By("already installed") return @@ -175,7 +175,7 @@ var _ = BeforeSuite(func() { }, 5*time.Minute, 2*time.Second).Should(BeTrue()) }) - By("installing cert-manager", func() { + By("installing cert-manager: "+e2eCfg.CertManagerVersion, func() { if isAlreadyInstalled(certManagerNamespace) { By("already installed") return @@ -199,7 +199,7 @@ var _ = BeforeSuite(func() { }, 5*time.Minute, 2*time.Second).Should(BeTrue()) }) - By("installing rancher", func() { + By("installing rancher: "+e2eCfg.RancherVersion, func() { if isAlreadyInstalled(cattleSystemNamespace) { By("already installed") return @@ -247,7 +247,24 @@ var _ = BeforeSuite(func() { }, 5*time.Minute, 2*time.Second).Should(BeTrue()) }) - By("installing system-upgrade-controller", func() { + By("installing system-upgrade-controller: "+e2eCfg.SystemUpgradeControllerVersion, func() { + // Install CRDs first + crdResp, err := http.Get(e2eCfg.SystemUpgradeControllerCRDsURL) + Expect(err).ToNot(HaveOccurred()) + defer crdResp.Body.Close() + crdData := bytes.NewBuffer([]byte{}) + + _, err = io.Copy(crdData, crdResp.Body) + Expect(err).ToNot(HaveOccurred()) + + temp, err := os.CreateTemp("", "temp") + Expect(err).ToNot(HaveOccurred()) + + defer os.RemoveAll(temp.Name()) + Expect(os.WriteFile(temp.Name(), crdData.Bytes(), os.ModePerm)).To(Succeed()) + Expect(kubectl.Apply(cattleSystemNamespace, temp.Name())).To(Succeed()) + + // Install system upgrade controller resp, err := http.Get(e2eCfg.SystemUpgradeControllerURL) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() @@ -259,7 +276,7 @@ var _ = BeforeSuite(func() { // It needs to look over cattle-system ns to be functional toApply := strings.ReplaceAll(data.String(), "namespace: system-upgrade", "namespace: "+cattleSystemNamespace) - temp, err := os.CreateTemp("", "temp") + temp, err = os.CreateTemp("", "temp") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(temp.Name()) diff --git a/tests/e2e/machineregistration_test.go b/tests/e2e/machineregistration_test.go index ec43204d6..a9a8a307a 100644 --- a/tests/e2e/machineregistration_test.go +++ b/tests/e2e/machineregistration_test.go @@ -34,7 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var _ = Describe("MachineRegistration e2e tests", func() { +var _ = Describe("MachineRegistration e2e tests", Ordered, func() { Context("registration", func() { var mRegistration *elementalv1.MachineRegistration diff --git a/tests/e2e/managedosimage_test.go b/tests/e2e/managedosimage_test.go index 5ad2b4f10..10865c64b 100644 --- a/tests/e2e/managedosimage_test.go +++ b/tests/e2e/managedosimage_test.go @@ -33,7 +33,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -var _ = Describe("ManagedOSImage e2e tests", func() { +var _ = Describe("ManagedOSImage e2e tests", Ordered, func() { Context("Using OSImage reference", func() { var ui *elementalv1.ManagedOSImage diff --git a/tests/e2e/managedosversionchannel_test.go b/tests/e2e/managedosversionchannel_test.go index 570293485..c74b80b7a 100644 --- a/tests/e2e/managedosversionchannel_test.go +++ b/tests/e2e/managedosversionchannel_test.go @@ -35,7 +35,7 @@ import ( const channelName = "testchannel" -var _ = Describe("ManagedOSVersionChannel e2e tests", func() { +var _ = Describe("ManagedOSVersionChannel e2e tests", Ordered, func() { var versions []elementalv1.ManagedOSVersion AfterEach(func() { diff --git a/tests/e2e/upgrades_test.go b/tests/e2e/upgrades_test.go index a9259e52f..7ec39d8fb 100644 --- a/tests/e2e/upgrades_test.go +++ b/tests/e2e/upgrades_test.go @@ -74,6 +74,7 @@ func upgradePod(k *kubectl.Kubectl) string { } func checkUpgradePod(k *kubectl.Kubectl, env, image, command, args, mm types.GomegaMatcher) { + By("checking upgrade pod") // Wait for the upgrade pod to appear k.EventuallyPodMatch( cattleSystemNamespace, @@ -106,7 +107,7 @@ func checkUpgradePod(k *kubectl.Kubectl, env, image, command, args, mm types.Gom ExpectWithOffset(1, mounts).To(mm) } -var _ = Describe("ManagedOSImage Upgrade e2e tests", func() { +var _ = Describe("ManagedOSImage Upgrade e2e tests", Ordered, func() { k := kubectl.New() Context("Using ManagedOSVersion reference", func() { @@ -128,32 +129,29 @@ var _ = Describe("ManagedOSImage Upgrade e2e tests", func() { k.Delete("managedosversionchannel", "--all", "--wait", "-n", fleetNamespace) // delete dangling upgrade pods - EventuallyWithOffset(1, func() []string { - pods, err := k.GetPodNames(cattleSystemNamespace, "upgrade.cattle.io/controller=system-upgrade-controller") - if err != nil { - fmt.Println(err) - } - fmt.Println(pods) - - applyPods := []string{} - for _, p := range pods { - if !strings.HasPrefix(p, "system-upgrade-controller") { - applyPods = append(applyPods, p) - } - - if strings.Contains(p, "apply-os-upgrader") { - By("deleting " + p) - k.Delete("pod", "-n", cattleSystemNamespace, "--wait", "--force", p) - err = k.WaitForPodDelete(cattleSystemNamespace, p) - Expect(err).ToNot(HaveOccurred()) - } + pods, err := k.GetPodNames(cattleSystemNamespace, "upgrade.cattle.io/controller=system-upgrade-controller") + if err != nil { + fmt.Println(err) + } + fmt.Println(pods) + + applyPods := []string{} + for _, p := range pods { + if !strings.HasPrefix(p, "system-upgrade-controller") { + applyPods = append(applyPods, p) } - return applyPods - }, 3*time.Minute, 2*time.Second).Should(Equal([]string{})) + if strings.Contains(p, "apply-os-upgrader") { + By("deleting " + p) + k.Delete("pod", "-n", cattleSystemNamespace, "--wait", "--force", p) + err = k.WaitForPodDelete(cattleSystemNamespace, p) + Expect(err).ToNot(HaveOccurred()) + } + } }) createsCorrectPlan := func(meta map[string]runtime.RawExtension, c *upgradev1.ContainerSpec, m types.GomegaMatcher) { + By("creating a new ManagedOSVersion") ov := catalog.NewManagedOSVersion( fleetNamespace, osVersion, "v1.0", "0.0.0", meta, @@ -164,6 +162,7 @@ var _ = Describe("ManagedOSImage Upgrade e2e tests", func() { return k.ApplyJSON("", osVersion, ov) }, 2*time.Minute, 2*time.Second).ShouldNot(HaveOccurred()) + By("creating a new ManagedOSImage") ui := catalog.NewManagedOSImage( fleetNamespace, osImage, @@ -176,6 +175,7 @@ var _ = Describe("ManagedOSImage Upgrade e2e tests", func() { return k.ApplyJSON("", osImage, ui) }, 2*time.Minute, 2*time.Second).ShouldNot(HaveOccurred()) + By("fetching bundle content") EventuallyWithOffset(1, func() string { r, err := kubectl.GetData(fleetNamespace, "bundle", "mos-update-osversion", `jsonpath={.spec.resources[*].content}`) if err != nil { @@ -201,13 +201,15 @@ var _ = Describe("ManagedOSImage Upgrade e2e tests", func() { ), ) + By("checking plan version") Eventually(func() string { up, err := getPlan("os-upgrader-update-osversion") if err == nil { return up.Spec.Version } + fmt.Println(err) return "" - }, 1*time.Minute, 2*time.Second).Should(Equal("v1.0")) + }, 3*time.Minute, 2*time.Second).Should(Equal("v1.0")) plan, err := getPlan("os-upgrader-update-osversion") Expect(err).ToNot(HaveOccurred()) diff --git a/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/kubectl.go b/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/kubectl.go index 28d39e88a..8750070f1 100644 --- a/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/kubectl.go +++ b/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/kubectl.go @@ -112,6 +112,12 @@ func (k *Kubectl) NamespaceWithReadyPod(namespace string, labelName string) (boo if !s.Ready { return false, nil } + if !s.Started { + return false, nil + } + if s.State.Running == nil { + return false, nil + } } } return true, nil @@ -291,7 +297,7 @@ func (k *Kubectl) Wait(namespace string, requiredStatus string, resourceName str }) if err != nil { - return errors.Wrapf(err, string(debug.Stack())) + return errors.Wrap(err, string(debug.Stack())) } return nil @@ -525,7 +531,7 @@ func RunCommandWithOutput(namespace string, podName string, commandInPod string) cmd.Stderr = &stderr err := cmd.Run() if err != nil { - return "", errors.Wrapf(err, stderr.String()) + return "", errors.Wrap(err, stderr.String()) } if len(out.String()) > 0 { return out.String(), nil diff --git a/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/pod.go b/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/pod.go index 7b6d1b4a7..797b8bb89 100644 --- a/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/pod.go +++ b/vendor/github.com/rancher-sandbox/ele-testhelpers/kubectl/pod.go @@ -74,7 +74,7 @@ type ContainerStatus struct { Image string `yaml:"image"` ImageID string `yaml:"imageID"` ContainerID string `yaml:"containerID,omitempty"` - Started *bool `yaml:"started,omitempty"` + Started bool `yaml:"started,omitempty"` } // PodCondition is the pod condition status diff --git a/vendor/modules.txt b/vendor/modules.txt index 198445e2c..12cbcaecc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -312,7 +312,7 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240227152220-1b9250417c8d +# github.com/rancher-sandbox/ele-testhelpers v0.0.0-20240926104948-8ac88aebed21 ## explicit; go 1.20 github.com/rancher-sandbox/ele-testhelpers/helpers github.com/rancher-sandbox/ele-testhelpers/http