Skip to content

Commit

Permalink
fix(e2e): always build bundle and set local config
Browse files Browse the repository at this point in the history
Closes #5632
  • Loading branch information
squakez committed Jun 17, 2024
1 parent 140ecde commit 78407fb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 54 deletions.
4 changes: 0 additions & 4 deletions .github/actions/kamel-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ runs:
image-namespace: ${{ inputs.image-namespace }}
make-rules: ${{ inputs.make-rules }}

#
# By default do not build the image bundle
#
- id: build-kamel-bundle
name: Build Kamel Metadata Bundle
uses: ./.github/actions/kamel-build-bundle
if: ${{ inputs.build-bundle == 'true' }}
with:
image-registry-push-host: ${{ inputs.image-registry-push-host }}
image-registry-pull-host: ${{ inputs.image-registry-pull-host }}
Expand Down
10 changes: 6 additions & 4 deletions e2e/install/helm/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ import (
)

func TestHelmInstallRunUninstall(t *testing.T) {
// Ensure no CRDs are already installed
ctx := TestContext()
Cleanup(t, ctx)
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
// Ensure no CRDs are already installed
Cleanup(t, ctx)
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")
CheckLocalInstallRegistry(t, g)
g.Expect(KAMEL_INSTALL_REGISTRY).NotTo(Equal(""))
os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../../")
ExpectExecSucceed(t, g, Make(t, "release-helm"))
ExpectExecSucceed(t, g,
Expand Down
18 changes: 7 additions & 11 deletions e2e/install/kustomize/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ import (
)

func TestKustomizeNamespaced(t *testing.T) {
g := NewWithT(t)
CheckLocalInstallRegistry(t, g)
// TODO, likely we need to adjust this test with a Kustomize overlay for Openshift
// which would not require the registry setting
registry := os.Getenv("KIND_REGISTRY")
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")
kustomizeDir := testutil.MakeTempCopyDir(t, "../../../install")
ctx := TestContext()
g.Expect(registry).NotTo(Equal(""))
// Ensure no CRDs are already installed
Cleanup(t, ctx)

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
g.Expect(KAMEL_INSTALL_REGISTRY).NotTo(Equal(""))
// We must change a few values in the Kustomize config
ExpectExecSucceed(t, g,
exec.Command(
Expand All @@ -70,7 +68,7 @@ func TestKustomizeNamespaced(t *testing.T) {
exec.Command(
"sed",
"-i",
fmt.Sprintf("s/address: .*/address: %s/", registry),
fmt.Sprintf("s/address: .*/address: %s/", KAMEL_INSTALL_REGISTRY),
fmt.Sprintf("%s/overlays/platform/integration-platform.yaml", kustomizeDir),
))
ExpectExecSucceed(t, g, Kubectl(
Expand Down Expand Up @@ -100,7 +98,7 @@ func TestKustomizeNamespaced(t *testing.T) {
)
g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil())
g.Eventually(PlatformHas(t, ctx, ns, func(pl *v1.IntegrationPlatform) bool {
return pl.Status.Build.Registry.Address == registry
return pl.Status.Build.Registry.Address == KAMEL_INSTALL_REGISTRY
}), TestTimeoutShort).Should(BeTrue())

// Test a simple integration is running
Expand Down Expand Up @@ -139,18 +137,16 @@ func TestKustomizeNamespaced(t *testing.T) {
}

func TestKustomizeDescoped(t *testing.T) {
g := NewWithT(t)
CheckLocalInstallRegistry(t, g)
// TODO, likely we need to adjust this test with a Kustomize overlay for Openshift
// which would not require the registry setting
registry := os.Getenv("KIND_REGISTRY")
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")
kustomizeDir := testutil.MakeTempCopyDir(t, "../../../install")
ctx := TestContext()
g.Expect(registry).NotTo(Equal(""))
// Ensure no CRDs are already installed
Cleanup(t, ctx)

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
g.Expect(KAMEL_INSTALL_REGISTRY).NotTo(Equal(""))
// We must change a few values in the Kustomize config
ExpectExecSucceed(t, g,
exec.Command(
Expand All @@ -169,7 +165,7 @@ func TestKustomizeDescoped(t *testing.T) {
exec.Command(
"sed",
"-i",
fmt.Sprintf("s/address: .*/address: %s/", registry),
fmt.Sprintf("s/address: .*/address: %s/", KAMEL_INSTALL_REGISTRY),
fmt.Sprintf("%s/overlays/platform/integration-platform.yaml", kustomizeDir),
))
ExpectExecSucceed(t, g, Kubectl(
Expand Down
2 changes: 1 addition & 1 deletion e2e/install/upgrade/kustomize_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func TestKustomizeUpgrade(t *testing.T) {

// Upgrade the operator by installing the current version
registry := os.Getenv("KIND_REGISTRY")
kustomizeDir := testutil.MakeTempCopyDir(t, "../../../install")
g.Expect(registry).NotTo(Equal(""))
kustomizeDir := testutil.MakeTempCopyDir(t, "../../../install")
// We must change a few values in the Kustomize config
ExpectExecSucceed(t, g,
exec.Command(
Expand Down
32 changes: 0 additions & 32 deletions e2e/support/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package support

import (
"context"
"fmt"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -82,27 +81,6 @@ func ExpectExecSucceed(t *testing.T, g *WithT, command *exec.Cmd) {
assert.NotContains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

// ExpectExecError Expect a command error with an exit code of 1
func ExpectExecError(t *testing.T, g *WithT, command *exec.Cmd) {
t.Helper()

var cmdOut strings.Builder
var cmdErr strings.Builder

defer func() {
if t.Failed() {
t.Logf("Output from exec command:\n%s\n", cmdOut.String())
t.Logf("Error from exec command:\n%s\n", cmdErr.String())
}
}()

session, err := gexec.Start(command, &cmdOut, &cmdErr)
session.Wait()
g.Eventually(session).ShouldNot(gexec.Exit(0))
require.NoError(t, err)
assert.Contains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

// Cleanup Clean up the cluster ready for the next set of tests
func Cleanup(t *testing.T, ctx context.Context) {
// Remove the locally installed operator
Expand All @@ -125,13 +103,3 @@ func UninstallAll(t *testing.T, ctx context.Context) error {
func UninstallFromNamespace(t *testing.T, ctx context.Context, ns string) error {
return Kamel(t, ctx, "uninstall", "--olm=false", "-n", ns).Execute()
}

func CheckLocalInstallRegistry(t *testing.T, g *WithT) {
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")
if KAMEL_INSTALL_REGISTRY != "" {
t.Logf("Detected a local registry for Camel K %s. Setting custom image accordingly.", KAMEL_INSTALL_REGISTRY)
customImage := fmt.Sprintf("%s/apache/camel-k", KAMEL_INSTALL_REGISTRY)
os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../../")
ExpectExecSucceed(t, g, Make(t, fmt.Sprintf("CUSTOM_IMAGE=%s", customImage), "set-version"))
}
}
4 changes: 2 additions & 2 deletions script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ test-install: do-build
FAILED=0; STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)"; \
go test -timeout 40m -v ./e2e/install/cli -tags=integration $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \
go test -timeout 40m -v ./e2e/install/kustomize -tags=integration $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \
go test -timeout 40m -v ./e2e/install/helm -tags=integration $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \
go test -timeout 60m -v ./e2e/install/helm -tags=integration $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \
exit $${FAILED}

#
Expand Down Expand Up @@ -767,7 +767,7 @@ $(GOIMPORT): $(LOCALBIN)
#####

KUSTOMIZE_DIR = "install/overlays/kubernetes/descoped"
MINIKUBE_REGISTRY = "$(shell kubectl -n kube-system get service registry -o jsonpath='{.spec.clusterIP}')"
MINIKUBE_REGISTRY = "$(shell kubectl -n kube-system get service registry -o jsonpath='{.spec.clusterIP}' 2> /dev/null)"
DEFAULT_NS = "camel-k"

.PHONY: install install-k8s-global install-k8s-ns install-openshift-global install-openshift-ns
Expand Down

0 comments on commit 78407fb

Please sign in to comment.