Skip to content

Commit bab8c7c

Browse files
ricardozaninirgdoliveira
authored andcommitted
Fix apache#504 - Build images before running e2e (apache#546)
1 parent c728a6c commit bab8c7c

File tree

95 files changed

+707
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+707
-239
lines changed

.ci/jenkins/Jenkinsfile.e2e.cluster

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pipeline {
4646
helper.checkoutRepo()
4747

4848
assert getTestImage(): 'Please provide a Test image'
49-
container.pullImage(getTestImage()) // Verify image exists
49+
container.pullImage(getTestImage()) // Verify image namespaceExists
5050
}
5151
}
5252
}

.github/workflows/e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ jobs:
8686
make deploy IMG=${{ env.OPERATOR_IMAGE_NAME }}
8787
kubectl wait pod -A -l control-plane=sonataflow-operator --for condition=Ready
8888
89-
- name: Run E2E Tests for Non-Persistent Flows
90-
run: make test-e2e label=flows-non-persistence
89+
- name: Run E2E Tests for Ephemeral Flows
90+
run: make test-e2e label=flows-ephemeral
9191

9292
- name: Run E2E Tests for Persistent Flows
9393
run: make test-e2e label=flows-persistence

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ vet: ## Run go vet against code.
119119

120120
.PHONY: test
121121
test: manifests generate envtest test-api ## Run tests.
122+
@$(MAKE) addheaders
123+
@$(MAKE) vet
124+
@$(MAKE) fmt
122125
@echo "🔍 Running controller tests..."
123126
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
124127
go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out > /dev/null 2>&1
@@ -399,30 +402,30 @@ generate-all: generate generate-deploy bundle
399402
@$(MAKE) fmt
400403

401404
.PHONY: test-e2e # You will need to have a Minikube/Kind cluster up and running to run this target, and run container-builder before the test
402-
label = "flows-non-persistence" # possible values are flows-non-persistence, flows-persistence, platform, cluster
405+
label = "flows-ephemeral" # possible values are flows-ephemeral, flows-persistence, platform, cluster
403406
test-e2e:
404407
ifeq ($(label), cluster)
405408
@echo "🌐 Running e2e tests for cluster..."
406409
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/clusterplatform_test.go \
407410
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
408-
-ginkgo.junit-report=./e2e-test-report-clusterplatform_test.xml -timeout 60m;
411+
-ginkgo.junit-report=./e2e-test-report-clusterplatform_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
409412
else ifeq ($(label), platform)
410413
@echo "📦 Running e2e tests for platform..."
411414
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/platform_test.go \
412415
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
413-
-ginkgo.junit-report=./e2e-test-report-platform_test.xml -timeout 60m;
414-
else ifeq ($(label), flows-non-persistence)
415-
@echo "🔄 Running e2e tests for flows-non-persistence..."
416+
-ginkgo.junit-report=./e2e-test-report-platform_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
417+
else ifeq ($(label), flows-ephemeral)
418+
@echo "🔄 Running e2e tests for flows-ephemeral..."
416419
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/workflow_test.go \
417420
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
418-
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m;
421+
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
419422
else ifeq ($(label), flows-persistence)
420423
@echo "🔁 Running e2e tests for flows-persistence..."
421424
go test ./test/e2e/e2e_suite_test.go ./test/e2e/helpers.go ./test/e2e/workflow_test.go \
422425
-v -ginkgo.v -ginkgo.no-color -ginkgo.github-output -ginkgo.label-filter=$(label) \
423-
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m;
426+
-ginkgo.junit-report=./e2e-test-report-workflow_test.xml -timeout 60m KUSTOMIZE=$(KUSTOMIZE);
424427
else
425-
@echo "❌ Invalid label. Please use one of: cluster, platform, flows-non-persistence, flows-persistence"
428+
@echo "❌ Invalid label. Please use one of: cluster, platform, flows-ephemeral, flows-persistence"
426429
endif
427430

428431

