Skip to content

Commit

Permalink
Build e2e chart locally (#852)
Browse files Browse the repository at this point in the history
* Build e2e chart locally

Signed-off-by: Andrea Mazzotti <[email protected]>

* Add mockgen to build tools

Signed-off-by: Andrea Mazzotti <[email protected]>

* Add missing GINKGO tool

Signed-off-by: Andrea Mazzotti <[email protected]>

* Reduce e2e tests concurrency

Signed-off-by: Andrea Mazzotti <[email protected]>

* Make test more verbose

Signed-off-by: Andrea Mazzotti <[email protected]>

* Bump system-upgrade-controller version

Signed-off-by: Andrea Mazzotti <[email protected]>

* Raise timeout

Signed-off-by: Andrea Mazzotti <[email protected]>

* Print error

Signed-off-by: Andrea Mazzotti <[email protected]>

* Add plan crd

Signed-off-by: Andrea Mazzotti <[email protected]>

* Adjust timeout

Signed-off-by: Andrea Mazzotti <[email protected]>

* Do not deploy operator twice

Signed-off-by: Andrea Mazzotti <[email protected]>

* Restore vendored helper

Signed-off-by: Andrea Mazzotti <[email protected]>

* Do not attempt to delete pods multiple times

Signed-off-by: Andrea Mazzotti <[email protected]>

* Remove debug println

Signed-off-by: Andrea Mazzotti <[email protected]>

* Disable e2e workflow

Signed-off-by: Andrea Mazzotti <[email protected]>

* Update ele-testhelpers library

Signed-off-by: Andrea Mazzotti <[email protected]>

---------

Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti authored Oct 1, 2024
1 parent 4e313f7 commit 08f6cda
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 168 deletions.
123 changes: 15 additions & 108 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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=
Expand All @@ -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
Expand All @@ -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) && \
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/elementalcli/mocks/elementalcli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/install/mocks/install.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/network/mocks/network.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/register/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/register/mocks/state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/util/mocks/command_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions scripts/generate_mocks.sh

This file was deleted.

13 changes: 13 additions & 0 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion tests/e2e/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/e2e/downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 08f6cda

Please sign in to comment.