Skip to content

Commit c053f87

Browse files
pedjakclaude
andcommitted
Migrate operator upgrade e2e tests to Godog/Cucumber BDD framework
Replace testify-based upgrade tests with a Godog test runner and Gherkin feature file. Add step definitions for OLM install/upgrade, component readiness via leader election leases, and reconciliation verification. Simplify Makefile upgrade targets using a reusable install script macro and fix template path resolution so tests work from any directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32761fc commit c053f87

10 files changed

Lines changed: 455 additions & 623 deletions

File tree

Makefile

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ verify-crd-compatibility: $(CRD_DIFF) manifests
238238

239239
#SECTION Test
240240

241+
define install-sh
242+
.PHONY: $(1)/install.sh
243+
$(1)/install.sh: manifests
244+
@echo -e "\n\U1F4D8 Using $(1).yaml as source manifest\n"
245+
sed "s/cert-git-version/cert-$$(VERSION)/g" manifests/$(1).yaml > $(2)
246+
MANIFEST=$(2) INSTALL_DEFAULT_CATALOGS=false DEFAULT_CATALOG=$$(RELEASE_CATALOGS) envsubst '$$$$DEFAULT_CATALOG,$$$$CERT_MGR_VERSION,$$$$INSTALL_DEFAULT_CATALOGS,$$$$MANIFEST' < scripts/install.tpl.sh > $(1)-install.sh
247+
endef
248+
249+
$(eval $(call install-sh,experimental,operator-controller-experimental.yaml))
250+
$(eval $(call install-sh,standard,operator-controller-standard.yaml))
251+
241252
.PHONY: test
242253
test: manifests generate fmt lint test-unit test-e2e test-regression #HELP Run all tests.
243254

@@ -335,52 +346,43 @@ run-latest-release:
335346
@echo -e "\n\U23EC Using $(RELEASE_INSTALL) as release installer\n"
336347
curl -L -s https://github.com/operator-framework/operator-controller/releases/latest/download/$(notdir $(RELEASE_INSTALL)) | bash -s
337348

338-
.PHONY: pre-upgrade-setup
339-
pre-upgrade-setup:
340-
./hack/test/pre-upgrade-setup.sh $(CATALOG_IMG) $(TEST_CLUSTER_CATALOG_NAME) $(TEST_CLUSTER_EXTENSION_NAME)
341-
342-
.PHONY: post-upgrade-checks
343-
post-upgrade-checks:
344-
go test -count=1 -v ./test/upgrade-e2e/...
349+
.PHONY: test-upgrade-e2e
350+
test-upgrade-e2e:
351+
RELEASE_INSTALL=$(RELEASE_INSTALL) \
352+
RELEASE_UPGRADE=$(RELEASE_UPGRADE) \
353+
KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) \
354+
ROOT_DIR=$(ROOT_DIR) \
355+
go test -count=1 -v ./test/upgrade-e2e/upgrade_test.go
345356

346357

347-
TEST_UPGRADE_E2E_TASKS := kind-cluster run-latest-release image-registry pre-upgrade-setup docker-build kind-load kind-deploy post-upgrade-checks kind-clean
358+
TEST_UPGRADE_E2E_TASKS := kind-cluster docker-build kind-load test-upgrade-e2e kind-clean
348359

349360
.PHONY: test-upgrade-st2st-e2e
350-
test-upgrade-st2st-e2e: SOURCE_MANIFEST := $(STANDARD_MANIFEST)
351-
test-upgrade-st2st-e2e: RELEASE_INSTALL := $(STANDARD_RELEASE_INSTALL)
361+
test-upgrade-st2st-e2e: RELEASE_INSTALL := https://github.com/operator-framework/operator-controller/releases/latest/download/install.sh
362+
test-upgrade-st2st-e2e: RELEASE_UPGRADE := $(ROOT_DIR)/standard-install.sh
352363
test-upgrade-st2st-e2e: KIND_CLUSTER_NAME := operator-controller-upgrade-st2st-e2e
353-
test-upgrade-st2st-e2e: export MANIFEST := $(STANDARD_RELEASE_MANIFEST)
354-
test-upgrade-st2st-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog
355-
test-upgrade-st2st-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package
356-
test-upgrade-st2st-e2e: $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (standard -> standard) e2e tests on a local kind cluster
364+
test-upgrade-st2st-e2e: standard/install.sh $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (standard -> standard) e2e tests on a local kind cluster
357365

358366
.PHONY: test-upgrade-ex2ex-e2e
359-
test-upgrade-ex2ex-e2e: SOURCE_MANIFEST := $(EXPERIMENTAL_MANIFEST)
360-
test-upgrade-ex2ex-e2e: RELEASE_INSTALL := $(EXPERIMENTAL_RELEASE_INSTALL)
367+
test-upgrade-ex2ex-e2e: RELEASE_INSTALL := https://github.com/operator-framework/operator-controller/releases/latest/download/install-experimental.sh
361368
test-upgrade-ex2ex-e2e: KIND_CLUSTER_NAME := operator-controller-upgrade-ex2ex-e2e
362-
test-upgrade-ex2ex-e2e: export MANIFEST := $(EXPERIMENTAL_RELEASE_MANIFEST)
363-
test-upgrade-ex2ex-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog
364-
test-upgrade-ex2ex-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package
365-
test-upgrade-ex2ex-e2e: $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (experimental -> experimental) e2e tests on a local kind cluster
369+
test-upgrade-ex2ex-e2e: RELEASE_UPGRADE := $(ROOT_DIR)/experimental-install.sh
370+
test-upgrade-ex2ex-e2e: experimental/install.sh $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (experimental -> experimental) e2e tests on a local kind cluster
366371