hack/local/run-e2e.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
# You must have minikube installed
2121
MINIKUBE_PROFILE=${1:-minikube}
2222
SKIP_IMG_BUILD=${2:-false}
23-
TEST_LABELS=${3:-"flows-non-persistence"} # possible values are flows-non-persistence, flows-persistence, platform, cluster
23+
TEST_LABELS=${3:-"flows-ephemeral"} # possible values are flows-ephemeral, flows-persistence, platform, cluster
24+
SKIP_UNDEPLOY=${4:-false}
2425

2526
# Emoticons and enhanced messages
2627
echo "🚀 Using minikube profile ${MINIKUBE_PROFILE}"
@@ -37,8 +38,13 @@ fi
3738
# clean up previous runs, hiding logs
3839
echo "🧹 Cleaning up previous test namespaces..."
3940
kubectl get namespaces -o name | awk -F/ '/^namespace\/test/ {print $2}' | xargs kubectl delete namespace &> /dev/null
40-
echo "🧹 Undeploying previous instances..."
41-
make undeploy ignore-not-found=true &> /dev/null
41+
42+
if [ "${SKIP_UNDEPLOY}" = false ]; then
43+
echo "🧹 Cleaning up previous test resources namespace..."
44+
kubectl delete namespace e2e-resources &> /dev/null
45+
echo "🧹 Undeploying previous instances..."
46+
make undeploy ignore-not-found=true &> /dev/null
47+
fi
4248

4349
# Image build process
4450
if [ "${SKIP_IMG_BUILD}" = "false" ]; then

internal/controller/platform/platformutils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const dockerFile = "FROM docker.io/apache/default-test-kie-sonataflow-builder:ma
3737

3838
func TestSonataFlowBuildController(t *testing.T) {
3939
platform := test.GetBasePlatform()
40-
dockerfileBytes, err := os.ReadFile("../../../test/builder/Dockerfile")
40+
dockerfileBytes, err := os.ReadFile("testdata/platformTest.Dockerfile")
4141
if err != nil {
4242
assert.Fail(t, "Unable to read base Dockerfile")
4343
}

test/builder/Dockerfile renamed to internal/controller/platform/testdata/platformTest.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ USER 1001
2424
WORKDIR /home/kogito/kogito-base
2525

2626
# Copy from build context to skeleton resources project
27-
COPY --chown=1001 . ./src/main/resources
27+
COPY --chown=1001 ../../../../test/builder ./src/main/resources
2828

2929
# Maven vars enhirited from the base image
3030
RUN ${MAVEN_HOME}/bin/mvn -U -B ${MAVEN_ARGS_APPEND} -s ${MAVEN_SETTINGS_PATH} clean install -DskipTests

test/builder/greetings.sw.json

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

test/e2e/clusterplatform_test.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
7373
Expect(err).NotTo(HaveOccurred())
7474
}
7575
}
76+
77+
// Remove SonataFlowClusterPlatform created in the last run
78+
cmd := exec.Command("kubectl", "delete", "sonataflowclusterplatform", "--all", "--wait")
79+
_, err := utils.Run(cmd)
80+
Expect(err).NotTo(HaveOccurred())
7681
})
7782
var _ = Context("with supporting services enabled", func() {
7883
DescribeTable("against a platform in a separate namespace", func(testcaseDir string, profile string, persistenceType string, withServices bool) {
7984
By("Deploy the SonataFlowPlatform CR")
8085
var manifests []byte
8186
EventuallyWithOffset(1, func() error {
8287
var err error
83-
cmd := exec.Command("kubectl", "kustomize", filepath.Join(projectDir,
84-
test.GetSonataFlowE2EPlatformServicesDirectory(), profile, clusterWideEphemeral))
88+
cmd := exec.Command("kubectl", "kustomize",
89+
test.GetPathFromE2EDirectory("platform", "services", profile, clusterWideEphemeral))
8590
manifests, err = utils.Run(cmd)
8691
return err
8792
}, time.Minute, time.Second).Should(Succeed())
@@ -91,7 +96,7 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
9196
_, err := utils.Run(cmd)
9297
Expect(err).NotTo(HaveOccurred())
9398

94-
By("Wait for SonatatFlowPlatform CR in " + targetNamespace + " to be ready")
99+
By("Wait for SonataFlowPlatform CR in " + targetNamespace + " to be ready")
95100
// wait for platform to be ready
96101
EventuallyWithOffset(1, func() error {
97102
cmd = exec.Command("kubectl", "wait", "sfplatform", "-n", targetNamespace, "sonataflow-platform", "--for", "condition=Succeed", "--timeout=5s")
@@ -116,7 +121,7 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
116121
}, 20*time.Minute, 5).Should(Succeed())
117122

118123
if withServices {
119-
By("Deploy SonatatFlowPlatform CR with services configured in " + targetNamespace2)
124+
By("Deploy SonataFlowPlatform CR with services configured in " + targetNamespace2)
120125
EventuallyWithOffset(1, func() error {
121126
var err error
122127
cmd := exec.Command("kubectl", "kustomize", filepath.Join(projectDir,
@@ -148,18 +153,24 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
148153
return returnedValue
149154
}, 20*time.Minute, 5).Should(Equal([]byte("''")))
150155

156+
By("Replacing the image with a prebuilt one and rollout")
157+
EventuallyWithOffset(1, func() error {
158+
return kubectlPatchSonataFlowImageAndRollout(targetNamespace2, prebuiltWorkflows.CallBack.Name, prebuiltWorkflows.CallBack.Tag)
159+
}, 3*time.Minute, time.Second).Should(Succeed())
160+
161+
By("Waiting for Data Index and Jobs Service URLs")
151162
dataIndexServiceUrl := services.GenerateServiceURL(constants.DefaultHTTPProtocol, targetNamespace2, "sonataflow-platform-"+constants.DataIndexServiceName)
152163
jobServiceUrl := services.GenerateServiceURL(constants.DefaultHTTPProtocol, targetNamespace2, "sonataflow-platform-"+constants.JobServiceName)
153164
EventuallyWithOffset(1, func() []byte {
154-
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, "callbackstatetimeouts", "-o", "jsonpath='{.status.services.dataIndexRef.url}'")
165+
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, prebuiltWorkflows.CallBack.Name, "-o", "jsonpath='{.status.services.dataIndexRef.url}'")
155166
returnedValue, _ := utils.Run(cmd)
156167
return returnedValue
157-
}, 20*time.Minute, 5).Should(Equal([]byte("'" + dataIndexServiceUrl + "'")))
168+
}, 3*time.Minute, 5).Should(Equal([]byte("'" + dataIndexServiceUrl + "'")))
158169
EventuallyWithOffset(1, func() []byte {
159-
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, "callbackstatetimeouts", "-o", "jsonpath='{.status.services.jobServiceRef.url}'")
170+
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, prebuiltWorkflows.CallBack.Name, "-o", "jsonpath='{.status.services.jobServiceRef.url}'")
160171
returnedValue, _ := utils.Run(cmd)
161172
return returnedValue
162-
}, 20*time.Minute, 5).Should(Equal([]byte("'" + jobServiceUrl + "'")))
173+
}, 3*time.Minute, 5).Should(Equal([]byte("'" + jobServiceUrl + "'")))
163174
} else {
164175
EventuallyWithOffset(1, func() error {
165176
var err error
@@ -193,32 +204,38 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
193204
returnedValue, _ := utils.Run(cmd)
194205
return returnedValue
195206
}, 20*time.Minute, 5).Should(Equal([]byte("'" + jobServiceUrl + "'")))
207+
208+
By("Replacing the image with a prebuilt one and rollout")
209+
EventuallyWithOffset(1, func() error {
210+
return kubectlPatchSonataFlowImageAndRollout(targetNamespace2, prebuiltWorkflows.CallBack.Name, prebuiltWorkflows.CallBack.Tag)
211+
}, 3*time.Minute, time.Second).Should(Succeed())
212+
213+
By("Waiting for Data Index and Jobs Service URLs")
196214
EventuallyWithOffset(1, func() []byte {
197-
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, "callbackstatetimeouts", "-o", "jsonpath='{.status.services.dataIndexRef.url}'")
215+
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, prebuiltWorkflows.CallBack.Name, "-o", "jsonpath='{.status.services.dataIndexRef.url}'")
198216
returnedValue, _ := utils.Run(cmd)
199217
return returnedValue
200-
}, 20*time.Minute, 5).Should(Equal([]byte("'" + dataIndexServiceUrl + "'")))
218+
}, 3*time.Minute, 5).Should(Equal([]byte("'" + dataIndexServiceUrl + "'")))
201219
EventuallyWithOffset(1, func() []byte {
202-
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, "callbackstatetimeouts", "-o", "jsonpath='{.status.services.jobServiceRef.url}'")
220+
cmd = exec.Command("kubectl", "get", "sf", "-n", targetNamespace2, prebuiltWorkflows.CallBack.Name, "-o", "jsonpath='{.status.services.jobServiceRef.url}'")
203221
returnedValue, _ := utils.Run(cmd)
204222
return returnedValue
205-
}, 20*time.Minute, 5).Should(Equal([]byte("'" + jobServiceUrl + "'")))
223+
}, 3*time.Minute, 5).Should(Equal([]byte("'" + jobServiceUrl + "'")))
206224
}
207225
cmd = exec.Command("kubectl", "delete", "SonataFlowClusterPlatform", "cluster", "--wait")
208226
_, err = utils.Run(cmd)
209227
Expect(err).NotTo(HaveOccurred())
210228
},
211-
Entry("without services configured", test.GetSonataFlowE2EPlatformNoServicesDirectory(), metadata.PreviewProfile.String(), ephemeral, false),
212-
Entry("with services configured", test.GetSonataFlowE2EPlatformServicesDirectory(), metadata.PreviewProfile.String(), "ephemeral-with-workflow", true),
229+
Entry("without services configured", test.GetPathFromE2EDirectory("platform", "noservices"), metadata.GitOpsProfile.String(), ephemeral, false),
230+
Entry("with services configured", test.GetPathFromE2EDirectory("platform", "services"), metadata.GitOpsProfile.String(), "ephemeral-with-workflow", true),
213231
)
214232