367372
.PHONY: test-upgrade-st2ex-e2e
368-
test-upgrade-st2ex-e2e: SOURCE_MANIFEST := $(EXPERIMENTAL_MANIFEST)
369-
test-upgrade-st2ex-e2e: RELEASE_INSTALL := $(STANDARD_RELEASE_INSTALL)
373+
test-upgrade-st2ex-e2e: RELEASE_INSTALL := https://github.com/operator-framework/operator-controller/releases/latest/download/install.sh
374+
test-upgrade-st2ex-e2e: RELEASE_UPGRADE := $(ROOT_DIR)/experimental-install.sh
370375
test-upgrade-st2ex-e2e: KIND_CLUSTER_NAME := operator-controller-upgrade-st2ex-e2e
371-
test-upgrade-st2ex-e2e: export MANIFEST := $(EXPERIMENTAL_RELEASE_MANIFEST)
372-
test-upgrade-st2ex-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog
373-
test-upgrade-st2ex-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package
374-
test-upgrade-st2ex-e2e: $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (standard -> experimental) e2e tests on a local kind cluster
376+
test-upgrade-st2ex-e2e: experimental/install.sh $(TEST_UPGRADE_E2E_TASKS) #HELP Run upgrade (standard -> experimental) e2e tests on a local kind cluster
375377

376378
.PHONY: test-st2ex-e2e
377-
test-st2ex-e2e: SOURCE_MANIFEST := $(STANDARD_MANIFEST)
378-
test-st2ex-e2e: RELEASE_INSTALL := $(STANDARD_RELEASE_INSTALL)
379+
test-st2ex-e2e: RELEASE_INSTALL := $(ROOT_DIR)/standard-install.sh
380+
test-st2ex-e2e: RELEASE_UPGRADE := $(ROOT_DIR)/experimental-install.sh
379381
test-st2ex-e2e: KIND_CLUSTER_NAME := operator-controller-st2ex-e2e
380382
test-st2ex-e2e: export MANIFEST := $(STANDARD_RELEASE_MANIFEST)
381383
test-st2ex-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog
382384
test-st2ex-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package
383-
test-st2ex-e2e: run-internal image-registry pre-upgrade-setup kind-deploy-experimental post-upgrade-checks kind-clean #HELP Run swichover (standard -> experimental) e2e tests on a local kind cluster
385+
test-st2ex-e2e: experimental/install.sh standard/install.sh $(TEST_UPGRADE_E2E_TASKS) #HELP Run swichover (standard -> experimental) e2e tests on a local kind cluster
384386

385387
.PHONY: e2e-coverage
386388
e2e-coverage:

hack/test/pre-upgrade-setup.sh

Lines changed: 0 additions & 172 deletions
This file was deleted.

test/e2e/steps/hooks.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ type scenarioContext struct {
3030
id string
3131
namespace string
3232
clusterExtensionName string
33+
clusterCatalogName string
3334
removedResources []unstructured.Unstructured
3435
backGroundCmds []*exec.Cmd
3536
metricsResponse map[string]string
37+
leaderPods map[string]string // component name -> leader pod name
3638

3739
extensionObjects []client.Object
3840
}
@@ -87,30 +89,37 @@ func RegisterHooks(sc *godog.ScenarioContext) {
8789
sc.After(ScenarioCleanup)
8890
}
8991

90-
func BeforeSuite() {
91-
if devMode {
92-
logger = textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
93-
} else {
94-
logger = textlogger.NewLogger(textlogger.NewConfig())
95-
}
96-
92+
func detectOLMDeployment() (*appsv1.Deployment, error) {
9793
raw, err := k8sClient("get", "deployments", "-A", "-l", "app.kubernetes.io/part-of=olm", "-o", "jsonpath={.items}")
9894
if err != nil {
99-
panic(fmt.Errorf("failed to get OLM deployments: %v", err))
95+
return nil, err
10096
}
10197
dl := []appsv1.Deployment{}
10298
if err := json.Unmarshal([]byte(raw), &dl); err != nil {
103-
panic(fmt.Errorf("failed to unmarshal OLM deployments: %v", err))
99+
return nil, fmt.Errorf("failed to unmarshal OLM deployments: %v", err)
104100
}
105-
var olm *appsv1.Deployment
106101

107102
for _, d := range dl {
108103
if d.Name == olmDeploymentName {
109-
olm = &d
110-
olmNamespace = d.Namespace
111-
break
104+
return &d, nil
112105
}
113106
}
107+
return nil, fmt.Errorf("failed to detect OLM Deployment")
108+
}
109+
110+
func BeforeSuite() {
111+
if devMode {
112+
logger = textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
113+
} else {
114+
logger = textlogger.NewLogger(textlogger.NewConfig())
115+
}
116+
117+
olm, err := detectOLMDeployment()
118+
if err != nil {
119+
logger.Info("OLM deployments not found; skipping feature gate detection (upgrade scenarios will install OLM in Background)")
120+
return
121+
}
122+
olmNamespace = olm.Namespace
114123

115124
featureGatePattern := regexp.MustCompile(`--feature-gates=([[:alnum:]]+)=(true|false)`)
116125
for _, c := range olm.Spec.Template.Spec.Containers {
@@ -144,6 +153,7 @@ func CreateScenarioContext(ctx context.Context, sc *godog.Scenario) (context.Con
144153
id: sc.Id,
145154
namespace: fmt.Sprintf("ns-%s", sc.Id),
146155
clusterExtensionName: fmt.Sprintf("ce-%s", sc.Id),
156+
leaderPods: make(map[string]string),
147157
}
148158
return context.WithValue(ctx, scenarioContextKey, scCtx), nil
149159
}

0 commit comments

Comments
 (0)