215233
DescribeTable("against a platform in a separate namespace", func(testcaseDir string, profile string, persistenceType string) {
216234
By("Deploy the SonataFlowPlatform CR")
217235
var manifests []byte
218236
EventuallyWithOffset(1, func() error {
219237
var err error
220-
cmd := exec.Command("kubectl", "kustomize", filepath.Join(projectDir,
221-
test.GetSonataFlowE2EPlatformServicesDirectory(), profile, clusterWideEphemeral))
238+
cmd := exec.Command("kubectl", "kustomize", test.GetPathFromE2EDirectory("platform", "services", profile, clusterWideEphemeral))
222239
manifests, err = utils.Run(cmd)
223240
return err
224241
}, time.Minute, time.Second).Should(Succeed())
@@ -287,8 +304,8 @@ var _ = Describe("Cluster Platform Use Cases :: ", Label("cluster"), Ordered, fu
287304
_, err = utils.Run(cmd)
288305
Expect(err).NotTo(HaveOccurred())
289306
},
290-
Entry("with only Data Index configured", test.GetSonataFlowE2EPlatformServicesDirectory(), metadata.PreviewProfile.String(), ephemeralDataIndex),
291-
Entry("with only Job Service configured", test.GetSonataFlowE2EPlatformServicesDirectory(), metadata.PreviewProfile.String(), ephemeralJobService),
307+
Entry("with only Data Index configured", test.GetPathFromE2EDirectory("platform", "services"), metadata.GitOpsProfile.String(), ephemeralDataIndex),
308+
Entry("with only Job Service configured", test.GetPathFromE2EDirectory("platform", "services"), metadata.GitOpsProfile.String(), ephemeralJobService),
292309
)
293310
})
294311
})

0 commit comments

Comments
 (0)