diff --git a/.github/actions/kamel-config-cluster-kind/action.yml b/.github/actions/kamel-config-cluster-kind/action.yml index 96648d8dee..6722ee287d 100644 --- a/.github/actions/kamel-config-cluster-kind/action.yml +++ b/.github/actions/kamel-config-cluster-kind/action.yml @@ -23,7 +23,7 @@ runs: steps: - id: install-cluster name: Install Cluster - uses: container-tools/kind-action@v2.0.3 + uses: container-tools/kind-action@v2.0.4 if: ${{ env.CLUSTER_KIND_CONFIGURED != 'true' }} with: version: v0.19.0 diff --git a/.github/actions/kamel-prepare-env/action.yml b/.github/actions/kamel-prepare-env/action.yml index fd76c31cc2..4fce0bca5c 100644 --- a/.github/actions/kamel-prepare-env/action.yml +++ b/.github/actions/kamel-prepare-env/action.yml @@ -97,7 +97,7 @@ runs: # Install a version of kubectl for generic access to cluster # - id: install-kubectl - uses: azure/setup-kubectl@v3 + uses: azure/setup-kubectl@v4 if: ${{ env.KAMEL_PREPARE_ENV != 'true' }} with: version: 'v1.27.4' diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index fde4cafa0a..31dacc8f86 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -90,7 +90,7 @@ jobs: -p "${{ github.event.inputs.skip-problematic }}" \ -q "${{ github.event.inputs.log-level }}" \ -t "${{ github.event.inputs.test-filters }}" - - name: Smoke tests + - name: Common tests uses: ./.github/actions/e2e-common with: cluster-config-data: ${{ secrets.E2E_CLUSTER_CONFIG }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eb578aec5..315b50871f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ **Closed issues:** +- XSD might be wrong [\#5250](https://github.com/apache/camel-k/issues/5250) - Update buil/Dokerfile to use go 1.21 [\#5231](https://github.com/apache/camel-k/issues/5231) - Error java.lang.ClassNotFoundException: io.quarkus.bootstrap.runner.QuarkusEntryPoint [\#5225](https://github.com/apache/camel-k/issues/5225) - Deployment Trait maxUnavailable and maxSurge default values differ from documentation and do not support % values [\#5223](https://github.com/apache/camel-k/issues/5223) @@ -14,12 +15,14 @@ - Builder property failure when using non xml tag characters [\#5195](https://github.com/apache/camel-k/issues/5195) - Error configuring property: camel.component.test\[00001\]port\[80\]tcp.addr because cannot find component with name test\[00001\]port\[80\]tcp. [\#5179](https://github.com/apache/camel-k/issues/5179) - Get environment variable value is empty in properties file [\#5178](https://github.com/apache/camel-k/issues/5178) +- Install operator image according to the target architecture [\#5169](https://github.com/apache/camel-k/issues/5169) - Debug Integrations failing [\#5161](https://github.com/apache/camel-k/issues/5161) - Multiple crons at the same Integration do not run as expected [\#5158](https://github.com/apache/camel-k/issues/5158) - Kamel delete KameletBinding only removes integration resource [\#5156](https://github.com/apache/camel-k/issues/5156) - Performance regression due to configmap/secrets whole cluster watch [\#5143](https://github.com/apache/camel-k/issues/5143) - Running integrations fail when the used registry has a port other than default 80 [\#5141](https://github.com/apache/camel-k/issues/5141) - camel-jackson configure configure "autoDiscoverObjectMapper" property for non-spring boot application [\#5140](https://github.com/apache/camel-k/issues/5140) +- Update github actions to a version that use node 20 [\#5130](https://github.com/apache/camel-k/issues/5130) - Integrations remain in Initialization loop when referenced config map has owner references [\#5114](https://github.com/apache/camel-k/issues/5114) - Externally built Integrations are deployed without a command in Camel-K 2.2.0 [\#5112](https://github.com/apache/camel-k/issues/5112) - Coverage report wrong percentage [\#5108](https://github.com/apache/camel-k/issues/5108) @@ -27,6 +30,7 @@ - Include the operator node-selector in the helm chart [\#5103](https://github.com/apache/camel-k/issues/5103) - TestCreateCatalog fail when DEFAULT\_RUNTIME\_VERSION=3.6.0-SNAPSHOT [\#5099](https://github.com/apache/camel-k/issues/5099) - Remove secondary IntegrationPlatform in favor of using IntegrationProfile settings [\#5097](https://github.com/apache/camel-k/issues/5097) +- Basic example fails on Docker Desktop MacOS [\#5095](https://github.com/apache/camel-k/issues/5095) - Quartz builds failing to start when using native builds [\#5088](https://github.com/apache/camel-k/issues/5088) - Ability to set different resources for jvm and native containers when both are used in the same Integration [\#5065](https://github.com/apache/camel-k/issues/5065) - Don't run dependabot on forked repos [\#5063](https://github.com/apache/camel-k/issues/5063) @@ -43,6 +47,8 @@ - Data type Kamelet hardcoded [\#5014](https://github.com/apache/camel-k/issues/5014) - Quarkus buildMode should sort JVM before Native execution [\#5001](https://github.com/apache/camel-k/issues/5001) - Failing to build native integration [\#5000](https://github.com/apache/camel-k/issues/5000) +- Azure Key Vault Trait: Support Azure Identity as authentication method [\#4983](https://github.com/apache/camel-k/issues/4983) +- Move handling of IntegrationPlatformResource to a separate operator [\#4948](https://github.com/apache/camel-k/issues/4948) - Use generated trait [\#4811](https://github.com/apache/camel-k/issues/4811) - Upgrade to Go 1.21 [\#4795](https://github.com/apache/camel-k/issues/4795) - Pointer to an external schema/CRD [\#4788](https://github.com/apache/camel-k/issues/4788) @@ -50,6 +56,7 @@ - 1st Integration after Camel K runtime version update failing [\#4776](https://github.com/apache/camel-k/issues/4776) - Provide alternative publishing strategy via pipeline [\#4747](https://github.com/apache/camel-k/issues/4747) - Quarkus native checks failure [\#4723](https://github.com/apache/camel-k/issues/4723) +- Build waiting condition [\#4542](https://github.com/apache/camel-k/issues/4542) - Add DataTypeRegistry as bean in Camel context [\#3845](https://github.com/apache/camel-k/issues/3845) - Remove duplication of the default platform creation [\#3433](https://github.com/apache/camel-k/issues/3433) - Use `go:embed` instead of vfsgen for embedded resources handling [\#3384](https://github.com/apache/camel-k/issues/3384) @@ -58,13 +65,21 @@ **Merged pull requests:** +- Fix wrong Kamelet sample content [\#5255](https://github.com/apache/camel-k/pull/5255) ([claudio4j](https://github.com/claudio4j)) +- Add Kamelet v1alpha1 sample [\#5254](https://github.com/apache/camel-k/pull/5254) ([claudio4j](https://github.com/claudio4j)) +- chore\(ci\): Upgrade kind action to 2.0.4 [\#5249](https://github.com/apache/camel-k/pull/5249) ([gansheer](https://github.com/gansheer)) +- chore: propagate capabilities to Kit [\#5247](https://github.com/apache/camel-k/pull/5247) ([squakez](https://github.com/squakez)) +- Azure Key Vault Trait: Support Azure Identity as authentication method [\#5244](https://github.com/apache/camel-k/pull/5244) ([oscerd](https://github.com/oscerd)) +- chore\(ci\): Upgrade setup-kubectl action [\#5243](https://github.com/apache/camel-k/pull/5243) ([gansheer](https://github.com/gansheer)) - chore\(e2e\): Fix smoke tests [\#5240](https://github.com/apache/camel-k/pull/5240) ([christophd](https://github.com/christophd)) +- chore\(e2e\): Separate common-it E2E tests, so they run more efficient [\#5239](https://github.com/apache/camel-k/pull/5239) ([christophd](https://github.com/christophd)) - fix\(cmd\): delete KameletBinding until they exists [\#5237](https://github.com/apache/camel-k/pull/5237) ([squakez](https://github.com/squakez)) - fix\(ctrl\): message digest change [\#5236](https://github.com/apache/camel-k/pull/5236) ([squakez](https://github.com/squakez)) - fix\(build\): Upgrade container image to golang 1.21 [\#5235](https://github.com/apache/camel-k/pull/5235) ([gansheer](https://github.com/gansheer)) - \[Regression\] fix\(quarkus\): don't override application.properties [\#5234](https://github.com/apache/camel-k/pull/5234) ([squakez](https://github.com/squakez)) - fix\(trait\): revert persisted status [\#5233](https://github.com/apache/camel-k/pull/5233) ([squakez](https://github.com/squakez)) - chore\(deps\): bump github.com/prometheus/common from 0.48.0 to 0.50.0 [\#5232](https://github.com/apache/camel-k/pull/5232) ([dependabot[bot]](https://github.com/apps/dependabot)) +- fix\(traits\): use Comparable matches [\#5230](https://github.com/apache/camel-k/pull/5230) ([squakez](https://github.com/squakez)) - fix\(trait\): Add documentation and test on multiple sources [\#5229](https://github.com/apache/camel-k/pull/5229) ([gansheer](https://github.com/gansheer)) - chore\(deps\): bump github.com/cloudevents/sdk-go/v2 from 2.13.0 to 2.15.2 [\#5228](https://github.com/apache/camel-k/pull/5228) ([dependabot[bot]](https://github.com/apps/dependabot)) - chore\(lint\): Update golangci-lint version to 1.55 [\#5227](https://github.com/apache/camel-k/pull/5227) ([christophd](https://github.com/christophd)) @@ -78,6 +93,7 @@ - chore\(deps\): bump github.com/stretchr/testify from 1.8.4 to 1.9.0 [\#5208](https://github.com/apache/camel-k/pull/5208) ([dependabot[bot]](https://github.com/apps/dependabot)) - fix\(e2e\): stricter pipe test check [\#5202](https://github.com/apache/camel-k/pull/5202) ([squakez](https://github.com/squakez)) - fix\(trait\): deprecate operator inspecting secrets [\#5201](https://github.com/apache/camel-k/pull/5201) ([squakez](https://github.com/squakez)) +- Install operator image according to the target architecture [\#5200](https://github.com/apache/camel-k/pull/5200) ([tdiesler](https://github.com/tdiesler)) - fix\(trait\): catalog to drive dependencies [\#5199](https://github.com/apache/camel-k/pull/5199) ([squakez](https://github.com/squakez)) - fix\(quarkus\): build time properties into file [\#5198](https://github.com/apache/camel-k/pull/5198) ([squakez](https://github.com/squakez)) - chore\(deps\): bump github.com/prometheus/client\_golang from 1.18.0 to 1.19.0 [\#5193](https://github.com/apache/camel-k/pull/5193) ([dependabot[bot]](https://github.com/apps/dependabot)) diff --git a/README.adoc b/README.adoc index 5eee363a21..6f602ad4e3 100644 --- a/README.adoc +++ b/README.adoc @@ -11,7 +11,7 @@ image:https://github.com/apache/camel-k/workflows/kubernetes/badge.svg["Kubernet image:https://github.com/apache/camel-k/workflows/knative/badge.svg["Knative", link="https://github.com/apache/camel-k/actions/workflows/knative.yml"] image:https://github.com/apache/camel-k/actions/workflows/nightly-release.yml/badge.svg["Nightly releases", link="https://github.com/apache/camel-k/actions/workflows/nightly-release.yml"] image:https://github.com/apache/camel-k/actions/workflows/nightly-native-test.yml/badge.svg["Quarkus native", link="https://github.com/apache/camel-k/actions/workflows/nightly-native-test.yml"] -image:https://img.shields.io/badge/Coverage-36.9%25-yellow.svg["Go coverage", link="https://github.com/apache/camel-k/actions/workflows/nightly-coverage.yml"] +image:https://img.shields.io/badge/Coverage-37.2%25-yellow.svg["Go coverage", link="https://github.com/apache/camel-k/actions/workflows/nightly-coverage.yml"] image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg["Chat on Zulip", link="https://camel.zulipchat.com"] Apache Camel K is a lightweight integration framework built from **Apache Camel** that runs natively on Kubernetes and is specifically designed for serverless and microservice architectures. Users of `Camel K` can instantly run integration code written in Camel DSL on their preferred **Cloud** provider. diff --git a/addons/vault/azure/azure_key_vault.go b/addons/vault/azure/azure_key_vault.go index 6a639442ba..a02fd2c17b 100644 --- a/addons/vault/azure/azure_key_vault.go +++ b/addons/vault/azure/azure_key_vault.go @@ -42,7 +42,7 @@ import ( // // To enable the automatic context reload on secrets updates you should define // the following trait options: -// -t azure-key-vault.enabled=true -t azure-key-vault.tenant-id="tenant-id" -t azure-key-vault.client-id="client-id" -t azure-key-vault.client-secret="client-secret" -t azure-key-vault.vault-name="vault-name" -t azure-key-vault.context-reload-enabled="true" -t azure-key-vault.refresh-enabled="true" -t azure-key-vault.refresh-period="30000" -t azure-key-vault.secrets="test*" -t azure-key-vault.eventhub-connection-string="connection-string" -t azure-key-vault.blob-account-name="account-name" -t azure-key-vault.blob-container-name="container-name" -t azure-key-vault.blob-access-key="account-name" +// -t azure-key-vault.enabled=true -t azure-key-vault.tenant-id="tenant-id" -t azure-key-vault.client-id="client-id" -t azure-key-vault.client-secret="client-secret" -t azure-key-vault.vault-name="vault-name" -t azure-key-vault.context-reload-enabled="true" -t azure-key-vault.refresh-enabled="true" -t azure-key-vault.refresh-period="30000" -t azure-key-vault.secrets="test*" -t azure-key-vault.eventhub-connection-string="connection-string" -t azure-key-vault.blob-account-name="account-name" -t azure-key-vault.blob-container-name="container-name" -t azure-key-vault.blob-access-key="account-name" -t azure-key-vault.azure-identity-enabled="true" // // +camel-k:trait=azure-key-vault. type Trait struct { @@ -63,6 +63,8 @@ type Trait struct { ContextReloadEnabled *bool `property:"context-reload-enabled" json:"contextReloadEnabled,omitempty"` // Define if we want to use the Refresh Feature for secrets RefreshEnabled *bool `property:"refresh-enabled" json:"refreshEnabled,omitempty"` + // Whether the Azure Identity Authentication should be used or not + AzureIdentityEnabled *bool `property:"azure-identity-enabled" json:"azureIdentityEnabled,omitempty"` // If Refresh is enabled, this defines the interval to check the refresh event RefreshPeriod string `property:"refresh-period" json:"refreshPeriod,omitempty"` // If Refresh is enabled, the regular expression representing the secrets we want to track @@ -107,6 +109,10 @@ func (t *azureKeyVaultTrait) Configure(environment *trait.Environment) (bool, *t t.RefreshEnabled = pointer.Bool(false) } + if t.AzureIdentityEnabled == nil { + t.AzureIdentityEnabled = pointer.Bool(false) + } + return true, nil, nil } @@ -143,6 +149,7 @@ func (t *azureKeyVaultTrait) Apply(environment *trait.Environment) error { environment.ApplicationProperties["camel.vault.azure.clientId"] = t.ClientID environment.ApplicationProperties["camel.vault.azure.vaultName"] = t.VaultName environment.ApplicationProperties["camel.vault.azure.refreshEnabled"] = strconv.FormatBool(*t.RefreshEnabled) + environment.ApplicationProperties["camel.vault.azure.azureIdentityEnabled"] = strconv.FormatBool(*t.AzureIdentityEnabled) environment.ApplicationProperties["camel.main.context-reload-enabled"] = strconv.FormatBool(*t.ContextReloadEnabled) environment.ApplicationProperties["camel.vault.azure.refreshPeriod"] = t.RefreshPeriod if t.Secrets != "" { diff --git a/addons/vault/azure/azure_key_vault_test.go b/addons/vault/azure/azure_key_vault_test.go index 202efe9be6..cc9c611712 100644 --- a/addons/vault/azure/azure_key_vault_test.go +++ b/addons/vault/azure/azure_key_vault_test.go @@ -152,6 +152,55 @@ func TestAzureKeyVaultTraitApplyWithSecretAndRefresh(t *testing.T) { assert.True(t, true, e.ApplicationProperties["camel.vault.azure.refreshEnabled"]) } +func TestAzureKeyVaultTraitAzureIdentityEnabledApplyWithSecretAndRefresh(t *testing.T) { + e := createEnvironment(t, camel.QuarkusCatalog, &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "test", + Name: "my-secret1", + }, + Data: map[string][]byte{ + "azure-client-secret": []byte("my-secret-key"), + }, + }, &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "test", + Name: "my-secret2", + }, + Data: map[string][]byte{ + "azure-storage-blob-key": []byte("my-access-key"), + }, + }) + azure := NewAzureKeyVaultTrait() + secrets, _ := azure.(*azureKeyVaultTrait) + secrets.Enabled = pointer.Bool(true) + secrets.TenantID = "tenant-id" + secrets.ClientID = "client-id" + secrets.ClientSecret = "secret:my-secret1/azure-client-secret" + secrets.VaultName = "my-vault" + secrets.RefreshEnabled = pointer.Bool(true) + secrets.AzureIdentityEnabled = pointer.Bool(true) + secrets.BlobAccessKey = "secret:my-secret2/azure-storage-blob-key" + secrets.BlobAccountName = "camel-k" + secrets.BlobContainerName = "camel-k-container" + ok, condition, err := secrets.Configure(e) + require.NoError(t, err) + assert.True(t, ok) + assert.Nil(t, condition) + + err = secrets.Apply(e) + require.NoError(t, err) + + assert.Equal(t, "client-id", e.ApplicationProperties["camel.vault.azure.clientId"]) + assert.Equal(t, "my-secret-key", e.ApplicationProperties["camel.vault.azure.clientSecret"]) + assert.Equal(t, "tenant-id", e.ApplicationProperties["camel.vault.azure.tenantId"]) + assert.Equal(t, "my-vault", e.ApplicationProperties["camel.vault.azure.vaultName"]) + assert.Equal(t, "camel-k", e.ApplicationProperties["camel.vault.azure.blobAccountName"]) + assert.Equal(t, "camel-k-container", e.ApplicationProperties["camel.vault.azure.blobContainerName"]) + assert.Equal(t, "my-access-key", e.ApplicationProperties["camel.vault.azure.blobAccessKey"]) + assert.True(t, true, e.ApplicationProperties["camel.vault.azure.refreshEnabled"]) + assert.True(t, true, e.ApplicationProperties["camel.vault.azure.azureIdentityEnabled"]) +} + func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error), objects ...runtime.Object) *trait.Environment { t.Helper() diff --git a/badge.out b/badge.out index 3f7e3235f9..1707b478fe 100644 --- a/badge.out +++ b/badge.out @@ -1,2 +1,2 @@ -![Coverage](https://img.shields.io/badge/Coverage-36.9%25-yellow) \ No newline at end of file +![Coverage](https://img.shields.io/badge/Coverage-37.2%25-yellow) \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile index 2ee4f8af34..e495e40f30 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -15,6 +15,8 @@ FROM eclipse-temurin:17-jdk as base +ARG IMAGE_ARCH + ARG MAVEN_DEFAULT_VERSION="3.8.6" ARG MAVEN_HOME="/usr/share/maven" ARG MAVEN_DIST_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN_DEFAULT_VERSION}/binaries/apache-maven-${MAVEN_DEFAULT_VERSION}-bin.zip" @@ -59,7 +61,7 @@ RUN chgrp -R 0 ${MVN_REPO} \ USER 1001:0 -ADD build/_output/bin/kamel /usr/local/bin/kamel +ADD build/_output/bin/kamel-${IMAGE_ARCH} /usr/local/bin/kamel FROM golang:1.21 as go diff --git a/coverage b/coverage index 4282804f3f..ad4af79d82 100644 --- a/coverage +++ b/coverage @@ -1 +1 @@ -36.9 +37.2 diff --git a/coverage.out b/coverage.out index a53803db53..216031e034 100644 --- a/coverage.out +++ b/coverage.out @@ -44,9 +44,9 @@ github.com/apache/camel-k/v2/addons/tracing/tracing.go:125: Apply 93. github.com/apache/camel-k/v2/addons/vault/aws/aws_secrets_manager.go:79: NewAwsSecretsManagerTrait 100.0% github.com/apache/camel-k/v2/addons/vault/aws/aws_secrets_manager.go:85: Configure 81.8% github.com/apache/camel-k/v2/addons/vault/aws/aws_secrets_manager.go:107: Apply 85.7% -github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:87: NewAzureKeyVaultTrait 100.0% -github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:93: Configure 77.8% -github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:113: Apply 87.5% +github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:89: NewAzureKeyVaultTrait 100.0% +github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:95: Configure 81.8% +github.com/apache/camel-k/v2/addons/vault/azure/azure_key_vault.go:119: Apply 87.9% github.com/apache/camel-k/v2/addons/vault/gcp/gcp_secret_manager.go:72: NewGcpSecretManagerTrait 100.0% github.com/apache/camel-k/v2/addons/vault/gcp/gcp_secret_manager.go:78: Configure 72.7% github.com/apache/camel-k/v2/addons/vault/gcp/gcp_secret_manager.go:102: Apply 84.6% @@ -410,154 +410,154 @@ github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1194: github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1208: DeepCopy 0.0% github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1218: DeepCopyObject 0.0% github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1226: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1254: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1264: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1286: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1296: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1328: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1338: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1352: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1362: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1370: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1379: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1389: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1397: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1422: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1432: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1439: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1449: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1459: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1469: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1483: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1493: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1501: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1514: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1524: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1544: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1554: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1563: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1573: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1581: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1593: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1603: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1610: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1620: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1630: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1640: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1654: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1664: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1672: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1680: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1690: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1703: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1713: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1763: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1773: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1821: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1831: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1841: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1851: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1923: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1933: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1960: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1970: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1977: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1987: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1996: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2006: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2014: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2021: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2031: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2045: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2055: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2063: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2068: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2078: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2083: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2093: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2134: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2144: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2161: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2171: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2184: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2194: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2204: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2214: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2219: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2229: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2247: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2257: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2295: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2305: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2315: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2325: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2330: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2340: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2349: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2359: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2367: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2381: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2391: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2405: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2415: DeepCopyObject 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2423: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2452: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2462: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2479: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2489: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2497: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2507: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2513: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2523: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2533: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2543: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2549: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2559: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2570: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2580: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2593: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2603: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2661: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2671: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2677: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2687: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2698: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2708: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2714: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2724: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2733: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2743: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2748: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2758: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2765: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2775: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2780: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2790: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2814: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2824: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2830: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2840: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2853: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2863: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2879: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2889: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2896: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2906: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2918: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2928: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2973: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2983: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2993: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3003: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3013: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3023: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3029: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3039: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3246: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3256: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3272: DeepCopy 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3282: DeepCopyInto 0.0% -github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3297: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1259: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1269: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1291: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1301: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1333: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1343: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1357: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1367: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1375: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1384: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1394: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1402: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1427: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1437: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1444: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1454: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1464: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1474: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1488: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1498: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1506: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1519: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1529: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1549: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1559: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1568: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1578: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1586: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1598: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1608: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1615: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1625: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1635: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1645: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1659: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1669: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1677: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1685: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1695: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1708: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1718: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1768: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1778: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1826: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1836: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1846: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1856: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1928: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1938: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1965: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1975: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1982: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:1992: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2001: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2011: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2019: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2026: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2036: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2050: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2060: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2068: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2073: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2083: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2088: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2098: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2139: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2149: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2166: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2176: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2189: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2199: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2209: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2219: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2224: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2234: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2252: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2262: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2300: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2310: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2320: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2330: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2335: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2345: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2354: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2364: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2372: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2386: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2396: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2410: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2420: DeepCopyObject 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2428: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2457: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2467: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2484: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2494: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2502: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2512: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2518: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2528: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2538: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2548: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2554: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2564: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2575: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2585: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2598: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2608: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2666: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2676: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2682: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2692: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2703: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2713: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2719: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2729: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2738: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2748: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2753: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2763: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2770: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2780: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2785: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2795: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2819: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2829: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2835: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2845: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2858: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2868: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2884: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2894: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2901: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2911: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2923: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2933: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2978: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2988: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:2998: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3008: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3018: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3028: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3034: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3044: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3251: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3261: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3277: DeepCopy 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3287: DeepCopyInto 0.0% +github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.deepcopy.go:3302: DeepCopy 0.0% github.com/apache/camel-k/v2/pkg/apis/camel/v1/zz_generated.defaults.go:15: RegisterDefaults 0.0% github.com/apache/camel-k/v2/pkg/apis/camel/v1alpha1/error_handler_types_support.go:42: Type 0.0% github.com/apache/camel-k/v2/pkg/apis/camel/v1alpha1/error_handler_types_support.go:47: Endpoint 0.0% @@ -1162,15 +1162,12 @@ github.com/apache/camel-k/v2/pkg/controller/integration/integration_controller.g github.com/apache/camel-k/v2/pkg/controller/integration/integration_controller.go:474: watchKnativeResources 0.0% github.com/apache/camel-k/v2/pkg/controller/integration/integration_controller.go:516: Reconcile 0.0% github.com/apache/camel-k/v2/pkg/controller/integration/integration_controller.go:597: update 0.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:40: lookupKitsForIntegration 81.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:88: sameOrMatch 0.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:99: integrationMatches 65.4% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:154: statusMatches 41.7% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:175: kitMatches 0.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:208: hasMatchingTraits 81.2% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:241: matchesComparableTrait 0.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:264: matchesTrait 100.0% -github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:269: hasMatchingSourcesForNative 100.0% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:38: lookupKitsForIntegration 81.0% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:86: sameOrMatch 0.0% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:97: integrationMatches 65.4% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:152: statusMatches 41.7% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:173: kitMatches 0.0% +github.com/apache/camel-k/v2/pkg/controller/integration/kits.go:206: hasMatchingSourcesForNative 100.0% github.com/apache/camel-k/v2/pkg/controller/integration/metrics.go:42: init 100.0% github.com/apache/camel-k/v2/pkg/controller/integration/monitor.go:49: NewMonitorAction 0.0% github.com/apache/camel-k/v2/pkg/controller/integration/monitor.go:57: Name 0.0% @@ -1424,32 +1421,32 @@ github.com/apache/camel-k/v2/pkg/trait/affinity.go:120: addPodAffinity github.com/apache/camel-k/v2/pkg/trait/affinity.go:171: addPodAntiAffinity 89.5% github.com/apache/camel-k/v2/pkg/trait/affinity.go:222: operatorToNodeSelectorOperator 25.0% github.com/apache/camel-k/v2/pkg/trait/affinity.go:240: operatorToLabelSelectorOperator 50.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:48: newBuilderTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:55: InfluencesKit 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:60: InfluencesBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:64: Configure 44.4% -github.com/apache/camel-k/v2/pkg/trait/builder.go:109: existsTaskRequest 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:119: adaptDeprecatedFields 95.8% -github.com/apache/camel-k/v2/pkg/trait/builder.go:152: newOrAppend 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:162: Apply 88.1% -github.com/apache/camel-k/v2/pkg/trait/builder.go:288: failIntegrationKit 80.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:297: builderTask 66.7% -github.com/apache/camel-k/v2/pkg/trait/builder.go:410: getImageName 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:418: getBaseImage 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:427: customTasks 91.7% -github.com/apache/camel-k/v2/pkg/trait/builder.go:457: taskConfOrDefault 66.7% -github.com/apache/camel-k/v2/pkg/trait/builder.go:465: parseTasksConf 92.1% -github.com/apache/camel-k/v2/pkg/trait/builder.go:526: splitContainerCommand 100.0% -github.com/apache/camel-k/v2/pkg/trait/builder.go:540: filter 81.8% -github.com/apache/camel-k/v2/pkg/trait/builder.go:581: publishingOrUserTask 80.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:49: newBuilderTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:56: InfluencesKit 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:60: Matches 90.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:89: Configure 44.4% +github.com/apache/camel-k/v2/pkg/trait/builder.go:134: existsTaskRequest 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:144: adaptDeprecatedFields 95.8% +github.com/apache/camel-k/v2/pkg/trait/builder.go:177: newOrAppend 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:187: Apply 88.1% +github.com/apache/camel-k/v2/pkg/trait/builder.go:313: failIntegrationKit 80.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:322: builderTask 66.7% +github.com/apache/camel-k/v2/pkg/trait/builder.go:435: getImageName 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:443: getBaseImage 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:452: customTasks 91.7% +github.com/apache/camel-k/v2/pkg/trait/builder.go:482: taskConfOrDefault 66.7% +github.com/apache/camel-k/v2/pkg/trait/builder.go:490: parseTasksConf 92.1% +github.com/apache/camel-k/v2/pkg/trait/builder.go:551: splitContainerCommand 100.0% +github.com/apache/camel-k/v2/pkg/trait/builder.go:565: filter 81.8% +github.com/apache/camel-k/v2/pkg/trait/builder.go:606: publishingOrUserTask 80.0% github.com/apache/camel-k/v2/pkg/trait/camel.go:45: newCamelTrait 100.0% github.com/apache/camel-k/v2/pkg/trait/camel.go:52: InfluencesKit 100.0% -github.com/apache/camel-k/v2/pkg/trait/camel.go:57: InfluencesBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/camel.go:61: Configure 80.0% -github.com/apache/camel-k/v2/pkg/trait/camel.go:74: Apply 93.8% -github.com/apache/camel-k/v2/pkg/trait/camel.go:105: loadOrCreateCatalog 56.2% -github.com/apache/camel-k/v2/pkg/trait/camel.go:144: computeConfigMaps 100.0% -github.com/apache/camel-k/v2/pkg/trait/camel.go:225: determineRuntimeVersion 66.7% +github.com/apache/camel-k/v2/pkg/trait/camel.go:56: Matches 75.0% +github.com/apache/camel-k/v2/pkg/trait/camel.go:65: Configure 80.0% +github.com/apache/camel-k/v2/pkg/trait/camel.go:78: Apply 93.8% +github.com/apache/camel-k/v2/pkg/trait/camel.go:109: loadOrCreateCatalog 56.2% +github.com/apache/camel-k/v2/pkg/trait/camel.go:148: computeConfigMaps 100.0% +github.com/apache/camel-k/v2/pkg/trait/camel.go:229: determineRuntimeVersion 66.7% github.com/apache/camel-k/v2/pkg/trait/container.go:58: newContainerTrait 100.0% github.com/apache/camel-k/v2/pkg/trait/container.go:70: Configure 80.0% github.com/apache/camel-k/v2/pkg/trait/container.go:113: isValidPullPolicy 100.0% @@ -1626,38 +1623,36 @@ github.com/apache/camel-k/v2/pkg/trait/quarkus.go:74: getLanguageSettings github.com/apache/camel-k/v2/pkg/trait/quarkus.go:92: getLegacyLanguageSettings 100.0% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:101: newQuarkusTrait 100.0% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:108: InfluencesKit 100.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:113: InfluencesBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:119: Matches 0.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:112: Matches 88.9% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:142: Configure 100.0% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:151: adaptDeprecatedFields 18.2% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:170: Apply 77.8% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:192: applyWhileBuildingKit 81.2% github.com/apache/camel-k/v2/pkg/trait/quarkus.go:227: validateNativeSupport 42.9% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:245: newIntegrationKit 70.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:300: propagateKitTraits 85.7% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:316: propagate 33.3% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:343: applyWhenBuildSubmitted 62.8% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:419: isNativeKit 50.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:430: isIncrementalImageBuild 75.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:441: applyWhenKitReady 28.6% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:455: isNativeIntegration 100.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:461: isEmbedded 66.7% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:471: containsMode 100.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:480: packageType 80.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:492: sourcesRequiredAtBuildTime 100.0% -github.com/apache/camel-k/v2/pkg/trait/quarkus.go:498: propagateSourcesRequiredAtBuildTime 80.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:245: newIntegrationKit 68.2% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:299: propagateKitTraits 85.7% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:315: propagate 33.3% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:342: applyWhenBuildSubmitted 62.8% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:418: isNativeKit 50.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:429: isIncrementalImageBuild 75.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:440: applyWhenKitReady 28.6% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:454: isNativeIntegration 100.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:460: isEmbedded 66.7% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:470: containsMode 100.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:479: packageType 80.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:491: sourcesRequiredAtBuildTime 100.0% +github.com/apache/camel-k/v2/pkg/trait/quarkus.go:497: propagateSourcesRequiredAtBuildTime 80.0% github.com/apache/camel-k/v2/pkg/trait/registry.go:46: newRegistryTrait 100.0% github.com/apache/camel-k/v2/pkg/trait/registry.go:53: InfluencesKit 100.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:58: InfluencesBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:62: Configure 28.6% -github.com/apache/camel-k/v2/pkg/trait/registry.go:80: Apply 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:124: addRegistryAndExtensionToMaven 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:149: getOpenShiftRegistrySecret 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:173: extractMavenServerCredentialsFromSecret 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:222: getDockerConfig 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:241: getOpenShiftImageRegistryCA 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:264: addImageRegistryCaToMavenBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/registry.go:281: decodeSecretKeySelector 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:57: Configure 28.6% +github.com/apache/camel-k/v2/pkg/trait/registry.go:75: Apply 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:119: addRegistryAndExtensionToMaven 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:144: getOpenShiftRegistrySecret 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:168: extractMavenServerCredentialsFromSecret 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:217: getDockerConfig 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:236: getOpenShiftImageRegistryCA 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:259: addImageRegistryCaToMavenBuild 0.0% +github.com/apache/camel-k/v2/pkg/trait/registry.go:276: decodeSecretKeySelector 0.0% github.com/apache/camel-k/v2/pkg/trait/route.go:43: newRouteTrait 100.0% github.com/apache/camel-k/v2/pkg/trait/route.go:53: IsAllowedInProfile 100.0% github.com/apache/camel-k/v2/pkg/trait/route.go:57: Configure 100.0% @@ -1710,44 +1705,43 @@ github.com/apache/camel-k/v2/pkg/trait/trait_configure.go:156: configureFro github.com/apache/camel-k/v2/pkg/trait/trait_configure.go:169: configureTrait 84.6% github.com/apache/camel-k/v2/pkg/trait/trait_factory.go:27: AddToTraits 100.0% github.com/apache/camel-k/v2/pkg/trait/trait_register.go:20: init 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:116: NewBaseTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:124: NewBasePlatformTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:143: ID 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:148: InjectClient 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:153: InfluencesKit 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:159: InfluencesBuild 0.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:164: IsPlatformTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:169: RequiresIntegrationPlatform 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:175: IsAllowedInProfile 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:180: Order 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:190: IsPlatformTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:247: GetTrait 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:257: IntegrationInPhase 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:271: IntegrationInRunningPhases 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:275: IntegrationKitInPhase 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:289: PlatformInPhase 66.7% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:303: InPhase 0.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:311: DetermineProfile 80.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:333: DetermineControllerStrategy 85.7% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:346: getControllerStrategyChoosers 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:360: GetIntegrationPodSpec 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:388: DetermineCatalogNamespace 18.2% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:408: computeApplicationProperties 83.3% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:439: addSourcesProperties 80.6% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:490: configureVolumesAndMounts 89.2% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:600: getVolume 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:628: getMount 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:641: convertToKeyToPath 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:658: getMountPoint 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:673: collectConfigurationValues 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:681: collectConfigurationPairs 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:685: collectConfigurations 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:689: GetIntegrationContainerName 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:701: isEmbedded 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:710: GetIntegrationContainer 100.0% -github.com/apache/camel-k/v2/pkg/trait/trait_types.go:715: getIntegrationContainerPort 76.9% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:113: NewBaseTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:121: NewBasePlatformTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:140: ID 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:145: InjectClient 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:150: InfluencesKit 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:155: IsPlatformTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:160: RequiresIntegrationPlatform 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:166: IsAllowedInProfile 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:171: Order 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:181: IsPlatformTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:238: GetTrait 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:248: IntegrationInPhase 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:262: IntegrationInRunningPhases 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:266: IntegrationKitInPhase 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:280: PlatformInPhase 66.7% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:294: InPhase 0.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:302: DetermineProfile 80.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:324: DetermineControllerStrategy 85.7% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:337: getControllerStrategyChoosers 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:351: GetIntegrationPodSpec 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:379: DetermineCatalogNamespace 18.2% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:399: computeApplicationProperties 83.3% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:430: addSourcesProperties 80.6% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:481: configureVolumesAndMounts 89.2% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:591: getVolume 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:619: getMount 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:632: convertToKeyToPath 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:649: getMountPoint 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:664: collectConfigurationValues 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:672: collectConfigurationPairs 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:676: collectConfigurations 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:680: GetIntegrationContainerName 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:692: isEmbedded 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:701: GetIntegrationContainer 100.0% +github.com/apache/camel-k/v2/pkg/trait/trait_types.go:706: getIntegrationContainerPort 76.9% github.com/apache/camel-k/v2/pkg/trait/util.go:46: ptrFrom 100.0% -github.com/apache/camel-k/v2/pkg/trait/util.go:52: Get 0.0% +github.com/apache/camel-k/v2/pkg/trait/util.go:52: Get 57.1% github.com/apache/camel-k/v2/pkg/trait/util.go:71: getIntegrationKit 0.0% github.com/apache/camel-k/v2/pkg/trait/util.go:80: collectConfigurationValues 100.0% github.com/apache/camel-k/v2/pkg/trait/util.go:107: collectConfigurations 100.0% @@ -1775,8 +1769,12 @@ github.com/apache/camel-k/v2/pkg/trait/util.go:486: newTraitsOptionsForInt github.com/apache/camel-k/v2/pkg/trait/util.go:495: NewSpecTraitsOptionsForIntegrationKit 0.0% github.com/apache/camel-k/v2/pkg/trait/util.go:499: NewTraitsOptionsForPipe 87.5% github.com/apache/camel-k/v2/pkg/trait/util.go:517: NewTraitsOptionsForKameletBinding 0.0% -github.com/apache/camel-k/v2/pkg/trait/util.go:534: FromAnnotations 68.2% -github.com/apache/camel-k/v2/pkg/trait/util.go:573: containsEndpoint 86.7% +github.com/apache/camel-k/v2/pkg/trait/util.go:534: FromAnnotations 92.3% +github.com/apache/camel-k/v2/pkg/trait/util.go:558: stringOrSlice 100.0% +github.com/apache/camel-k/v2/pkg/trait/util.go:575: containsEndpoint 86.7% +github.com/apache/camel-k/v2/pkg/trait/util.go:600: HasMatchingTraits 92.3% +github.com/apache/camel-k/v2/pkg/trait/util.go:626: matchesComparableTrait 69.2% +github.com/apache/camel-k/v2/pkg/trait/util.go:647: matchesTrait 100.0% github.com/apache/camel-k/v2/pkg/util/bindings/api_support.go:24: AsYamlDSL 0.0% github.com/apache/camel-k/v2/pkg/util/bindings/api_support.go:36: GenerateID 100.0% github.com/apache/camel-k/v2/pkg/util/bindings/api_support.go:46: GenerateID 0.0% @@ -2259,4 +2257,4 @@ github.com/apache/camel-k/v2/pkg/util/util.go:649: WithTempDir 0.0% github.com/apache/camel-k/v2/pkg/util/util.go:664: ConfigTreePropertySplit 0.0% github.com/apache/camel-k/v2/pkg/util/util.go:685: trimQuotes 0.0% github.com/apache/camel-k/v2/pkg/util/util.go:696: NavigateConfigTree 0.0% -total: (statements) 36.9% +total: (statements) 37.2% diff --git a/docs/modules/ROOT/pages/architecture/traits.adoc b/docs/modules/ROOT/pages/architecture/traits.adoc index fc56b11928..dee146ccb3 100644 --- a/docs/modules/ROOT/pages/architecture/traits.adoc +++ b/docs/modules/ROOT/pages/architecture/traits.adoc @@ -49,6 +49,15 @@ type Trait interface { IsAllowedInProfile(v1.TraitProfile) bool Order() int } + +type Comparable interface { + Matches(trait Trait) bool +} + +type ComparableTrait interface { + Trait + Comparable +} ---- Each trait will implement this interface. The most important methods that will be invoked by the xref:architecture/operator.adoc[Operator] are `Configure()` and `Apply()`. Basically, the `Configure()` method will set those inputs aforementioned (each trait has its own). The method is in charge to verify also the correctness of those expected parameters, where it makes sense (i.e., a well expected `Kubernetes` resource name). The function can return a `TraitCondition` object containing any informative or warning condition to be attached to the resulting Integration (for instance, traits forcefully altered by the platform, or deprecation notices). @@ -59,6 +68,6 @@ The `Order()` method helps in resolving the order of execution of different trai The `InfluencesKit()`, `IsPlatformTrait()` and `RequiresIntegrationPlatform()` methods are easy to understand. They are used to determine if a trait has to influence an `IntegrationKit` build/initialization, if it's a platform trait (ie, needed by the platform itself) or are requiring the presence of an `IntegrationPlatform`. -The presence of `InfluencesBuild()` will let specify the level of granularity of a trait down to its properties for a rebuild. So, if you need, you can compare the traits properties coming from the `prev` (previous) Integration to decide if it is worth to rebuild an Integration or the trait can reuse the one already provided in `this` version. +For those traits that `InfluencesKit()` you may need to provide a `Matches(trait Trait)` func in order to specify those trait parameters that influences a build. This is required by the platform to decide if it is worth to rebuild an Integration or the trait can reuse the one already provided. Finally, through the `IsAllowedInProfile()` method we can override the default behavior (allow the trait for any profile). We must specify the profile we expect for this trait to be executed properly. diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index b81ddd8514..f08fee353e 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -2494,6 +2494,13 @@ Maven repositories that can be used by the kit the sources to add at build time +|`capabilities` + +[]string +| + + +features offered by the IntegrationKit + |=== diff --git a/docs/modules/traits/pages/azure-key-vault.adoc b/docs/modules/traits/pages/azure-key-vault.adoc index a5d8ffc69c..6ff6e162d9 100644 --- a/docs/modules/traits/pages/azure-key-vault.adoc +++ b/docs/modules/traits/pages/azure-key-vault.adoc @@ -13,7 +13,7 @@ the following trait options: To enable the automatic context reload on secrets updates you should define the following trait options: --t azure-key-vault.enabled=true -t azure-key-vault.tenant-id="tenant-id" -t azure-key-vault.client-id="client-id" -t azure-key-vault.client-secret="client-secret" -t azure-key-vault.vault-name="vault-name" -t azure-key-vault.context-reload-enabled="true" -t azure-key-vault.refresh-enabled="true" -t azure-key-vault.refresh-period="30000" -t azure-key-vault.secrets="test*" -t azure-key-vault.eventhub-connection-string="connection-string" -t azure-key-vault.blob-account-name="account-name" -t azure-key-vault.blob-container-name="container-name" -t azure-key-vault.blob-access-key="account-name" +-t azure-key-vault.enabled=true -t azure-key-vault.tenant-id="tenant-id" -t azure-key-vault.client-id="client-id" -t azure-key-vault.client-secret="client-secret" -t azure-key-vault.vault-name="vault-name" -t azure-key-vault.context-reload-enabled="true" -t azure-key-vault.refresh-enabled="true" -t azure-key-vault.refresh-period="30000" -t azure-key-vault.secrets="test*" -t azure-key-vault.eventhub-connection-string="connection-string" -t azure-key-vault.blob-account-name="account-name" -t azure-key-vault.blob-container-name="container-name" -t azure-key-vault.blob-access-key="account-name" -t azure-key-vault.azure-identity-enabled="true" This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**. @@ -67,6 +67,10 @@ Syntax: [configmap\|secret]:name[/key], where name represents the resource name, | bool | Define if we want to use the Refresh Feature for secrets +| azure-key-vault.azure-identity-enabled +| bool +| Whether the Azure Identity Authentication should be used or not + | azure-key-vault.refresh-period | string | If Refresh is enabled, this defines the interval to check the refresh event diff --git a/e2e/advanced/build_order_strategy_test.go b/e2e/advanced/build_order_strategy_test.go index 42ebe538bb..666b774c70 100644 --- a/e2e/advanced/build_order_strategy_test.go +++ b/e2e/advanced/build_order_strategy_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,80 +38,67 @@ import ( func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-build-order-deps" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--max-running-pipelines", "4", - "--build-order-strategy", string(v1.BuildOrderStrategyDependencies))).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--max-running-pipelines", "4", "--build-order-strategy", string(v1.BuildOrderStrategyDependencies))).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(CreateTimerKamelet(t, operatorID, ns, "timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "timer-source")()).To(Succeed()) integrationA := RandomizedSuffixName("java-a") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", integrationA, - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationA).Execute()).To(Succeed()) - g.Eventually(IntegrationKit(t, ns, integrationA), TestTimeoutMedium).ShouldNot(BeEmpty()) - integrationKitNameA := IntegrationKit(t, ns, integrationA)() - g.Eventually(Build(t, ns, integrationKitNameA), TestTimeoutMedium).ShouldNot(BeNil()) + g.Eventually(IntegrationKit(t, ctx, ns, integrationA), TestTimeoutMedium).ShouldNot(BeEmpty()) + integrationKitNameA := IntegrationKit(t, ctx, ns, integrationA)() + g.Eventually(Build(t, ctx, ns, integrationKitNameA), TestTimeoutMedium).ShouldNot(BeNil()) integrationB := RandomizedSuffixName("java-b") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", integrationB, - "-d", "camel:cron", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationB, "-d", "camel:cron").Execute()).To(Succeed()) integrationC := RandomizedSuffixName("java-c") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", integrationC, - "-d", "camel:cron", - "-d", "camel:zipfile", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationC, "-d", "camel:cron", "-d", "camel:zipfile").Execute()).To(Succeed()) integrationZ := RandomizedSuffixName("groovy-z") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-source.groovy", - "--name", integrationZ, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationKit(t, ns, integrationB), TestTimeoutMedium).ShouldNot(BeEmpty()) - g.Eventually(IntegrationKit(t, ns, integrationC), TestTimeoutMedium).ShouldNot(BeEmpty()) - g.Eventually(IntegrationKit(t, ns, integrationZ), TestTimeoutMedium).ShouldNot(BeEmpty()) - - integrationKitNameB := IntegrationKit(t, ns, integrationB)() - integrationKitNameC := IntegrationKit(t, ns, integrationC)() - integrationKitNameZ := IntegrationKit(t, ns, integrationZ)() - - g.Eventually(BuildPhase(t, ns, integrationKitNameA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationA), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationA, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationA), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameA)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - - g.Eventually(BuildPhase(t, ns, integrationKitNameB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationB), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationB, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationB), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameB)().Status.BaseImage).Should(ContainSubstring(integrationKitNameA)) - - g.Eventually(BuildPhase(t, ns, integrationKitNameC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationC), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationC, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationC), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameC)().Status.BaseImage).Should(ContainSubstring(integrationKitNameB)) - - g.Eventually(BuildPhase(t, ns, integrationKitNameZ), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationZ), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationZ, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationZ), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameZ)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - - buildA := Build(t, ns, integrationKitNameA)() - buildB := Build(t, ns, integrationKitNameB)() - buildC := Build(t, ns, integrationKitNameC)() - buildZ := Build(t, ns, integrationKitNameZ)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.groovy", "--name", integrationZ).Execute()).To(Succeed()) + + g.Eventually(IntegrationKit(t, ctx, ns, integrationB), TestTimeoutMedium).ShouldNot(BeEmpty()) + g.Eventually(IntegrationKit(t, ctx, ns, integrationC), TestTimeoutMedium).ShouldNot(BeEmpty()) + g.Eventually(IntegrationKit(t, ctx, ns, integrationZ), TestTimeoutMedium).ShouldNot(BeEmpty()) + + integrationKitNameB := IntegrationKit(t, ctx, ns, integrationB)() + integrationKitNameC := IntegrationKit(t, ctx, ns, integrationC)() + integrationKitNameZ := IntegrationKit(t, ctx, ns, integrationZ)() + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationA), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationA, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationA), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameA)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationB), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationB, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationB), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameB)().Status.BaseImage).Should(ContainSubstring(integrationKitNameA)) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationC), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationC, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationC), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameC)().Status.BaseImage).Should(ContainSubstring(integrationKitNameB)) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameZ), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationZ), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationZ, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationZ), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameZ)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + + buildA := Build(t, ctx, ns, integrationKitNameA)() + buildB := Build(t, ctx, ns, integrationKitNameB)() + buildC := Build(t, ctx, ns, integrationKitNameC)() + buildZ := Build(t, ctx, ns, integrationKitNameZ)() g.Expect(buildA.Status.StartedAt.Before(buildB.Status.StartedAt)).Should(BeTrue()) g.Expect(buildA.Status.StartedAt.Before(buildC.Status.StartedAt)).Should(BeTrue()) @@ -118,66 +106,66 @@ func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) { g.Expect(buildZ.Status.StartedAt.Before(buildB.Status.StartedAt)).Should(BeTrue()) g.Expect(buildZ.Status.StartedAt.Before(buildC.Status.StartedAt)).Should(BeTrue()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } /* func TestRunBuildOrderStrategyFIFO(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {x operatorID := "camel-k-build-order-fifo" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--build-order-strategy", string(v1.BuildOrderStrategyFIFO)).Execute()).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--build-order-strategy", string(v1.BuildOrderStrategyFIFO)).Execute()).To(Succeed()) g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(CreateTimerKamelet(t, ns, "timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, ns, "timer-source")()).To(Succeed()) integrationA := RandomizedSuffixName("java-a") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationA, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, integrationA)).Should(Equal(v1.IntegrationPhaseBuildingKit)) + g.Eventually(IntegrationPhase(t, ctx, ns, integrationA)).Should(Equal(v1.IntegrationPhaseBuildingKit)) integrationB := RandomizedSuffixName("java-b") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationB, "-d", "camel:joor", ).Execute()).To(Succeed()) integrationZ := RandomizedSuffixName("groovy-z") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-source.groovy", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.groovy", "--name", integrationZ, ).Execute()).To(Succeed()) - integrationKitNameA := IntegrationKit(t, ns, integrationA)() - g.Eventually(BuildPhase(t, ns, integrationKitNameA), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) - - g.Eventually(IntegrationPhase(t, ns, integrationB)).Should(Equal(v1.IntegrationPhaseBuildingKit)) - integrationKitNameB := IntegrationKit(t, ns, integrationB)() - g.Eventually(BuildPhase(t, ns, integrationKitNameB), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) - - g.Eventually(IntegrationPhase(t, ns, integrationZ)).Should(Equal(v1.IntegrationPhaseBuildingKit)) - integrationKitNameZ := IntegrationKit(t, ns, integrationZ)() - g.Eventually(BuildPhase(t, ns, integrationKitNameZ), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) - - g.Eventually(BuildPhase(t, ns, integrationKitNameA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationA), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationA, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationA), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameA)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - - g.Eventually(BuildPhase(t, ns, integrationKitNameB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationB), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationB, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationB), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameB)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - - g.Eventually(BuildPhase(t, ns, integrationKitNameZ), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(IntegrationPodPhase(t, ns, integrationZ), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, integrationZ, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, integrationZ), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, integrationKitNameZ)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + integrationKitNameA := IntegrationKit(t, ctx, ns, integrationA)() + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameA), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) + + g.Eventually(IntegrationPhase(t, ctx, ns, integrationB)).Should(Equal(v1.IntegrationPhaseBuildingKit)) + integrationKitNameB := IntegrationKit(t, ctx, ns, integrationB)() + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameB), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) + + g.Eventually(IntegrationPhase(t, ctx, ns, integrationZ)).Should(Equal(v1.IntegrationPhaseBuildingKit)) + integrationKitNameZ := IntegrationKit(t, ctx, ns, integrationZ)() + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameZ), TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning)) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationA), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationA, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationA), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameA)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationB), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationB, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationB), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameB)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + + g.Eventually(BuildPhase(t, ctx, ns, integrationKitNameZ), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationZ), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationZ, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationZ), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Kit(t, ctx, ns, integrationKitNameZ)().Status.BaseImage).Should(Equal(defaults.BaseImage())) g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) diff --git a/e2e/advanced/builder_test.go b/e2e/advanced/builder_test.go index d18100be63..c5a0919aca 100644 --- a/e2e/advanced/builder_test.go +++ b/e2e/advanced/builder_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "testing" "time" @@ -38,50 +39,48 @@ import ( func TestBuilderTimeout(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) - g.Eventually(PlatformConditionStatus(t, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(PlatformConditionStatus(t, ctx, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() // set a short timeout to simulate the build timeout pl.Spec.Build.Timeout = &metav1.Duration{ Duration: 10 * time.Second, } - TestClient(t).Update(TestContext, pl) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) - g.Eventually(PlatformTimeout(t, ns)).Should(Equal( + TestClient(t).Update(ctx, pl) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(PlatformTimeout(t, ctx, ns)).Should(Equal( &metav1.Duration{ Duration: 10 * time.Second, }, )) - operatorPod := OperatorPod(t, ns)() + operatorPod := OperatorPod(t, ctx, ns)() operatorPodImage := operatorPod.Spec.Containers[0].Image t.Run("run yaml", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", - "--name", name, - "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) // As the build hits timeout, it keeps trying building - g.Eventually(IntegrationPhase(t, ns, name)).Should(Equal(v1.IntegrationPhaseBuildingKit)) - integrationKitName := IntegrationKit(t, ns, name)() + g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseBuildingKit)) + integrationKitName := IntegrationKit(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuilderPodPhase(t, ns, builderKitName)).Should(Equal(corev1.PodPending)) - g.Eventually(BuildPhase(t, ns, integrationKitName)).Should(Equal(v1.BuildPhaseRunning)) - g.Eventually(BuilderPod(t, ns, builderKitName)().Spec.InitContainers[0].Name).Should(Equal("builder")) - g.Eventually(BuilderPod(t, ns, builderKitName)().Spec.InitContainers[0].Image).Should(Equal(operatorPodImage)) + g.Eventually(BuilderPodPhase(t, ctx, ns, builderKitName)).Should(Equal(corev1.PodPending)) + g.Eventually(BuildPhase(t, ctx, ns, integrationKitName)).Should(Equal(v1.BuildPhaseRunning)) + g.Eventually(BuilderPod(t, ctx, ns, builderKitName)().Spec.InitContainers[0].Name).Should(Equal("builder")) + g.Eventually(BuilderPod(t, ctx, ns, builderKitName)().Spec.InitContainers[0].Image).Should(Equal(operatorPodImage)) // After a few minutes (5 max retries), this has to be in error state - g.Eventually(BuildPhase(t, ns, integrationKitName), TestTimeoutMedium).Should(Equal(v1.BuildPhaseError)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(BuildFailureRecovery(t, ns, integrationKitName), TestTimeoutMedium).Should(Equal(5)) - g.Eventually(BuilderPodPhase(t, ns, builderKitName), TestTimeoutMedium).Should(Equal(corev1.PodFailed)) + g.Eventually(BuildPhase(t, ctx, ns, integrationKitName), TestTimeoutMedium).Should(Equal(v1.BuildPhaseError)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(BuildFailureRecovery(t, ctx, ns, integrationKitName), TestTimeoutMedium).Should(Equal(5)) + g.Eventually(BuilderPodPhase(t, ctx, ns, builderKitName), TestTimeoutMedium).Should(Equal(corev1.PodFailed)) }) }) } diff --git a/e2e/advanced/catalog_builder_test.go b/e2e/advanced/catalog_builder_test.go index cd8faa52bf..7b85e0ef59 100644 --- a/e2e/advanced/catalog_builder_test.go +++ b/e2e/advanced/catalog_builder_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "strings" "testing" @@ -38,18 +39,18 @@ import ( func TestCamelCatalogBuilder(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) - g.Eventually(PlatformConditionStatus(t, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(PlatformConditionStatus(t, ctx, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion)) - g.Eventually(CamelCatalog(t, ns, catalogName)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogPhase(t, ns, catalogName), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Eventually(CamelCatalog(t, ctx, ns, catalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogPhase(t, ctx, ns, catalogName), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) // Run an integration with a catalog not compatible // The operator should create the catalog, but fail on reconciliation as it is not compatible @@ -58,23 +59,21 @@ func TestCamelCatalogBuilder(t *testing.T) { name := RandomizedSuffixName("java-1-15") nonCompatibleCatalogName := "camel-catalog-1.15.0" g.Expect( - KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "camel.runtime-version=1.15.0", - ).Execute()).To(Succeed()) + KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version=1.15.0").Execute()).To(Succeed()) - g.Eventually(CamelCatalog(t, ns, nonCompatibleCatalogName)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogPhase(t, ns, nonCompatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseError)) - g.Eventually(CamelCatalogCondition(t, ns, nonCompatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("Container image tool missing in catalog")) + g.Eventually(CamelCatalog(t, ctx, ns, nonCompatibleCatalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogPhase(t, ctx, ns, nonCompatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseError)) + g.Eventually(CamelCatalogCondition(t, ctx, ns, nonCompatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("Container image tool missing in catalog")) - g.Eventually(IntegrationKit(t, ns, name)).ShouldNot(Equal("")) - kitName := IntegrationKit(t, ns, name)() - g.Eventually(KitPhase(t, ns, kitName)).Should(Equal(v1.IntegrationKitPhaseError)) - g.Eventually(KitCondition(t, ns, kitName, v1.IntegrationKitConditionCatalogAvailable)().Reason).Should(Equal("Camel Catalog 1.15.0 error")) - g.Eventually(IntegrationPhase(t, ns, name)).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionKitAvailable)().Status).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationKit(t, ctx, ns, name)).ShouldNot(Equal("")) + kitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, ns, kitName)).Should(Equal(v1.IntegrationKitPhaseError)) + g.Eventually(KitCondition(t, ctx, ns, kitName, v1.IntegrationKitConditionCatalogAvailable)().Reason).Should(Equal("Camel Catalog 1.15.0 error")) + g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionKitAvailable)().Status).Should(Equal(corev1.ConditionFalse)) // Clean up - g.Eventually(DeleteIntegrations(t, ns)).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) // Run an integration with a compatible catalog @@ -85,24 +84,22 @@ func TestCamelCatalogBuilder(t *testing.T) { compatibleCatalogName := "camel-catalog-" + strings.ToLower(compatibleVersion) // First of all we delete the catalog, if by any chance it was created previously - g.Expect(DeleteCamelCatalog(t, ns, compatibleCatalogName)()).Should(BeTrue()) - g.Eventually(CamelCatalog(t, ns, compatibleCatalogName)).Should(BeNil()) + g.Expect(DeleteCamelCatalog(t, ctx, ns, compatibleCatalogName)()).Should(BeTrue()) + g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).Should(BeNil()) g.Expect( - KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "camel.runtime-version="+compatibleVersion, - ).Execute()).To(Succeed()) - - g.Eventually(CamelCatalog(t, ns, compatibleCatalogName)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogPhase(t, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) - g.Eventually(CamelCatalogCondition(t, ns, compatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(Equal("Container image tool found in catalog")) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). + KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) + + g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogPhase(t, ctx, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Eventually(CamelCatalogCondition(t, ctx, ns, compatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(Equal("Container image tool found in catalog")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) // Clean up - g.Eventually(DeleteIntegrations(t, ns)).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) t.Run("Run catalog container exists", func(t *testing.T) { @@ -111,32 +108,30 @@ func TestCamelCatalogBuilder(t *testing.T) { compatibleCatalogName := "camel-catalog-" + strings.ToLower(compatibleVersion) // First of all we delete the catalog, if by any chance it was created previously - g.Expect(DeleteCamelCatalog(t, ns, compatibleCatalogName)()).Should(BeTrue()) - g.Eventually(CamelCatalog(t, ns, compatibleCatalogName)).Should(BeNil()) + g.Expect(DeleteCamelCatalog(t, ctx, ns, compatibleCatalogName)()).Should(BeTrue()) + g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).Should(BeNil()) g.Expect( - KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "camel.runtime-version="+compatibleVersion, - ).Execute()).To(Succeed()) + KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) - g.Eventually(CamelCatalog(t, ns, compatibleCatalogName)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogPhase(t, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) - g.Eventually(CamelCatalogCondition(t, ns, compatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should( + g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogPhase(t, ctx, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Eventually(CamelCatalogCondition(t, ctx, ns, compatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should( Equal("Container image tool found in catalog"), ) - g.Eventually(IntegrationKit(t, ns, name)).ShouldNot(Equal("")) - kitName := IntegrationKit(t, ns, name)() - g.Eventually(KitPhase(t, ns, kitName)).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(IntegrationPodPhase(t, ns, name)).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationKit(t, ctx, ns, name)).ShouldNot(Equal("")) + kitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, ns, kitName)).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name)).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Clean up - g.Eventually(DeleteIntegrations(t, ns)).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/debug_test.go b/e2e/advanced/debug_test.go index 1bee4ba18b..6806e57d55 100644 --- a/e2e/advanced/debug_test.go +++ b/e2e/advanced/debug_test.go @@ -39,68 +39,68 @@ import ( func TestKamelCLIDebug(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("debug local default port check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) g.Expect(portIsInUse("127.0.0.1", "5005")()).To(BeFalse()) - debugTestContext, cancel := context.WithCancel(TestContext) + debugTestContext, cancel := context.WithCancel(ctx) defer cancelAndWait(cancel) go KamelWithContext(t, debugTestContext, "debug", "yaml", "-n", ns).ExecuteContext(debugTestContext) g.Eventually(portIsInUse("127.0.0.1", "5005"), TestTimeoutMedium, 5*time.Second).Should(BeTrue()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("debug local port check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) g.Expect(portIsInUse("127.0.0.1", "5006")()).To(BeFalse()) - debugTestContext, cancel := context.WithCancel(TestContext) + debugTestContext, cancel := context.WithCancel(ctx) defer cancelAndWait(cancel) go KamelWithContext(t, debugTestContext, "debug", "yaml", "--port", "5006", "-n", ns).ExecuteContext(debugTestContext) g.Eventually(portIsInUse("127.0.0.1", "5006"), TestTimeoutMedium, 5*time.Second).Should(BeTrue()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("debug logs check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - debugTestContext, cancel := context.WithCancel(TestContext) + debugTestContext, cancel := context.WithCancel(ctx) defer cancelAndWait(cancel) go KamelWithContext(t, debugTestContext, "debug", "yaml", "-n", ns).ExecuteContext(debugTestContext) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutMedium).Should(ContainSubstring("Listening for transport dt_socket at address: 5005")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(ContainSubstring("Listening for transport dt_socket at address: 5005")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Pod config test", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - debugTestContext, cancel := context.WithCancel(TestContext) + debugTestContext, cancel := context.WithCancel(ctx) defer cancelAndWait(cancel) go KamelWithContext(t, debugTestContext, "debug", "yaml", "-n", ns).ExecuteContext(debugTestContext) g.Eventually(func() string { - return IntegrationPod(t, ns, "yaml")().Spec.Containers[0].Args[0] + return IntegrationPod(t, ctx, ns, "yaml")().Spec.Containers[0].Args[0] }).Should(ContainSubstring("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005")) - g.Expect(IntegrationPod(t, ns, "yaml")().GetLabels()["camel.apache.org/debug"]).To(Not(BeNil())) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(IntegrationPod(t, ctx, ns, "yaml")().GetLabels()["camel.apache.org/debug"]).To(Not(BeNil())) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/deployment_test.go b/e2e/advanced/deployment_test.go index 3d58c6eb77..ba3b931926 100644 --- a/e2e/advanced/deployment_test.go +++ b/e2e/advanced/deployment_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,12 +37,12 @@ import ( func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-failing-deploy" nsRestr := "restr" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) // Create restricted namespace ExpectExecSucceed(t, g, exec.Command( @@ -68,14 +69,14 @@ func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) { ) // Create an Integration into a restricted namespace name := RandomizedSuffixName("java-fail") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed()) // Check the error is reported into the Integration - g.Eventually(IntegrationPhase(t, nsRestr, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationCondition(t, nsRestr, name, v1.IntegrationConditionReady)().Status). + g.Eventually(IntegrationPhase(t, ctx, nsRestr, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Status). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, nsRestr, name, v1.IntegrationConditionReady)().Message). + g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Message). Should(ContainSubstring("is forbidden: violates PodSecurity")) // Clean up - g.Eventually(DeleteIntegrations(t, nsRestr)).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, nsRestr)).Should(Equal(0)) }) } diff --git a/e2e/advanced/dump_test.go b/e2e/advanced/dump_test.go index 96c218af17..37b5e0bcc7 100644 --- a/e2e/advanced/dump_test.go +++ b/e2e/advanced/dump_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "testing" @@ -37,9 +38,9 @@ import ( func TestKamelCLIDump(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("dump empty namespace", func(t *testing.T) { - dump := GetOutputString(Kamel(t, "dump", "-n", ns)) + dump := GetOutputString(Kamel(t, ctx, "dump", "-n", ns)) g.Expect(dump).To(ContainSubstring("Found 0 integrations:")) g.Expect(dump).To(ContainSubstring("Found 0 deployments:")) @@ -47,16 +48,16 @@ func TestKamelCLIDump(t *testing.T) { t.Run("dump non-empty namespace", func(t *testing.T) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "yaml")).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml")).Should(ContainSubstring("Magicstring!")) - dump := GetOutputString(Kamel(t, "dump", "-n", ns)) + dump := GetOutputString(Kamel(t, ctx, "dump", "-n", ns)) g.Expect(dump).To(ContainSubstring("Found 1 platforms")) g.Expect(dump).To(ContainSubstring("Found 1 integrations")) g.Expect(dump).To(ContainSubstring("name: yaml")) diff --git a/e2e/advanced/environment_test.go b/e2e/advanced/environment_test.go index bff92d2691..eadde81f63 100644 --- a/e2e/advanced/environment_test.go +++ b/e2e/advanced/environment_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "os" "strings" @@ -41,7 +42,7 @@ import ( func TestEnvironmentTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // HTTP proxy configuration httpProxy := "http://proxy" noProxy := []string{ @@ -52,7 +53,7 @@ func TestEnvironmentTrait(t *testing.T) { } // Retrieve the Kubernetes Service ClusterIPs to populate the NO_PROXY environment variable - svc := Service(t, TestDefaultNamespace, "kubernetes")() + svc := Service(t, ctx, TestDefaultNamespace, "kubernetes")() g.Expect(svc).NotTo(BeNil()) noProxy = append(noProxy, svc.Spec.ClusterIPs...) @@ -67,23 +68,20 @@ func TestEnvironmentTrait(t *testing.T) { // Install Camel K with the HTTP proxy environment variable operatorID := "camel-k-trait-environment" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy), - "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","), - )).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run integration with default environment", func(t *testing.T) { name := RandomizedSuffixName("java-default") - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", name, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", name, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationPod(t, ns, name)()).To(WithTransform(podEnvVars, And( + g.Expect(IntegrationPod(t, ctx, ns, name)()).To(WithTransform(podEnvVars, And( ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}), ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ @@ -104,15 +102,12 @@ func TestEnvironmentTrait(t *testing.T) { t.Run("Run integration with custom environment", func(t *testing.T) { name := RandomizedSuffixName("java-custom-proxy") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "environment.vars=HTTP_PROXY=http://custom.proxy", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(IntegrationPod(t, ns, name)()).To(WithTransform(podEnvVars, And( + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "environment.vars=HTTP_PROXY=http://custom.proxy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + g.Expect(IntegrationPod(t, ctx, ns, name)()).To(WithTransform(podEnvVars, And( ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}), ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ @@ -133,15 +128,12 @@ func TestEnvironmentTrait(t *testing.T) { t.Run("Run integration without default HTTP proxy environment", func(t *testing.T) { name := RandomizedSuffixName("java-no-proxy") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "environment.http-proxy=false", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(IntegrationPod(t, ns, name)()).To(WithTransform(podEnvVars, And( + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "environment.http-proxy=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + g.Expect(IntegrationPod(t, ctx, ns, name)()).To(WithTransform(podEnvVars, And( ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}), ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ @@ -160,15 +152,15 @@ func TestEnvironmentTrait(t *testing.T) { ))) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() envTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "environment") g.Expect(envTrait).ToNot(BeNil()) g.Expect(len(envTrait)).To(Equal(1)) g.Expect(envTrait["httpProxy"]).To(Equal(false)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/incremental_build_test.go b/e2e/advanced/incremental_build_test.go index b34f6c84bb..cdb1ba38ce 100644 --- a/e2e/advanced/incremental_build_test.go +++ b/e2e/advanced/incremental_build_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "testing" @@ -38,33 +39,29 @@ import ( func TestRunIncrementalBuildRoutine(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-incremental-build-routine" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - g.Eventually(Kit(t, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) t.Run("Reuse previous kit", func(t *testing.T) { nameClone := "java-clone" - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameClone, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationCloneKitName := IntegrationKit(t, ns, nameClone)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationCloneKitName := IntegrationKit(t, ctx, ns, nameClone)() g.Eventually(integrationCloneKitName).Should(Equal(integrationKitName)) }) @@ -72,193 +69,162 @@ func TestRunIncrementalBuildRoutine(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameIncremental, - "-d", "camel:zipfile", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationIncrementalKitName := IntegrationKit(t, ns, nameIncremental)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationIncrementalKitName := IntegrationKit(t, ctx, ns, nameIncremental)() // the container comes in a format like // 10.108.177.66/test-d7cad110-bb1d-4e79-8a0e-ebd44f6fe5d4/camel-k-kit-c8357r4k5tp6fn1idm60@sha256:d49716f0429ad8b23a1b8d20a357d64b1aa42a67c1a2a534ebd4c54cd598a18d // we should be saving just to check the substring is contained - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRunIncrementalBuildPod(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-incremental-build-pod" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - g.Eventually(Kit(t, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) - g.Eventually(BuilderPodsCount(t, ns)).Should(Equal(1)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Eventually(BuilderPodsCount(t, ctx, ns)).Should(Equal(1)) t.Run("Reuse previous kit", func(t *testing.T) { nameClone := RandomizedSuffixName("java-clone") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameClone, - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationCloneKitName := IntegrationKit(t, ns, nameClone)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone, "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationCloneKitName := IntegrationKit(t, ctx, ns, nameClone)() g.Eventually(integrationCloneKitName).Should(Equal(integrationKitName)) - g.Eventually(BuilderPodsCount(t, ns)).Should(Equal(1)) + g.Eventually(BuilderPodsCount(t, ctx, ns)).Should(Equal(1)) }) t.Run("Create incremental kit", func(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameIncremental, - "-d", "camel:zipfile", - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationIncrementalKitName := IntegrationKit(t, ns, nameIncremental)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationIncrementalKitName := IntegrationKit(t, ctx, ns, nameIncremental)() // the container comes in a format like // 10.108.177.66/test-d7cad110-bb1d-4e79-8a0e-ebd44f6fe5d4/camel-k-kit-c8357r4k5tp6fn1idm60@sha256:d49716f0429ad8b23a1b8d20a357d64b1aa42a67c1a2a534ebd4c54cd598a18d // we should be saving just to check the substring is contained - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) - g.Eventually(BuilderPodsCount(t, ns)).Should(Equal(2)) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Eventually(BuilderPodsCount(t, ctx, ns)).Should(Equal(2)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRunIncrementalBuildOff(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-standard-build" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) t.Run("Don't reuse previous kit", func(t *testing.T) { nameClone := RandomizedSuffixName("java-clone") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameClone, - "-t", "builder.incremental-image-build=false", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationCloneKitName := IntegrationKit(t, ns, nameClone)() - g.Eventually(Kit(t, ns, integrationCloneKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone, "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationCloneKitName := IntegrationKit(t, ctx, ns, nameClone)() + g.Eventually(Kit(t, ctx, ns, integrationCloneKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) }) t.Run("Don't create incremental kit", func(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameIncremental, - "-d", "camel:zipfile", - "-t", "builder.incremental-image-build=false", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationIncrementalKitName := IntegrationKit(t, ns, nameIncremental)() - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationIncrementalKitName := IntegrationKit(t, ctx, ns, nameIncremental)() + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-incremental-different-base" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - g.Eventually(Kit(t, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) t.Run("Create incremental kit", func(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", nameIncremental, - "-d", "camel:zipfile", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationIncrementalKitName := IntegrationKit(t, ns, nameIncremental)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationIncrementalKitName := IntegrationKit(t, ctx, ns, nameIncremental)() // the container comes in a format like // 10.108.177.66/test-d7cad110-bb1d-4e79-8a0e-ebd44f6fe5d4/camel-k-kit-c8357r4k5tp6fn1idm60@sha256:d49716f0429ad8b23a1b8d20a357d64b1aa42a67c1a2a534ebd4c54cd598a18d // we should be save just to check the substring is contained - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) - g.Eventually(Kit(t, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) + g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) }) t.Run("Create new hierarchy kit", func(t *testing.T) { // We should spin off a new hierarchy of builds newBaseImage := "eclipse-temurin:17.0.8.1_1-jdk-ubi9-minimal" name = RandomizedSuffixName("java-new") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-d", "camel:mongodb", - "-t", fmt.Sprintf("builder.base-image=%s", newBaseImage), - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName = IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(newBaseImage)) - g.Eventually(Kit(t, ns, integrationKitName)().Status.RootImage).Should(Equal(newBaseImage)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-d", "camel:mongodb", "-t", fmt.Sprintf("builder.base-image=%s", newBaseImage)).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKitName = IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(newBaseImage)) + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(newBaseImage)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/integration_profile_test.go b/e2e/advanced/integration_profile_test.go index 422490ecd4..0a14026e23 100644 --- a/e2e/advanced/integration_profile_test.go +++ b/e2e/advanced/integration_profile_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" "github.com/apache/camel-k/v2/pkg/util/defaults" @@ -38,10 +39,10 @@ import ( func TestIntegrationProfile(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-integration-profile" - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) @@ -50,44 +51,44 @@ func TestIntegrationProfile(t *testing.T) { LimitCPU: "0.2", } - g.Expect(CreateIntegrationProfile(t, &integrationProfile)).To(Succeed()) - g.Eventually(SelectedIntegrationProfilePhase(t, ns, "ipr-global"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) + g.Expect(CreateIntegrationProfile(t, ctx, &integrationProfile)).To(Succeed()) + g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns, "ipr-global"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) - WithNewTestNamespace(t, func(g *WithT, ns1 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns1 string) { integrationProfile := v1.NewIntegrationProfile(ns1, "ipr-local") integrationProfile.SetOperatorID(operatorID) integrationProfile.Spec.Traits.Container = &traitv1.ContainerTrait{ LimitCPU: "0.1", } - g.Expect(CreateIntegrationProfile(t, &integrationProfile)).To(Succeed()) - g.Eventually(SelectedIntegrationProfilePhase(t, ns1, "ipr-local"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) + g.Expect(CreateIntegrationProfile(t, ctx, &integrationProfile)).To(Succeed()) + g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns1, "ipr-local"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) t.Run("Run integration with global integration profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodHas(t, ns1, "limited", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPod(t, ctx, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } containerName := pod.Spec.Containers[0].Name return containerName == "ck-integration-global" }), TestTimeoutShort).Should(BeTrue()) - g.Eventually(IntegrationPodHas(t, ns1, "limited", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } cpuLimits := pod.Spec.Containers[0].Resources.Limits.Cpu() return cpuLimits != nil && cpuLimits.AsApproximateFloat64() > 0 }), TestTimeoutShort).Should(BeTrue()) - g.Expect(Kamel(t, "delete", "limited", "-n", ns1).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "limited", "-n", ns1).Execute()).To(Succeed()) }) t.Run("Run integration with namespace local integration profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-local", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-local", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodHas(t, ns1, "limited", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPod(t, ctx, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -95,20 +96,20 @@ func TestIntegrationProfile(t *testing.T) { return containerName == "integration" }), TestTimeoutShort).Should(BeTrue()) - g.Eventually(IntegrationPodHas(t, ns1, "limited", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } cpuLimits := pod.Spec.Containers[0].Resources.Limits.Cpu() return cpuLimits != nil && cpuLimits.AsApproximateFloat64() > 0 }), TestTimeoutShort).Should(BeTrue()) - g.Expect(Kamel(t, "delete", "limited", "-n", ns1).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "limited", "-n", ns1).Execute()).To(Succeed()) }) t.Run("Run integration without integration profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns1, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns1, "normal"), TestTimeoutShort).Should(Not(BeNil())) - g.Eventually(IntegrationPodHas(t, ns1, "normal", func(pod *corev1.Pod) bool { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPod(t, ctx, ns1, "normal"), TestTimeoutShort).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns1, "normal", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -118,7 +119,7 @@ func TestIntegrationProfile(t *testing.T) { }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns1).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns1).Execute()).To(Succeed()) }) }) } @@ -126,10 +127,10 @@ func TestIntegrationProfile(t *testing.T) { func TestIntegrationProfileInfluencesKit(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-ipr-kit" - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) @@ -137,44 +138,44 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) { Properties: []string{"b1=foo"}, } - g.Expect(CreateIntegrationProfile(t, &integrationProfile)).To(Succeed()) - g.Eventually(SelectedIntegrationProfilePhase(t, ns, "ipr-global"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) + g.Expect(CreateIntegrationProfile(t, ctx, &integrationProfile)).To(Succeed()) + g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns, "ipr-global"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns, "normal"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodPhase(t, ns, "normal"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "normal", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "normal"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPod(t, ctx, ns, "normal"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "normal"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "normal", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "normal"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Verify that a new kit has been built based on the default base image - integrationKitName := IntegrationKit(t, ns, "normal")() - g.Eventually(Kit(t, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - g.Eventually(Kit(t, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) + integrationKitName := IntegrationKit(t, ctx, ns, "normal")() + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", "simple", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "simple", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns, "simple"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodPhase(t, ns, "simple"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "simple", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "simple"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPod(t, ctx, ns, "simple"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "simple"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "simple", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "simple"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Verify that a new kit has been built based on the previous kit - integrationKitNameWithProfile := IntegrationKit(t, ns, "simple")() + integrationKitNameWithProfile := IntegrationKit(t, ctx, ns, "simple")() g.Eventually(integrationKitNameWithProfile).ShouldNot(Equal(integrationKitName)) - g.Eventually(Kit(t, ns, integrationKitNameWithProfile)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) - g.Eventually(Kit(t, ns, integrationKitNameWithProfile)().Status.RootImage).Should(Equal(defaults.BaseImage())) + g.Eventually(Kit(t, ctx, ns, integrationKitNameWithProfile)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) + g.Eventually(Kit(t, ctx, ns, integrationKitNameWithProfile)().Status.RootImage).Should(Equal(defaults.BaseImage())) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestPropagateIntegrationProfileChanges(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-ipr-changes" - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) integrationProfile := v1.NewIntegrationProfile(ns, "debug-profile") integrationProfile.SetOperatorID(operatorID) @@ -185,13 +186,13 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) { Level: "DEBUG", } - g.Expect(CreateIntegrationProfile(t, &integrationProfile)).To(Succeed()) - g.Eventually(SelectedIntegrationProfilePhase(t, ns, "debug-profile"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) + g.Expect(CreateIntegrationProfile(t, ctx, &integrationProfile)).To(Succeed()) + g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns, "debug-profile"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", "simple", "--integration-profile", "debug-profile", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "simple", "--integration-profile", "debug-profile", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns, "simple"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodHas(t, ns, "simple", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPod(t, ctx, ns, "simple"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns, "simple", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -199,13 +200,13 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) { return containerName == "ck-ipr" }), TestTimeoutShort).Should(BeTrue()) - g.Expect(UpdateIntegrationProfile(t, ns, func(ipr *v1.IntegrationProfile) { + g.Expect(UpdateIntegrationProfile(t, ctx, ns, func(ipr *v1.IntegrationProfile) { ipr.Spec.Traits.Container = &traitv1.ContainerTrait{ Name: "ck-ipr-new", } })).To(Succeed()) - g.Eventually(IntegrationPodHas(t, ns, "simple", func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns, "simple", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -214,6 +215,6 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) { }), TestTimeoutShort).Should(BeTrue()) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/kamelet_repo_test.go b/e2e/advanced/kamelet_repo_test.go index fd9e3502bf..d85a2c2bb4 100644 --- a/e2e/advanced/kamelet_repo_test.go +++ b/e2e/advanced/kamelet_repo_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "testing" @@ -36,37 +37,31 @@ import ( func TestKameletFromCustomRepository(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) kameletName := "timer-custom-source" - removeKamelet(t, kameletName, ns) + removeKamelet(t, ctx, kameletName, ns) - g.Eventually(Kamelet(t, kameletName, ns)).Should(BeNil()) + g.Eventually(Kamelet(t, ctx, kameletName, ns)).Should(BeNil()) // Add the custom repository - g.Expect(Kamel(t, "kamelet", "add-repo", - "github:squakez/ck-kamelet-test-repo/kamelets", - "-n", ns, - "-x", operatorID).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "kamelet", "add-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns, "-x", operatorID).Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerCustomKameletIntegration.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "timer-custom-kamelet-integration"), TestTimeoutLong). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerCustomKameletIntegration.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-custom-kamelet-integration"), TestTimeoutLong). Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "timer-custom-kamelet-integration")).Should(ContainSubstring("hello world")) + g.Eventually(IntegrationLogs(t, ctx, ns, "timer-custom-kamelet-integration")).Should(ContainSubstring("hello world")) // Remove the custom repository - g.Expect(Kamel(t, "kamelet", "remove-repo", - "github:squakez/ck-kamelet-test-repo/kamelets", - "-n", ns, - "-x", operatorID).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "kamelet", "remove-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns, "-x", operatorID).Execute()).To(Succeed()) }) } -func removeKamelet(t *testing.T, name string, ns string) { - kamelet := Kamelet(t, name, ns)() - TestClient(t).Delete(TestContext, kamelet) +func removeKamelet(t *testing.T, ctx context.Context, name string, ns string) { + kamelet := Kamelet(t, ctx, name, ns)() + TestClient(t).Delete(ctx, kamelet) } diff --git a/e2e/advanced/local_platform_test.go b/e2e/advanced/local_platform_test.go index 1b6923d91d..ec03d1317a 100644 --- a/e2e/advanced/local_platform_test.go +++ b/e2e/advanced/local_platform_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,29 +37,29 @@ import ( func TestLocalPlatform(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-platform-local" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(UpdatePlatform(t, ns, operatorID, func(pl *v1.IntegrationPlatform) { + g.Expect(UpdatePlatform(t, ctx, ns, operatorID, func(pl *v1.IntegrationPlatform) { pl.Spec.Build.Maven.Properties = make(map[string]string) pl.Spec.Build.Maven.Properties["build-global-prop1"] = "build-global-value1" // set maximum number of running builds pl.Spec.Build.MaxRunningBuilds = 1 })).To(Succeed()) - g.Eventually(PlatformHas(t, ns, func(pl *v1.IntegrationPlatform) bool { + g.Eventually(PlatformHas(t, ctx, ns, func(pl *v1.IntegrationPlatform) bool { return pl.Status.Build.MaxRunningBuilds == 1 }), TestTimeoutMedium).Should(BeTrue()) - WithNewTestNamespace(t, func(g *WithT, ns1 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns1 string) { // Install platform (use the installer to get staging if present) - g.Expect(KamelInstallWithID(t, "local-platform", ns1, "--skip-operator-setup")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, "local-platform", ns1, "--skip-operator-setup")).To(Succeed()) - g.Expect(UpdatePlatform(t, ns1, "local-platform", func(pl *v1.IntegrationPlatform) { + g.Expect(UpdatePlatform(t, ctx, ns1, "local-platform", func(pl *v1.IntegrationPlatform) { pl.Spec.Build.Maven.Properties = make(map[string]string) pl.Spec.Build.Maven.Properties["build-local-prop1"] = "build-local-value1" pl.SetOperatorID(operatorID) @@ -68,17 +69,17 @@ func TestLocalPlatform(t *testing.T) { } })).To(Succeed()) - g.Eventually(PlatformPhase(t, ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(PlatformHas(t, ns1, func(pl *v1.IntegrationPlatform) bool { + g.Eventually(PlatformPhase(t, ctx, ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformHas(t, ctx, ns1, func(pl *v1.IntegrationPlatform) bool { return pl.Status.Cluster != "" }), TestTimeoutShort).Should(BeTrue()) - g.Eventually(PlatformHas(t, ns1, func(pl *v1.IntegrationPlatform) bool { + g.Eventually(PlatformHas(t, ctx, ns1, func(pl *v1.IntegrationPlatform) bool { return pl.Status.Build.MaxRunningBuilds == 1 }), TestTimeoutShort).Should(BeTrue()) - pl := PlatformByName(t, ns, operatorID)() - local := Platform(t, ns1)() + pl := PlatformByName(t, ctx, ns, operatorID)() + local := Platform(t, ctx, ns1)() g.Expect(local.Status.Build.PublishStrategy).To(Equal(pl.Status.Build.PublishStrategy)) g.Expect(local.Status.Build.BuildConfiguration.Strategy).To(Equal(pl.Status.Build.BuildConfiguration.Strategy)) g.Expect(local.Status.Build.BuildConfiguration.OrderStrategy).To(Equal(pl.Status.Build.BuildConfiguration.OrderStrategy)) @@ -89,9 +90,9 @@ func TestLocalPlatform(t *testing.T) { g.Expect(local.Status.Build.Maven.Properties["build-global-prop1"]).To(Equal("build-global-value1")) g.Expect(local.Status.Build.Maven.Properties["build-local-prop1"]).To(Equal("build-local-value1")) - g.Expect(KamelRunWithID(t, operatorID, ns1, "--name", "local-integration", "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPod(t, ns1, "local-integration"), TestTimeoutMedium).Should(Not(BeNil())) - g.Eventually(IntegrationPodHas(t, ns1, "local-integration", func(pod *corev1.Pod) bool { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "local-integration", "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPod(t, ctx, ns1, "local-integration"), TestTimeoutMedium).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns1, "local-integration", func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -100,7 +101,7 @@ func TestLocalPlatform(t *testing.T) { }), TestTimeoutShort).Should(BeTrue()) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns1).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns1).Execute()).To(Succeed()) }) }) } diff --git a/e2e/advanced/main_test.go b/e2e/advanced/main_test.go index b579b4c7d8..dd14d866d6 100644 --- a/e2e/advanced/main_test.go +++ b/e2e/advanced/main_test.go @@ -43,33 +43,32 @@ func TestMain(m *testing.M) { } fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false") - if fastSetup != "true" { - os.Exit(m.Run()) + if fastSetup == "true" { + operatorID := platform.DefaultPlatformName + ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) + + g := NewGomega(func(message string, callerSkip ...int) { + fmt.Printf("Test fast setup failed! - %s\n", message) + }) + + var t *testing.T + g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-source"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "timer-source", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "timer-source"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) } - operatorID := platform.DefaultPlatformName - ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - - g := NewGomega(func(message string, callerSkip ...int) { - fmt.Printf("Test fast setup failed! - %s\n", message) - }) - - var t *testing.T - g.Expect(TestClient(t)).ShouldNot(BeNil()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-source.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "timer-source"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "timer-source", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "timer-source"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - os.Exit(m.Run()) } diff --git a/e2e/advanced/maven_http_proxy_test.go b/e2e/advanced/maven_http_proxy_test.go index b2e0996737..4dd7a8af2c 100644 --- a/e2e/advanced/maven_http_proxy_test.go +++ b/e2e/advanced/maven_http_proxy_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "crypto/rand" "crypto/rsa" "crypto/x509" @@ -60,7 +61,7 @@ var httpdTlsMountPath = "/etc/tls/private" func TestMavenProxy(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns) // Generate the TLS certificate @@ -114,21 +115,21 @@ func TestMavenProxy(t *testing.T) { corev1.TLSPrivateKeyKey: privateKeyPem, }, } - g.Expect(TestClient(t).Create(TestContext, secret)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, secret)).To(Succeed()) // HTTPD ConfigMap config := newHTTPDConfigMap(ns, hostname) - g.Expect(TestClient(t).Create(TestContext, config)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, config)).To(Succeed()) // HTTPD Deployment deployment := newHTTPDDeployment(ns, config.Name, secret.Name) - g.Expect(TestClient(t).Create(TestContext, deployment)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, deployment)).To(Succeed()) service := newHTTPDService(deployment) - g.Expect(TestClient(t).Create(TestContext, service)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, service)).To(Succeed()) // Wait for the Deployment to become ready - g.Eventually(Deployment(t, ns, deployment.Name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, + g.Eventually(Deployment(t, ctx, ns, deployment.Name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, Fields{ "Status": MatchFields(IgnoreExtras, Fields{ @@ -137,7 +138,7 @@ func TestMavenProxy(t *testing.T) { }), )) - svc := Service(t, TestDefaultNamespace, "kubernetes")() + svc := Service(t, ctx, TestDefaultNamespace, "kubernetes")() g.Expect(svc).NotTo(BeNil()) // It may be needed to populate the values from the cluster, machine and service network CIDRs @@ -150,11 +151,11 @@ func TestMavenProxy(t *testing.T) { // Install Camel K with the HTTP proxy operatorID := "camel-k-maven-proxy" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) olm, olmErr := olm.IsAPIAvailable(TestClient(t)) installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(t), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name()) - permission, pErr := kubernetes.CheckPermission(TestContext, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit") + permission, pErr := kubernetes.CheckPermission(ctx, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit") olmInstall := pErr == nil && olmErr == nil && inErr == nil && olm && installed && permission var defaultProxy configv1.Proxy if olmInstall { @@ -163,12 +164,12 @@ func TestMavenProxy(t *testing.T) { key := ctrl.ObjectKey{ Name: "cluster", } - g.Expect(TestClient(t).Get(TestContext, key, &defaultProxy)).To(Succeed()) + g.Expect(TestClient(t).Get(ctx, key, &defaultProxy)).To(Succeed()) newProxy := defaultProxy.DeepCopy() newProxy.Spec.HTTPProxy = fmt.Sprintf("http://%s", hostname) newProxy.Spec.NoProxy = strings.Join(noProxy, ",") - g.Expect(TestClient(t).Update(TestContext, newProxy)) + g.Expect(TestClient(t).Update(ctx, newProxy)) defer func() { // @@ -177,30 +178,24 @@ func TestMavenProxy(t *testing.T) { // does not work on some platforms, eg. OCP4 // patch := []byte(`[{"op": "replace","path": "/spec","value": {}},{"op": "replace","path": "/status","value": {}}]`) - TestClient(t).Patch(TestContext, &defaultProxy, ctrl.RawPatch(types.JSONPatchType, patch)) + TestClient(t).Patch(ctx, &defaultProxy, ctrl.RawPatch(types.JSONPatchType, patch)) }() // ENV values should be injected by the OLM - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) } else { - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), - // TODO: enable TLS for the HTTPS proxy when Maven supports it - // "--operator-env-vars", fmt.Sprintf("HTTPS_PROXY=https://%s", hostname), - // "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey, - "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","), - )).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) } - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Run the Integration name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) proxies := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -208,23 +203,23 @@ func TestMavenProxy(t *testing.T) { APIVersion: corev1.SchemeGroupVersion.String(), }, } - err = TestClient(t).List(TestContext, &proxies, + err = TestClient(t).List(ctx, &proxies, ctrl.InNamespace(ns), ctrl.MatchingLabels(deployment.Spec.Selector.MatchLabels), ) g.Expect(err).To(Succeed()) g.Expect(proxies.Items).To(HaveLen(1)) - logs := Logs(t, ns, proxies.Items[0].Name, corev1.PodLogOptions{})() + logs := Logs(t, ctx, ns, proxies.Items[0].Name, corev1.PodLogOptions{})() g.Expect(logs).NotTo(BeEmpty()) g.Expect(logs).To(ContainSubstring("\"CONNECT repo.maven.apache.org:443 HTTP/1.1\" 200")) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, deployment)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, service)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, secret)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, config)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, deployment)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, service)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, secret)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, config)).To(Succeed()) }) } diff --git a/e2e/advanced/operator_id_filtering_test.go b/e2e/advanced/operator_id_filtering_test.go index e73ea68c35..390d010c83 100644 --- a/e2e/advanced/operator_id_filtering_test.go +++ b/e2e/advanced/operator_id_filtering_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "fmt" "testing" "time" @@ -37,91 +38,89 @@ import ( func TestOperatorIDCamelCatalogReconciliation(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(DefaultCamelCatalogPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(DefaultCamelCatalogPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) }) } func TestOperatorIDFiltering(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { - WithNewTestNamespace(t, func(g *WithT, nsop1 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop1 string) { operator1 := "operator-1" - g.Expect(CopyCamelCatalog(t, nsop1, operator1)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, nsop1, operator1)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operator1, nsop1, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, nsop1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, nsop1, operator1)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, nsop1, operator1)).To(Succeed()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operator1, nsop1, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, nsop1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - WithNewTestNamespace(t, func(g *WithT, nsop2 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop2 string) { operator2 := "operator-2" - g.Expect(CopyCamelCatalog(t, nsop2, operator2)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, nsop2, operator2)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operator2, nsop2, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, nsop2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, nsop2, operator2)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, nsop2, operator2)).To(Succeed()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operator2, nsop2, "--global", "--force")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, nsop2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Operators ignore non-scoped integrations", func(t *testing.T) { - g.Expect(KamelRunWithID(t, "operator-x", ns, "files/yaml.yaml", "--name", "untouched", "--force").Execute()).To(Succeed()) - g.Consistently(IntegrationPhase(t, ns, "untouched"), 10*time.Second).Should(BeEmpty()) + g.Expect(KamelRunWithID(t, ctx, "operator-x", ns, "files/yaml.yaml", "--name", "untouched", "--force").Execute()).To(Succeed()) + g.Consistently(IntegrationPhase(t, ctx, ns, "untouched"), 10*time.Second).Should(BeEmpty()) }) t.Run("Operators run scoped integrations", func(t *testing.T) { - g.Expect(KamelRunWithID(t, "operator-x", ns, "files/yaml.yaml", "--name", "moving", "--force").Execute()).To(Succeed()) - g.Expect(AssignIntegrationToOperator(t, ns, "moving", operator1)).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, "operator-x", ns, "files/yaml.yaml", "--name", "moving", "--force").Execute()).To(Succeed()) + g.Expect(AssignIntegrationToOperator(t, ctx, ns, "moving", operator1)).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) t.Run("Operators can handoff scoped integrations", func(t *testing.T) { - g.Expect(AssignIntegrationToOperator(t, ns, "moving", operator2)).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseBuildingKit)) - g.Eventually(IntegrationPhase(t, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(AssignIntegrationToOperator(t, ctx, ns, "moving", operator2)).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseBuildingKit)) + g.Eventually(IntegrationPhase(t, ctx, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) t.Run("Operators can be deactivated after completely handing off scoped integrations", func(t *testing.T) { - g.Expect(ScaleOperator(t, nsop1, 0)).To(Succeed()) - g.Expect(Kamel(t, "rebuild", "-n", ns, "moving").Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(ScaleOperator(t, nsop1, 1)).To(Succeed()) + g.Expect(ScaleOperator(t, ctx, nsop1, 0)).To(Succeed()) + g.Expect(Kamel(t, ctx, "rebuild", "-n", ns, "moving").Execute()).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "moving"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "moving"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "moving"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(ScaleOperator(t, ctx, nsop1, 1)).To(Succeed()) }) t.Run("Operators can run scoped integrations with fixed image", func(t *testing.T) { - image := IntegrationPodImage(t, ns, "moving")() + image := IntegrationPodImage(t, ctx, ns, "moving")() g.Expect(image).NotTo(BeEmpty()) // Save resources by deleting "moving" integration - g.Expect(Kamel(t, "delete", "moving", "-n", ns).Execute()).To(Succeed()) - - g.Expect(KamelRunWithID(t, "operator-x", ns, "files/yaml.yaml", "--name", "pre-built", "--force", - "-t", fmt.Sprintf("container.image=%s", image), "-t", "jvm.enabled=true").Execute()).To(Succeed()) - g.Consistently(IntegrationPhase(t, ns, "pre-built"), 10*time.Second).Should(BeEmpty()) - g.Expect(AssignIntegrationToOperator(t, ns, "pre-built", operator2)).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "pre-built"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(Kamel(t, "delete", "pre-built", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "moving", "-n", ns).Execute()).To(Succeed()) + + g.Expect(KamelRunWithID(t, ctx, "operator-x", ns, "files/yaml.yaml", "--name", "pre-built", "--force", "-t", fmt.Sprintf("container.image=%s", image), "-t", "jvm.enabled=true").Execute()).To(Succeed()) + g.Consistently(IntegrationPhase(t, ctx, ns, "pre-built"), 10*time.Second).Should(BeEmpty()) + g.Expect(AssignIntegrationToOperator(t, ctx, ns, "pre-built", operator2)).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "pre-built"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(Kamel(t, ctx, "delete", "pre-built", "-n", ns).Execute()).To(Succeed()) }) t.Run("Operators can run scoped Pipes", func(t *testing.T) { - g.Expect(KamelBindWithID(t, "operator-x", ns, "timer-source?message=Hello", "log-sink", - "--name", "klb", "--force").Execute()).To(Succeed()) - g.Consistently(Integration(t, ns, "klb"), 10*time.Second).Should(BeNil()) - - g.Expect(AssignPipeToOperator(t, ns, "klb", operator1)).To(Succeed()) - g.Eventually(Integration(t, ns, "klb"), TestTimeoutShort).ShouldNot(BeNil()) - g.Eventually(IntegrationPhase(t, ns, "klb"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "klb"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelBindWithID(t, ctx, "operator-x", ns, "timer-source?message=Hello", "log-sink", "--name", "klb", "--force").Execute()).To(Succeed()) + g.Consistently(Integration(t, ctx, ns, "klb"), 10*time.Second).Should(BeNil()) + + g.Expect(AssignPipeToOperator(t, ctx, ns, "klb", operator1)).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "klb"), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(IntegrationPhase(t, ctx, ns, "klb"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "klb"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) }) }) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/operator_metrics_test.go b/e2e/advanced/operator_metrics_test.go index 004ce29508..376aeb0cc1 100644 --- a/e2e/advanced/operator_metrics_test.go +++ b/e2e/advanced/operator_metrics_test.go @@ -24,6 +24,7 @@ package advanced import ( "bytes" + "context" "fmt" "math" "os" @@ -58,24 +59,20 @@ func TestMetrics(t *testing.T) { t.Skip("WARNING: Test marked as problematic ... skipping") } - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { name := RandomizedSuffixName("java") operatorID := "camel-k-metrics" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--log-level", "debug")).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "prometheus.enabled=true", - "-t", "prometheus.pod-monitor=false", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--log-level", "debug")).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "prometheus.enabled=true", "-t", "prometheus.pod-monitor=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() g.Expect(pod).NotTo(BeNil()) // pod.Namespace could be different from ns if using global operator @@ -83,19 +80,19 @@ func TestMetrics(t *testing.T) { logOptions := &corev1.PodLogOptions{ Container: "camel-k-operator", } - logs, err := StructuredLogs(t, pod.Namespace, pod.Name, logOptions, false) + logs, err := StructuredLogs(t, ctx, pod.Namespace, pod.Name, logOptions, false) g.Expect(err).To(BeNil()) g.Expect(logs).NotTo(BeEmpty()) response, err := TestClient(t).CoreV1().RESTClient().Get(). - AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/metrics", pod.Namespace, pod.Name)).DoRaw(TestContext) + AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/metrics", pod.Namespace, pod.Name)).DoRaw(ctx) g.Expect(err).To(BeNil()) metrics, err := parsePrometheusData(response) g.Expect(err).To(BeNil()) - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() g.Expect(it).NotTo(BeNil()) - build := Build(t, ns, it.Status.IntegrationKit.Name)() + build := Build(t, ctx, ns, it.Status.IntegrationKit.Name)() g.Expect(build).NotTo(BeNil()) t.Run("Build duration metric", func(t *testing.T) { @@ -541,7 +538,7 @@ func TestMetrics(t *testing.T) { }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/platform_traits_test.go b/e2e/advanced/platform_traits_test.go index a23c7603d4..662d1f4e18 100644 --- a/e2e/advanced/platform_traits_test.go +++ b/e2e/advanced/platform_traits_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" @@ -38,36 +39,31 @@ import ( func TestTraitOnIntegrationPlatform(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-platform-trait-test" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) containerTestName := "testname" - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - ip := Platform(t, ns)() - ip.Spec.Traits = v1.Traits{Logging: &trait.LoggingTrait{Level: "DEBUG"}, Container: &trait.ContainerTrait{Name: containerTestName}} - - if err := TestClient(t).Update(TestContext, ip); err != nil { - t.Fatal("Can't create IntegrationPlatform", err) - } - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(UpdatePlatform(t, ctx, ns, operatorID, func(ip *v1.IntegrationPlatform) { + ip.Spec.Traits = v1.Traits{Logging: &trait.LoggingTrait{Level: "DEBUG"}, Container: &trait.ContainerTrait{Name: containerTestName}} + })).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") t.Run("Run integration with platform traits", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationPod(t, ns, name)().Spec.Containers[0].Name).To(BeEquivalentTo(containerTestName)) + g.Expect(IntegrationPod(t, ctx, ns, name)().Spec.Containers[0].Name).To(BeEquivalentTo(containerTestName)) found := false - for _, env := range IntegrationPod(t, ns, name)().Spec.Containers[0].Env { + for _, env := range IntegrationPod(t, ctx, ns, name)().Spec.Containers[0].Env { if env.Name == "QUARKUS_LOG_LEVEL" { g.Expect(env.Value).To(BeEquivalentTo("DEBUG")) found = true @@ -75,9 +71,9 @@ func TestTraitOnIntegrationPlatform(t *testing.T) { } } g.Expect(found).To(BeTrue(), "Can't find QUARKUS_LOG_LEVEL ENV variable") - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("DEBUG")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("DEBUG")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) } diff --git a/e2e/advanced/promote_test.go b/e2e/advanced/promote_test.go index b03e1686e2..6491908554 100644 --- a/e2e/advanced/promote_test.go +++ b/e2e/advanced/promote_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" corev1 "k8s.io/api/core/v1" @@ -39,141 +40,137 @@ func TestKamelCLIPromote(t *testing.T) { one := int64(1) two := int64(2) // Dev environment namespace - WithNewTestNamespace(t, func(g *WithT, nsDev string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsDev string) { operatorDevID := "camel-k-cli-promote-dev" - g.Expect(CopyCamelCatalog(t, nsDev, operatorDevID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, nsDev, operatorDevID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorDevID, nsDev)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, nsDev, operatorDevID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, nsDev, operatorDevID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, nsDev, operatorDevID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorDevID, nsDev)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, nsDev, operatorDevID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Dev content configmap var cmData = make(map[string]string) cmData["my-configmap-key"] = "I am development configmap!" - CreatePlainTextConfigmap(t, nsDev, "my-cm-promote", cmData) + CreatePlainTextConfigmap(t, ctx, nsDev, "my-cm-promote", cmData) // Dev secret var secData = make(map[string]string) secData["my-secret-key"] = "very top secret development" - CreatePlainTextSecret(t, nsDev, "my-sec-promote", secData) + CreatePlainTextSecret(t, ctx, nsDev, "my-sec-promote", secData) t.Run("plain integration dev", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorDevID, nsDev, "./files/promote-route.groovy", - "--config", "configmap:my-cm-promote", - "--config", "secret:my-sec-promote", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationObservedGeneration(t, nsDev, "promote-route")).Should(Equal(&one)) + g.Expect(KamelRunWithID(t, ctx, operatorDevID, nsDev, "./files/promote-route.groovy", "--config", "configmap:my-cm-promote", "--config", "secret:my-sec-promote").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationObservedGeneration(t, ctx, nsDev, "promote-route")).Should(Equal(&one)) //g.Eventually(IntegrationConditionStatus(t, nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!")) - g.Eventually(IntegrationLogs(t, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret development")) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!")) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret development")) }) t.Run("kamelet integration dev", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorDevID, nsDev, "my-own-timer-source")()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorDevID, nsDev, "./files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsDev, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsDev, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) + g.Expect(CreateTimerKamelet(t, ctx, operatorDevID, nsDev, "my-own-timer-source")()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorDevID, nsDev, "./files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsDev, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) }) t.Run("binding dev", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorDevID, nsDev, "kb-timer-source")()).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorDevID, nsDev, "kb-timer-source", "log:info", "-p", "source.message=my-kamelet-binding-rocks").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsDev, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsDev, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks")) + g.Expect(CreateTimerKamelet(t, ctx, operatorDevID, nsDev, "kb-timer-source")()).To(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorDevID, nsDev, "kb-timer-source", "log:info", "-p", "source.message=my-kamelet-binding-rocks").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsDev, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks")) }) // Prod environment namespace - WithNewTestNamespace(t, func(g *WithT, nsProd string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsProd string) { operatorProdID := "camel-k-cli-promote-prod" - g.Expect(CopyCamelCatalog(t, nsProd, operatorProdID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, nsProd, operatorProdID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorProdID, nsProd)).To(Succeed()) - g.Eventually(PlatformPhase(t, nsProd), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, nsProd, operatorProdID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, nsProd, operatorProdID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorProdID, nsProd)).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, nsProd), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("no configmap in destination", func(t *testing.T) { - g.Expect(Kamel(t, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).NotTo(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).NotTo(Succeed()) }) // Prod content configmap var cmData = make(map[string]string) cmData["my-configmap-key"] = "I am production!" - CreatePlainTextConfigmap(t, nsProd, "my-cm-promote", cmData) + CreatePlainTextConfigmap(t, ctx, nsProd, "my-cm-promote", cmData) t.Run("no secret in destination", func(t *testing.T) { - g.Expect(Kamel(t, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).NotTo(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).NotTo(Succeed()) }) // Prod secret var secData = make(map[string]string) secData["my-secret-key"] = "very top secret production" - CreatePlainTextSecret(t, nsProd, "my-sec-promote", secData) + CreatePlainTextSecret(t, ctx, nsProd, "my-sec-promote", secData) t.Run("plain integration promotion", func(t *testing.T) { - g.Expect(Kamel(t, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed()) - g.Eventually(IntegrationObservedGeneration(t, nsProd, "promote-route")).Should(Equal(&one)) - g.Eventually(IntegrationPodPhase(t, nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production!")) - g.Eventually(IntegrationLogs(t, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret production")) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed()) + g.Eventually(IntegrationObservedGeneration(t, ctx, nsProd, "promote-route")).Should(Equal(&one)) + g.Eventually(IntegrationPodPhase(t, ctx, nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production!")) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret production")) // They must use the same image - g.Expect(IntegrationPodImage(t, nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(t, nsDev, "promote-route")())) + g.Expect(IntegrationPodImage(t, ctx, nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(t, ctx, nsDev, "promote-route")())) }) t.Run("plain integration promotion update", func(t *testing.T) { // We need to update the Integration CR in order the operator to restart it both in dev and prod envs - g.Expect(KamelRunWithID(t, operatorDevID, nsDev, "./files/promote-route-edited.groovy", "--name", "promote-route", - "--config", "configmap:my-cm-promote").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorDevID, nsDev, "./files/promote-route-edited.groovy", "--name", "promote-route", "--config", "configmap:my-cm-promote").Execute()).To(Succeed()) // The generation has to be incremented - g.Eventually(IntegrationObservedGeneration(t, nsDev, "promote-route")).Should(Equal(&two)) - g.Eventually(IntegrationPodPhase(t, nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!")) + g.Eventually(IntegrationObservedGeneration(t, ctx, nsDev, "promote-route")).Should(Equal(&two)) + g.Eventually(IntegrationPodPhase(t, ctx, nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!")) // Update the configmap only in prod var cmData = make(map[string]string) cmData["my-configmap-key"] = "I am production, but I was updated!" - UpdatePlainTextConfigmap(t, nsProd, "my-cm-promote", cmData) + UpdatePlainTextConfigmap(t, ctx, nsProd, "my-cm-promote", cmData) // Promote the edited Integration - g.Expect(Kamel(t, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed()) // The generation has to be incremented also in prod - g.Eventually(IntegrationObservedGeneration(t, nsDev, "promote-route")).Should(Equal(&two)) - g.Eventually(IntegrationPodPhase(t, nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production, but I was updated!")) + g.Eventually(IntegrationObservedGeneration(t, ctx, nsDev, "promote-route")).Should(Equal(&two)) + g.Eventually(IntegrationPodPhase(t, ctx, nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production, but I was updated!")) // They must use the same image - g.Expect(IntegrationPodImage(t, nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(t, nsDev, "promote-route")())) + g.Expect(IntegrationPodImage(t, ctx, nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(t, ctx, nsDev, "promote-route")())) }) t.Run("no kamelet in destination", func(t *testing.T) { - g.Expect(Kamel(t, "promote", "-n", nsDev, "timer-kamelet-usage", "--to", nsProd).Execute()).NotTo(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "timer-kamelet-usage", "--to", nsProd).Execute()).NotTo(Succeed()) }) t.Run("kamelet integration promotion", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorProdID, nsProd, "my-own-timer-source")()).To(Succeed()) - g.Expect(Kamel(t, "promote", "-n", nsDev, "timer-kamelet-usage", "--to", nsProd).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsProd, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsProd, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) + g.Expect(CreateTimerKamelet(t, ctx, operatorProdID, nsProd, "my-own-timer-source")()).To(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "timer-kamelet-usage", "--to", nsProd).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsProd, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) // They must use the same image - g.Expect(IntegrationPodImage(t, nsProd, "timer-kamelet-usage")()).Should(Equal(IntegrationPodImage(t, nsDev, "timer-kamelet-usage")())) + g.Expect(IntegrationPodImage(t, ctx, nsProd, "timer-kamelet-usage")()).Should(Equal(IntegrationPodImage(t, ctx, nsDev, "timer-kamelet-usage")())) }) t.Run("no kamelet for binding in destination", func(t *testing.T) { - g.Expect(Kamel(t, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).NotTo(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).NotTo(Succeed()) }) t.Run("binding promotion", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorProdID, nsProd, "kb-timer-source")()).To(Succeed()) - g.Expect(Kamel(t, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsProd, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks")) + g.Expect(CreateTimerKamelet(t, ctx, operatorProdID, nsProd, "kb-timer-source")()).To(Succeed()) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsProd, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks")) // They must use the same image - g.Expect(IntegrationPodImage(t, nsProd, "kb-timer-source-to-log")()).Should(Equal(IntegrationPodImage(t, nsDev, "kb-timer-source-to-log")())) + g.Expect(IntegrationPodImage(t, ctx, nsProd, "kb-timer-source-to-log")()).Should(Equal(IntegrationPodImage(t, ctx, nsDev, "kb-timer-source-to-log")())) //Binding update - g.Expect(KamelBindWithID(t, operatorDevID, nsDev, "kb-timer-source", "log:info", "-p", "source.message=my-kamelet-binding-rocks-again").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsDev, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsDev, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again")) - g.Expect(Kamel(t, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, nsProd, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again")) + g.Expect(KamelBindWithID(t, ctx, operatorDevID, nsDev, "kb-timer-source", "log:info", "-p", "source.message=my-kamelet-binding-rocks-again").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsDev, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsDev, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again")) + g.Expect(Kamel(t, ctx, "promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, nsProd, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again")) }) }) }) diff --git a/e2e/advanced/reset_test.go b/e2e/advanced/reset_test.go index 6b0773dc81..8724addcdb 100644 --- a/e2e/advanced/reset_test.go +++ b/e2e/advanced/reset_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -35,60 +36,60 @@ import ( func TestKamelReset(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-cli-reset" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Reset the whole platform", func(t *testing.T) { name := RandomizedSuffixName("yaml1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, IntegrationKit(t, ns, name)())).Should(Not(BeNil())) - g.Eventually(Integration(t, ns, name)).Should(Not(BeNil())) + g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) + g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, "reset", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns).Execute()).To(Succeed()) - g.Expect(Integration(t, ns, name)()).To(BeNil()) - g.Expect(Kits(t, ns)()).To(HaveLen(0)) + g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) + g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) t.Run("Reset skip-integrations", func(t *testing.T) { name := RandomizedSuffixName("yaml2") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Kit(t, ns, IntegrationKit(t, ns, name)())).Should(Not(BeNil())) - g.Eventually(Integration(t, ns, name)).Should(Not(BeNil())) + g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) + g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, "reset", "-n", ns, "--skip-integrations").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-integrations").Execute()).To(Succeed()) - g.Expect(Integration(t, ns, name)()).To(Not(BeNil())) - g.Expect(Kits(t, ns)()).To(HaveLen(0)) + g.Expect(Integration(t, ctx, ns, name)()).To(Not(BeNil())) + g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) t.Run("Reset skip-kits", func(t *testing.T) { name := RandomizedSuffixName("yaml3") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - kitName := IntegrationKit(t, ns, name)() - g.Eventually(Kit(t, ns, kitName)).Should(Not(BeNil())) - g.Eventually(Integration(t, ns, name)).Should(Not(BeNil())) + kitName := IntegrationKit(t, ctx, ns, name)() + g.Eventually(Kit(t, ctx, ns, kitName)).Should(Not(BeNil())) + g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, "reset", "-n", ns, "--skip-kits").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-kits").Execute()).To(Succeed()) - g.Expect(Integration(t, ns, name)()).To(BeNil()) - g.Expect(Kit(t, ns, kitName)()).To(Not(BeNil())) + g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) + g.Expect(Kit(t, ctx, ns, kitName)()).To(Not(BeNil())) }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/synthetic_test.go b/e2e/advanced/synthetic_test.go index f6282dd0a9..4ed0d84134 100644 --- a/e2e/advanced/synthetic_test.go +++ b/e2e/advanced/synthetic_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,17 +38,17 @@ import ( func TestSyntheticIntegrationOff(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // Install Camel K without synthetic Integration feature variable (default) operatorID := "camel-k-synthetic-env-off" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Run the external deployment ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/deploy.yaml", "-n", ns)) - g.Eventually(DeploymentCondition(t, ns, "my-camel-sb-svc", appsv1.DeploymentProgressing), TestTimeoutShort). + g.Eventually(DeploymentCondition(t, ctx, ns, "my-camel-sb-svc", appsv1.DeploymentProgressing), TestTimeoutShort). Should(MatchFields(IgnoreExtras, Fields{ "Status": Equal(corev1.ConditionTrue), "Reason": Equal("NewReplicaSetAvailable"), @@ -55,24 +56,24 @@ func TestSyntheticIntegrationOff(t *testing.T) { // Label the deployment --> Verify the Integration is not created ExpectExecSucceed(t, g, Kubectl("label", "deploy", "my-camel-sb-svc", "camel.apache.org/integration=my-it", "-n", ns)) - g.Eventually(Integration(t, ns, "my-it"), TestTimeoutShort).Should(BeNil()) + g.Eventually(Integration(t, ctx, ns, "my-it"), TestTimeoutShort).Should(BeNil()) }) } func TestSyntheticIntegrationFromDeployment(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // Install Camel K with the synthetic Integration feature variable operatorID := "camel-k-synthetic-env" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", "CAMEL_K_SYNTHETIC_INTEGRATIONS=true", )).To(Succeed()) // Run the external deployment ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/deploy.yaml", "-n", ns)) - g.Eventually(DeploymentCondition(t, ns, "my-camel-sb-svc", appsv1.DeploymentProgressing), TestTimeoutShort). + g.Eventually(DeploymentCondition(t, ctx, ns, "my-camel-sb-svc", appsv1.DeploymentProgressing), TestTimeoutShort). Should(MatchFields(IgnoreExtras, Fields{ "Status": Equal(corev1.ConditionTrue), "Reason": Equal("NewReplicaSetAvailable"), @@ -80,47 +81,47 @@ func TestSyntheticIntegrationFromDeployment(t *testing.T) { // Label the deployment --> Verify the Integration is created (cannot still monitor) ExpectExecSucceed(t, g, Kubectl("label", "deploy", "my-camel-sb-svc", "camel.apache.org/integration=my-it", "-n", ns)) - g.Eventually(IntegrationPhase(t, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should( + g.Eventually(IntegrationPhase(t, ctx, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationCondition(t, ctx, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionMonitoringPodsAvailableReason))) // Label the deployment template --> Verify the Integration is monitored ExpectExecSucceed(t, g, Kubectl("patch", "deployment", "my-camel-sb-svc", "--patch", `{"spec": {"template": {"metadata": {"labels": {"camel.apache.org/integration": "my-it"}}}}}`, "-n", ns)) - g.Eventually(IntegrationPhase(t, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationPhase(t, ctx, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) one := int32(1) - g.Eventually(IntegrationStatusReplicas(t, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) // Delete the deployment --> Verify the Integration is eventually garbage collected ExpectExecSucceed(t, g, Kubectl("delete", "deploy", "my-camel-sb-svc", "-n", ns)) - g.Eventually(Integration(t, ns, "my-it"), TestTimeoutShort).Should(BeNil()) + g.Eventually(Integration(t, ctx, ns, "my-it"), TestTimeoutShort).Should(BeNil()) // Recreate the deployment and label --> Verify the Integration is monitored ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/deploy.yaml", "-n", ns)) ExpectExecSucceed(t, g, Kubectl("label", "deploy", "my-camel-sb-svc", "camel.apache.org/integration=my-it", "-n", ns)) ExpectExecSucceed(t, g, Kubectl("patch", "deployment", "my-camel-sb-svc", "--patch", `{"spec": {"template": {"metadata": {"labels": {"camel.apache.org/integration": "my-it"}}}}}`, "-n", ns)) - g.Eventually(IntegrationPhase(t, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationStatusReplicas(t, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) + g.Eventually(IntegrationPhase(t, ctx, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) // Remove label from the deployment --> Verify the Integration is deleted ExpectExecSucceed(t, g, Kubectl("label", "deploy", "my-camel-sb-svc", "camel.apache.org/integration-", "-n", ns)) - g.Eventually(Integration(t, ns, "my-it"), TestTimeoutShort).Should(BeNil()) + g.Eventually(Integration(t, ctx, ns, "my-it"), TestTimeoutShort).Should(BeNil()) // Add label back to the deployment --> Verify the Integration is created ExpectExecSucceed(t, g, Kubectl("label", "deploy", "my-camel-sb-svc", "camel.apache.org/integration=my-it", "-n", ns)) - g.Eventually(IntegrationPhase(t, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationStatusReplicas(t, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) + g.Eventually(IntegrationPhase(t, ctx, ns, "my-it"), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "my-it", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "my-it"), TestTimeoutShort).Should(Equal(&one)) // Scale the deployment --> verify replicas are correctly set ExpectExecSucceed(t, g, Kubectl("scale", "deploy", "my-camel-sb-svc", "--replicas", "2", "-n", ns)) two := int32(2) - g.Eventually(IntegrationStatusReplicas(t, ns, "my-it"), TestTimeoutShort).Should(Equal(&two)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "my-it"), TestTimeoutShort).Should(Equal(&two)) // Delete Integration and deployments --> verify no Integration exists any longer - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) ExpectExecSucceed(t, g, Kubectl("delete", "deploy", "my-camel-sb-svc", "-n", ns)) - g.Eventually(Integration(t, ns, "my-it"), TestTimeoutShort).Should(BeNil()) + g.Eventually(Integration(t, ctx, ns, "my-it"), TestTimeoutShort).Should(BeNil()) }) } diff --git a/e2e/advanced/tekton_test.go b/e2e/advanced/tekton_test.go index 448f4c7e0c..6edb89744c 100644 --- a/e2e/advanced/tekton_test.go +++ b/e2e/advanced/tekton_test.go @@ -23,6 +23,7 @@ limitations under the License. package advanced import ( + "context" "testing" . "github.com/onsi/gomega" @@ -35,14 +36,14 @@ import ( func TestTektonLikeBehavior(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { - g.Expect(CreateOperatorServiceAccount(t, ns)).To(Succeed()) - g.Expect(CreateOperatorRole(t, ns)).To(Succeed()) - g.Expect(CreateOperatorRoleBinding(t, ns)).To(Succeed()) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + g.Expect(CreateOperatorServiceAccount(t, ctx, ns)).To(Succeed()) + g.Expect(CreateOperatorRole(t, ctx, ns)).To(Succeed()) + g.Expect(CreateOperatorRoleBinding(t, ctx, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).Should(BeNil()) - g.Expect(CreateKamelPod(t, ns, "tekton-task", "install", "--skip-cluster-setup", "--force")).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) + g.Expect(CreateKamelPod(t, ctx, ns, "tekton-task", "install", "--skip-cluster-setup", "--force")).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) }) } diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go index 7aed010f91..0ed06c7e07 100644 --- a/e2e/builder/build_test.go +++ b/e2e/builder/build_test.go @@ -23,6 +23,7 @@ limitations under the License. package builder import ( + "context" "errors" "fmt" "testing" @@ -42,14 +43,14 @@ type kitOptions struct { } func TestKitMaxBuildLimit(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { - createOperator(t, g, ns, "8m0s", "--global", "--force") + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() // set maximum number of running builds and order strategy pl.Spec.Build.MaxRunningBuilds = 2 pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategySequential - if err := TestClient(t).Update(TestContext, pl); err != nil { + if err := TestClient(t).Update(ctx, pl); err != nil { t.Error(err) t.FailNow() } @@ -58,31 +59,31 @@ func TestKitMaxBuildLimit(t *testing.T) { buildB := "integration-b" buildC := "integration-c" - WithNewTestNamespace(t, func(g *WithT, ns1 string) { - WithNewTestNamespace(t, func(g *WithT, ns2 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns1 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns2 string) { pl1 := v1.NewIntegrationPlatform(ns1, fmt.Sprintf("camel-k-%s", ns)) pl.Spec.DeepCopyInto(&pl1.Spec) pl1.Spec.Build.Maven.Settings = v1.ValueSource{} pl1.SetOperatorID(fmt.Sprintf("camel-k-%s", ns)) - if err := TestClient(t).Create(TestContext, &pl1); err != nil { + if err := TestClient(t).Create(ctx, &pl1); err != nil { t.Error(err) t.FailNow() } - g.Eventually(PlatformPhase(t, ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformPhase(t, ctx, ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) pl2 := v1.NewIntegrationPlatform(ns2, fmt.Sprintf("camel-k-%s", ns)) pl.Spec.DeepCopyInto(&pl2.Spec) pl2.Spec.Build.Maven.Settings = v1.ValueSource{} pl2.SetOperatorID(fmt.Sprintf("camel-k-%s", ns)) - if err := TestClient(t).Create(TestContext, &pl2); err != nil { + if err := TestClient(t).Create(ctx, &pl2); err != nil { t.Error(err) t.FailNow() } - g.Eventually(PlatformPhase(t, ns2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformPhase(t, ctx, ns2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - doKitBuildInNamespace(t, g, buildA, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -92,7 +93,7 @@ func TestKitMaxBuildLimit(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildB, ns1, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildB, ns1, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -102,7 +103,7 @@ func TestKitMaxBuildLimit(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildC, ns2, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildC, ns2, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -117,41 +118,41 @@ func TestKitMaxBuildLimit(t *testing.T) { } limit := 0 - for limit < 5 && BuildPhase(t, ns, buildA)() == v1.BuildPhaseRunning { + for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ns, buildA), BuildPhase(t, ns1, buildB), BuildPhase(t, ns2, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) + g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns1, buildB), BuildPhase(t, ctx, ns2, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) limit++ } // make sure we have verified max build limit at least once if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ns, buildA)(), buildA))) + t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) t.FailNow() } // verify that all builds are successful - g.Eventually(BuildPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns1, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns1, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns1, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns1, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns2, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns2, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns2, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns2, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) }) }) }) } func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { - createOperator(t, g, ns, "8m0s", "--global", "--force") + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() // set maximum number of running builds and order strategy pl.Spec.Build.MaxRunningBuilds = 2 pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO - if err := TestClient(t).Update(TestContext, pl); err != nil { + if err := TestClient(t).Update(ctx, pl); err != nil { t.Error(err) t.FailNow() } @@ -160,7 +161,7 @@ func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { buildB := "integration-b" buildC := "integration-c" - doKitBuildInNamespace(t, g, buildA, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -170,7 +171,7 @@ func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildB, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -180,7 +181,7 @@ func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildC, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -195,37 +196,37 @@ func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { } limit := 0 - for limit < 5 && BuildPhase(t, ns, buildA)() == v1.BuildPhaseRunning { + for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ns, buildA), BuildPhase(t, ns, buildB), BuildPhase(t, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) + g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns, buildB), BuildPhase(t, ctx, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) limit++ } // make sure we have verified max build limit at least once if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ns, buildA)(), buildA))) + t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) t.FailNow() } // verify that all builds are successful - g.Eventually(BuildPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) }) } func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { - createOperator(t, g, ns, "8m0s", "--global", "--force") + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() // set maximum number of running builds and order strategy pl.Spec.Build.MaxRunningBuilds = 2 pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyDependencies - if err := TestClient(t).Update(TestContext, pl); err != nil { + if err := TestClient(t).Update(ctx, pl); err != nil { t.Error(err) t.FailNow() } @@ -234,7 +235,7 @@ func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { buildB := "integration-b" buildC := "integration-c" - doKitBuildInNamespace(t, g, buildA, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -244,7 +245,7 @@ func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildB, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:cron", "camel:log", "camel:joor", @@ -254,7 +255,7 @@ func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildC, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", "camel:joor", "camel:http", @@ -269,37 +270,37 @@ func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { } limit := 0 - for limit < 5 && BuildPhase(t, ns, buildA)() == v1.BuildPhaseRunning { + for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ns, buildA), BuildPhase(t, ns, buildB), BuildPhase(t, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) + g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns, buildB), BuildPhase(t, ctx, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) limit++ } // make sure we have verified max build limit at least once if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ns, buildA)(), buildA))) + t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) t.FailNow() } // verify that all builds are successful - g.Eventually(BuildPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) }) } func TestMaxBuildLimitWaitingBuilds(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { - createOperator(t, g, ns, "8m0s", "--global", "--force") + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() // set maximum number of running builds and order strategy pl.Spec.Build.MaxRunningBuilds = 1 pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO - if err := TestClient(t).Update(TestContext, pl); err != nil { + if err := TestClient(t).Update(ctx, pl); err != nil { t.Error(err) t.FailNow() } @@ -308,7 +309,7 @@ func TestMaxBuildLimitWaitingBuilds(t *testing.T) { buildB := "integration-b" buildC := "integration-c" - doKitBuildInNamespace(t, g, buildA, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", @@ -318,7 +319,7 @@ func TestMaxBuildLimitWaitingBuilds(t *testing.T) { }, }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - doKitBuildInNamespace(t, g, buildB, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:cron", "camel:log", "camel:joor", @@ -328,7 +329,7 @@ func TestMaxBuildLimitWaitingBuilds(t *testing.T) { }, }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - doKitBuildInNamespace(t, g, buildC, ns, TestTimeoutShort, kitOptions{ + doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ operatorID: fmt.Sprintf("camel-k-%s", ns), dependencies: []string{ "camel:timer", "camel:log", "camel:joor", "camel:http", @@ -339,24 +340,24 @@ func TestMaxBuildLimitWaitingBuilds(t *testing.T) { }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) // verify that last build is waiting - g.Eventually(BuildConditions(t, ns, buildC), TestTimeoutMedium).ShouldNot(BeNil()) + g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutMedium).ShouldNot(BeNil()) g.Eventually( - BuildCondition(t, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) g.Eventually( - BuildCondition(t, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, TestTimeoutShort).Should(Equal(v1.BuildConditionWaitingReason)) // verify that last build is scheduled - g.Eventually(BuildPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildConditions(t, ns, buildC), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutLong).ShouldNot(BeNil()) g.Eventually( - BuildCondition(t, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually( - BuildCondition(t, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, TestTimeoutShort).Should(Equal(v1.BuildConditionReadyReason)) }) } @@ -392,22 +393,22 @@ func doKitFullBuild(t *testing.T, name string, buildTimeout string, testTimeout options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { t.Helper() - WithNewTestNamespace(t, func(g *WithT, ns string) { - createOperator(t, g, ns, buildTimeout) - doKitBuildInNamespace(t, g, name, ns, testTimeout, options, buildPhase, kitPhase) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + createOperator(t, ctx, g, ns, buildTimeout) + doKitBuildInNamespace(t, ctx, g, name, ns, testTimeout, options, buildPhase, kitPhase) }) } -func createOperator(t *testing.T, g *WithT, ns string, buildTimeout string, installArgs ...string) { +func createOperator(t *testing.T, ctx context.Context, g *WithT, ns string, buildTimeout string, installArgs ...string) { args := []string{"--build-timeout", buildTimeout} args = append(args, installArgs...) operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, args...)).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, args...)).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) } -func doKitBuildInNamespace(t *testing.T, g *WithT, name string, ns string, testTimeout time.Duration, options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { +func doKitBuildInNamespace(t *testing.T, ctx context.Context, g *WithT, name string, ns string, testTimeout time.Duration, options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { buildKitArgs := []string{"kit", "create", name, "-n", ns} for _, dependency := range options.dependencies { @@ -423,13 +424,13 @@ func doKitBuildInNamespace(t *testing.T, g *WithT, name string, ns string, testT buildKitArgs = append(buildKitArgs, "--operator-id", fmt.Sprintf("camel-k-%s", ns)) } - g.Expect(Kamel(t, buildKitArgs...).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, buildKitArgs...).Execute()).To(Succeed()) - g.Eventually(Build(t, ns, name), testTimeout).ShouldNot(BeNil()) + g.Eventually(Build(t, ctx, ns, name), testTimeout).ShouldNot(BeNil()) if buildPhase != v1.BuildPhaseNone { - g.Eventually(BuildPhase(t, ns, name), testTimeout).Should(Equal(buildPhase)) + g.Eventually(BuildPhase(t, ctx, ns, name), testTimeout).Should(Equal(buildPhase)) } if kitPhase != v1.IntegrationKitPhaseNone { - g.Eventually(KitPhase(t, ns, name), testTimeout).Should(Equal(kitPhase)) + g.Eventually(KitPhase(t, ctx, ns, name), testTimeout).Should(Equal(kitPhase)) } } diff --git a/e2e/builder/registry_test.go b/e2e/builder/registry_test.go index 653b944124..4eb413cb5b 100644 --- a/e2e/builder/registry_test.go +++ b/e2e/builder/registry_test.go @@ -23,6 +23,7 @@ limitations under the License. package builder import ( + "context" "os" "testing" @@ -41,21 +42,16 @@ func TestRunWithDockerHubRegistry(t *testing.T) { return } - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-docker-hub" - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--registry", "docker.io", - "--organization", user, - "--registry-auth-username", user, - "--registry-auth-password", pass, - "--cluster-type", "kubernetes")).To(Succeed()) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "groovy"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodImage(t, ns, "groovy"), TestTimeoutShort).Should(HavePrefix("docker.io")) - - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--registry", "docker.io", "--organization", user, "--registry-auth-username", user, "--registry-auth-password", pass, "--cluster-type", "kubernetes")).To(Succeed()) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "groovy"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodImage(t, ctx, ns, "groovy"), TestTimeoutShort).Should(HavePrefix("docker.io")) + + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } @@ -68,20 +64,15 @@ func TestRunWithGithubPackagesRegistry(t *testing.T) { return } - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-github-registry" - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--registry", "docker.pkg.github.com", - "--organization", repo, - "--registry-auth-username", user, - "--registry-auth-password", pass, - "--cluster-type", "kubernetes")).To(Succeed()) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "groovy"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodImage(t, ns, "groovy"), TestTimeoutShort).Should(HavePrefix("docker.pkg.github.com")) - - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--registry", "docker.pkg.github.com", "--organization", repo, "--registry-auth-username", user, "--registry-auth-password", pass, "--cluster-type", "kubernetes")).To(Succeed()) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "groovy"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodImage(t, ctx, ns, "groovy"), TestTimeoutShort).Should(HavePrefix("docker.pkg.github.com")) + + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/bind_test.go b/e2e/common/cli/bind_test.go index 6e45011c6a..90daf7fdbd 100644 --- a/e2e/common/cli/bind_test.go +++ b/e2e/common/cli/bind_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "testing" corev1 "k8s.io/api/core/v1" @@ -33,33 +34,33 @@ import ( ) func TestKamelCLIBind(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { kameletName := "test-timer-source" - g.Expect(CreateTimerKamelet(t, operatorID, ns, kameletName)()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, kameletName)()).To(Succeed()) t.Run("bind timer to log", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, kameletName, "log:info", "-p", "source.message=helloTest").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "test-timer-source-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "test-timer-source-to-log")).Should(ContainSubstring("Body: helloTest")) - g.Expect(KamelBindWithID(t, operatorID, ns, "test-timer-source", "log:info", "-p", "source.message=newText").Execute()).To(Succeed()) - g.Eventually(IntegrationLogs(t, ns, "test-timer-source-to-log")).Should(ContainSubstring("Body: newText")) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, kameletName, "log:info", "-p", "source.message=helloTest").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "test-timer-source-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "test-timer-source-to-log")).Should(ContainSubstring("Body: helloTest")) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "test-timer-source", "log:info", "-p", "source.message=newText").Execute()).To(Succeed()) + g.Eventually(IntegrationLogs(t, ctx, ns, "test-timer-source-to-log")).Should(ContainSubstring("Body: newText")) }) t.Run("unsuccessful binding, no property", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, operatorNS+"/timer-source", "log:info").Execute()).NotTo(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, operatorNS+"/timer-source", "log:info").Execute()).NotTo(Succeed()) }) t.Run("bind uris", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, "timer:foo", "log:bar").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "timer-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "timer-to-log")).Should(ContainSubstring("Body is null")) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "timer:foo", "log:bar").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "timer-to-log")).Should(ContainSubstring("Body is null")) }) t.Run("bind with custom SA", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, "timer:foo", "log:bar", "--service-account", "my-service-account").Execute()).To(Succeed()) - g.Eventually(IntegrationSpecSA(t, ns, "timer-to-log")).Should(Equal("my-service-account")) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "timer:foo", "log:bar", "--service-account", "my-service-account").Execute()).To(Succeed()) + g.Eventually(IntegrationSpecSA(t, ctx, ns, "timer-to-log")).Should(Equal("my-service-account")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/config_test.go b/e2e/common/cli/config_test.go index 46c2a560e2..e29297616d 100644 --- a/e2e/common/cli/config_test.go +++ b/e2e/common/cli/config_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "os" "strings" "testing" @@ -39,30 +40,30 @@ import ( ) func TestKamelCLIConfig(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("check default namespace", func(t *testing.T) { _, err := os.Stat(cmd.DefaultConfigLocation) assert.True(t, os.IsNotExist(err), "No file at "+cmd.DefaultConfigLocation+" was expected") t.Cleanup(func() { os.Remove(cmd.DefaultConfigLocation) }) - g.Expect(Kamel(t, "config", "--default-namespace", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "config", "--default-namespace", ns).Execute()).To(Succeed()) _, err = os.Stat(cmd.DefaultConfigLocation) require.NoError(t, err, "A file at "+cmd.DefaultConfigLocation+" was expected") - g.Expect(Kamel(t, "run", "--operator-id", operatorID, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "run", "--operator-id", operatorID, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // first line of the integration logs - logs := strings.Split(IntegrationLogs(t, ns, "yaml")(), "\n")[0] - podName := IntegrationPod(t, ns, "yaml")().Name + logs := strings.Split(IntegrationLogs(t, ctx, ns, "yaml")(), "\n")[0] + podName := IntegrationPod(t, ctx, ns, "yaml")().Name - logsCLI := GetOutputStringAsync(Kamel(t, "log", "yaml")) + logsCLI := GetOutputStringAsync(Kamel(t, ctx, "log", "yaml")) g.Eventually(logsCLI).Should(ContainSubstring("Monitoring pod " + podName)) g.Eventually(logsCLI).Should(ContainSubstring(logs)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/delete_test.go b/e2e/common/cli/delete_test.go index cba51eef23..2ed2aba0e6 100644 --- a/e2e/common/cli/delete_test.go +++ b/e2e/common/cli/delete_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "testing" corev1 "k8s.io/api/core/v1" @@ -33,47 +34,47 @@ import ( ) func TestKamelCLIDelete(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("delete running integration", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Expect(Kamel(t, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, "yaml")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "yaml"), TestTimeoutLong).Should(BeNil()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(Kamel(t, ctx, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "yaml")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "yaml"), TestTimeoutLong).Should(BeNil()) }) t.Run("delete building integration", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Expect(Kamel(t, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, "yaml")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "yaml"), TestTimeoutLong).Should(BeNil()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "yaml")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "yaml"), TestTimeoutLong).Should(BeNil()) }) t.Run("delete several integrations", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Expect(Kamel(t, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, "yaml")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "yaml"), TestTimeoutLong).Should(BeNil()) - g.Expect(Kamel(t, "delete", "java", "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, "java")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "java"), TestTimeoutLong).Should(BeNil()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(Kamel(t, ctx, "delete", "yaml", "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "yaml")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "yaml"), TestTimeoutLong).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "java", "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "java")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "java"), TestTimeoutLong).Should(BeNil()) }) t.Run("delete all integrations", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, "yaml")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "yaml"), TestTimeoutLong).Should(BeNil()) - g.Eventually(Integration(t, ns, "java")).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, "java"), TestTimeoutLong).Should(BeNil()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, "yaml")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "yaml"), TestTimeoutLong).Should(BeNil()) + g.Eventually(Integration(t, ctx, ns, "java")).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "java"), TestTimeoutLong).Should(BeNil()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/describe_test.go b/e2e/common/cli/describe_test.go index 8e5f6a5623..f4cf6ce9bb 100644 --- a/e2e/common/cli/describe_test.go +++ b/e2e/common/cli/describe_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "fmt" "regexp" "testing" @@ -36,13 +37,12 @@ import ( ) func TestKamelCliDescribe(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) t.Run("Test kamel describe integration", func(t *testing.T) { - integration := GetOutputString(Kamel(t, "describe", "integration", "yaml", "-n", ns)) + integration := GetOutputString(Kamel(t, ctx, "describe", "integration", "yaml", "-n", ns)) r, _ := regexp.Compile("(?sm).*Name:\\s+yaml.*") g.Expect(integration).To(MatchRegexp(r.String())) @@ -54,9 +54,9 @@ func TestKamelCliDescribe(t *testing.T) { }) t.Run("Test kamel describe integration kit", func(t *testing.T) { - kitName := Integration(t, ns, "yaml")().Status.IntegrationKit.Name - kitNamespace := Integration(t, ns, "yaml")().Status.IntegrationKit.Namespace - kit := GetOutputString(Kamel(t, "describe", "kit", kitName, "-n", kitNamespace)) + kitName := Integration(t, ctx, ns, "yaml")().Status.IntegrationKit.Name + kitNamespace := Integration(t, ctx, ns, "yaml")().Status.IntegrationKit.Namespace + kit := GetOutputString(Kamel(t, ctx, "describe", "kit", kitName, "-n", kitNamespace)) r, _ := regexp.Compile("(?sm).*Namespace:\\s+" + kitNamespace + ".*") g.Expect(kit).To(MatchRegexp(r.String())) @@ -71,7 +71,7 @@ func TestKamelCliDescribe(t *testing.T) { }) t.Run("Test kamel describe integration platform", func(t *testing.T) { - platform := GetOutputString(Kamel(t, "describe", "platform", operatorID, "-n", operatorNS)) + platform := GetOutputString(Kamel(t, ctx, "describe", "platform", operatorID, "-n", operatorNS)) g.Expect(platform).To(ContainSubstring(fmt.Sprintf("Name: %s", operatorID))) r, _ := regexp.Compile("(?sm).*Namespace:\\s+" + operatorNS + ".*") @@ -81,6 +81,6 @@ func TestKamelCliDescribe(t *testing.T) { g.Expect(platform).To(MatchRegexp(r.String())) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/dev_mode_test.go b/e2e/common/cli/dev_mode_test.go index c257a37234..0c84b46767 100644 --- a/e2e/common/cli/dev_mode_test.go +++ b/e2e/common/cli/dev_mode_test.go @@ -37,7 +37,7 @@ import ( ) func TestRunDevMode(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { /* * TODO * The changing of the yaml file constant from "string" to "magic" is not being @@ -50,7 +50,7 @@ func TestRunDevMode(t *testing.T) { } t.Run("run yaml dev mode", func(t *testing.T) { - ctx, cancel := context.WithCancel(TestContext) + ctx, cancel := context.WithCancel(ctx) defer cancel() piper, pipew := io.Pipe() defer pipew.Close() @@ -79,7 +79,7 @@ func TestRunDevMode(t *testing.T) { }) t.Run("run yaml remote dev mode", func(t *testing.T) { - ctx, cancel := context.WithCancel(TestContext) + ctx, cancel := context.WithCancel(ctx) defer cancel() piper, pipew := io.Pipe() defer pipew.Close() @@ -114,15 +114,15 @@ func TestRunDevMode(t *testing.T) { name := RandomizedSuffixName("yaml") // First run (warm up) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name)).Should(BeNil()) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutMedium).Should(BeNil()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name)).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutMedium).Should(BeNil()) // Second run (rebuild) - ctx, cancel := context.WithCancel(TestContext) + ctx, cancel := context.WithCancel(ctx) defer cancel() piper, pipew := io.Pipe() defer pipew.Close() @@ -148,6 +148,6 @@ func TestRunDevMode(t *testing.T) { g.Eventually(logScanner.IsFound("Magicstring!"), timeout).Should(BeTrue()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/duplicate_parameters_test.go b/e2e/common/cli/duplicate_parameters_test.go index 5a1f546180..4882d96aa3 100644 --- a/e2e/common/cli/duplicate_parameters_test.go +++ b/e2e/common/cli/duplicate_parameters_test.go @@ -35,7 +35,7 @@ import ( func TestDuplicateParameters(t *testing.T) { g := NewWithT(t) - ctx, cancel := context.WithCancel(TestContext) + ctx, cancel := context.WithCancel(TestContext()) defer cancel() // run kamel to output the traits/configuration structure in json format to check the processed values diff --git a/e2e/common/cli/get_test.go b/e2e/common/cli/get_test.go index 2ab5cc5040..c9b0ee3511 100644 --- a/e2e/common/cli/get_test.go +++ b/e2e/common/cli/get_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "fmt" "testing" @@ -34,46 +35,46 @@ import ( ) func TestKamelCLIGet(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("get integration", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // regex is used for the compatibility of tests between OC and vanilla K8 // kamel get may have different output depending on the platform - g.Eventually(IntegrationKit(t, ns, "yaml")).ShouldNot(Equal("")) - kitName := IntegrationKit(t, ns, "yaml")() - kitNamespace := IntegrationKitNamespace(t, ns, "yaml")() + g.Eventually(IntegrationKit(t, ctx, ns, "yaml")).ShouldNot(Equal("")) + kitName := IntegrationKit(t, ctx, ns, "yaml")() + kitNamespace := IntegrationKitNamespace(t, ctx, ns, "yaml")() regex := fmt.Sprintf("^NAME\tPHASE\tKIT\n\\s*yaml\tRunning\t(%s/%s|%s)", kitNamespace, kitName, kitName) - g.Expect(GetOutputString(Kamel(t, "get", "-n", ns))).To(MatchRegexp(regex)) + g.Expect(GetOutputString(Kamel(t, ctx, "get", "-n", ns))).To(MatchRegexp(regex)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("get several integrations", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - - g.Eventually(IntegrationKit(t, ns, "java")).ShouldNot(Equal("")) - g.Eventually(IntegrationKit(t, ns, "yaml")).ShouldNot(Equal("")) - kitName1 := IntegrationKit(t, ns, "java")() - kitName2 := IntegrationKit(t, ns, "yaml")() - kitNamespace1 := IntegrationKitNamespace(t, ns, "java")() - kitNamespace2 := IntegrationKitNamespace(t, ns, "yaml")() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + g.Eventually(IntegrationKit(t, ctx, ns, "java")).ShouldNot(Equal("")) + g.Eventually(IntegrationKit(t, ctx, ns, "yaml")).ShouldNot(Equal("")) + kitName1 := IntegrationKit(t, ctx, ns, "java")() + kitName2 := IntegrationKit(t, ctx, ns, "yaml")() + kitNamespace1 := IntegrationKitNamespace(t, ctx, ns, "java")() + kitNamespace2 := IntegrationKitNamespace(t, ctx, ns, "yaml")() regex := fmt.Sprintf("^NAME\tPHASE\tKIT\n\\s*java\tRunning\t"+ "(%s/%s|%s)\n\\s*yaml\tRunning\t(%s/%s|%s)\n", kitNamespace1, kitName1, kitName1, kitNamespace2, kitName2, kitName2) - g.Expect(GetOutputString(Kamel(t, "get", "-n", ns))).To(MatchRegexp(regex)) + g.Expect(GetOutputString(Kamel(t, ctx, "get", "-n", ns))).To(MatchRegexp(regex)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("get no integrations", func(t *testing.T) { - g.Expect(GetOutputString(Kamel(t, "get", "-n", ns))).NotTo(ContainSubstring("Running")) - g.Expect(GetOutputString(Kamel(t, "get", "-n", ns))).NotTo(ContainSubstring("Building Kit")) + g.Expect(GetOutputString(Kamel(t, ctx, "get", "-n", ns))).NotTo(ContainSubstring("Running")) + g.Expect(GetOutputString(Kamel(t, ctx, "get", "-n", ns))).NotTo(ContainSubstring("Building Kit")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/help_test.go b/e2e/common/cli/help_test.go index cdb6eab54c..c51dd91e45 100644 --- a/e2e/common/cli/help_test.go +++ b/e2e/common/cli/help_test.go @@ -31,10 +31,11 @@ import ( ) func TestKamelCLIHelp(t *testing.T) { + ctx := TestContext() g := NewWithT(t) t.Run("default help message", func(t *testing.T) { - helpMsg := GetOutputString(Kamel(t, "help")) + helpMsg := GetOutputString(Kamel(t, ctx, "help")) g.Expect(helpMsg).To(ContainSubstring("Apache Camel K is a lightweight integration platform, born on Kubernetes")) g.Expect(helpMsg).To(ContainSubstring("Usage:")) g.Expect(helpMsg).To(ContainSubstring("Available Commands:")) @@ -42,14 +43,14 @@ func TestKamelCLIHelp(t *testing.T) { }) t.Run("'get' command help (short flag)", func(t *testing.T) { - helpMsg := GetOutputString(Kamel(t, "get", "-h")) + helpMsg := GetOutputString(Kamel(t, ctx, "get", "-h")) g.Expect(helpMsg).To(ContainSubstring("Get the status of integrations deployed on Kubernetes")) g.Expect(helpMsg).To(ContainSubstring("Usage:")) g.Expect(helpMsg).To(ContainSubstring("Flags:")) }) t.Run("'bind' command help (long flag)", func(t *testing.T) { - helpMsg := GetOutputString(Kamel(t, "bind", "--help")) + helpMsg := GetOutputString(Kamel(t, ctx, "bind", "--help")) g.Expect(helpMsg).To(ContainSubstring("Bind Kubernetes resources, such as Kamelets, in an integration flow.")) g.Expect(helpMsg).To(ContainSubstring("kamel bind [source] [sink] ... [flags]")) g.Expect(helpMsg).To(ContainSubstring("Global Flags:")) diff --git a/e2e/common/cli/log_test.go b/e2e/common/cli/log_test.go index 50258be0b5..38a2d34d72 100644 --- a/e2e/common/cli/log_test.go +++ b/e2e/common/cli/log_test.go @@ -23,35 +23,37 @@ limitations under the License. package cli import ( + "context" "strings" "testing" - . "github.com/apache/camel-k/v2/e2e/support" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + + . "github.com/apache/camel-k/v2/e2e/support" ) func TestKamelCLILog(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("check integration log", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", "log-yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "log-yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", "log-yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "log-yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // first line of the integration logs - firstLine := strings.Split(IntegrationLogs(t, ns, "log-yaml")(), "\n")[0] - podName := IntegrationPod(t, ns, "log-yaml")().Name + firstLine := strings.Split(IntegrationLogs(t, ctx, ns, "log-yaml")(), "\n")[0] + podName := IntegrationPod(t, ctx, ns, "log-yaml")().Name - logsCLI := GetOutputStringAsync(Kamel(t, "log", "log-yaml", "-n", ns)) + logsCLI := GetOutputStringAsync(Kamel(t, ctx, "log", "log-yaml", "-n", ns)) g.Eventually(logsCLI).Should(ContainSubstring("Monitoring pod " + podName)) g.Eventually(logsCLI).Should(ContainSubstring(firstLine)) - logs := strings.Split(IntegrationLogs(t, ns, "log-yaml")(), "\n") + logs := strings.Split(IntegrationLogs(t, ctx, ns, "log-yaml")(), "\n") lastLine := logs[len(logs)-1] - logsCLI = GetOutputStringAsync(Kamel(t, "log", "log-yaml", "-n", ns, "--tail", "5")) + logsCLI = GetOutputStringAsync(Kamel(t, ctx, "log", "log-yaml", "-n", ns, "--tail", "5")) g.Eventually(logsCLI).Should(ContainSubstring("Monitoring pod " + podName)) g.Eventually(logsCLI).Should(ContainSubstring(lastLine)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/cli/main_test.go b/e2e/common/cli/main_test.go index c4dfbe1faf..fafad4f139 100644 --- a/e2e/common/cli/main_test.go +++ b/e2e/common/cli/main_test.go @@ -46,17 +46,18 @@ func TestMain(m *testing.M) { var t *testing.T g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() // Install global operator for tests in this package, all tests must use this operatorID - g.Expect(NewNamedTestNamespace(t, operatorNS, false)).ShouldNot(BeNil()) - g.Expect(CopyCamelCatalog(t, operatorNS, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operatorID, operatorNS, "--global", "--force")).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, operatorNS, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(NewNamedTestNamespace(t, ctx, operatorNS, false)).ShouldNot(BeNil()) + g.Expect(CopyCamelCatalog(t, ctx, operatorNS, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operatorID, operatorNS, "--global", "--force")).To(Succeed()) + g.Eventually(SelectedPlatformPhase(t, ctx, operatorNS, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) exitCode := m.Run() - g.Expect(UninstallFromNamespace(t, operatorNS)) - g.Expect(DeleteNamespace(t, operatorNS)).To(Succeed()) + g.Expect(UninstallFromNamespace(t, ctx, operatorNS)) + g.Expect(DeleteNamespace(t, ctx, operatorNS)).To(Succeed()) os.Exit(exitCode) } diff --git a/e2e/common/cli/offline_commands_test.go b/e2e/common/cli/offline_commands_test.go index 6ee536e6d4..a6d506e408 100644 --- a/e2e/common/cli/offline_commands_test.go +++ b/e2e/common/cli/offline_commands_test.go @@ -32,13 +32,13 @@ import ( func TestKamelVersionWorksOffline(t *testing.T) { g := NewWithT(t) - g.Expect(Kamel(t, "version", "--kube-config", "non-existent-kubeconfig-file").Execute()).To(Succeed()) + g.Expect(Kamel(t, TestContext(), "version", "--kube-config", "non-existent-kubeconfig-file").Execute()).To(Succeed()) } func TestKamelHelpOptionWorksOffline(t *testing.T) { g := NewWithT(t) - traitCmd := Kamel(t, "run", "Xxx.java", "--help") + traitCmd := Kamel(t, TestContext(), "run", "Xxx.java", "--help") traitCmd.SetOut(io.Discard) g.Expect(traitCmd.Execute()).To(Succeed()) } @@ -46,9 +46,9 @@ func TestKamelHelpOptionWorksOffline(t *testing.T) { func TestKamelCompletionWorksOffline(t *testing.T) { g := NewWithT(t) - bashCmd := Kamel(t, "completion", "bash", "--kube-config", "non-existent-kubeconfig-file") + bashCmd := Kamel(t, TestContext(), "completion", "bash", "--kube-config", "non-existent-kubeconfig-file") bashCmd.SetOut(io.Discard) - zshCmd := Kamel(t, "completion", "zsh", "--kube-config", "non-existent-kubeconfig-file") + zshCmd := Kamel(t, TestContext(), "completion", "zsh", "--kube-config", "non-existent-kubeconfig-file") zshCmd.SetOut(io.Discard) g.Expect(bashCmd.Execute()).To(Succeed()) g.Expect(zshCmd.Execute()).To(Succeed()) diff --git a/e2e/common/cli/run_test.go b/e2e/common/cli/run_test.go index 548cb95bc1..4a1a05cd44 100644 --- a/e2e/common/cli/run_test.go +++ b/e2e/common/cli/run_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "os" "testing" @@ -39,38 +40,38 @@ import ( var sampleJar = "https://raw.githubusercontent.com/apache/camel-k/main/e2e/common/traits/files/jvm/sample-1.0.jar" func TestKamelCLIRun(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("Examples from GitHub", func(t *testing.T) { t.Run("Java", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "github:apache/camel-k-examples/generic-examples/languages/Sample.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Java (RAW)", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "https://raw.githubusercontent.com/apache/camel-k-examples/main/generic-examples/languages/Sample.java").Execute()). To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Java (branch)", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "github:apache/camel-k-examples/generic-examples/languages/Sample.java?branch=main").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, "sample"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "sample", v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, "sample"), TestTimeoutShort).Should(ContainSubstring("Hello Camel K!")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) // GIST does not like GITHUB_TOKEN apparently, we must temporarily remove it @@ -79,26 +80,26 @@ func TestKamelCLIRun(t *testing.T) { t.Run("Gist (ID)", func(t *testing.T) { name := RandomizedSuffixName("github-gist-id") - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", name, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", name, "gist:e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Gist (URL)", func(t *testing.T) { name := RandomizedSuffixName("github-gist-url") - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", name, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", name, "https://gist.github.com/lburgazzoli/e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) // Revert GITHUB TOKEN @@ -106,80 +107,80 @@ func TestKamelCLIRun(t *testing.T) { os.Unsetenv("GITHUB_TOKEN_TMP") // Clean up - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Run and update", func(t *testing.T) { name := RandomizedSuffixName("run") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/run.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/run.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magic default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magic default")) // Re-run the Integration with an updated configuration - g.Expect(KamelRunWithID(t, operatorID, ns, "files/run.yaml", "--name", name, "-p", "property=value").Execute()). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/run.yaml", "--name", name, "-p", "property=value").Execute()). To(Succeed()) // Check the Deployment has progressed successfully - g.Eventually(DeploymentCondition(t, ns, name, appsv1.DeploymentProgressing), TestTimeoutShort). + g.Eventually(DeploymentCondition(t, ctx, ns, name, appsv1.DeploymentProgressing), TestTimeoutShort). Should(MatchFields(IgnoreExtras, Fields{ "Status": Equal(corev1.ConditionTrue), "Reason": Equal("NewReplicaSetAvailable"), })) // Check the new configuration is taken into account - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magic value")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magic value")) // Clean up - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Run with glob patterns", func(t *testing.T) { t.Run("YAML", func(t *testing.T) { name := RandomizedSuffixName("run") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/glob/run*", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/glob/run*", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 1 default")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 2 default")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 1 default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 2 default")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("Java", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/glob/Java*", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/glob/Java*", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 1 default")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 2 default")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 1 default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 2 default")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) t.Run("All", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/glob/*", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/glob/*", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 1 default")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 2 default")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 1 default")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 2 default")) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 1 default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello run 2 default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 1 default")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Hello java 2 default")) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) // Clean up - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) }) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { /* * TODO * The dependency cannot be read by maven while building. See #3708 @@ -192,21 +193,21 @@ func TestKamelCLIRun(t *testing.T) { } // Requires a local integration platform in order to resolve the insecure registry // Install platform (use the installer to get staging if present) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--skip-operator-setup")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--skip-operator-setup")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(KamelRunWithID(t, operatorID, ns, "../traits/files/jvm/Classpath.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "../traits/files/jvm/Classpath.java", "-d", sampleJar, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) }) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { /* * TODO * The dependency cannot be read by maven while building. See #3708 @@ -219,18 +220,18 @@ func TestKamelCLIRun(t *testing.T) { } // Requires a local integration platform in order to resolve the insecure registry // Install platform (use the installer to get staging if present) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--skip-operator-setup")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--skip-operator-setup")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(KamelRunWithID(t, operatorID, ns, "../traits/files/jvm/Classpath.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "../traits/files/jvm/Classpath.java", "-d", sampleJar, "-d", "https://raw.githubusercontent.com/apache/camel-k-examples/main/generic-examples/languages/Sample.java|targetPath=/tmp/foo", ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) }) - g.Eventually(DeleteIntegrations(t, ns), TestTimeoutLong).Should(Equal(0)) + g.Eventually(DeleteIntegrations(t, ctx, ns), TestTimeoutLong).Should(Equal(0)) }) } diff --git a/e2e/common/cli/version_test.go b/e2e/common/cli/version_test.go index 488ee7a036..ee9bad90d0 100644 --- a/e2e/common/cli/version_test.go +++ b/e2e/common/cli/version_test.go @@ -35,7 +35,7 @@ func TestKamelCLIVersion(t *testing.T) { g := NewWithT(t) t.Run("check version correctness", func(t *testing.T) { - version := GetOutputString(Kamel(t, "version")) + version := GetOutputString(Kamel(t, TestContext(), "version")) g.Expect(version).To(ContainSubstring(defaults.Version)) }) } diff --git a/e2e/common/config/config_reload_test.go b/e2e/common/config/config_reload_test.go index d59c719ad8..7b5cf9d708 100644 --- a/e2e/common/config/config_reload_test.go +++ b/e2e/common/config/config_reload_test.go @@ -23,6 +23,7 @@ limitations under the License. package config import ( + "context" "fmt" "strconv" "testing" @@ -38,106 +39,94 @@ import ( func TestConfigmapHotReload(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-config-hot-reload" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("config-configmap-route") var cmData = make(map[string]string) cmData["my-configmap-key"] = "my configmap content" - CreatePlainTextConfigmapWithLabels(t, ns, "my-hot-cm", cmData, map[string]string{"camel.apache.org/integration": "test"}) - - g.Expect(KamelRunWithID(t, operatorID, ns, - "./files/config-configmap-route.groovy", - "--config", - "configmap:my-hot-cm", - "-t", - "mount.hot-reload=true", - "--name", - name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content")) + CreatePlainTextConfigmapWithLabels(t, ctx, ns, "my-hot-cm", cmData, map[string]string{"camel.apache.org/integration": "test"}) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-configmap-route.groovy", + "--config", "configmap:my-hot-cm", + "-t", "mount.hot-reload=true", + "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content")) cmData["my-configmap-key"] = "my configmap content updated" - UpdatePlainTextConfigmapWithLabels(t, ns, "my-hot-cm", cmData, map[string]string{"camel.apache.org/integration": "test"}) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content updated")) + UpdatePlainTextConfigmapWithLabels(t, ctx, ns, "my-hot-cm", cmData, map[string]string{"camel.apache.org/integration": "test"}) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content updated")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestConfigmapHotReloadDefault(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-config-hot-reload-default" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("config-configmap-route") var cmData = make(map[string]string) cmData["my-configmap-key"] = "my configmap content" - CreatePlainTextConfigmapWithLabels(t, ns, "my-hot-cm-2", cmData, map[string]string{"camel.apache.org/integration": "test"}) - - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-configmap-route.groovy", - "--config", - "configmap:my-hot-cm-2", - "--name", - name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content")) + CreatePlainTextConfigmapWithLabels(t, ctx, ns, "my-hot-cm-2", cmData, map[string]string{"camel.apache.org/integration": "test"}) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-configmap-route.groovy", + "--config", "configmap:my-hot-cm-2", + "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("my configmap content")) cmData["my-configmap-key"] = "my configmap content updated" - UpdatePlainTextConfigmapWithLabels(t, ns, "my-hot-cm-2", cmData, map[string]string{"camel.apache.org/integration": "test"}) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(Not(ContainSubstring("my configmap content updated"))) + UpdatePlainTextConfigmapWithLabels(t, ctx, ns, "my-hot-cm-2", cmData, map[string]string{"camel.apache.org/integration": "test"}) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(Not(ContainSubstring("my configmap content updated"))) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestSecretHotReload(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-secret-hot-reload" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("config-secret-route") var secData = make(map[string]string) secData["my-secret-key"] = "very top secret" - CreatePlainTextSecretWithLabels(t, ns, "my-hot-sec", secData, map[string]string{"camel.apache.org/integration": "test"}) - - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-secret-route.groovy", - "--config", - "secret:my-hot-sec", - "-t", - "mount.hot-reload=true", - "--name", - name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("very top secret")) + CreatePlainTextSecretWithLabels(t, ctx, ns, "my-hot-sec", secData, map[string]string{"camel.apache.org/integration": "test"}) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-secret-route.groovy", + "--config", "secret:my-hot-sec", + "-t", "mount.hot-reload=true", + "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("very top secret")) secData["my-secret-key"] = "very top secret updated" - UpdatePlainTextSecretWithLabels(t, ns, "my-hot-sec", secData, map[string]string{"camel.apache.org/integration": "test"}) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("very top secret updated")) + UpdatePlainTextSecretWithLabels(t, ctx, ns, "my-hot-sec", secData, map[string]string{"camel.apache.org/integration": "test"}) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("very top secret updated")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } @@ -150,38 +139,34 @@ func TestConfigmapWithOwnerRefHotReload(t *testing.T) { } func CheckConfigmapWithOwnerRef(t *testing.T, hotreload bool) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-config-owner-ref-%s", strconv.FormatBool(hotreload)) - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("config-configmap-route") cmName := RandomizedSuffixName("my-hot-cm-") - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-configmap-route.groovy", - "--config", - "configmap:"+cmName, - "--name", - name, - "-t", - "mount.hot-reload="+strconv.FormatBool(hotreload), - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-configmap-route.groovy", + "--config", "configmap:"+cmName, + "--name", name, + "-t", "mount.hot-reload="+strconv.FormatBool(hotreload)).Execute()).To(Succeed()) + + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) var cmData = make(map[string]string) cmData["my-configmap-key"] = "my configmap content" - CreatePlainTextConfigmapWithOwnerRefWithLabels(t, ns, cmName, cmData, name, Integration(t, ns, name)().UID, map[string]string{"camel.apache.org/integration": "test"}) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutLong).Should(ContainSubstring("my configmap content")) + CreatePlainTextConfigmapWithOwnerRefWithLabels(t, ctx, ns, cmName, cmData, name, Integration(t, ctx, ns, name)().UID, map[string]string{"camel.apache.org/integration": "test"}) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutLong).Should(ContainSubstring("my configmap content")) cmData["my-configmap-key"] = "my configmap content updated" - UpdatePlainTextConfigmapWithLabels(t, ns, cmName, cmData, map[string]string{"camel.apache.org/integration": "test"}) + UpdatePlainTextConfigmapWithLabels(t, ctx, ns, cmName, cmData, map[string]string{"camel.apache.org/integration": "test"}) if hotreload { - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutLong).Should(ContainSubstring("my configmap content updated")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutLong).Should(ContainSubstring("my configmap content updated")) } else { - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutLong).Should(Not(ContainSubstring("my configmap content updated"))) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutLong).Should(Not(ContainSubstring("my configmap content updated"))) } - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go index fee9466979..c60267d751 100644 --- a/e2e/common/config/config_test.go +++ b/e2e/common/config/config_test.go @@ -23,6 +23,7 @@ limitations under the License. package config import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,108 +38,105 @@ import ( func TestRunConfigExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-config" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Simple property", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-route.groovy", "-p", "my.message=test-property").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("test-property")) - g.Expect(Kamel(t, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-route.groovy", "-p", "my.message=test-property").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("test-property")) + g.Expect(Kamel(t, ctx, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property file", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-file-route.groovy", "--property", "file:./files/my.properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) - g.Expect(Kamel(t, "delete", "property-file-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-file-route.groovy", "--property", "file:./files/my.properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) + g.Expect(Kamel(t, ctx, "delete", "property-file-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property precedence", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-file-route.groovy", "-p", "my.key.2=universe", "-p", "file:./files/my.properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello universe")) - g.Expect(Kamel(t, "delete", "property-file-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-file-route.groovy", "-p", "my.key.2=universe", "-p", "file:./files/my.properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello universe")) + g.Expect(Kamel(t, ctx, "delete", "property-file-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property from ConfigMap", func(t *testing.T) { var cmData = make(map[string]string) cmData["my.message"] = "my-configmap-property-value" - CreatePlainTextConfigmap(t, ns, "my-cm-test-property", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-test-property", cmData) - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-route.groovy", "-p", "configmap:my-cm-test-property").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-value")) - g.Expect(Kamel(t, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-route.groovy", "-p", "configmap:my-cm-test-property").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-value")) + g.Expect(Kamel(t, ctx, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property from ConfigMap as property file", func(t *testing.T) { var cmData = make(map[string]string) cmData["my.properties"] = "my.message=my-configmap-property-entry" - CreatePlainTextConfigmap(t, ns, "my-cm-test-properties", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-test-properties", cmData) - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-route.groovy", "-p", "configmap:my-cm-test-properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-entry")) - g.Expect(Kamel(t, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-route.groovy", "-p", "configmap:my-cm-test-properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-entry")) + g.Expect(Kamel(t, ctx, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property from Secret", func(t *testing.T) { var secData = make(map[string]string) secData["my.message"] = "my-secret-property-value" - CreatePlainTextSecret(t, ns, "my-sec-test-property", secData) + CreatePlainTextSecret(t, ctx, ns, "my-sec-test-property", secData) - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-route.groovy", "-p", "secret:my-sec-test-property").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-value")) - g.Expect(Kamel(t, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-route.groovy", "-p", "secret:my-sec-test-property").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-value")) + g.Expect(Kamel(t, ctx, "delete", "property-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Property from Secret as property file", func(t *testing.T) { var secData = make(map[string]string) secData["my.properties"] = "my.message=my-secret-property-entry" - CreatePlainTextSecret(t, ns, "my-sec-test-properties", secData) + CreatePlainTextSecret(t, ctx, ns, "my-sec-test-properties", secData) - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-route.groovy", "-p", "secret:my-sec-test-properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-entry")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-route.groovy", "--name", "property-route-secret", "-p", "secret:my-sec-test-properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route-secret"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route-secret", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-route-secret"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-entry")) }) t.Run("Property from Secret inlined", func(t *testing.T) { var secData = make(map[string]string) secData["my-message"] = "my-secret-external-value" - CreatePlainTextSecret(t, ns, "my-sec-inlined", secData) + CreatePlainTextSecret(t, ctx, ns, "my-sec-inlined", secData) // TODO: remove jvm.options trait as soon as CAMEL-20054 gets fixed - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/property-secret-route.groovy", - "-t", "mount.configs=secret:my-sec-inlined", - "-t", "jvm.options=-Dcamel.k.mount-path.secrets=/etc/camel/conf.d/_secrets", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "property-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "property-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "property-secret-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-external-value")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/property-secret-route.groovy", "-t", "mount.configs=secret:my-sec-inlined", "-t", "jvm.options=-Dcamel.k.mount-path.secrets=/etc/camel/conf.d/_secrets").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "property-secret-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-external-value")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "property-secret-route")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "property-secret-route")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "property-secret-route")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "property-secret-route")() mountTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "mount") g.Expect(mountTrait).ToNot(BeNil()) g.Expect(len(mountTrait)).To(Equal(1)) g.Expect(mountTrait["configs"]).ToNot(BeNil()) - g.Expect(Kamel(t, "delete", "property-secret-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "property-secret-route", "-n", ns).Execute()).To(Succeed()) }) @@ -147,59 +145,59 @@ func TestRunConfigExamples(t *testing.T) { // Store a configmap on the cluster var cmData = make(map[string]string) cmData["my-configmap-key"] = "my-configmap-content" - CreatePlainTextConfigmap(t, ns, "my-cm", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm", cmData) // Store a configmap with multiple values var cmDataMulti = make(map[string]string) cmDataMulti["my-configmap-key"] = "should-not-see-it" cmDataMulti["my-configmap-key-2"] = "my-configmap-content-2" - CreatePlainTextConfigmap(t, ns, "my-cm-multi", cmDataMulti) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-multi", cmDataMulti) t.Run("Config configmap", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "config-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "config-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) }) t.Run("Resource configmap", func(t *testing.T) { // We can reuse the configmap created previously - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/resource-configmap-route.groovy", "--resource", "configmap:my-cm").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "resource-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "resource-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "resource-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/resource-configmap-route.groovy", "--resource", "configmap:my-cm").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "resource-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "resource-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) }) t.Run("Resource configmap with destination", func(t *testing.T) { // We can reuse the configmap created previously - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/resource-configmap-location-route.groovy", "--resource", "configmap:my-cm@/tmp/app").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "resource-configmap-location-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "resource-configmap-location-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "resource-configmap-location-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/resource-configmap-location-route.groovy", "--resource", "configmap:my-cm@/tmp/app").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "resource-configmap-location-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "resource-configmap-location-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-location-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) }) t.Run("Resource configmap with filtered key and destination", func(t *testing.T) { // We'll use the configmap contaning 2 values filtering only 1 key - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/resource-configmap-key-location-route.groovy", "--resource", "configmap:my-cm-multi/my-configmap-key-2@/tmp/app/test.txt").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "resource-configmap-key-location-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "resource-configmap-key-location-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "resource-configmap-key-location-route"), TestTimeoutShort).ShouldNot(ContainSubstring(cmDataMulti["my-configmap-key"])) - g.Eventually(IntegrationLogs(t, ns, "resource-configmap-key-location-route"), TestTimeoutShort).Should(ContainSubstring(cmDataMulti["my-configmap-key-2"])) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/resource-configmap-key-location-route.groovy", "--resource", "configmap:my-cm-multi/my-configmap-key-2@/tmp/app/test.txt").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "resource-configmap-key-location-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "resource-configmap-key-location-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-key-location-route"), TestTimeoutShort).ShouldNot(ContainSubstring(cmDataMulti["my-configmap-key"])) + g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-key-location-route"), TestTimeoutShort).Should(ContainSubstring(cmDataMulti["my-configmap-key-2"])) }) - // Store a configmap as property file - var cmDataProps = make(map[string]string) - cmDataProps["my.properties"] = "my.key.1=hello\nmy.key.2=world" - CreatePlainTextConfigmap(t, ns, "my-cm-properties", cmDataProps) - t.Run("Config configmap as property file", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-configmap-properties-route.groovy", "--config", "configmap:my-cm-properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "config-configmap-properties-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "config-configmap-properties-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "config-configmap-properties-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) + // Store a configmap as property file + var cmDataProps = make(map[string]string) + cmDataProps["my.properties"] = "my.key.1=hello\nmy.key.2=world" + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-properties", cmDataProps) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-configmap-properties-route.groovy", "--config", "configmap:my-cm-properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-properties-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) }) // Secret @@ -207,127 +205,123 @@ func TestRunConfigExamples(t *testing.T) { // Store a secret on the cluster var secData = make(map[string]string) secData["my-secret-key"] = "very top secret" - CreatePlainTextSecret(t, ns, "my-sec", secData) + CreatePlainTextSecret(t, ctx, ns, "my-sec", secData) // Store a secret with multi values var secDataMulti = make(map[string]string) secDataMulti["my-secret-key"] = "very top secret" secDataMulti["my-secret-key-2"] = "even more secret" - CreatePlainTextSecret(t, ns, "my-sec-multi", secDataMulti) + CreatePlainTextSecret(t, ctx, ns, "my-sec-multi", secDataMulti) t.Run("Config secret", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-secret-route.groovy", "--config", "secret:my-sec").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "config-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "config-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"])) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-secret-route.groovy", "--config", "secret:my-sec").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"])) }) t.Run("Resource secret", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/resource-secret-route.groovy", "--resource", "secret:my-sec").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "resource-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "resource-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "resource-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"])) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/resource-secret-route.groovy", "--resource", "secret:my-sec").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "resource-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "resource-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "resource-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"])) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Secret with filtered key", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/config-secret-key-route.groovy", "--config", "secret:my-sec-multi/my-secret-key-2").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "config-secret-key-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "config-secret-key-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "config-secret-key-route"), TestTimeoutShort).ShouldNot(ContainSubstring(secDataMulti["my-secret-key"])) - g.Eventually(IntegrationLogs(t, ns, "config-secret-key-route"), TestTimeoutShort).Should(ContainSubstring(secDataMulti["my-secret-key-2"])) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/config-secret-key-route.groovy", "--config", "secret:my-sec-multi/my-secret-key-2").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-secret-key-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-secret-key-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-secret-key-route"), TestTimeoutShort).ShouldNot(ContainSubstring(secDataMulti["my-secret-key"])) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-secret-key-route"), TestTimeoutShort).Should(ContainSubstring(secDataMulti["my-secret-key-2"])) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) // Build-Properties t.Run("Build time property", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-route.groovy", "--build-property", "quarkus.application.name=my-super-application").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-route.groovy", "--build-property", "quarkus.application.name=my-super-application").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application")) // Don't delete - we need it for next test execution }) // We need to check also that the property (which is available in the IntegrationKit) is correctly replaced and we don't reuse the same kit t.Run("Build time property updated", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-route.groovy", "--name", "build-property-route-updated", - "--build-property", "quarkus.application.name=my-super-application-updated").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-route-updated"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-route-updated", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-route-updated"), TestTimeoutShort).Should(ContainSubstring("my-super-application-updated")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-route.groovy", "--name", "build-property-route-updated", "--build-property", "quarkus.application.name=my-super-application-updated").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-route-updated"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-route-updated", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-route-updated"), TestTimeoutShort).Should(ContainSubstring("my-super-application-updated")) // Verify the integration kits are different - g.Eventually(IntegrationKit(t, ns, "build-property-route-updated")).ShouldNot(Equal(IntegrationKit(t, ns, "build-property-route")())) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Eventually(IntegrationKit(t, ctx, ns, "build-property-route-updated")).ShouldNot(Equal(IntegrationKit(t, ctx, ns, "build-property-route")())) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) // Build-Properties file t.Run("Build time property file", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Build time property file with precedence", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "quarkus.application.name=my-overridden-application", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutMedium).Should(ContainSubstring("my-overridden-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--name", "build-property-file-route-precedence", "--build-property", "quarkus.application.name=my-overridden-application", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route-precedence"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route-precedence", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route-precedence"), TestTimeoutShort).Should(ContainSubstring("my-overridden-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route-precedence", "-n", ns).Execute()).To(Succeed()) }) t.Run("Build time property from ConfigMap", func(t *testing.T) { var cmData = make(map[string]string) cmData["quarkus.application.name"] = "my-cool-application" - CreatePlainTextConfigmap(t, ns, "my-cm-test-build-property", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-test-build-property", cmData) - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "configmap:my-cm-test-build-property").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutLong).Should(ContainSubstring("my-cool-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "configmap:my-cm-test-build-property").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-cool-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Build time property from ConfigMap as property file", func(t *testing.T) { var cmData = make(map[string]string) cmData["my.properties"] = "quarkus.application.name=my-super-cool-application" - CreatePlainTextConfigmap(t, ns, "my-cm-test-build-properties", cmData) - - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "configmap:my-cm-test-build-properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-cool-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-test-build-properties", cmData) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--name", "build-property-file-route-cm", "--build-property", "configmap:my-cm-test-build-properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route-cm"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route-cm", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route-cm"), TestTimeoutShort).Should(ContainSubstring("my-super-cool-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route-cm", "-n", ns).Execute()).To(Succeed()) }) t.Run("Build time property from Secret", func(t *testing.T) { var secData = make(map[string]string) secData["quarkus.application.name"] = "my-great-application" - CreatePlainTextSecret(t, ns, "my-sec-test-build-property", secData) - - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "secret:my-sec-test-build-property").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-great-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + CreatePlainTextSecret(t, ctx, ns, "my-sec-test-build-property", secData) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "secret:my-sec-test-build-property").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-great-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) }) t.Run("Build time property from Secret as property file", func(t *testing.T) { var secData = make(map[string]string) secData["my.properties"] = "quarkus.application.name=my-awsome-application" - CreatePlainTextSecret(t, ns, "my-sec-test-build-properties", secData) - - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "secret:my-sec-test-build-properties").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-awsome-application")) - g.Expect(Kamel(t, "delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed()) + CreatePlainTextSecret(t, ctx, ns, "my-sec-test-build-properties", secData) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/build-property-file-route.groovy", "--name", "build-property-file-route-secret", "--build-property", "secret:my-sec-test-build-properties").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "build-property-file-route-secret"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "build-property-file-route-secret", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "build-property-file-route-secret"), TestTimeoutShort).Should(ContainSubstring("my-awsome-application")) + g.Expect(Kamel(t, ctx, "delete", "build-property-file-route-secret", "-n", ns).Execute()).To(Succeed()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/config/kamelet_config_test.go b/e2e/common/config/kamelet_config_test.go index 67114fdedb..8dcc0c2c1b 100644 --- a/e2e/common/config/kamelet_config_test.go +++ b/e2e/common/config/kamelet_config_test.go @@ -23,6 +23,7 @@ limitations under the License. package config import ( + "context" "testing" . "github.com/onsi/gomega" @@ -38,102 +39,102 @@ import ( func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-config-kamelet-user-property" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run test default config using properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig01-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig01-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int01") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationConfiguration01.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationConfiguration01.java", "-p", "camel.kamelet.iconfig01-timer-source.message='Default message 01'", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("Default message 01")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("Default message 01")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig01-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig01-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config using mounted secret", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig03-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig03-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int3") secretName := "my-iconfig-int3-secret" var secData = make(map[string]string) secData["camel.kamelet.iconfig03-timer-source.message"] = "very top mounted secret message" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationConfiguration03.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationConfiguration03.java", "-t", "mount.configs=secret:"+secretName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top mounted secret message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top mounted secret message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig03-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig03-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config using mounted configmap", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig04-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig04-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int4") cmName := "my-iconfig-int4-configmap" var cmData = make(map[string]string) cmData["camel.kamelet.iconfig04-timer-source.message"] = "very top mounted configmap message" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationConfiguration04.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationConfiguration04.java", "-t", "mount.configs=configmap:"+cmName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top mounted configmap message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top mounted configmap message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "iconfig04-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig04-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test named config using properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig05-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig05-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int5") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration05.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration05.java", "-p", "camel.kamelet.iconfig05-timer-source.message='Default message 05'", "-p", "camel.kamelet.iconfig05-timer-source.mynamedconfig.message='My Named Config message'", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My Named Config message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My Named Config message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig05-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig05-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test named config using labeled secret", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig06-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig06-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int6") secretName := "my-iconfig-int6-secret" @@ -143,78 +144,78 @@ func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) { var labels = make(map[string]string) labels["camel.apache.org/kamelet"] = "iconfig06-timer-source" labels["camel.apache.org/kamelet.configuration"] = "mynamedconfig" - g.Expect(CreatePlainTextSecretWithLabels(t, ns, secretName, secData, labels)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) + g.Expect(CreatePlainTextSecretWithLabels(t, ctx, ns, secretName, secData, labels)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration06.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration06.java", "-p", "camel.kamelet.iconfig06-timer-source.message='Default message 06'", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top named secret message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top named secret message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig06-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig06-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test named config using mounted secret", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig07-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig07-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int7") secretName := "my-iconfig-int7-secret" var secData = make(map[string]string) secData["camel.kamelet.iconfig07-timer-source.mynamedconfig.message"] = "very top named mounted secret message" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration07.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration07.java", "-p", "camel.kamelet.iconfig07-timer-source.message='Default message 07'", "-t", "mount.configs=secret:"+secretName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top named mounted secret message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top named mounted secret message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig07-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig07-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test named config using mounted configmap", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig08-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig08-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int8") cmName := "my-iconfig-int8-configmap" var cmData = make(map[string]string) cmData["camel.kamelet.iconfig08-timer-source.mynamedconfig.message"] = "very top named mounted configmap message" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration08.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationNamedConfiguration08.java", "-p", "camel.kamelet.iconfig08-timer-source.message='Default message 08'", "-t", "mount.configs=configmap:"+cmName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top named mounted configmap message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top named mounted configmap message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "iconfig08-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig08-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config using labeled secret", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "iconfig09-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "iconfig09-timer-source")()).To(Succeed()) name := RandomizedSuffixName("iconfig-test-timer-source-int9") secretName := "my-iconfig-int9-secret" @@ -223,70 +224,70 @@ func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) { secData["camel.kamelet.iconfig09-timer-source.message"] = "very top labeled secret message" var labels = make(map[string]string) labels["camel.apache.org/kamelet"] = "iconfig09-timer-source" - g.Expect(CreatePlainTextSecretWithLabels(t, ns, secretName, secData, labels)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) + g.Expect(CreatePlainTextSecretWithLabels(t, ctx, ns, secretName, secData, labels)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(Not(BeNil())) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegrationConfiguration09.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegrationConfiguration09.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("very top labeled secret message")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("very top labeled secret message")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) - g.Eventually(SecretByName(t, ns, secretName), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "iconfig09-timer-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) + g.Eventually(SecretByName(t, ctx, ns, secretName), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "iconfig09-timer-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config inlined properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "config01-timer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "config01-log-sink")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "config01-timer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "config01-log-sink")()).To(Succeed()) name := RandomizedSuffixName("config-test-timer-source-int1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-kamelet-integration-inlined-configuration-01.yaml", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-kamelet-integration-inlined-configuration-01.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("important message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("integrationLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("important message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("integrationLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "config01-timer-source")).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config01-log-sink")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "config01-timer-source")).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config01-log-sink")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config parameters properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "config02-timer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "config02-log-sink")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "config02-timer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "config02-log-sink")()).To(Succeed()) name := RandomizedSuffixName("config-test-timer-source-int2") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-02.yaml", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-02.yaml", "-p", "my-message='My parameter message 02'", "-p", "my-logger='myIntegrationLogger02'", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My parameter message 02")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myIntegrationLogger02")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My parameter message 02")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myIntegrationLogger02")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteKamelet(t, ns, "config02-timer-source")).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config02-log-sink")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteKamelet(t, ctx, ns, "config02-timer-source")).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config02-log-sink")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config secret properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "config03-timer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "config03-log-sink")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "config03-timer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "config03-log-sink")()).To(Succeed()) name := RandomizedSuffixName("config-test-timer-source-int3") secretName := "my-config-int3-secret" @@ -294,28 +295,28 @@ func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) { var secData = make(map[string]string) secData["my-message"] = "My secret message 03" secData["my-logger"] = "mySecretIntegrationLogger03" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-03.yaml", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-03.yaml", "-t", "mount.configs=secret:"+secretName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My secret message 03")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("mySecretIntegrationLogger03")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My secret message 03")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("mySecretIntegrationLogger03")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config03-timer-source")).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config03-log-sink")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config03-timer-source")).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config03-log-sink")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run test default config configmap properties", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "config04-timer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "config04-log-sink")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "config04-timer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "config04-log-sink")()).To(Succeed()) name := RandomizedSuffixName("config-test-timer-source-int4") cmName := "my-config-int4-configmap" @@ -323,22 +324,22 @@ func TestKameletImplicitConfigDefaultUserProperty(t *testing.T) { var cmData = make(map[string]string) cmData["my-message"] = "My configmap message 04" cmData["my-logger"] = "myConfigmapIntegrationLogger04" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-04.yaml", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-kamelet-integration-parameters-configuration-04.yaml", "-t", "mount.configs=configmap:"+cmName, "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My configmap message 04")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myConfigmapIntegrationLogger04")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My configmap message 04")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myConfigmapIntegrationLogger04")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config04-timer-source")).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, "config04-log-sink")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config04-timer-source")).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "config04-log-sink")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) diff --git a/e2e/common/config/pipe_config_test.go b/e2e/common/config/pipe_config_test.go index b471b10121..3c3acc4382 100644 --- a/e2e/common/config/pipe_config_test.go +++ b/e2e/common/config/pipe_config_test.go @@ -23,6 +23,7 @@ limitations under the License. package config import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,32 +37,32 @@ import ( func TestPipeConfig(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-pipe-config" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("test custom source/sink pipe", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "my-pipe-timer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "my-pipe-log-sink")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "my-pipe-timer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "my-pipe-log-sink")()).To(Succeed()) t.Run("run test default config using properties", func(t *testing.T) { name := RandomizedSuffixName("my-pipe-with-properties") - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-p", "source.message=My pipe message", "-p", "sink.loggerName=myPipeLogger", "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) t.Run("run test implicit default config using labeled secret", func(t *testing.T) { @@ -72,20 +73,20 @@ func TestPipeConfig(t *testing.T) { secData["camel.kamelet.my-pipe-timer-source.message"] = "My pipe secret message" var labels = make(map[string]string) labels["camel.apache.org/kamelet"] = "my-pipe-timer-source" - g.Expect(CreatePlainTextSecretWithLabels(t, ns, secretName, secData, labels)).To(Succeed()) + g.Expect(CreatePlainTextSecretWithLabels(t, ctx, ns, secretName, secData, labels)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-p", "sink.loggerName=myDefaultLogger", "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe secret message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myDefaultLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe secret message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myDefaultLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) }) t.Run("run test implicit default config using mounted secret", func(t *testing.T) { @@ -95,20 +96,20 @@ func TestPipeConfig(t *testing.T) { var secData = make(map[string]string) secData["camel.kamelet.my-pipe-timer-source.message"] = "My pipe secret message" secData["camel.kamelet.my-pipe-log-sink.loggerName"] = "myPipeSecretLogger" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=secret:"+secretName, "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe secret message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeSecretLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe secret message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeSecretLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) }) t.Run("run test implicit default config using mounted configmap", func(t *testing.T) { @@ -118,20 +119,20 @@ func TestPipeConfig(t *testing.T) { var cmData = make(map[string]string) cmData["camel.kamelet.my-pipe-timer-source.message"] = "My pipe configmap message" cmData["camel.kamelet.my-pipe-log-sink.loggerName"] = "myPipeConfigmapLogger" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=configmap:"+cmName, "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe configmap message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeConfigmapLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe configmap message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeConfigmapLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) }) t.Run("run test implicit named config using mounted secret", func(t *testing.T) { @@ -141,9 +142,9 @@ func TestPipeConfig(t *testing.T) { var secData = make(map[string]string) secData["camel.kamelet.my-pipe-timer-source.mynamedconfig.message"] = "My pipe named secret message" secData["camel.kamelet.my-pipe-log-sink.mynamedconfig.loggerName"] = "myPipeNamedSecretLogger" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=secret:"+secretName, @@ -152,12 +153,12 @@ func TestPipeConfig(t *testing.T) { "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe named secret message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeNamedSecretLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe named secret message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeNamedSecretLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) }) t.Run("run test implicit named config using mounted configmap", func(t *testing.T) { @@ -167,9 +168,9 @@ func TestPipeConfig(t *testing.T) { var cmData = make(map[string]string) cmData["camel.kamelet.my-pipe-timer-source.mynamedconfig.message"] = "My pipe named configmap message" cmData["camel.kamelet.my-pipe-log-sink.mynamedconfig.loggerName"] = "myPipeNamedConfigmapLogger" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=configmap:"+cmName, @@ -178,12 +179,12 @@ func TestPipeConfig(t *testing.T) { "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe named configmap message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeNamedConfigmapLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe named configmap message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeNamedConfigmapLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) }) t.Run("run test implicit specific config using mounted secret", func(t *testing.T) { name := RandomizedSuffixName("my-pipe-with-specific-secret") @@ -192,9 +193,9 @@ func TestPipeConfig(t *testing.T) { var secData = make(map[string]string) secData["mynamedconfig.message"] = "My pipe specific secret message" secData["mynamedconfig.loggerName"] = "myPipeSpecificSecretLogger" - g.Expect(CreatePlainTextSecret(t, ns, secretName, secData)).To(Succeed()) + g.Expect(CreatePlainTextSecret(t, ctx, ns, secretName, secData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=secret:"+secretName, @@ -203,12 +204,12 @@ func TestPipeConfig(t *testing.T) { "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe specific secret message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeSpecificSecretLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe specific secret message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeSpecificSecretLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteSecret(t, ns, secretName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteSecret(t, ctx, ns, secretName)).To(Succeed()) }) t.Run("run test implicit specific config using mounted configmap", func(t *testing.T) { name := RandomizedSuffixName("my-pipe-with-specific-configmap") @@ -217,9 +218,9 @@ func TestPipeConfig(t *testing.T) { var cmData = make(map[string]string) cmData["mynamedconfig.message"] = "My pipe specific configmap message" cmData["mynamedconfig.loggerName"] = "myPipeSpecificConfgmapLogger" - g.Expect(CreatePlainTextConfigmap(t, ns, cmName, cmData)).To(Succeed()) + g.Expect(CreatePlainTextConfigmap(t, ctx, ns, cmName, cmData)).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-pipe-timer-source", "my-pipe-log-sink", "-t", "mount.configs=configmap:"+cmName, @@ -228,15 +229,15 @@ func TestPipeConfig(t *testing.T) { "--name", name, ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("My pipe specific configmap message")) - g.Eventually(IntegrationLogs(t, ns, name)).Should(ContainSubstring("myPipeSpecificConfgmapLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("My pipe specific configmap message")) + g.Eventually(IntegrationLogs(t, ctx, ns, name)).Should(ContainSubstring("myPipeSpecificConfgmapLogger")) - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteConfigmap(t, ns, cmName)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteConfigmap(t, ctx, ns, cmName)).To(Succeed()) }) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/groovy_test.go b/e2e/common/languages/groovy_test.go index d4aa497244..424f1d02e5 100644 --- a/e2e/common/languages/groovy_test.go +++ b/e2e/common/languages/groovy_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleGroovyExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-groovy" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run groovy", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "groovy"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "groovy", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/groovy.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "groovy"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "groovy", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "groovy"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/java_test.go b/e2e/common/languages/java_test.go index 9e6873e116..7a94420f42 100644 --- a/e2e/common/languages/java_test.go +++ b/e2e/common/languages/java_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleJavaExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-java" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run java", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/js_test.go b/e2e/common/languages/js_test.go index 4234f28077..a07d3dbe94 100644 --- a/e2e/common/languages/js_test.go +++ b/e2e/common/languages/js_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleJavaScriptExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-js" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run js", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/js.js").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "js"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "js", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "js"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/js.js").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "js"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "js", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "js"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/kotlin_test.go b/e2e/common/languages/kotlin_test.go index e1e360d46d..c0cac74937 100644 --- a/e2e/common/languages/kotlin_test.go +++ b/e2e/common/languages/kotlin_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleKotlinExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-kotlin" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run kotlin", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/kotlin.kts").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "kotlin"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "kotlin", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "kotlin"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/kotlin.kts").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "kotlin"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "kotlin", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "kotlin"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/polyglot_test.go b/e2e/common/languages/polyglot_test.go index 21a5d51f1a..457ded99ff 100644 --- a/e2e/common/languages/polyglot_test.go +++ b/e2e/common/languages/polyglot_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,22 +37,22 @@ import ( func TestRunPolyglotExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-polyglot" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run polyglot", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "--name", "polyglot", "files/js-polyglot.js", "files/yaml-polyglot.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "polyglot"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "polyglot", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "polyglot"), TestTimeoutShort).Should(ContainSubstring("Magicpolyglot-yaml")) - g.Eventually(IntegrationLogs(t, ns, "polyglot"), TestTimeoutShort).Should(ContainSubstring("Magicpolyglot-js")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "polyglot", "files/js-polyglot.js", "files/yaml-polyglot.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "polyglot"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "polyglot", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "polyglot"), TestTimeoutShort).Should(ContainSubstring("Magicpolyglot-yaml")) + g.Eventually(IntegrationLogs(t, ctx, ns, "polyglot"), TestTimeoutShort).Should(ContainSubstring("Magicpolyglot-js")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/xml_test.go b/e2e/common/languages/xml_test.go index a53d4da320..90c3ccde0b 100644 --- a/e2e/common/languages/xml_test.go +++ b/e2e/common/languages/xml_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleXmlExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-xml" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run xml", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/xml.xml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "xml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "xml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "xml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/xml.xml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "xml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "xml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "xml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/languages/yaml_test.go b/e2e/common/languages/yaml_test.go index 270445375c..6eb6b44825 100644 --- a/e2e/common/languages/yaml_test.go +++ b/e2e/common/languages/yaml_test.go @@ -23,6 +23,7 @@ limitations under the License. package languages import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,21 +37,21 @@ import ( func TestRunSimpleYamlExamples(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes-yaml" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run yaml", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/main_test.go b/e2e/common/main_test.go index ff84d996c0..c077ae4b0c 100644 --- a/e2e/common/main_test.go +++ b/e2e/common/main_test.go @@ -41,25 +41,29 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } - operatorID := platform.DefaultPlatformName - ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) + fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false") + if fastSetup == "true" { + operatorID := platform.DefaultPlatformName + ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - g := NewGomega(func(message string, callerSkip ...int) { - fmt.Printf("Test setup failed! - %s\n", message) - }) + g := NewGomega(func(message string, callerSkip ...int) { + fmt.Printf("Test setup failed! - %s\n", message) + }) - var t *testing.T + var t *testing.T - g.Expect(TestClient(t)).ShouldNot(BeNil()) - g.Expect(KamelRunWithID(t, operatorID, ns, "languages/files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "languages/files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(KamelRunWithID(t, operatorID, ns, "languages/files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "languages/files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + } os.Exit(m.Run()) } diff --git a/e2e/common/misc/client_test.go b/e2e/common/misc/client_test.go index 9a5f447397..54dbbd99d8 100644 --- a/e2e/common/misc/client_test.go +++ b/e2e/common/misc/client_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -41,32 +42,31 @@ import ( func TestClientFunctionalities(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { - + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { cfg, err := config.GetConfig() require.NoError(t, err) camel, err := versioned.NewForConfig(cfg) require.NoError(t, err) - lst, err := camel.CamelV1().Integrations(ns).List(TestContext, metav1.ListOptions{}) + lst, err := camel.CamelV1().Integrations(ns).List(ctx, metav1.ListOptions{}) require.NoError(t, err) assert.Empty(t, lst.Items) - integration, err := camel.CamelV1().Integrations(ns).Create(TestContext, &v1.Integration{ + integration, err := camel.CamelV1().Integrations(ns).Create(ctx, &v1.Integration{ ObjectMeta: metav1.ObjectMeta{ Name: "dummy", }, }, metav1.CreateOptions{}) require.NoError(t, err) - lst, err = camel.CamelV1().Integrations(ns).List(TestContext, metav1.ListOptions{}) + lst, err = camel.CamelV1().Integrations(ns).List(ctx, metav1.ListOptions{}) require.NoError(t, err) assert.NotEmpty(t, lst.Items) assert.Equal(t, lst.Items[0].Name, integration.Name) - err = camel.CamelV1().Integrations(ns).Delete(TestContext, "dummy", metav1.DeleteOptions{}) + err = camel.CamelV1().Integrations(ns).Delete(ctx, "dummy", metav1.DeleteOptions{}) require.NoError(t, err) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/cron_test.go b/e2e/common/misc/cron_test.go index 339af3da71..256ef653cf 100644 --- a/e2e/common/misc/cron_test.go +++ b/e2e/common/misc/cron_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,49 +37,49 @@ import ( func TestRunCronExample(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-cron" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("cron", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/cron.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationCronJob(t, ns, "cron"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ns, "cron", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "cron"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron"), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-yaml", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/cron-yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationCronJob(t, ns, "cron-yaml"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ns, "cron-yaml", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "cron-yaml"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-yaml"), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-yaml", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-yaml"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-timer", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/cron-timer.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationCronJob(t, ns, "cron-timer"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ns, "cron-timer", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "cron-timer"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-timer.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-timer"), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-timer", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-timer"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-fallback", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/cron-fallback.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "cron-fallback"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-fallback.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-fallback"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-quartz", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/cron-quartz.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "cron-quartz"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "cron-quartz", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "cron-quartz"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-quartz.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-quartz"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-quartz", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-quartz"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/integration_fail_test.go b/e2e/common/misc/integration_fail_test.go index b2468bea32..cdd731be46 100644 --- a/e2e/common/misc/integration_fail_test.go +++ b/e2e/common/misc/integration_fail_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" "time" @@ -37,158 +38,157 @@ import ( func TestBadRouteIntegration(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-bad-route" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run bad java route", func(t *testing.T) { name := RandomizedSuffixName("bad-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/BadRoute.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/BadRoute.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) // Make sure the Integration can be scaled - g.Expect(ScaleIntegration(t, ns, name, 2)).To(Succeed()) + g.Expect(ScaleIntegration(t, ctx, ns, name, 2)).To(Succeed()) // Check the scale cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(2)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(2)) // Check it also cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) // Check the Integration stays in error phase - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) // Kit valid - kitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) + kitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) }) t.Run("run missing dependency java route", func(t *testing.T) { name := RandomizedSuffixName("java-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-d", "mvn:com.example:nonexistent:1.0").Execute()).To(Succeed()) // Integration in error - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should( + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionKitAvailableReason))) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort).Should( WithTransform(IntegrationConditionMessage, ContainSubstring("is in state \"Error\""))) // Kit in error - kitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseError)) + kitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseError)) //Build in error with 5 attempts - build := Build(t, integrationKitNamespace, kitName)() + build := Build(t, ctx, integrationKitNamespace, kitName)() g.Eventually(build.Status.Phase, TestTimeoutShort).Should(Equal(v1.BuildPhaseError)) g.Eventually(build.Status.Failure.Recovery.Attempt, TestTimeoutShort).Should(Equal(5)) // Fixing the route should reconcile the Integration - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseRunning)) // New Kit success - kitRecoveryName := IntegrationKit(t, ns, name)() - integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) + kitRecoveryName := IntegrationKit(t, ctx, ns, name)() + integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) g.Expect(kitRecoveryName).NotTo(Equal(kitName)) // New Build success - buildRecovery := Build(t, integrationKitRecoveryNamespace, kitRecoveryName)() + buildRecovery := Build(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName)() g.Eventually(buildRecovery.Status.Phase, TestTimeoutShort).Should(Equal(v1.BuildPhaseSucceeded)) }) t.Run("run invalid dependency java route", func(t *testing.T) { name := RandomizedSuffixName("invalid-dependency") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-d", "camel:non-existent").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-d", "camel:non-existent").Execute()).To(Succeed()) // Integration in error with Initialization Failed condition - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionInitializationFailedReason)), WithTransform(IntegrationConditionMessage, HavePrefix("error during trait customization")), )) // Kit shouldn't be created - g.Consistently(IntegrationKit(t, ns, name), 10*time.Second).Should(BeEmpty()) + g.Consistently(IntegrationKit(t, ctx, ns, name), 10*time.Second).Should(BeEmpty()) // Fixing the route should reconcile the Integration in Initialization Failed condition to Running - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // New Kit success - kitRecoveryName := IntegrationKit(t, ns, name)() - integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) + kitRecoveryName := IntegrationKit(t, ctx, ns, name)() + integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) // New Build success - buildRecovery := Build(t, integrationKitRecoveryNamespace, kitRecoveryName)() + buildRecovery := Build(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName)() g.Eventually(buildRecovery.Status.Phase, TestTimeoutShort).Should(Equal(v1.BuildPhaseSucceeded)) }) t.Run("run unresolvable component java route", func(t *testing.T) { name := RandomizedSuffixName("unresolvable-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Unresolvable.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Unresolvable.java", "--name", name).Execute()).To(Succeed()) // Integration in error with Initialization Failed condition - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionInitializationFailedReason)), WithTransform(IntegrationConditionMessage, HavePrefix("error during trait customization")), )) // Kit shouldn't be created - g.Consistently(IntegrationKit(t, ns, name), 10*time.Second).Should(BeEmpty()) + g.Consistently(IntegrationKit(t, ctx, ns, name), 10*time.Second).Should(BeEmpty()) // Fixing the route should reconcile the Integration in Initialization Failed condition to Running - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // New Kit success - kitRecoveryName := IntegrationKit(t, ns, name)() - integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) + kitRecoveryName := IntegrationKit(t, ctx, ns, name)() + integrationKitRecoveryNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) // New Build success - buildRecovery := Build(t, integrationKitRecoveryNamespace, kitRecoveryName)() + buildRecovery := Build(t, ctx, integrationKitRecoveryNamespace, kitRecoveryName)() g.Eventually(buildRecovery.Status.Phase, TestTimeoutShort).Should(Equal(v1.BuildPhaseSucceeded)) }) t.Run("run invalid java route", func(t *testing.T) { name := RandomizedSuffixName("invalid-java-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/InvalidJava.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/InvalidJava.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Compilation error")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Compilation error")) // Kit valid - kitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() - g.Eventually(KitPhase(t, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) + kitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() + g.Eventually(KitPhase(t, ctx, integrationKitNamespace, kitName), TestTimeoutShort).Should(Equal(v1.IntegrationKitPhaseReady)) // Fixing the route should reconcile the Integration in Initialization Failed condition to Running - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Kit should not have changed - kitRecoveryName := IntegrationKit(t, ns, name)() + kitRecoveryName := IntegrationKit(t, ctx, ns, name)() g.Expect(kitRecoveryName).To(Equal(kitName)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/integration_trait_update_test.go b/e2e/common/misc/integration_trait_update_test.go index d56fee0f16..839c51e580 100644 --- a/e2e/common/misc/integration_trait_update_test.go +++ b/e2e/common/misc/integration_trait_update_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" "time" @@ -36,27 +37,27 @@ import ( func TestTraitUpdates(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-trait-update" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("run and update trait", func(t *testing.T) { name := RandomizedSuffixName("yaml-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) var numberOfPods = func(pods *int32) bool { return *pods >= 1 && *pods <= 2 } // Adding a property will change the camel trait - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name, "-p", "hello=world").Execute()).To(Succeed()) - g.Consistently(IntegrationPodsNumbers(t, ns, name), TestTimeoutShort, 1*time.Second).Should(Satisfy(numberOfPods)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name, "-p", "hello=world").Execute()).To(Succeed()) + g.Consistently(IntegrationPodsNumbers(t, ctx, ns, name), TestTimeoutShort, 1*time.Second).Should(Satisfy(numberOfPods)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/kamelet_test.go b/e2e/common/misc/kamelet_test.go index 6558d4ba80..f9b58f279d 100644 --- a/e2e/common/misc/kamelet_test.go +++ b/e2e/common/misc/kamelet_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,13 +37,13 @@ import ( func TestKameletClasspathLoading(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-kamelet-loading" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Store a configmap on the cluster var cmData = make(map[string]string) @@ -117,28 +118,23 @@ spec: constant: "{{contentType}}" - to: kamelet:sink ` - CreatePlainTextConfigmap(t, ns, "my-kamelet-cm", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-kamelet-cm", cmData) // Basic t.Run("test basic case", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/TimerKameletIntegration.java", "-t", "kamelets.enabled=false", - "--resource", "configmap:my-kamelet-cm@/kamelets", - "-p camel.component.kamelet.location=file:/kamelets", - "-d", "camel:yaml-dsl", - // kamelet dependencies - "-d", "camel:timer").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "timer-kamelet-integration"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "timer-kamelet-integration")).Should(ContainSubstring("important message")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerKameletIntegration.java", "-t", "kamelets.enabled=false", "--resource", "configmap:my-kamelet-cm@/kamelets", "-p camel.component.kamelet.location=file:/kamelets", "-d", "camel:yaml-dsl", "-d", "camel:timer").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-kamelet-integration"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "timer-kamelet-integration")).Should(ContainSubstring("important message")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "timer-kamelet-integration")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "timer-kamelet-integration")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "timer-kamelet-integration")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "timer-kamelet-integration")() kameletsTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "kamelets") g.Expect(kameletsTrait).ToNot(BeNil()) g.Expect(len(kameletsTrait)).To(Equal(1)) g.Expect(kameletsTrait["enabled"]).To(Equal(false)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/kamelet_update_test.go b/e2e/common/misc/kamelet_update_test.go index f97eb530cd..2be7c7e82c 100644 --- a/e2e/common/misc/kamelet_update_test.go +++ b/e2e/common/misc/kamelet_update_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" "time" @@ -37,27 +38,27 @@ const customLabel = "custom-label" func TestBundleKameletUpdate(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-kamelet-bundle" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(createBundleKamelet(t, operatorID, ns, "my-http-sink")()).To(Succeed()) // Going to be replaced - g.Expect(createUserKamelet(t, operatorID, ns, "user-sink")()).To(Succeed()) // Left intact by the operator + g.Expect(createBundleKamelet(t, ctx, operatorID, ns, "my-http-sink")()).To(Succeed()) // Going to be replaced + g.Expect(createUserKamelet(t, ctx, operatorID, ns, "user-sink")()).To(Succeed()) // Left intact by the operator - g.Eventually(Kamelet(t, "my-http-sink", ns)). + g.Eventually(Kamelet(t, ctx, "my-http-sink", ns)). Should(WithTransform(KameletLabels, HaveKeyWithValue(customLabel, "true"))) - g.Consistently(Kamelet(t, "user-sink", ns), 5*time.Second, 1*time.Second). + g.Consistently(Kamelet(t, ctx, "user-sink", ns), 5*time.Second, 1*time.Second). Should(WithTransform(KameletLabels, HaveKeyWithValue(customLabel, "true"))) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } -func createBundleKamelet(t *testing.T, operatorID string, ns string, name string) func() error { +func createBundleKamelet(t *testing.T, ctx context.Context, operatorID string, ns string, name string) func() error { flow := map[string]interface{}{ "from": map[string]interface{}{ "uri": "kamelet:source", @@ -68,10 +69,10 @@ func createBundleKamelet(t *testing.T, operatorID string, ns string, name string customLabel: "true", v1.KameletBundledLabel: "true", } - return CreateKamelet(t, operatorID, ns, name, flow, nil, labels) + return CreateKamelet(t, operatorID, ctx, ns, name, flow, nil, labels) } -func createUserKamelet(t *testing.T, operatorID string, ns string, name string) func() error { +func createUserKamelet(t *testing.T, ctx context.Context, operatorID string, ns string, name string) func() error { flow := map[string]interface{}{ "from": map[string]interface{}{ "uri": "kamelet:source", @@ -81,5 +82,5 @@ func createUserKamelet(t *testing.T, operatorID string, ns string, name string) labels := map[string]string{ customLabel: "true", } - return CreateKamelet(t, operatorID, ns, name, flow, nil, labels) + return CreateKamelet(t, operatorID, ctx, ns, name, flow, nil, labels) } diff --git a/e2e/common/misc/maven_repository_test.go b/e2e/common/misc/maven_repository_test.go index 5b2ea10d1e..3be75182e3 100644 --- a/e2e/common/misc/maven_repository_test.go +++ b/e2e/common/misc/maven_repository_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,29 +37,25 @@ import ( func TestRunExtraRepository(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-extra-repository" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--maven-repository", "https://maven.repository.redhat.com/ga@id=redhat", - "--dependency", "mvn:org.jolokia:jolokia-core:1.7.1.redhat-00001", - "--name", name, - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--maven-repository", "https://maven.repository.redhat.com/ga@id=redhat", "--dependency", "mvn:org.jolokia:jolokia-core:1.7.1.redhat-00001", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Integration(t, ns, name)).Should(WithTransform(IntegrationSpec, And( + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(Integration(t, ctx, ns, name)).Should(WithTransform(IntegrationSpec, And( HaveExistingField("Repositories"), HaveField("Repositories", ContainElements("https://maven.repository.redhat.com/ga@id=redhat")), ))) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/pipe_test.go b/e2e/common/misc/pipe_test.go index ef2f609362..eb79f82083 100644 --- a/e2e/common/misc/pipe_test.go +++ b/e2e/common/misc/pipe_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,75 +38,66 @@ import ( func TestPipe(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-pipe" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Error Handler testing t.Run("test error handler", func(t *testing.T) { - g.Expect(createErrorProducerKamelet(t, operatorID, ns, "my-own-error-producer-source")()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, "my-own-log-sink")()).To(Succeed()) + g.Expect(createErrorProducerKamelet(t, ctx, operatorID, ns, "my-own-error-producer-source")()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, "my-own-log-sink")()).To(Succeed()) t.Run("throw error test", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, - "my-own-error-producer-source", - "my-own-log-sink", + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-own-error-producer-source", "my-own-log-sink", "--error-handler", "sink:my-own-log-sink", "-p", "source.message=throw Error", "-p", "sink.loggerName=integrationLogger", "-p", "error-handler.loggerName=kameletErrorHandler", // Needed in the test to make sure to do the right string comparison later "-t", "logging.color=false", - "--name", "throw-error-binding", - ).Execute()).To(Succeed()) + "--name", "throw-error-binding").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "throw-error-binding"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "throw-error-binding"), TestTimeoutShort).Should(ContainSubstring("[kameletErrorHandler] (Camel (camel-1) thread #1 - timer://tick)")) - g.Eventually(IntegrationLogs(t, ns, "throw-error-binding"), TestTimeoutShort).ShouldNot(ContainSubstring("[integrationLogger] (Camel (camel-1) thread #1 - timer://tick)")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "throw-error-binding"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "throw-error-binding"), TestTimeoutShort).Should(ContainSubstring("[kameletErrorHandler] (Camel (camel-1) thread #1 - timer://tick)")) + g.Eventually(IntegrationLogs(t, ctx, ns, "throw-error-binding"), TestTimeoutShort).ShouldNot(ContainSubstring("[integrationLogger] (Camel (camel-1) thread #1 - timer://tick)")) }) t.Run("don't throw error test", func(t *testing.T) { - g.Expect(KamelBindWithID(t, operatorID, ns, - "my-own-error-producer-source", - "my-own-log-sink", + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-own-error-producer-source", "my-own-log-sink", "--error-handler", "sink:my-own-log-sink", "-p", "source.message=true", "-p", "sink.loggerName=integrationLogger", "-p", "error-handler.loggerName=kameletErrorHandler", // Needed in the test to make sure to do the right string comparison later "-t", "logging.color=false", - "--name", "no-error-binding", - ).Execute()).To(Succeed()) + "--name", "no-error-binding").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "no-error-binding"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "no-error-binding"), TestTimeoutShort).ShouldNot(ContainSubstring("[kameletErrorHandler] (Camel (camel-1) thread #1 - timer://tick)")) - g.Eventually(IntegrationLogs(t, ns, "no-error-binding"), TestTimeoutShort).Should(ContainSubstring("[integrationLogger] (Camel (camel-1) thread #1 - timer://tick)")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "no-error-binding"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "no-error-binding"), TestTimeoutShort).ShouldNot(ContainSubstring("[kameletErrorHandler] (Camel (camel-1) thread #1 - timer://tick)")) + g.Eventually(IntegrationLogs(t, ctx, ns, "no-error-binding"), TestTimeoutShort).Should(ContainSubstring("[integrationLogger] (Camel (camel-1) thread #1 - timer://tick)")) }) }) //Pipe with traits testing t.Run("test Pipe with trait", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, ns, "my-own-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "my-own-timer-source")()).To(Succeed()) // Log sink kamelet exists from previous test - g.Expect(KamelBindWithID(t, operatorID, ns, - "my-own-timer-source", - "my-own-log-sink", + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-own-timer-source", "my-own-log-sink", "-p", "source.message=hello from test", "-p", "sink.loggerName=integrationLogger", "--annotation", "trait.camel.apache.org/camel.properties=[\"camel.prop1=a\",\"camel.prop2=b\"]", - "--name", "kb-with-traits", - ).Execute()).To(Succeed()) + "--name", "kb-with-traits").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "kb-with-traits"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "kb-with-traits"), TestTimeoutShort).Should(ContainSubstring("hello from test")) - g.Eventually(IntegrationLogs(t, ns, "kb-with-traits"), TestTimeoutShort).Should(ContainSubstring("integrationLogger")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "kb-with-traits"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "kb-with-traits"), TestTimeoutShort).Should(ContainSubstring("hello from test")) + g.Eventually(IntegrationLogs(t, ctx, ns, "kb-with-traits"), TestTimeoutShort).Should(ContainSubstring("integrationLogger")) }) // Pipe with wrong spec @@ -113,22 +105,22 @@ func TestPipe(t *testing.T) { name := RandomizedSuffixName("bad-klb") kb := v1.NewPipe(ns, name) kb.Spec = v1.PipeSpec{} - _, err := kubernetes.ReplaceResource(TestContext, TestClient(t), &kb) + _, err := kubernetes.ReplaceResource(ctx, TestClient(t), &kb) g.Eventually(err).Should(BeNil()) - g.Eventually(PipePhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.PipePhaseError)) - g.Eventually(PipeConditionStatus(t, ns, name, v1.PipeConditionReady), TestTimeoutShort).ShouldNot(Equal(corev1.ConditionTrue)) - g.Eventually(PipeCondition(t, ns, name, v1.PipeIntegrationConditionError), TestTimeoutShort).Should( + g.Eventually(PipePhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.PipePhaseError)) + g.Eventually(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutShort).ShouldNot(Equal(corev1.ConditionTrue)) + g.Eventually(PipeCondition(t, ctx, ns, name, v1.PipeIntegrationConditionError), TestTimeoutShort).Should( WithTransform(PipeConditionMessage, And( ContainSubstring("could not determine source URI"), ContainSubstring("no ref or URI specified in endpoint"), ))) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } -func createErrorProducerKamelet(t *testing.T, operatorID string, ns string, name string) func() error { +func createErrorProducerKamelet(t *testing.T, ctx context.Context, operatorID string, ns string, name string) func() error { props := map[string]v1.JSONSchemaProp{ "message": { Type: "string", @@ -156,5 +148,5 @@ func createErrorProducerKamelet(t *testing.T, operatorID string, ns string, name }, } - return CreateKamelet(t, operatorID, ns, name, flow, props, nil) + return CreateKamelet(t, operatorID, ctx, ns, name, flow, props, nil) } diff --git a/e2e/common/misc/pipe_with_image_test.go b/e2e/common/misc/pipe_with_image_test.go index f898de01b1..de47c8cdab 100644 --- a/e2e/common/misc/pipe_with_image_test.go +++ b/e2e/common/misc/pipe_with_image_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,71 +38,53 @@ import ( func TestPipeWithImage(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-pipe-image" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) bindingID := "with-image-binding" t.Run("run with initial image", func(t *testing.T) { expectedImage := "docker.io/jmalloc/echo-server:0.3.2" - g.Expect(KamelBindWithID(t, operatorID, ns, - "my-own-timer-source", - "my-own-log-sink", - "--annotation", "trait.camel.apache.org/container.image="+expectedImage, - "--annotation", "trait.camel.apache.org/jvm.enabled=false", - "--annotation", "trait.camel.apache.org/kamelets.enabled=false", - "--annotation", "trait.camel.apache.org/dependencies.enabled=false", - "--annotation", "test=1", - "--name", bindingID, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationGeneration(t, ns, bindingID)). + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-own-timer-source", "my-own-log-sink", "--annotation", "trait.camel.apache.org/container.image="+expectedImage, "--annotation", "trait.camel.apache.org/jvm.enabled=false", "--annotation", "trait.camel.apache.org/kamelets.enabled=false", "--annotation", "trait.camel.apache.org/dependencies.enabled=false", "--annotation", "test=1", "--name", bindingID).Execute()).To(Succeed()) + + g.Eventually(IntegrationGeneration(t, ctx, ns, bindingID)). Should(gstruct.PointTo(BeNumerically("==", 1))) - g.Eventually(Integration(t, ns, bindingID)).Should(WithTransform(Annotations, And( + g.Eventually(Integration(t, ctx, ns, bindingID)).Should(WithTransform(Annotations, And( HaveKeyWithValue("test", "1"), HaveKeyWithValue("trait.camel.apache.org/container.image", expectedImage), ))) - g.Eventually(IntegrationStatusImage(t, ns, bindingID)). + g.Eventually(IntegrationStatusImage(t, ctx, ns, bindingID)). Should(Equal(expectedImage)) - g.Eventually(IntegrationPodPhase(t, ns, bindingID), TestTimeoutLong). + g.Eventually(IntegrationPodPhase(t, ctx, ns, bindingID), TestTimeoutLong). Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodImage(t, ns, bindingID)). + g.Eventually(IntegrationPodImage(t, ctx, ns, bindingID)). Should(Equal(expectedImage)) }) t.Run("run with new image", func(t *testing.T) { expectedImage := "docker.io/jmalloc/echo-server:0.3.3" - g.Expect(KamelBindWithID(t, operatorID, ns, - "my-own-timer-source", - "my-own-log-sink", - "--annotation", "trait.camel.apache.org/container.image="+expectedImage, - "--annotation", "trait.camel.apache.org/jvm.enabled=false", - "--annotation", "trait.camel.apache.org/kamelets.enabled=false", - "--annotation", "trait.camel.apache.org/dependencies.enabled=false", - "--annotation", "test=2", - "--name", bindingID, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationGeneration(t, ns, bindingID)). + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-own-timer-source", "my-own-log-sink", "--annotation", "trait.camel.apache.org/container.image="+expectedImage, "--annotation", "trait.camel.apache.org/jvm.enabled=false", "--annotation", "trait.camel.apache.org/kamelets.enabled=false", "--annotation", "trait.camel.apache.org/dependencies.enabled=false", "--annotation", "test=2", "--name", bindingID).Execute()).To(Succeed()) + g.Eventually(IntegrationGeneration(t, ctx, ns, bindingID)). Should(gstruct.PointTo(BeNumerically("==", 1))) - g.Eventually(Integration(t, ns, bindingID)).Should(WithTransform(Annotations, And( + g.Eventually(Integration(t, ctx, ns, bindingID)).Should(WithTransform(Annotations, And( HaveKeyWithValue("test", "2"), HaveKeyWithValue("trait.camel.apache.org/container.image", expectedImage), ))) - g.Eventually(IntegrationStatusImage(t, ns, bindingID)). + g.Eventually(IntegrationStatusImage(t, ctx, ns, bindingID)). Should(Equal(expectedImage)) - g.Eventually(IntegrationPodPhase(t, ns, bindingID), TestTimeoutLong). + g.Eventually(IntegrationPodPhase(t, ctx, ns, bindingID), TestTimeoutLong). Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodImage(t, ns, bindingID)). + g.Eventually(IntegrationPodImage(t, ctx, ns, bindingID)). Should(Equal(expectedImage)) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/registry_maven_wagon_test.go b/e2e/common/misc/registry_maven_wagon_test.go index 3d590a3e8f..9f474eee56 100644 --- a/e2e/common/misc/registry_maven_wagon_test.go +++ b/e2e/common/misc/registry_maven_wagon_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "fmt" "path/filepath" "testing" @@ -47,13 +48,13 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) { return } - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-registry-maven-repo" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("image registry is a maven repository", func(t *testing.T) { // Create integration that should decrypt an encrypted message to "foobar" and log it @@ -63,59 +64,55 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) { pom, err := filepath.Abs("files/registry/sample-decryption-1.0.pom") require.NoError(t, err) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/FoobarDecryption.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/FoobarDecryption.java", "--name", name, "-d", fmt.Sprintf("file://%s", jar), - "-d", fmt.Sprintf("file://%s", pom), - ).Execute()).To(Succeed()) + "-d", fmt.Sprintf("file://%s", pom)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("foobar")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("foobar")) }) t.Run("local files are mounted in the integration container at the default path", func(t *testing.T) { name := RandomizedSuffixName("laughing-route-default-path") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/LaughingRoute.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/LaughingRoute.java", "--name", name, "-p", "location=/deployments/?filename=laugh.txt", - "-d", "file://files/registry/laugh.txt", - ).Execute()).To(Succeed()) + "-d", "file://files/registry/laugh.txt").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) }) t.Run("local files are mounted in the integration container at a custom path", func(t *testing.T) { name := RandomizedSuffixName("laughing-route-custom-path") customPath := "this/is/a/custom/path/" - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/LaughingRoute.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/LaughingRoute.java", "--name", name, "-p", fmt.Sprintf("location=%s", customPath), - "-d", fmt.Sprintf("file://files/registry/laugh.txt?targetPath=%slaugh.txt", customPath), - ).Execute()).To(Succeed()) + "-d", fmt.Sprintf("file://files/registry/laugh.txt?targetPath=%slaugh.txt", customPath)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) }) t.Run("local directory is mounted in the integration container", func(t *testing.T) { name := RandomizedSuffixName("laughing-route-directory") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/LaughingRoute.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/LaughingRoute.java", "--name", name, "-p", "location=files/registry/", - "-d", fmt.Sprintf("file://files/registry/laughs/?targetPath=files/registry/"), - ).Execute()).To(Succeed()) + "-d", fmt.Sprintf("file://files/registry/laughs/?targetPath=files/registry/")).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("hehe")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("haha")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("hehe")) }) t.Run("pom file is extracted from JAR", func(t *testing.T) { @@ -124,29 +121,28 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) { jar, err := filepath.Abs("files/registry/sample-decryption-1.0.jar") require.NoError(t, err) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/FoobarDecryption.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/FoobarDecryption.java", "--name", name, - "-d", fmt.Sprintf("file://%s", jar), - ).Execute()).To(Succeed()) + "-d", fmt.Sprintf("file://%s", jar)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("foobar")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("foobar")) }) t.Run("dependency can be used at build time", func(t *testing.T) { // Create integration that should run a Xslt transformation whose template needs to be present at build time name := RandomizedSuffixName("xslt") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/registry/classpath/Xslt.java", "--name", name, - "-d", "file://files/registry/classpath/cheese.xsl?targetPath=xslt/cheese.xsl&classpath=true", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/registry/classpath/Xslt.java", + "--name", name, + "-d", "file://files/registry/classpath/cheese.xsl?targetPath=xslt/cheese.xsl&classpath=true").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("A")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("A")) }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/rest_test.go b/e2e/common/misc/rest_test.go index 1bbfdaf16e..680f06adb7 100644 --- a/e2e/common/misc/rest_test.go +++ b/e2e/common/misc/rest_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "fmt" "io" "net/http" @@ -41,43 +42,43 @@ import ( func TestRunRest(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-rest" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/rest-consumer.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "rest-consumer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-consumer.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) t.Run("Service works", func(t *testing.T) { name := RandomizedSuffixName("John") - service := Service(t, ns, "rest-consumer") + service := Service(t, ctx, ns, "rest-consumer") g.Eventually(service, TestTimeoutShort).ShouldNot(BeNil()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/rest-producer.yaml", "-p", "serviceName=rest-consumer", "-p", "name="+name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "rest-producer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "rest-consumer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name))) - g.Eventually(IntegrationLogs(t, ns, "rest-producer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-producer.yaml", "-p", "serviceName=rest-consumer", "-p", "name="+name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name))) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) }) if ocp { t.Run("Route works", func(t *testing.T) { name := RandomizedSuffixName("Peter") - route := Route(t, ns, "rest-consumer") + route := Route(t, ctx, ns, "rest-consumer") g.Eventually(route, TestTimeoutShort).ShouldNot(BeNil()) - g.Eventually(RouteStatus(t, ns, "rest-consumer"), TestTimeoutMedium).Should(Equal("True")) + g.Eventually(RouteStatus(t, ctx, ns, "rest-consumer"), TestTimeoutMedium).Should(Equal("True")) url := fmt.Sprintf("http://%s/customers/%s", route().Spec.Host, name) g.Eventually(httpRequest(url), TestTimeoutMedium).Should(Equal(fmt.Sprintf("%s Doe", name))) - g.Eventually(IntegrationLogs(t, ns, "rest-consumer"), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("get %s", name))) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer"), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("get %s", name))) }) } - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/scale_binding_test.go b/e2e/common/misc/scale_binding_test.go index dc9bbe3b57..0b1bdd6433 100644 --- a/e2e/common/misc/scale_binding_test.go +++ b/e2e/common/misc/scale_binding_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "testing" . "github.com/onsi/gomega" @@ -42,13 +43,13 @@ import ( func TestPipeScale(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-pipe-scale" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) @@ -58,26 +59,26 @@ func TestPipeScale(t *testing.T) { } name := RandomizedSuffixName("timer2log") - g.Expect(KamelBindWithID(t, operatorID, ns, "timer-source?message=HelloPipe", "log-sink", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(PipeConditionStatus(t, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("HelloPipe")) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "timer-source?message=HelloPipe", "log-sink", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("HelloPipe")) t.Run("Update Pipe scale spec", func(t *testing.T) { - g.Expect(ScalePipe(t, ns, name, 3)).To(Succeed()) + g.Expect(ScalePipe(t, ctx, ns, name, 3)).To(Succeed()) // Check the scale cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(3)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(3)) // Check it also cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 3))) // Check it also cascades into the Pipe scale subresource Status field - g.Eventually(PipeStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(PipeStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 3))) // Check the readiness condition becomes truthy back - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) // Finally check the readiness condition becomes truthy back onPipe - g.Eventually(PipeConditionStatus(t, ns, name, v1.PipeConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) }) t.Run("ScalePipe with polymorphic client", func(t *testing.T) { @@ -86,21 +87,21 @@ func TestPipeScale(t *testing.T) { // Patch the integration scale subresource patch := "{\"spec\":{\"replicas\":2}}" - _, err = scaleClient.Scales(ns).Patch(TestContext, v1.SchemeGroupVersion.WithResource("Pipes"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{}) + _, err = scaleClient.Scales(ns).Patch(ctx, v1.SchemeGroupVersion.WithResource("Pipes"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{}) g.Expect(err).To(BeNil()) // Check the readiness condition is still truthy as down-scaling - g.Expect(PipeConditionStatus(t, ns, name, v1.PipeConditionReady)()).To(Equal(corev1.ConditionTrue)) + g.Expect(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady)()).To(Equal(corev1.ConditionTrue)) // Check the Integration scale subresource Spec field - g.Eventually(IntegrationSpecReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationSpecReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) // Then check it cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(2)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(2)) // Check it cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) // Finally check it cascades into the Pipe scale subresource Status field - g.Eventually(PipeStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(PipeStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) }) @@ -109,33 +110,33 @@ func TestPipeScale(t *testing.T) { g.Expect(err).To(BeNil()) // Getter - PipeScale, err := camel.CamelV1().Pipes(ns).GetScale(TestContext, name, metav1.GetOptions{}) + PipeScale, err := camel.CamelV1().Pipes(ns).GetScale(ctx, name, metav1.GetOptions{}) g.Expect(err).To(BeNil()) g.Expect(PipeScale.Spec.Replicas).To(BeNumerically("==", 2)) g.Expect(PipeScale.Status.Replicas).To(BeNumerically("==", 2)) // Setter PipeScale.Spec.Replicas = 1 - _, err = camel.CamelV1().Pipes(ns).UpdateScale(TestContext, name, PipeScale, metav1.UpdateOptions{}) + _, err = camel.CamelV1().Pipes(ns).UpdateScale(ctx, name, PipeScale, metav1.UpdateOptions{}) g.Expect(err).To(BeNil()) // Check the readiness condition is still truthy as down-scaling inPipe - g.Expect(PipeConditionStatus(t, ns, name, v1.PipeConditionReady)()).To(Equal(corev1.ConditionTrue)) + g.Expect(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady)()).To(Equal(corev1.ConditionTrue)) // Check the Pipe scale subresource Spec field - g.Eventually(PipeSpecReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(PipeSpecReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 1))) // Check the readiness condition is still truthy as down-scaling - g.Expect(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) + g.Expect(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) // Check the Integration scale subresource Spec field - g.Eventually(IntegrationSpecReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationSpecReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 1))) // Then check it cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(1)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(1)) // Finally check it cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 1))) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/scale_integration_test.go b/e2e/common/misc/scale_integration_test.go index c3b6974274..d2fb9a37d6 100644 --- a/e2e/common/misc/scale_integration_test.go +++ b/e2e/common/misc/scale_integration_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "fmt" "testing" @@ -41,31 +42,31 @@ import ( func TestIntegrationScale(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-integration-scale" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) t.Run("Update integration scale spec", func(t *testing.T) { - g.Expect(ScaleIntegration(t, ns, name, 3)).To(Succeed()) + g.Expect(ScaleIntegration(t, ctx, ns, name, 3)).To(Succeed()) // Check the readiness condition becomes falsy - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) // Check the scale cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(3)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(3)) // Check it also cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 3))) // Finally check the readiness condition becomes truthy back - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) }) t.Run("Scale integration with polymorphic client", func(t *testing.T) { @@ -74,18 +75,18 @@ func TestIntegrationScale(t *testing.T) { // Patch the integration scale subresource patch := "{\"spec\":{\"replicas\":2}}" - _, err = scaleClient.Scales(ns).Patch(TestContext, v1.SchemeGroupVersion.WithResource("integrations"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{}) + _, err = scaleClient.Scales(ns).Patch(ctx, v1.SchemeGroupVersion.WithResource("integrations"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{}) g.Expect(err).To(BeNil()) // Check the readiness condition is still truthy as down-scaling - g.Expect(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) + g.Expect(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) // Check the Integration scale subresource Spec field - g.Eventually(IntegrationSpecReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationSpecReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) // Then check it cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(2)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(2)) // Finally check it cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 2))) }) @@ -94,46 +95,46 @@ func TestIntegrationScale(t *testing.T) { g.Expect(err).To(BeNil()) // Getter - integrationScale, err := camel.CamelV1().Integrations(ns).GetScale(TestContext, name, metav1.GetOptions{}) + integrationScale, err := camel.CamelV1().Integrations(ns).GetScale(ctx, name, metav1.GetOptions{}) g.Expect(err).To(BeNil()) g.Expect(integrationScale.Spec.Replicas).To(BeNumerically("==", 2)) g.Expect(integrationScale.Status.Replicas).To(BeNumerically("==", 2)) // Setter integrationScale.Spec.Replicas = 1 - integrationScale, err = camel.CamelV1().Integrations(ns).UpdateScale(TestContext, name, integrationScale, metav1.UpdateOptions{}) + integrationScale, err = camel.CamelV1().Integrations(ns).UpdateScale(ctx, name, integrationScale, metav1.UpdateOptions{}) g.Expect(err).To(BeNil()) // Check the readiness condition is still truthy as down-scaling - g.Expect(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) + g.Expect(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady)()).To(Equal(corev1.ConditionTrue)) // Check the Integration scale subresource Spec field - g.Eventually(IntegrationSpecReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationSpecReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 1))) // Then check it cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(1)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(1)) // Finally check it cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 1))) }) t.Run("Scale integration with external image", func(t *testing.T) { - image := IntegrationPodImage(t, ns, name)() + image := IntegrationPodImage(t, ctx, ns, name)() g.Expect(image).NotTo(BeEmpty()) // Save resources by deleting the integration - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", "pre-built", "-t", fmt.Sprintf("container.image=%s", image)).Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Expect(ScaleIntegration(t, ns, "pre-built", 0)).To(Succeed()) - g.Eventually(IntegrationPod(t, ns, "pre-built"), TestTimeoutMedium).Should(BeNil()) - g.Expect(ScaleIntegration(t, ns, "pre-built", 1)).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - - g.Expect(Kamel(t, "delete", "pre-built", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", "pre-built", "-t", fmt.Sprintf("container.image=%s", image)).Execute()).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(ScaleIntegration(t, ctx, ns, "pre-built", 0)).To(Succeed()) + g.Eventually(IntegrationPod(t, ctx, ns, "pre-built"), TestTimeoutMedium).Should(BeNil()) + g.Expect(ScaleIntegration(t, ctx, ns, "pre-built", 1)).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, "pre-built"), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "pre-built"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + g.Expect(Kamel(t, ctx, "delete", "pre-built", "-n", ns).Execute()).To(Succeed()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/structured_logs_test.go b/e2e/common/misc/structured_logs_test.go index 47d7d59ecc..da6765bdea 100644 --- a/e2e/common/misc/structured_logs_test.go +++ b/e2e/common/misc/structured_logs_test.go @@ -23,6 +23,7 @@ limitations under the License. package misc import ( + "context" "fmt" "testing" @@ -37,22 +38,20 @@ import ( func TestStructuredLogs(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-structured-logs" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "logging.format=json").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "logging.format=json").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() g.Expect(pod).NotTo(BeNil()) // pod.Namespace could be different from ns if using global operator @@ -60,15 +59,15 @@ func TestStructuredLogs(t *testing.T) { logOptions := &corev1.PodLogOptions{ Container: "camel-k-operator", } - logs, err := StructuredLogs(t, pod.Namespace, pod.Name, logOptions, false) + logs, err := StructuredLogs(t, ctx, pod.Namespace, pod.Name, logOptions, false) g.Expect(err).To(BeNil()) g.Expect(logs).NotTo(BeEmpty()) - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() g.Expect(it).NotTo(BeNil()) - build := Build(t, IntegrationKitNamespace(t, ns, name)(), IntegrationKit(t, ns, name)())() + build := Build(t, ctx, IntegrationKitNamespace(t, ctx, ns, name)(), IntegrationKit(t, ctx, ns, name)())() g.Expect(build).NotTo(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/runtimes/runtimes_test.go b/e2e/common/runtimes/runtimes_test.go index fa43dd5307..45829d674c 100644 --- a/e2e/common/runtimes/runtimes_test.go +++ b/e2e/common/runtimes/runtimes_test.go @@ -23,6 +23,7 @@ limitations under the License. package runtimes import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,48 +37,48 @@ import ( func TestSourceLessIntegrations(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-runtimes" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) var cmData = make(map[string]string) cmData["my-file.txt"] = "Hello World!" - CreatePlainTextConfigmap(t, ns, "my-cm-sourceless", cmData) + CreatePlainTextConfigmap(t, ctx, ns, "my-cm-sourceless", cmData) t.Run("Camel Main", func(t *testing.T) { itName := "my-camel-main-v1" - g.Expect(KamelRunWithID(t, operatorID, ns, "--image", "docker.io/squakez/my-camel-main:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationCondition(t, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring("Apache Camel (Main)")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-main:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("Apache Camel (Main)")) }) t.Run("Camel Spring Boot", func(t *testing.T) { itName := "my-camel-sb-v1" - g.Expect(KamelRunWithID(t, operatorID, ns, "--image", "docker.io/squakez/my-camel-sb:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationCondition(t, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring("Spring Boot")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-sb:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("Spring Boot")) }) t.Run("Camel Quarkus", func(t *testing.T) { itName := "my-camel-quarkus-v1" - g.Expect(KamelRunWithID(t, operatorID, ns, "--image", "docker.io/squakez/my-camel-quarkus:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationCondition(t, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) - g.Eventually(IntegrationLogs(t, ns, itName), TestTimeoutShort).Should(ContainSubstring("powered by Quarkus")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-quarkus:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionTraitInfo)().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator")) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"])) + g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("powered by Quarkus")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/affinity_test.go b/e2e/common/traits/affinity_test.go index 8621cd8fbb..3b99863f59 100644 --- a/e2e/common/traits/affinity_test.go +++ b/e2e/common/traits/affinity_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "fmt" "testing" @@ -39,16 +40,16 @@ import ( func TestAffinityTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-affinity" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) var hostname string - if node, err := selectSchedulableNode(t); err == nil { + if node, err := selectSchedulableNode(t, ctx); err == nil { hostname = node.Labels["kubernetes.io/hostname"] } else { // if 'get nodes' is not allowed, just skip tests for node affinity @@ -58,15 +59,12 @@ func TestAffinityTrait(t *testing.T) { if hostname != "" { t.Run("Run Java with node affinity", func(t *testing.T) { name1 := RandomizedSuffixName("java1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name1, - "-t", "affinity.enabled=true", - "-t", fmt.Sprintf("affinity.node-affinity-labels=kubernetes.io/hostname in(%s)", hostname)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name1), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name1, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name1), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name1)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name1, "-t", "affinity.enabled=true", "-t", fmt.Sprintf("affinity.node-affinity-labels=kubernetes.io/hostname in(%s)", hostname)).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name1), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name1, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name1), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name1)() g.Expect(pod.Spec.Affinity).NotTo(BeNil()) g.Expect(pod.Spec.Affinity.NodeAffinity).To(Equal(&corev1.NodeAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: nodeSelector("kubernetes.io/hostname", corev1.NodeSelectorOpIn, hostname), @@ -74,28 +72,25 @@ func TestAffinityTrait(t *testing.T) { g.Expect(pod.Spec.NodeName).To(Equal(hostname)) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name1)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name1)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name1)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name1)() affinityTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "affinity") g.Expect(affinityTrait).NotTo(BeNil()) g.Expect(len(affinityTrait)).To(Equal(2)) g.Expect(affinityTrait["enabled"]).To(Equal(true)) g.Expect(affinityTrait["nodeAffinityLabels"]).NotTo(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } t.Run("Run Java with pod affinity", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", "java2", - "-t", "affinity.enabled=true", - "-t", "affinity.pod-affinity-labels=camel.apache.org/integration").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java2"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java2", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java2"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, "java2")() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", "java2", "-t", "affinity.enabled=true", "-t", "affinity.pod-affinity-labels=camel.apache.org/integration").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java2"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java2", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java2"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, "java2")() g.Expect(pod.Spec.Affinity).NotTo(BeNil()) g.Expect(pod.Spec.Affinity.PodAffinity).To(Equal(&corev1.PodAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ @@ -103,19 +98,16 @@ func TestAffinityTrait(t *testing.T) { }, })) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run Java with pod anti affinity", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", "java3", - "-t", "affinity.enabled=true", - "-t", "affinity.pod-anti-affinity-labels=camel.apache.org/integration").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java3"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java3", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java3"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, "java3")() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", "java3", "-t", "affinity.enabled=true", "-t", "affinity.pod-anti-affinity-labels=camel.apache.org/integration").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java3"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java3", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java3"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, "java3")() g.Expect(pod.Spec.Affinity).NotTo(BeNil()) g.Expect(pod.Spec.Affinity.PodAntiAffinity).To(Equal(&corev1.PodAntiAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ @@ -123,13 +115,13 @@ func TestAffinityTrait(t *testing.T) { }, })) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) } -func selectSchedulableNode(t *testing.T) (*corev1.Node, error) { - nodes, err := TestClient(t).CoreV1().Nodes().List(TestContext, metav1.ListOptions{}) +func selectSchedulableNode(t *testing.T, ctx context.Context) (*corev1.Node, error) { + nodes, err := TestClient(t).CoreV1().Nodes().List(ctx, metav1.ListOptions{}) if err != nil { return nil, err } diff --git a/e2e/common/traits/builder_test.go b/e2e/common/traits/builder_test.go index 42dc5b1b7b..e52dc1447d 100644 --- a/e2e/common/traits/builder_test.go +++ b/e2e/common/traits/builder_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "fmt" "testing" @@ -30,7 +31,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -39,105 +39,99 @@ import ( func TestBuilderTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-builder" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run build strategy routine", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "builder.order-strategy=sequential", - "-t", "builder.strategy=routine").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.order-strategy=sequential", "-t", "builder.strategy=routine").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategySequential)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategySequential)) // Default resource CPU Check - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run build order strategy dependencies", func(t *testing.T) { name := RandomizedSuffixName("java-dependencies-strategy") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, + // This is required in order to avoid reusing a Kit already existing (which is the default behavior) + "--build-property", "strategy=dependencies", "-t", "builder.order-strategy=dependencies").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategyDependencies)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategyDependencies)) // Default resource CPU Check - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) - - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) - - // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() - builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "builder") - g.Expect(builderTrait).NotTo(BeNil()) - g.Expect(len(builderTrait)).To(Equal(1)) - g.Expect(builderTrait["orderStrategy"]).To(Equal("dependencies")) - - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) + + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run build order strategy fifo", func(t *testing.T) { name := RandomizedSuffixName("java-fifo-strategy") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, + // This is required in order to avoid reusing a Kit already existing (which is the default behavior) + "--build-property", "strategy=fifo", "-t", "builder.order-strategy=fifo").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategyFIFO)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyRoutine)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategyFIFO)) // Default resource CPU Check - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run build resources configuration", func(t *testing.T) { name := RandomizedSuffixName("java-resource-config") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, + // This is required in order to avoid reusing a Kit already existing (which is the default behavior) + "--build-property", "resources=new-build", "-t", "builder.tasks-request-cpu=builder:500m", "-t", "builder.tasks-limit-cpu=builder:1000m", "-t", "builder.tasks-request-memory=builder:2Gi", @@ -145,147 +139,132 @@ func TestBuilderTrait(t *testing.T) { "-t", "builder.strategy=pod", ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyPod)) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategySequential)) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("500m")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("1000m")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("2Gi")) - g.Eventually(BuildConfig(t, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("3Gi")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyPod)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategySequential)) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("500m")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("1000m")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("2Gi")) + g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitMemory, TestTimeoutShort).Should(Equal("3Gi")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) // Let's assert we set the resources on the builder container - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Requests.Cpu().String(), TestTimeoutShort).Should(Equal("500m")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Limits.Cpu().String(), TestTimeoutShort).Should(Equal("1")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Requests.Memory().String(), TestTimeoutShort).Should(Equal("2Gi")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Limits.Memory().String(), TestTimeoutShort).Should(Equal("3Gi")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Requests.Cpu().String(), TestTimeoutShort).Should(Equal("500m")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Limits.Cpu().String(), TestTimeoutShort).Should(Equal("1")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Requests.Memory().String(), TestTimeoutShort).Should(Equal("2Gi")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Resources.Limits.Memory().String(), TestTimeoutShort).Should(Equal("3Gi")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run custom pipeline task", func(t *testing.T) { name := RandomizedSuffixName("java-pipeline") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "builder.tasks=custom1;alpine;tree", - "-t", "builder.tasks=custom2;alpine;cat maven/pom.xml", - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.tasks=custom1;alpine;tree", "-t", "builder.tasks=custom2;alpine;cat maven/pom.xml", "-t", "builder.strategy=pod").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) - g.Eventually(len(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers), TestTimeoutShort).Should(Equal(4)) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[1].Name, TestTimeoutShort).Should(Equal("custom1")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[2].Name, TestTimeoutShort).Should(Equal("custom2")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(len(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers), TestTimeoutShort).Should(Equal(4)) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[1].Name, TestTimeoutShort).Should(Equal("custom1")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[2].Name, TestTimeoutShort).Should(Equal("custom2")) // Check containers conditions - g.Eventually(Build(t, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(Build(t, ctx, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Status, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Status, TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Message, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Message, TestTimeoutShort).Should(ContainSubstring("generated-bytecode.jar")) - g.Eventually(Build(t, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(Build(t, ctx, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom2 succeeded")).Status, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom2 succeeded")).Status, TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom2 succeeded")).Message, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom2 succeeded")).Message, TestTimeoutShort).Should(ContainSubstring("")) // Check logs - g.Eventually(Logs(t, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`generated-bytecode.jar`)) - g.Eventually(Logs(t, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom2"})).Should(ContainSubstring(`camel-k-runtime-bom`)) + g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`generated-bytecode.jar`)) + g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom2"})).Should(ContainSubstring(`camel-k-runtime-bom`)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run custom pipeline task error", func(t *testing.T) { name := RandomizedSuffixName("java-error") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "builder.tasks=custom1;alpine;cat missingfile.txt", - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.tasks=custom1;alpine;cat missingfile.txt", "-t", "builder.strategy=pod").Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, name)).Should(Equal(v1.IntegrationPhaseBuildingKit)) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseBuildingKit)) + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() // Check containers conditions - g.Eventually(Build(t, integrationKitNamespace, integrationKitName), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(BuildConditions(t, integrationKitNamespace, integrationKitName), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(BuildCondition(t, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded")), TestTimeoutMedium).ShouldNot(BeNil()) + g.Eventually(Build(t, ctx, integrationKitNamespace, integrationKitName), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(BuildConditions(t, ctx, integrationKitNamespace, integrationKitName), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(BuildCondition(t, ctx, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded")), TestTimeoutMedium).ShouldNot(BeNil()) g.Eventually( - BuildCondition(t, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded"))().Status, + BuildCondition(t, ctx, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded"))().Status, TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) g.Eventually( - BuildCondition(t, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded"))().Message, + BuildCondition(t, ctx, integrationKitNamespace, integrationKitName, v1.BuildConditionType("Container custom1 succeeded"))().Message, TestTimeoutShort).Should(ContainSubstring("No such file or directory")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Run maven profile", func(t *testing.T) { name := RandomizedSuffixName("java-maven-profile") mavenProfile1Cm := newMavenProfileConfigMap(ns, "maven-profile-owasp", "owasp-profile") - g.Expect(TestClient(t).Create(TestContext, mavenProfile1Cm)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, mavenProfile1Cm)).To(Succeed()) mavenProfile2Cm := newMavenProfileConfigMap(ns, "maven-profile-dependency", "dependency-profile") - g.Expect(TestClient(t).Create(TestContext, mavenProfile2Cm)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, mavenProfile2Cm)).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "builder.maven-profiles=configmap:maven-profile-owasp/owasp-profile", - "-t", "builder.maven-profiles=configmap:maven-profile-dependency/dependency-profile", - "-t", "builder.tasks=custom1;alpine;cat maven/pom.xml", - "-t", "builder.strategy=pod", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.maven-profiles=configmap:maven-profile-owasp/owasp-profile", "-t", "builder.maven-profiles=configmap:maven-profile-dependency/dependency-profile", "-t", "builder.tasks=custom1;alpine;cat maven/pom.xml", "-t", "builder.strategy=pod").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKitName := IntegrationKit(t, ns, name)() - integrationKitNamespace := IntegrationKitNamespace(t, ns, name)() + integrationKitName := IntegrationKit(t, ctx, ns, name)() + integrationKitNamespace := IntegrationKitNamespace(t, ctx, ns, name)() builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) - g.Eventually(len(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers), TestTimeoutShort).Should(Equal(3)) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[1].Name, TestTimeoutShort).Should(Equal("custom1")) - g.Eventually(BuilderPod(t, integrationKitNamespace, builderKitName)().Spec.InitContainers[2].Name, TestTimeoutShort).Should(Equal("package")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(len(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers), TestTimeoutShort).Should(Equal(3)) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[0].Name, TestTimeoutShort).Should(Equal("builder")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[1].Name, TestTimeoutShort).Should(Equal("custom1")) + g.Eventually(BuilderPod(t, ctx, integrationKitNamespace, builderKitName)().Spec.InitContainers[2].Name, TestTimeoutShort).Should(Equal("package")) // Check containers conditions - g.Eventually(Build(t, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) + g.Eventually(Build(t, ctx, integrationKitNamespace, integrationKitName), TestTimeoutShort).ShouldNot(BeNil()) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Status, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Status, TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually( - Build(t, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Message, + Build(t, ctx, integrationKitNamespace, integrationKitName)().Status.GetCondition(v1.BuildConditionType("Container custom1 succeeded")).Message, TestTimeoutShort).Should(ContainSubstring("")) // Check logs - g.Eventually(Logs(t, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`owasp-profile`)) - g.Eventually(Logs(t, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`dependency-profile`)) + g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`owasp-profile`)) + g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`dependency-profile`)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, mavenProfile1Cm)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, mavenProfile2Cm)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, mavenProfile1Cm)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, mavenProfile2Cm)).To(Succeed()) }) }) } diff --git a/e2e/common/traits/camel_test.go b/e2e/common/traits/camel_test.go index 439bca8f2f..e854b53b64 100644 --- a/e2e/common/traits/camel_test.go +++ b/e2e/common/traits/camel_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,43 +37,38 @@ import ( func TestCamelTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-camel" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("properties changes should not rebuild", func(t *testing.T) { - g.Expect(Kamel(t, "reset", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns).Execute()).To(Succeed()) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) // checking the integration status - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - integrationKit := IntegrationKit(t, ns, name)() - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-p", "a=1", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationKit(t, ns, name)).Should(Equal(integrationKit)) - - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Integration(t, ns, name), TestTimeoutLong).Should(BeNil()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + integrationKit := IntegrationKit(t, ctx, ns, name)() + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-p", "a=1").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationKit(t, ctx, ns, name)).Should(Equal(integrationKit)) + + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Integration(t, ctx, ns, name), TestTimeoutLong).Should(BeNil()) }) // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/container_test.go b/e2e/common/traits/container_test.go index 12e1937f2b..1365d139bb 100644 --- a/e2e/common/traits/container_test.go +++ b/e2e/common/traits/container_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,35 +38,28 @@ import ( func TestContainerTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-container" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Container image pull policy and resources configuration", func(t *testing.T) { name := RandomizedSuffixName("java1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "container.image-pull-policy=Always", - "-t", "container.request-cpu=0.005", - "-t", "container.request-memory=100Mi", - "-t", "container.limit-cpu=200m", - "-t", "container.limit-memory=500Mi", - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodHas(t, ns, name, func(pod *corev1.Pod) bool { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "container.image-pull-policy=Always", "-t", "container.request-cpu=0.005", "-t", "container.request-memory=100Mi", "-t", "container.limit-cpu=200m", "-t", "container.limit-memory=500Mi", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodHas(t, ctx, ns, name, func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } imagePullPolicy := pod.Spec.Containers[0].ImagePullPolicy return imagePullPolicy == "Always" }), TestTimeoutShort).Should(BeTrue()) - g.Eventually(IntegrationPodHas(t, ns, name, func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns, name, func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -73,7 +67,7 @@ func TestContainerTrait(t *testing.T) { requestsCpu := pod.Spec.Containers[0].Resources.Requests.Cpu() return limitsCpu != nil && limitsCpu.String() == "200m" && requestsCpu != nil && requestsCpu.String() == "5m" }), TestTimeoutShort).Should(BeTrue()) - g.Eventually(IntegrationPodHas(t, ns, name, func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns, name, func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -87,14 +81,11 @@ func TestContainerTrait(t *testing.T) { t.Run("Container name", func(t *testing.T) { name := RandomizedSuffixName("java2") containerName := "my-container-name" - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "container.name="+containerName, - "--name", name, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodHas(t, ns, name, func(pod *corev1.Pod) bool { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "container.name="+containerName, "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodHas(t, ctx, ns, name, func(pod *corev1.Pod) bool { if len(pod.Spec.Containers) != 1 { return false } @@ -103,8 +94,8 @@ func TestContainerTrait(t *testing.T) { }), TestTimeoutShort).Should(BeTrue()) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() containerTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "container") g.Expect(containerTrait).ToNot(BeNil()) g.Expect(len(containerTrait)).To(Equal(1)) @@ -113,6 +104,6 @@ func TestContainerTrait(t *testing.T) { }) // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/deployment_test.go b/e2e/common/traits/deployment_test.go index 68d57b6b5d..37fb099cad 100644 --- a/e2e/common/traits/deployment_test.go +++ b/e2e/common/traits/deployment_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" appsv1 "k8s.io/api/apps/v1" @@ -40,26 +41,24 @@ import ( func TestRecreateDeploymentStrategyTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-deployment" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run with Recreate Deployment Strategy", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "deployment.strategy="+string(appsv1.RecreateDeploymentStrategyType)). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "deployment.strategy="+string(appsv1.RecreateDeploymentStrategyType)). Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Deployment(t, ns, name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, + g.Eventually(Deployment(t, ctx, ns, name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, Fields{ "Spec": MatchFields(IgnoreExtras, Fields{ @@ -72,39 +71,38 @@ func TestRecreateDeploymentStrategyTrait(t *testing.T) { )) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() deploymentTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "deployment") g.Expect(deploymentTrait).ToNot(BeNil()) g.Expect(len(deploymentTrait)).To(Equal(1)) g.Expect(deploymentTrait["strategy"]).To(Equal(string(appsv1.RecreateDeploymentStrategyType))) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRollingUpdateDeploymentStrategyTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-deployment-rolling" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run with RollingUpdate Deployment Strategy", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "deployment.strategy="+string(appsv1.RollingUpdateDeploymentStrategyType)). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "deployment.strategy="+string(appsv1.RollingUpdateDeploymentStrategyType)). Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(Deployment(t, ns, "java"), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, + g.Eventually(Deployment(t, ctx, ns, "java"), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, Fields{ "Spec": MatchFields(IgnoreExtras, Fields{ @@ -117,6 +115,6 @@ func TestRollingUpdateDeploymentStrategyTrait(t *testing.T) { )) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/error_handler_test.go b/e2e/common/traits/error_handler_test.go index 3292750f7e..5e727b508e 100644 --- a/e2e/common/traits/error_handler_test.go +++ b/e2e/common/traits/error_handler_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,27 +37,21 @@ import ( func TestErrorHandlerTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-errorhandler" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run errored integration with error handler", func(t *testing.T) { name := RandomizedSuffixName("error-handler") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/ErroredRoute.java", - "--name", name, - "-t", "error-handler.enabled=true", - "-t", "error-handler.ref=defaultErrorHandler", - "-p", "camel.beans.defaultErrorHandler=#class:org.apache.camel.builder.DeadLetterChannelBuilder", - "-p", "camel.beans.defaultErrorHandler.deadLetterUri=log:my-special-error-handler-in-place?level=ERROR&showCaughtException=false&showBody=false&showBodyType=false&showExchangePattern=false", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).ShouldNot(ContainSubstring("InvalidPayloadException")) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("my-special-error-handler-in-place")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/ErroredRoute.java", "--name", name, "-t", "error-handler.enabled=true", "-t", "error-handler.ref=defaultErrorHandler", "-p", "camel.beans.defaultErrorHandler=#class:org.apache.camel.builder.DeadLetterChannelBuilder", "-p", "camel.beans.defaultErrorHandler.deadLetterUri=log:my-special-error-handler-in-place?level=ERROR&showCaughtException=false&showBody=false&showBodyType=false&showExchangePattern=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).ShouldNot(ContainSubstring("InvalidPayloadException")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("my-special-error-handler-in-place")) }) }) } diff --git a/e2e/common/traits/errored_trait_test.go b/e2e/common/traits/errored_trait_test.go index 9d967d2df5..a113e021eb 100644 --- a/e2e/common/traits/errored_trait_test.go +++ b/e2e/common/traits/errored_trait_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,23 +37,20 @@ import ( func TestErroredTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-error" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Integration trait should fail", func(t *testing.T) { name := RandomizedSuffixName("it-errored") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "kamelets.list=missing", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "kamelets.list=missing").Execute()).To(Succeed()) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionInitializationFailedReason)), WithTransform(IntegrationConditionMessage, HavePrefix("error during trait customization")), )) @@ -60,28 +58,25 @@ func TestErroredTrait(t *testing.T) { t.Run("Pipe trait should fail", func(t *testing.T) { name := RandomizedSuffixName("kb-errored") - g.Expect(KamelBindWithID(t, operatorID, ns, "timer:foo", "log:bar", - "--name", name, - "-t", "kamelets.list=missing", - ).Execute()).To(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "timer:foo", "log:bar", "--name", name, "-t", "kamelets.list=missing").Execute()).To(Succeed()) // Pipe - g.Eventually(PipePhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.PipePhaseError)) - g.Eventually(PipeConditionStatus(t, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually(PipeCondition(t, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should( + g.Eventually(PipePhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.PipePhaseError)) + g.Eventually(PipeConditionStatus(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(PipeCondition(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should( WithTransform(PipeConditionMessage, And( ContainSubstring("error during trait customization"), ContainSubstring("[missing] not found"), ))) // Integration related - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionInitializationFailedReason)), WithTransform(IntegrationConditionMessage, HavePrefix("error during trait customization")), )) }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/health_test.go b/e2e/common/traits/health_test.go index 0f2ff7bf96..7e1cd608cf 100644 --- a/e2e/common/traits/health_test.go +++ b/e2e/common/traits/health_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "encoding/json" "fmt" "strings" @@ -45,51 +46,44 @@ import ( func TestHealthTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-health" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Readiness condition with stopped route scaled", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "health.enabled=true", - // Enable Jolokia for the test to stop the Camel route - "-t", "jolokia.enabled=true", - "-t", "jolokia.use-ssl-client-authentication=false", - "-t", "jolokia.protocol=http", - "--name", name, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "health.enabled=true", "-t", "jolokia.enabled=true", "-t", "jolokia.use-ssl-client-authentication=false", "-t", "jolokia.protocol=http", "--name", name).Execute()).To(Succeed()) + + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(ScaleIntegration(t, ns, name, 3)).To(Succeed()) + g.Expect(ScaleIntegration(t, ctx, ns, name, 3)).To(Succeed()) // Check the readiness condition becomes falsy - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) // Check the scale cascades into the Deployment scale - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutShort).Should(HaveLen(3)) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutShort).Should(HaveLen(3)) // Check it also cascades into the Integration scale subresource Status field - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(gstruct.PointTo(BeNumerically("==", 3))) // Finally check the readiness condition becomes truthy back - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() healthTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "health") g.Expect(healthTrait).ToNot(BeNil()) g.Expect(len(healthTrait)).To(Equal(1)) g.Expect(healthTrait["enabled"]).To(Equal(true)) - pods := IntegrationPods(t, ns, name)() + pods := IntegrationPods(t, ctx, ns, name)() for i, pod := range pods { // Stop the Camel route @@ -104,19 +98,19 @@ func TestHealthTrait(t *testing.T) { response, err := TestClient(t).CoreV1().RESTClient().Post(). AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod.Name)). Body(body). - DoRaw(TestContext) + DoRaw(ctx) g.Expect(err).To(BeNil()) g.Expect(response).To(ContainSubstring(`"status":200`)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)), WithTransform(IntegrationConditionMessage, Equal(fmt.Sprintf("%d/3 pods are not ready", i+1))))) } - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( Satisfy(func(c *v1.IntegrationCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -153,30 +147,23 @@ func TestHealthTrait(t *testing.T) { return true })) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Readiness condition with stopped route", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "health.enabled=true", - // Enable Jolokia for the test to stop the Camel route - "-t", "jolokia.enabled=true", - "-t", "jolokia.use-ssl-client-authentication=false", - "-t", "jolokia.protocol=http", - "--name", name, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "health.enabled=true", "-t", "jolokia.enabled=true", "-t", "jolokia.use-ssl-client-authentication=false", "-t", "jolokia.protocol=http", "--name", name).Execute()).To(Succeed()) + + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() // Stop the Camel route request := map[string]string{ @@ -190,12 +177,12 @@ func TestHealthTrait(t *testing.T) { response, err := TestClient(t).CoreV1().RESTClient().Post(). AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod.Name)). Body(body). - DoRaw(TestContext) + DoRaw(ctx) g.Expect(err).To(BeNil()) g.Expect(response).To(ContainSubstring(`"status":200`)) // Check the ready condition has turned false - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) // And it contains details about the runtime state @@ -210,11 +197,11 @@ func TestHealthTrait(t *testing.T) { // status: "False" // type: Ready // - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)), WithTransform(IntegrationConditionMessage, Equal("1/1 pods are not ready")))) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( Satisfy(func(c *v1.IntegrationCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -247,10 +234,10 @@ func TestHealthTrait(t *testing.T) { return data["check.kind"].(string) == "READINESS" && data["route.status"].(string) == "Stopped" })) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseError)) // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Readiness condition with stopped binding", func(t *testing.T) { @@ -258,27 +245,17 @@ func TestHealthTrait(t *testing.T) { source := RandomizedSuffixName("my-health-timer-source") sink := RandomizedSuffixName("my-health-log-sink") - g.Expect(CreateTimerKamelet(t, operatorID, ns, source)()).To(Succeed()) - g.Expect(CreateLogKamelet(t, operatorID, ns, sink)()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, source)()).To(Succeed()) + g.Expect(CreateLogKamelet(t, ctx, operatorID, ns, sink)()).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, - source, - sink, - "-p", "source.message=Magicstring!", - "-p", "sink.loggerName=binding", - "--annotation", "trait.camel.apache.org/health.enabled=true", - "--annotation", "trait.camel.apache.org/jolokia.enabled=true", - "--annotation", "trait.camel.apache.org/jolokia.use-ssl-client-authentication=false", - "--annotation", "trait.camel.apache.org/jolokia.protocol=http", - "--name", name, - ).Execute()).To(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, source, sink, "-p", "source.message=Magicstring!", "-p", "sink.loggerName=binding", "--annotation", "trait.camel.apache.org/health.enabled=true", "--annotation", "trait.camel.apache.org/jolokia.enabled=true", "--annotation", "trait.camel.apache.org/jolokia.use-ssl-client-authentication=false", "--annotation", "trait.camel.apache.org/jolokia.protocol=http", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() // Stop the Camel route request := map[string]string{ @@ -292,21 +269,21 @@ func TestHealthTrait(t *testing.T) { response, err := TestClient(t).CoreV1().RESTClient().Post(). AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod.Name)). Body(body). - DoRaw(TestContext) + DoRaw(ctx) g.Expect(err).To(BeNil()) g.Expect(response).To(ContainSubstring(`"status":200`)) // Check the ready condition has turned false - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) // And it contains details about the runtime state - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)), WithTransform(IntegrationConditionMessage, Equal("1/1 pods are not ready")))) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( Satisfy(func(c *v1.IntegrationCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -339,7 +316,7 @@ func TestHealthTrait(t *testing.T) { return data["check.kind"].(string) == "READINESS" && data["route.status"].(string) == "Stopped" && data["route.id"].(string) == "binding" })) - g.Eventually(PipeCondition(t, ns, name, camelv1.PipeConditionReady), TestTimeoutLong).Should( + g.Eventually(PipeCondition(t, ctx, ns, name, camelv1.PipeConditionReady), TestTimeoutLong).Should( Satisfy(func(c *camelv1.PipeCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -373,31 +350,28 @@ func TestHealthTrait(t *testing.T) { })) // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, source)).To(Succeed()) - g.Expect(DeleteKamelet(t, ns, sink)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, source)).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, sink)).To(Succeed()) }) t.Run("Readiness condition with never ready route", func(t *testing.T) { name := RandomizedSuffixName("never-ready") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/NeverReady.java", - "--name", name, - "-t", "health.enabled=true", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/NeverReady.java", "--name", name, "-t", "health.enabled=true").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) - g.Consistently(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), 1*time.Minute). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(v1.IntegrationPhaseRunning)) + g.Consistently(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), 1*time.Minute). Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) // Check that the error message is propagated from health checks even if deployment never becomes ready - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)), WithTransform(IntegrationConditionMessage, Equal("1/1 pods are not ready")))) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( Satisfy(func(c *v1.IntegrationCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -434,23 +408,18 @@ func TestHealthTrait(t *testing.T) { t.Run("Startup condition with never ready route", func(t *testing.T) { name := RandomizedSuffixName("startup-probe-never-ready-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/NeverReady.java", - "--name", name, - "-t", "health.enabled=true", - "-t", "health.startup-probe-enabled=true", - "-t", "health.startup-timeout=60", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/NeverReady.java", "--name", name, "-t", "health.enabled=true", "-t", "health.startup-probe-enabled=true", "-t", "health.startup-timeout=60").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Consistently(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), 1*time.Minute).Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Consistently(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), 1*time.Minute).Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionRuntimeNotReadyReason)), WithTransform(IntegrationConditionMessage, Equal("1/1 pods are not ready")))) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should( Satisfy(func(c *v1.IntegrationCondition) bool { if c.Status != corev1.ConditionFalse { return false @@ -496,17 +465,12 @@ func TestHealthTrait(t *testing.T) { t.Run("Startup condition with ready route", func(t *testing.T) { name := RandomizedSuffixName("startup-probe-ready-route") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "health.enabled=true", - "-t", "health.startup-probe-enabled=true", - "-t", "health.startup-timeout=60", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "health.enabled=true", "-t", "health.startup-probe-enabled=true", "-t", "health.startup-timeout=60").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPhase(t, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationCondition(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(And( + g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(And( WithTransform(IntegrationConditionReason, Equal(v1.IntegrationConditionDeploymentReadyReason)), WithTransform(IntegrationConditionMessage, Equal("1/1 ready replicas")))) @@ -519,6 +483,6 @@ func TestHealthTrait(t *testing.T) { }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/istio_test.go b/e2e/common/traits/istio_test.go index 97cafe4b50..bfe419efbc 100644 --- a/e2e/common/traits/istio_test.go +++ b/e2e/common/traits/istio_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,32 +38,30 @@ import ( func TestIstioTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-istio" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run Java with Istio", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "istio.enabled=true").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "istio.enabled=true").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod.ObjectMeta.Annotations).NotTo(BeNil()) annotations := pod.ObjectMeta.Annotations g.Expect(annotations["sidecar.istio.io/inject"]).To(Equal("true")) g.Expect(annotations["traffic.sidecar.istio.io/includeOutboundIPRanges"]).To(Equal("10.0.0.0/8,172.16.0.0/12,192.168.0.0/16")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() istioTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "istio") g.Expect(istioTrait).ToNot(BeNil()) g.Expect(len(istioTrait)).To(Equal(1)) @@ -70,6 +69,6 @@ func TestIstioTrait(t *testing.T) { }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/jolokia_test.go b/e2e/common/traits/jolokia_test.go index 470732744f..bb62cb096b 100644 --- a/e2e/common/traits/jolokia_test.go +++ b/e2e/common/traits/jolokia_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "fmt" "testing" @@ -38,35 +39,30 @@ import ( func TestJolokiaTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-jolokia" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run Java with Jolokia", func(t *testing.T) { name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "jolokia.enabled=true", - "-t", "jolokia.use-ssl-client-authentication=false", - "-t", "jolokia.protocol=http", - "-t", "jolokia.extended-client-check=false").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "jolokia.enabled=true", "-t", "jolokia.use-ssl-client-authentication=false", "-t", "jolokia.protocol=http", "-t", "jolokia.extended-client-check=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name) response, err := TestClient(t).CoreV1().RESTClient().Get(). - AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod().Name)).DoRaw(TestContext) + AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod().Name)).DoRaw(ctx) g.Expect(err).To(BeNil()) g.Expect(response).To(ContainSubstring(`"status":200`)) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() jolokiaTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "jolokia") g.Expect(jolokiaTrait).ToNot(BeNil()) g.Expect(len(jolokiaTrait)).To(Equal(4)) @@ -77,6 +73,6 @@ func TestJolokiaTrait(t *testing.T) { }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/jvm_test.go b/e2e/common/traits/jvm_test.go index 329c90f908..958763f794 100644 --- a/e2e/common/traits/jvm_test.go +++ b/e2e/common/traits/jvm_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "os" "testing" @@ -39,13 +40,13 @@ import ( func TestJVMTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-jvm" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Store a configmap holding a jar var cmData = make(map[string][]byte) @@ -53,27 +54,24 @@ func TestJVMTrait(t *testing.T) { source, err := os.ReadFile("./files/jvm/sample-1.0.jar") require.NoError(t, err) cmData["sample-1.0.jar"] = source - err = CreateBinaryConfigmap(t, ns, "my-deps", cmData) + err = CreateBinaryConfigmap(t, ctx, ns, "my-deps", cmData) require.NoError(t, err) t.Run("JVM trait classpath", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "./files/jvm/Classpath.java", - "--resource", "configmap:my-deps", - "-t", "jvm.classpath=/etc/camel/resources/my-deps/sample-1.0.jar", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "./files/jvm/Classpath.java", "--resource", "configmap:my-deps", "-t", "jvm.classpath=/etc/camel/resources/my-deps/sample-1.0.jar").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "classpath")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "classpath")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "classpath")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "classpath")() jvmTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "jvm") g.Expect(jvmTrait).ToNot(BeNil()) g.Expect(len(jvmTrait)).To(Equal(1)) g.Expect(jvmTrait["classpath"]).To(Equal("/etc/camel/resources/my-deps/sample-1.0.jar")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/kamelet_test.go b/e2e/common/traits/kamelet_test.go index d04d848030..bd744ea2a4 100644 --- a/e2e/common/traits/kamelet_test.go +++ b/e2e/common/traits/kamelet_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,13 +37,13 @@ import ( func TestKameletTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-kamelet" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("discover kamelet capabilities", func(t *testing.T) { template := map[string]interface{}{ @@ -55,22 +56,22 @@ func TestKameletTrait(t *testing.T) { }, }, } - g.Expect(CreateKamelet(t, operatorID, ns, "capabilities-webhook-source", template, nil, nil)()).To(Succeed()) + g.Expect(CreateKamelet(t, operatorID, ctx, ns, "capabilities-webhook-source", template, nil, nil)()).To(Succeed()) name := RandomizedSuffixName("webhook") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/webhook.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Started capabilities-webhook-source-1 (platform-http:///webhook)")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/webhook.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Started capabilities-webhook-source-1 (platform-http:///webhook)")) // Verify Integration capabilities - g.Eventually(IntegrationStatusCapabilities(t, ns, name), TestTimeoutShort).Should(ContainElements("platform-http")) + g.Eventually(IntegrationStatusCapabilities(t, ctx, ns, name), TestTimeoutShort).Should(ContainElements("platform-http")) // Verify expected resources from Kamelet (Service in this case) - service := Service(t, ns, name) + service := Service(t, ctx, ns, name) g.Eventually(service, TestTimeoutShort).ShouldNot(BeNil()) }) // Clean-up - g.Expect(DeleteKamelet(t, ns, "capabilities-webhook-source")).To(Succeed()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteKamelet(t, ctx, ns, "capabilities-webhook-source")).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/master_test.go b/e2e/common/traits/master_test.go index 014b26c33d..96541a8cc5 100644 --- a/e2e/common/traits/master_test.go +++ b/e2e/common/traits/master_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" "time" @@ -38,47 +39,36 @@ import ( func TestMasterTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-master" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("master works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Master.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "master"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "master"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Master.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "master"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "master"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("only one integration with master runs", func(t *testing.T) { nameFirst := RandomizedSuffixName("first") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Master.java", - "--name", nameFirst, - "--label", "leader-group=same", - "-t", "master.label-key=leader-group", - "-t", "master.label-value=same", - "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameFirst), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, nameFirst), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Master.java", "--name", nameFirst, "--label", "leader-group=same", "-t", "master.label-key=leader-group", "-t", "master.label-value=same", "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameFirst), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameFirst), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Start a second integration with the same lock (it should not start the route) nameSecond := RandomizedSuffixName("second") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Master.java", - "--name", nameSecond, - "--label", "leader-group=same", - "-t", "master.label-key=leader-group", - "-t", "master.label-value=same", - "-t", "master.resource-name=first-lock", - "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, nameSecond), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, nameSecond), TestTimeoutShort).Should(ContainSubstring("started in")) - g.Eventually(IntegrationLogs(t, ns, nameSecond), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Master.java", "--name", nameSecond, "--label", "leader-group=same", "-t", "master.label-key=leader-group", "-t", "master.label-value=same", "-t", "master.resource-name=first-lock", "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, nameSecond), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, nameSecond), TestTimeoutShort).Should(ContainSubstring("started in")) + g.Eventually(IntegrationLogs(t, ctx, ns, nameSecond), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, nameFirst)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, nameFirst)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, nameFirst)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, nameFirst)() builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "addons", "master") g.Expect(builderTrait).ToNot(BeNil()) g.Expect(len(builderTrait)).To(Equal(2)) @@ -86,6 +76,6 @@ func TestMasterTrait(t *testing.T) { g.Expect(builderTrait["labelValue"]).To(Equal("same")) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/openapi_test.go b/e2e/common/traits/openapi_test.go index e761d632a6..ef3de8e35b 100644 --- a/e2e/common/traits/openapi_test.go +++ b/e2e/common/traits/openapi_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "io/ioutil" "testing" @@ -38,38 +39,34 @@ import ( func TestOpenAPI(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-openapi" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) openapiContent, err := ioutil.ReadFile("./files/openapi/petstore-api.yaml") require.NoError(t, err) var cmDataProps = make(map[string]string) cmDataProps["petstore-api.yaml"] = string(openapiContent) - CreatePlainTextConfigmap(t, ns, "my-openapi", cmDataProps) + CreatePlainTextConfigmap(t, ctx, ns, "my-openapi", cmDataProps) - g.Expect(KamelRunWithID(t, operatorID, ns, - "--name", "petstore", - "--open-api", "configmap:my-openapi", - "files/openapi/petstore.groovy", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "petstore", "--open-api", "configmap:my-openapi", "files/openapi/petstore.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "petstore"), TestTimeoutLong). + g.Eventually(IntegrationPodPhase(t, ctx, ns, "petstore"), TestTimeoutLong). Should(Equal(corev1.PodRunning)) - g.Eventually(DeploymentWithIntegrationLabel(t, ns, "petstore"), TestTimeoutLong). + g.Eventually(DeploymentWithIntegrationLabel(t, ctx, ns, "petstore"), TestTimeoutLong). Should(Not(BeNil())) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started listPets (rest://get:/v1:/pets)")) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started createPets (rest://post:/v1:/pets)")) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started showPetById (rest://get:/v1:/pets/%7BpetId%7D)")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/pdb_test.go b/e2e/common/traits/pdb_test.go index bd6e91a2e1..86e873ae3f 100644 --- a/e2e/common/traits/pdb_test.go +++ b/e2e/common/traits/pdb_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "net/http" "testing" @@ -45,28 +46,24 @@ import ( func TestPodDisruptionBudgetTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-pdb" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "pdb.enabled=true", - "-t", "pdb.min-available=2", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "pdb.enabled=true", "-t", "pdb.min-available=2").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() pdbTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "pdb") g.Expect(pdbTrait).ToNot(BeNil()) g.Expect(len(pdbTrait)).To(Equal(2)) @@ -74,12 +71,12 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { g.Expect(pdbTrait["minAvailable"]).To(Equal("2")) // Check PodDisruptionBudget - g.Eventually(podDisruptionBudget(t, ns, name), TestTimeoutShort).ShouldNot(BeNil()) - pdb := podDisruptionBudget(t, ns, name)() + g.Eventually(podDisruptionBudget(t, ctx, ns, name), TestTimeoutShort).ShouldNot(BeNil()) + pdb := podDisruptionBudget(t, ctx, ns, name)() // Assert PDB Spec g.Expect(pdb.Spec.MinAvailable).To(PointTo(Equal(intstr.FromInt(2)))) // Assert PDB Status - g.Eventually(podDisruptionBudget(t, ns, name), TestTimeoutShort). + g.Eventually(podDisruptionBudget(t, ctx, ns, name), TestTimeoutShort). Should(MatchFieldsP(IgnoreExtras, Fields{ "Status": MatchFields(IgnoreExtras, Fields{ "ObservedGeneration": BeNumerically("==", 1), @@ -91,17 +88,17 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { })) // Scale Integration - g.Expect(ScaleIntegration(t, ns, name, 2)).To(Succeed()) - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutMedium).Should(HaveLen(2)) - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Expect(ScaleIntegration(t, ctx, ns, name, 2)).To(Succeed()) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutMedium).Should(HaveLen(2)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(PointTo(BeNumerically("==", 2))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Check PodDisruptionBudget - pdb = podDisruptionBudget(t, ns, name)() + pdb = podDisruptionBudget(t, ctx, ns, name)() g.Expect(pdb).NotTo(BeNil()) // Assert PDB Status according to the scale change - g.Eventually(podDisruptionBudget(t, ns, name), TestTimeoutShort). + g.Eventually(podDisruptionBudget(t, ctx, ns, name), TestTimeoutShort). Should(MatchFieldsP(IgnoreExtras, Fields{ "Status": MatchFields(IgnoreExtras, Fields{ "ObservedGeneration": BeNumerically("==", 1), @@ -113,9 +110,9 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { })) // Eviction attempt - pods := IntegrationPods(t, ns, name)() + pods := IntegrationPods(t, ctx, ns, name)() g.Expect(pods).To(HaveLen(2)) - err := TestClient(t).CoreV1().Pods(ns).EvictV1(TestContext, &policyv1.Eviction{ + err := TestClient(t).CoreV1().Pods(ns).EvictV1(ctx, &policyv1.Eviction{ ObjectMeta: metav1.ObjectMeta{ Name: pods[0].Name, }, @@ -139,26 +136,26 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { // Scale Integration to Scale > PodDisruptionBudgetSpec.MinAvailable // for the eviction request to succeed once replicas are ready - g.Expect(ScaleIntegration(t, ns, name, 3)).To(Succeed()) - g.Eventually(IntegrationPods(t, ns, name), TestTimeoutMedium).Should(HaveLen(3)) - g.Eventually(IntegrationStatusReplicas(t, ns, name), TestTimeoutShort). + g.Expect(ScaleIntegration(t, ctx, ns, name, 3)).To(Succeed()) + g.Eventually(IntegrationPods(t, ctx, ns, name), TestTimeoutMedium).Should(HaveLen(3)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, name), TestTimeoutShort). Should(PointTo(BeNumerically("==", 3))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - pods = IntegrationPods(t, ns, name)() + pods = IntegrationPods(t, ctx, ns, name)() g.Expect(pods).To(HaveLen(3)) - g.Expect(TestClient(t).CoreV1().Pods(ns).EvictV1(TestContext, &policyv1.Eviction{ + g.Expect(TestClient(t).CoreV1().Pods(ns).EvictV1(ctx, &policyv1.Eviction{ ObjectMeta: metav1.ObjectMeta{ Name: pods[0].Name, }, })).To(Succeed()) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } -func podDisruptionBudget(t *testing.T, ns string, name string) func() *policyv1.PodDisruptionBudget { +func podDisruptionBudget(t *testing.T, ctx context.Context, ns string, name string) func() *policyv1.PodDisruptionBudget { return func() *policyv1.PodDisruptionBudget { pdb := policyv1.PodDisruptionBudget{ TypeMeta: metav1.TypeMeta{ @@ -170,7 +167,7 @@ func podDisruptionBudget(t *testing.T, ns string, name string) func() *policyv1. Name: name, }, } - err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(&pdb), &pdb) + err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(&pdb), &pdb) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { diff --git a/e2e/common/traits/pod_test.go b/e2e/common/traits/pod_test.go index fbe662c8e4..54726a5744 100644 --- a/e2e/common/traits/pod_test.go +++ b/e2e/common/traits/pod_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -36,13 +37,13 @@ import ( func TestPodTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-pod" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) tc := []struct { name string @@ -55,10 +56,10 @@ func TestPodTrait(t *testing.T) { //nolint: thelper assertions: func(t *testing.T, ns string, name string) { // check that integrations is working and reading data created by sidecar container - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Content from the sidecar container")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Content from the sidecar container")) // check that env var is injected - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("hello from the template")) - pod := IntegrationPod(t, ns, name)() + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("hello from the template")) + pod := IntegrationPod(t, ctx, ns, name)() // check if ENV variable is applied envValue := getEnvVar("TEST_VARIABLE", pod.Spec) @@ -70,7 +71,7 @@ func TestPodTrait(t *testing.T) { templateName: "files/template-with-supplemental-groups.yaml", //nolint: thelper assertions: func(t *testing.T, ns string, name string) { - g.Eventually(IntegrationPodHas(t, ns, name, func(pod *corev1.Pod) bool { + g.Eventually(IntegrationPodHas(t, ctx, ns, name, func(pod *corev1.Pod) bool { if pod.Spec.SecurityContext == nil { return false } @@ -91,23 +92,20 @@ func TestPodTrait(t *testing.T) { test := tc[i] t.Run(test.name, func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PodTest.groovy", - "--name", name, - "--pod-template", test.templateName, - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PodTest.groovy", "--name", name, "--pod-template", test.templateName).Execute()).To(Succeed()) // check integration is deployed - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) test.assertions(t, ns, name) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/prometheus_test.go b/e2e/common/traits/prometheus_test.go index 1937e1de80..d50e27059c 100644 --- a/e2e/common/traits/prometheus_test.go +++ b/e2e/common/traits/prometheus_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "fmt" "testing" @@ -46,37 +47,35 @@ import ( func TestPrometheusTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-prometheus" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) // Do not create PodMonitor for the time being as CI test runs on OCP 3.11 createPodMonitor := false - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "-t", "prometheus.enabled=true", - "-t", fmt.Sprintf("prometheus.pod-monitor=%v", createPodMonitor)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "-t", "prometheus.enabled=true", "-t", fmt.Sprintf("prometheus.pod-monitor=%v", createPodMonitor)).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "java")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "java")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "java")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "java")() prometheusTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "prometheus") g.Expect(prometheusTrait).ToNot(BeNil()) g.Expect(len(prometheusTrait)).To(Equal(2)) g.Expect(prometheusTrait["enabled"]).To(Equal(true)) g.Expect(prometheusTrait["podMonitor"]).ToNot(BeNil()) t.Run("Metrics endpoint works", func(t *testing.T) { - pod := IntegrationPod(t, ns, "java") + pod := IntegrationPod(t, ctx, ns, "java") response, err := TestClient(t).CoreV1().RESTClient().Get(). - AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/q/metrics", ns, pod().Name)).DoRaw(TestContext) + AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/q/metrics", ns, pod().Name)).DoRaw(ctx) if err != nil { assert.Fail(t, err.Error()) } @@ -85,23 +84,23 @@ func TestPrometheusTrait(t *testing.T) { if ocp && createPodMonitor { t.Run("PodMonitor is created", func(t *testing.T) { - sm := podMonitor(t, ns, "java") + sm := podMonitor(t, ctx, ns, "java") g.Eventually(sm, TestTimeoutShort).ShouldNot(BeNil()) }) } - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } -func podMonitor(t *testing.T, ns string, name string) func() *monitoringv1.PodMonitor { +func podMonitor(t *testing.T, ctx context.Context, ns string, name string) func() *monitoringv1.PodMonitor { return func() *monitoringv1.PodMonitor { pm := monitoringv1.PodMonitor{} key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - err := TestClient(t).Get(TestContext, key, &pm) + err := TestClient(t).Get(ctx, key, &pm) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { diff --git a/e2e/common/traits/pull_secret_test.go b/e2e/common/traits/pull_secret_test.go index 989e67b974..7436cfec1e 100644 --- a/e2e/common/traits/pull_secret_test.go +++ b/e2e/common/traits/pull_secret_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -38,47 +39,44 @@ import ( func TestPullSecretTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-pull-secret" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) g.Expect(err).To(BeNil()) t.Run("Image pull secret is set on pod", func(t *testing.T) { name := RandomizedSuffixName("java1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "pull-secret.enabled=true", - "-t", "pull-secret.secret-name=dummy-secret").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "pull-secret.enabled=true", "-t", "pull-secret.secret-name=dummy-secret").Execute()).To(Succeed()) // pod may not run because the pull secret is dummy - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Or(Equal(corev1.PodRunning), Equal(corev1.PodPending))) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Or(Equal(corev1.PodRunning), Equal(corev1.PodPending))) - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod.Spec.ImagePullSecrets).NotTo(BeEmpty()) g.Expect(pod.Spec.ImagePullSecrets[0].Name).To(Equal("dummy-secret")) }) t.Run("Explicitly disable image pull secret", func(t *testing.T) { name := RandomizedSuffixName("java2") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "pull-secret.enabled=false").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "pull-secret.enabled=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() pullSecretTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "pull-secret") g.Expect(pullSecretTrait).ToNot(BeNil()) g.Expect(len(pullSecretTrait)).To(Equal(1)) g.Expect(pullSecretTrait["enabled"]).To(Equal(false)) - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() if ocp { // OpenShift `default` service account has imagePullSecrets so it's always set g.Expect(pod.Spec.ImagePullSecrets).NotTo(BeEmpty()) @@ -91,18 +89,18 @@ func TestPullSecretTrait(t *testing.T) { // OpenShift always has an internal registry so image pull secret is set by default t.Run("Image pull secret is automatically set by default", func(t *testing.T) { name := RandomizedSuffixName("java3") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod.Spec.ImagePullSecrets).NotTo(BeEmpty()) g.Expect(pod.Spec.ImagePullSecrets[0].Name).To(HavePrefix("default-dockercfg-")) }) } // Clean-up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/route_test.go b/e2e/common/traits/route_test.go index 3df7694528..ce31bfa617 100644 --- a/e2e/common/traits/route_test.go +++ b/e2e/common/traits/route_test.go @@ -24,6 +24,7 @@ package traits import ( "bytes" + "context" "crypto/rand" "crypto/rsa" "crypto/tls" @@ -74,13 +75,13 @@ var skipClientTLSVerification = true func TestRunRoutes(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-route" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--trait-profile=openshift")).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--trait-profile=openshift")).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) if !ocp { @@ -91,7 +92,7 @@ func TestRunRoutes(t *testing.T) { // create a test secret of type tls with certificates // this secret is used to setupt the route TLS object across diferent tests - secret, err := createSecret(t, ns) + secret, err := createSecret(t, ctx, ns) require.NoError(t, err) // they refer to the certificates create in the secret and are reused the different tests @@ -102,45 +103,41 @@ func TestRunRoutes(t *testing.T) { // Insecure Route / No TLS // ============================= t.Run("Route unsecure http works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - route := Route(t, ns, integrationName) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + route := Route(t, ctx, ns, integrationName) g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before doing an http request, // otherwise the route is unavailable and the http request will fail time.Sleep(waitBeforeHttpRequest) url := fmt.Sprintf("http://%s/hello?name=Simple", route().Spec.Host) g.Eventually(httpRequest(url, false), TestTimeoutShort).Should(Equal("Hello Simple")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) // ============================= // TLS Route Edge // ============================= t.Run("Route Edge https works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.tls-termination=edge").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - route := Route(t, ns, integrationName) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.tls-termination=edge").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + route := Route(t, ctx, ns, integrationName) g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before an http request, // otherwise the route is unavailable and the http request will fail time.Sleep(waitBeforeHttpRequest) url := fmt.Sprintf("https://%s/hello?name=TLS_Edge", route().Spec.Host) g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello TLS_Edge")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) // ============================= // TLS Route Edge with custom certificate // ============================= t.Run("Route Edge (custom certificate) https works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "route.tls-termination=edge", - "-t", "route.tls-certificate-secret="+refCert, - "-t", "route.tls-key-secret="+refKey, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - route := Route(t, ns, integrationName) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.tls-termination=edge", "-t", "route.tls-certificate-secret="+refCert, "-t", "route.tls-key-secret="+refKey).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + route := Route(t, ctx, ns, integrationName) g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before an http request, // otherwise the route is unavailable and the http request will fail @@ -148,24 +145,16 @@ func TestRunRoutes(t *testing.T) { code := "TLS_EdgeCustomCertificate" url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code) g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) // ============================= // TLS Route Passthrough // ============================= t.Run("Route passthrough https works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - // the --resource mounts the certificates inside secret as files in the integration pod - "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, - // quarkus platform-http uses these two properties to setup the HTTP endpoint with TLS support - "-p", "quarkus.http.ssl.certificate.file=/etc/ssl/"+secretName+"/tls.crt", - "-p", "quarkus.http.ssl.certificate.key-file=/etc/ssl/"+secretName+"/tls.key", - "-t", "route.tls-termination=passthrough", - "-t", "container.port=8443", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - route := Route(t, ns, integrationName) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, "-p", "quarkus.http.ssl.certificate.file=/etc/ssl/"+secretName+"/tls.crt", "-p", "quarkus.http.ssl.certificate.key-file=/etc/ssl/"+secretName+"/tls.key", "-t", "route.tls-termination=passthrough", "-t", "container.port=8443").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + route := Route(t, ctx, ns, integrationName) g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before an http request, // otherwise the route is unavailable and the http request will fail @@ -173,29 +162,17 @@ func TestRunRoutes(t *testing.T) { code := "TLS_Passthrough" url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code) g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) // ============================= // TLS Route Reencrypt // ============================= t.Run("Route Reencrypt https works", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - // the --resource mounts the certificates inside secret as files in the integration pod - "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, - // quarkus platform-http uses these two properties to setup the HTTP endpoint with TLS support - "-p", "quarkus.http.ssl.certificate.file=/etc/ssl/"+secretName+"/tls.crt", - "-p", "quarkus.http.ssl.certificate.key-file=/etc/ssl/"+secretName+"/tls.key", - "-t", "route.tls-termination=reencrypt", - // the destination CA certificate which the route service uses to validate the HTTP endpoint TLS certificate - "-t", "route.tls-destination-ca-certificate-secret="+refCert, - "-t", "route.tls-certificate-secret="+refCert, - "-t", "route.tls-key-secret="+refKey, - "-t", "container.port=8443", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - - route := Route(t, ns, integrationName) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, "-p", "quarkus.http.ssl.certificate.file=/etc/ssl/"+secretName+"/tls.crt", "-p", "quarkus.http.ssl.certificate.key-file=/etc/ssl/"+secretName+"/tls.key", "-t", "route.tls-termination=reencrypt", "-t", "route.tls-destination-ca-certificate-secret="+refCert, "-t", "route.tls-certificate-secret="+refCert, "-t", "route.tls-key-secret="+refKey, "-t", "container.port=8443").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + route := Route(t, ctx, ns, integrationName) g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before an http request, // otherwise the route is unavailable and the http request will fail @@ -203,14 +180,13 @@ func TestRunRoutes(t *testing.T) { code := "TLS_Reencrypt" url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code) g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) t.Run("Route annotations added", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "route.annotations.'haproxy.router.openshift.io/balance'=roundrobin").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - route := RouteFull(t, ns, integrationName)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.annotations.'haproxy.router.openshift.io/balance'=roundrobin").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + route := RouteFull(t, ctx, ns, integrationName)() g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil()) // must wait a little time after route is created, before an http request, // otherwise the route is unavailable and the http request will fail @@ -219,16 +195,16 @@ func TestRunRoutes(t *testing.T) { g.Expect(annotations["haproxy.router.openshift.io/balance"]).To(Equal("roundrobin")) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, integrationName)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, integrationName)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, integrationName)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, integrationName)() routeTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "route") g.Expect(routeTrait).ToNot(BeNil()) g.Expect(len(routeTrait)).To(Equal(1)) g.Expect(routeTrait["enabled"]).To(Equal(true)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) - g.Expect(TestClient(t).Delete(TestContext, &secret)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, &secret)).To(Succeed()) }) } @@ -280,8 +256,8 @@ func httpClient(tlsEnabled bool, timeout time.Duration) (*http.Client, error) { return &client, nil } -func createSecret(t *testing.T, ns string) (corev1.Secret, error) { - keyCertPair := generateSampleKeyAndCertificate(t, ns) +func createSecret(t *testing.T, ctx context.Context, ns string) (corev1.Secret, error) { + keyCertPair := generateSampleKeyAndCertificate(t, ctx, ns) sec := corev1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -297,12 +273,12 @@ func createSecret(t *testing.T, ns string) (corev1.Secret, error) { corev1.TLSCertKey: keyCertPair.Certificate, }, } - return sec, TestClient(t).Create(TestContext, &sec) + return sec, TestClient(t).Create(ctx, &sec) } -func generateSampleKeyAndCertificate(t *testing.T, ns string) keyCertificatePair { +func generateSampleKeyAndCertificate(t *testing.T, ctx context.Context, ns string) keyCertificatePair { serialNumber := big.NewInt(util.RandomInt63()) - domainName, err := ClusterDomainName(t) + domainName, err := ClusterDomainName(t, ctx) if err != nil { fmt.Printf("Error retrieving cluster domain object, then the http client request will skip TLS validation: %s\n", err) skipClientTLSVerification = true diff --git a/e2e/common/traits/service_binding_test.go b/e2e/common/traits/service_binding_test.go index 8eca83f105..b5862d2fa5 100644 --- a/e2e/common/traits/service_binding_test.go +++ b/e2e/common/traits/service_binding_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "fmt" "testing" @@ -38,13 +39,13 @@ import ( func TestServiceBindingTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-service-binding" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Integration Service Binding", func(t *testing.T) { // Create our mock service config @@ -69,17 +70,14 @@ func TestServiceBindingTrait(t *testing.T) { }, } serviceRef := fmt.Sprintf("%s:%s/%s", service.TypeMeta.Kind, ns, service.ObjectMeta.Name) - g.Expect(TestClient(t).Create(TestContext, service)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, service)).To(Succeed()) // Create integration and bind it to our service name := RandomizedSuffixName("service-binding") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/ServiceBinding.java", - "--name", name, - "--connect", serviceRef, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("%s:%s", host, port))) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/ServiceBinding.java", "--name", name, "--connect", serviceRef).Execute()).To(Succeed()) + + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("%s:%s", host, port))) }) t.Run("Binding Service Binding", func(t *testing.T) { @@ -102,16 +100,14 @@ func TestServiceBindingTrait(t *testing.T) { }, } serviceRef := fmt.Sprintf("%s:%s/%s", service.TypeMeta.Kind, ns, service.ObjectMeta.Name) - g.Expect(TestClient(t).Create(TestContext, service)).To(Succeed()) - g.Expect(CreateTimerKamelet(t, operatorID, ns, "my-timer-source")()).To(Succeed()) - g.Expect(KamelBindWithID(t, operatorID, ns, "my-timer-source", "log:info", - "-p", "source.message=Hello+world", - "--connect", serviceRef).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "my-timer-source-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "my-timer-source-to-log")).Should(ContainSubstring("Body: Hello+world")) + g.Expect(TestClient(t).Create(ctx, service)).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, "my-timer-source")()).To(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "my-timer-source", "log:info", "-p", "source.message=Hello+world", "--connect", serviceRef).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "my-timer-source-to-log"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "my-timer-source-to-log")).Should(ContainSubstring("Body: Hello+world")) }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/service_test.go b/e2e/common/traits/service_test.go index ea776dd1c8..e18e23735e 100644 --- a/e2e/common/traits/service_test.go +++ b/e2e/common/traits/service_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -37,95 +38,87 @@ import ( func TestServiceTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-service" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("NodePort service", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "service.enabled=true", - "-t", "service.node-port=true").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "service.enabled=true", "-t", "service.node-port=true").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // // Service names can vary with the ExternalName Service // sometimes being created first and being given the root name // - g.Eventually(ServicesByType(t, ns, corev1.ServiceTypeNodePort), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeNodePort), TestTimeoutLong).ShouldNot(BeEmpty()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Default service (ClusterIP)", func(t *testing.T) { // Service trait is enabled by default - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // // Service names can vary with the ExternalName Service // sometimes being created first and being given the root name // - g.Eventually(ServicesByType(t, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("NodePort service from Type", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "service.enabled=true", - "-t", "service.type=NodePort").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "service.enabled=true", "-t", "service.type=NodePort").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // // Service names can vary with the ExternalName Service // sometimes being created first and being given the root name // - g.Eventually(ServicesByType(t, ns, corev1.ServiceTypeNodePort), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeNodePort), TestTimeoutLong).ShouldNot(BeEmpty()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("ClusterIP service from Type", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "service.enabled=true", - "-t", "service.type=ClusterIP").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "service.enabled=true", "-t", "service.type=ClusterIP").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // // Service names can vary with the ExternalName Service // sometimes being created first and being given the root name // - g.Eventually(ServicesByType(t, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "platform-http-server")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "platform-http-server")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "platform-http-server")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "platform-http-server")() serviceTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "service") g.Expect(serviceTrait).ToNot(BeNil()) g.Expect(len(serviceTrait)).To(Equal(2)) g.Expect(serviceTrait["enabled"]).To(Equal(true)) g.Expect(serviceTrait["type"]).To(Equal("ClusterIP")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("LoadBalancer service from Type", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/PlatformHttpServer.java", - "-t", "service.enabled=true", - "-t", "service.type=LoadBalancer").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "service.enabled=true", "-t", "service.type=LoadBalancer").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) // // Service names can vary with the ExternalName Service // sometimes being created first and being given the root name // - g.Eventually(ServicesByType(t, ns, corev1.ServiceTypeLoadBalancer), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeLoadBalancer), TestTimeoutLong).ShouldNot(BeEmpty()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) } diff --git a/e2e/common/traits/toleration_test.go b/e2e/common/traits/toleration_test.go index e47330f73a..98e8def887 100644 --- a/e2e/common/traits/toleration_test.go +++ b/e2e/common/traits/toleration_test.go @@ -23,6 +23,7 @@ limitations under the License. package traits import ( + "context" "testing" . "github.com/onsi/gomega" @@ -38,26 +39,22 @@ import ( func TestTolerationTrait(t *testing.T) { t.Parallel() - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-traits-toleration" - g.Expect(CopyCamelCatalog(t, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Run Java with node toleration operation exists", func(t *testing.T) { name := RandomizedSuffixName("java1") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "toleration.enabled=true", - "-t", "toleration.taints=camel.apache.org/master:NoExecute:300", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "toleration.enabled=true", "-t", "toleration.taints=camel.apache.org/master:NoExecute:300").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod.Spec.Tolerations).NotTo(BeNil()) g.Expect(pod.Spec.Tolerations).To(ContainElement(corev1.Toleration{ @@ -70,16 +67,12 @@ func TestTolerationTrait(t *testing.T) { t.Run("Run Java with node toleration operation equals", func(t *testing.T) { name := RandomizedSuffixName("java2") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - "-t", "toleration.enabled=true", - "-t", "toleration.taints=camel.apache.org/master=test:NoExecute:300", - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "toleration.enabled=true", "-t", "toleration.taints=camel.apache.org/master=test:NoExecute:300").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod.Spec.Tolerations).NotTo(BeNil()) g.Expect(pod.Spec.Tolerations).To(ContainElement(corev1.Toleration{ @@ -91,26 +84,18 @@ func TestTolerationTrait(t *testing.T) { }) t.Run("Run Java with master node toleration", func(t *testing.T) { - if len(Nodes(t)()) == 1 { + if len(Nodes(t, ctx)()) == 1 { t.Skip("Skip master node toleration test on single-node cluster") } name := RandomizedSuffixName("java3") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", - "--name", name, - // Use the affinity trait to force the scheduling of the Integration pod onto a master node - "-t", "affinity.enabled=true", - "-t", "affinity.node-affinity-labels=node-role.kubernetes.io/master", - // And tolerate the corresponding taint - "-t", "toleration.enabled=true", - "-t", "toleration.taints=node-role.kubernetes.io/master:NoSchedule", - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - pod := IntegrationPod(t, ns, name)() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "affinity.enabled=true", "-t", "affinity.node-affinity-labels=node-role.kubernetes.io/master", "-t", "toleration.enabled=true", "-t", "toleration.taints=node-role.kubernetes.io/master:NoSchedule").Execute()).To(Succeed()) + + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + + pod := IntegrationPod(t, ctx, ns, name)() g.Expect(pod).NotTo(BeNil()) // Check the Integration pod contains the toleration @@ -121,8 +106,8 @@ func TestTolerationTrait(t *testing.T) { })) // Check the Integration pod is running on a master node - g.Expect(Node(t, pod.Spec.NodeName)()).NotTo(BeNil()) - g.Expect(Node(t, pod.Spec.NodeName)()).To(PointTo(MatchFields(IgnoreExtras, Fields{ + g.Expect(Node(t, ctx, pod.Spec.NodeName)()).NotTo(BeNil()) + g.Expect(Node(t, ctx, pod.Spec.NodeName)()).To(PointTo(MatchFields(IgnoreExtras, Fields{ "Spec": MatchFields(IgnoreExtras, Fields{ "Taints": ContainElement(corev1.Taint{ Key: "node-role.kubernetes.io/master", @@ -133,6 +118,6 @@ func TestTolerationTrait(t *testing.T) { }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/install/cli/global_kamelet_test.go b/e2e/install/cli/global_kamelet_test.go index 160b763a62..40a17645a8 100644 --- a/e2e/install/cli/global_kamelet_test.go +++ b/e2e/install/cli/global_kamelet_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "testing" . "github.com/onsi/gomega" @@ -32,42 +33,42 @@ import ( ) func TestRunGlobalKamelet(t *testing.T) { - WithGlobalOperatorNamespace(t, func(g *WithT, operatorNamespace string) { + WithGlobalOperatorNamespace(t, func(ctx context.Context, g *WithT, operatorNamespace string) { operatorID := "camel-k-global-kamelet" - g.Expect(KamelInstallWithID(t, operatorID, operatorNamespace, "--global", "--force")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, operatorNamespace, "--global", "--force")).To(Succeed()) t.Run("Global operator + namespaced kamelet test", func(t *testing.T) { // NS2: namespace without operator - WithNewTestNamespace(t, func(g *WithT, ns2 string) { - g.Expect(CreateTimerKamelet(t, operatorID, ns2, "my-own-timer-source")()).To(Succeed()) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns2 string) { + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns2, "my-own-timer-source")()).To(Succeed()) - g.Expect(KamelInstallWithID(t, operatorID, ns2, "--skip-operator-setup", "--olm=false")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns2, "--skip-operator-setup", "--olm=false")).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns2, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns2, "timer-kamelet-usage"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns2, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns2).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns2, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns2, "timer-kamelet-usage"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns2, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns2).Execute()).To(Succeed()) }) }) t.Run("Global operator + global kamelet test", func(t *testing.T) { - g.Expect(CreateTimerKamelet(t, operatorID, operatorNamespace, "my-own-timer-source")()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, operatorNamespace, "my-own-timer-source")()).To(Succeed()) // NS3: namespace without operator - WithNewTestNamespace(t, func(g *WithT, ns3 string) { - g.Expect(KamelInstallWithID(t, operatorID, ns3, "--skip-operator-setup", "--olm=false")).To(Succeed()) - - g.Expect(KamelRunWithID(t, operatorID, ns3, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns3, "timer-kamelet-usage"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns3, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns3).Execute()).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, Kamelet(t, "my-own-timer-source", operatorNamespace)())).To(Succeed()) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns3 string) { + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns3, "--skip-operator-setup", "--olm=false")).To(Succeed()) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns3, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns3, "timer-kamelet-usage"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns3, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns3).Execute()).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, Kamelet(t, ctx, "my-own-timer-source", operatorNamespace)())).To(Succeed()) }) }) - g.Expect(Kamel(t, "uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles=false", "--skip-cluster-role-bindings=false").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles=false", "--skip-cluster-role-bindings=false").Execute()).To(Succeed()) }) } diff --git a/e2e/install/cli/global_test.go b/e2e/install/cli/global_test.go index 10db634cac..436c92e63f 100644 --- a/e2e/install/cli/global_test.go +++ b/e2e/install/cli/global_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "fmt" "strings" "testing" @@ -40,88 +41,88 @@ import ( ) func TestRunGlobalInstall(t *testing.T) { - WithGlobalOperatorNamespace(t, func(g *WithT, operatorNamespace string) { - g.Expect(KamelInstall(t, operatorNamespace, "--global", "--force")).To(Succeed()) - g.Eventually(OperatorPodPhase(t, operatorNamespace), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + WithGlobalOperatorNamespace(t, func(ctx context.Context, g *WithT, operatorNamespace string) { + g.Expect(KamelInstall(t, ctx, operatorNamespace, "--global", "--force")).To(Succeed()) + g.Eventually(OperatorPodPhase(t, ctx, operatorNamespace), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) t.Run("Global CamelCatalog reconciliation", func(t *testing.T) { - g.Eventually(Platform(t, operatorNamespace)).ShouldNot(BeNil()) - g.Eventually(PlatformConditionStatus(t, operatorNamespace, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). + g.Eventually(Platform(t, ctx, operatorNamespace)).ShouldNot(BeNil()) + g.Eventually(PlatformConditionStatus(t, ctx, operatorNamespace, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion)) - g.Eventually(CamelCatalog(t, operatorNamespace, catalogName)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogPhase(t, operatorNamespace, catalogName), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Eventually(CamelCatalog(t, ctx, operatorNamespace, catalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogPhase(t, ctx, operatorNamespace, catalogName), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) }) t.Run("Global test on namespace with platform", func(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns2 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns2 string) { // Creating namespace local platform - g.Expect(KamelInstall(t, ns2, "--skip-operator-setup", "--olm=false")).To(Succeed()) - g.Eventually(Platform(t, ns2)).ShouldNot(BeNil()) + g.Expect(KamelInstall(t, ctx, ns2, "--skip-operator-setup", "--olm=false")).To(Succeed()) + g.Eventually(Platform(t, ctx, ns2)).ShouldNot(BeNil()) // Run with global operator id - g.Expect(KamelRun(t, ns2, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns2, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns2, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ns2, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(ns2 + "\\/.*")) - kit := IntegrationKit(t, ns2, "java")() - g.Expect(Kamel(t, "delete", "--all", "-n", ns2).Execute()).To(Succeed()) - g.Expect(Kits(t, ns2)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) - g.Expect(Kits(t, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) - - g.Expect(Lease(t, ns2, platform.DefaultPlatformName)()).To(BeNil(), "No locking Leases expected") + g.Expect(KamelRun(t, ctx, ns2, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns2, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns2, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ctx, ns2, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(ns2 + "\\/.*")) + kit := IntegrationKit(t, ctx, ns2, "java")() + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns2).Execute()).To(Succeed()) + g.Expect(Kits(t, ctx, ns2)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) + g.Expect(Kits(t, ctx, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) + + g.Expect(Lease(t, ctx, ns2, platform.DefaultPlatformName)()).To(BeNil(), "No locking Leases expected") }) }) t.Run("Global test on namespace with its own operator", func(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns3 string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns3 string) { operatorID := "camel-k-local-ns3" if NoOlmOperatorImage != "" { - g.Expect(KamelInstallWithID(t, operatorID, ns3, "--olm=false", "--operator-image", NoOlmOperatorImage)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns3, "--olm=false", "--operator-image", NoOlmOperatorImage)).To(Succeed()) } else { - g.Expect(KamelInstallWithID(t, operatorID, ns3, "--olm=false")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns3, "--olm=false")).To(Succeed()) } - g.Eventually(OperatorPodPhase(t, ns3), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Expect(KamelRunWithID(t, operatorID, ns3, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns3, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns3, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ns3, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(ns3 + "\\/.*")) - kit := IntegrationKit(t, ns3, "java")() - g.Expect(Kits(t, ns3)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) - g.Expect(Kamel(t, "delete", "--all", "-n", ns3).Execute()).To(Succeed()) - - g.Expect(Lease(t, ns3, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") - g.Expect(Lease(t, ns3, platform.GetOperatorLockName(operatorID))()).ShouldNot(BeNil(), + g.Eventually(OperatorPodPhase(t, ctx, ns3), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns3, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns3, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns3, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ctx, ns3, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(ns3 + "\\/.*")) + kit := IntegrationKit(t, ctx, ns3, "java")() + g.Expect(Kits(t, ctx, ns3)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns3).Execute()).To(Succeed()) + + g.Expect(Lease(t, ctx, ns3, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") + g.Expect(Lease(t, ctx, ns3, platform.GetOperatorLockName(operatorID))()).ShouldNot(BeNil(), "Controller Runtime is expected to use Leases for leader election: if this changes we should update our locking logic", ) }) }) t.Run("Global test on namespace without platform", func(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns4 string) { - g.Expect(KamelRun(t, ns4, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns4, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns4, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ns4, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(operatorNamespace + "\\/.*")) - kit := IntegrationKit(t, ns4, "java")() - g.Expect(Kamel(t, "delete", "--all", "-n", ns4).Execute()).To(Succeed()) - g.Expect(Kits(t, ns4)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) - g.Expect(Kits(t, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) // Kit built globally - - g.Expect(Lease(t, ns4, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns4 string) { + g.Expect(KamelRun(t, ctx, ns4, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns4, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns4, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ctx, ns4, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(operatorNamespace + "\\/.*")) + kit := IntegrationKit(t, ctx, ns4, "java")() + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns4).Execute()).To(Succeed()) + g.Expect(Kits(t, ctx, ns4)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) + g.Expect(Kits(t, ctx, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) // Kit built globally + + g.Expect(Lease(t, ctx, ns4, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") }) }) t.Run("Global test on namespace without platform with external kit", func(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns5 string) { - g.Expect(KamelRun(t, ns5, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns5, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns5, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ns5, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(operatorNamespace + "\\/.*")) - kit := IntegrationKit(t, ns5, "java")() - g.Expect(Kamel(t, "delete", "--all", "-n", ns5).Execute()).To(Succeed()) - g.Expect(Kits(t, ns5)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) - globalKits := Kits(t, operatorNamespace)() + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns5 string) { + g.Expect(KamelRun(t, ctx, ns5, "files/Java.java").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns5, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns5, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(IntegrationConditionMessage(IntegrationCondition(t, ctx, ns5, "java", v1.IntegrationConditionPlatformAvailable)())).To(MatchRegexp(operatorNamespace + "\\/.*")) + kit := IntegrationKit(t, ctx, ns5, "java")() + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns5).Execute()).To(Succeed()) + g.Expect(Kits(t, ctx, ns5)()).Should(WithTransform(integrationKitsToNamesTransform(), Not(ContainElement(kit)))) + globalKits := Kits(t, ctx, operatorNamespace)() g.Expect(globalKits).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) // Reusing the same global kit // external kit mirroring the global one @@ -134,24 +135,24 @@ func TestRunGlobalInstall(t *testing.T) { }, }, Spec: v1.IntegrationKitSpec{ - Image: getKitImage(t, operatorNamespace, kit), + Image: getKitImage(t, ctx, operatorNamespace, kit), }, } - g.Expect(TestClient(t).Create(TestContext, &externalKit)).Should(BeNil()) + g.Expect(TestClient(t).Create(ctx, &externalKit)).Should(BeNil()) - g.Expect(KamelRun(t, ns5, "files/Java.java", "--name", "ext", "--kit", "external", "-t", "jvm.enabled=true").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns5, "ext"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns5, "ext"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Expect(IntegrationKit(t, ns5, "ext")()).Should(Equal("external")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns5).Execute()).To(Succeed()) - g.Expect(Kits(t, ns5)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement("external"))) // the external one - g.Expect(Kits(t, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) // the global one + g.Expect(KamelRun(t, ctx, ns5, "files/Java.java", "--name", "ext", "--kit", "external", "-t", "jvm.enabled=true").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns5, "ext"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns5, "ext"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(IntegrationKit(t, ctx, ns5, "ext")()).Should(Equal("external")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns5).Execute()).To(Succeed()) + g.Expect(Kits(t, ctx, ns5)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement("external"))) // the external one + g.Expect(Kits(t, ctx, operatorNamespace)()).Should(WithTransform(integrationKitsToNamesTransform(), ContainElement(kit))) // the global one - g.Expect(Lease(t, ns5, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") + g.Expect(Lease(t, ctx, ns5, platform.OperatorLockName)()).To(BeNil(), "No locking Leases expected") }) }) - g.Expect(Kamel(t, "uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles").Execute()).To(Succeed()) }) } @@ -165,7 +166,7 @@ func integrationKitsToNamesTransform() func([]v1.IntegrationKit) []string { } } -func getKitImage(t *testing.T, ns string, name string) string { +func getKitImage(t *testing.T, ctx context.Context, ns string, name string) string { get := v1.IntegrationKit{ TypeMeta: metav1.TypeMeta{ Kind: "IntegrationKit", @@ -180,7 +181,7 @@ func getKitImage(t *testing.T, ns string, name string) string { Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &get); err != nil { + if err := TestClient(t).Get(ctx, key, &get); err != nil { return "" } return get.Status.Image diff --git a/e2e/install/cli/install_test.go b/e2e/install/cli/install_test.go index 7500b6eb3e..ff6bfaaf67 100644 --- a/e2e/install/cli/install_test.go +++ b/e2e/install/cli/install_test.go @@ -24,6 +24,7 @@ package cli import ( "bytes" + "context" "fmt" "os" "reflect" @@ -47,40 +48,40 @@ import ( ) func TestBasicInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) - g.Eventually(PlatformConditionStatus(t, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(PlatformConditionStatus(t, ctx, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) // Check if restricted security context has been applyed - operatorPod := OperatorPod(t, ns)() + operatorPod := OperatorPod(t, ctx, ns)() g.Expect(operatorPod.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(Equal(kubernetes.DefaultOperatorSecurityContext().RunAsNonRoot)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.Capabilities).To(Equal(kubernetes.DefaultOperatorSecurityContext().Capabilities)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.SeccompProfile).To(Equal(kubernetes.DefaultOperatorSecurityContext().SeccompProfile)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation).To(Equal(kubernetes.DefaultOperatorSecurityContext().AllowPrivilegeEscalation)) t.Run("run yaml", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Check if file exists in operator pod - g.Expect(OperatorPod(t, ns)().Name).NotTo(Equal("")) - g.Expect(OperatorPod(t, ns)().Spec.Containers[0].Name).NotTo(Equal("")) + g.Expect(OperatorPod(t, ctx, ns)().Name).NotTo(Equal("")) + g.Expect(OperatorPod(t, ctx, ns)().Spec.Containers[0].Name).NotTo(Equal("")) req := TestClient(t).CoreV1().RESTClient().Post(). Resource("pods"). - Name(OperatorPod(t, ns)().Name). + Name(OperatorPod(t, ctx, ns)().Name). Namespace(ns). SubResource("exec"). - Param("container", OperatorPod(t, ns)().Spec.Containers[0].Name) + Param("container", OperatorPod(t, ctx, ns)().Spec.Containers[0].Name) req.VersionedParams(&corev1.PodExecOptions{ - Container: OperatorPod(t, ns)().Spec.Containers[0].Name, + Container: OperatorPod(t, ctx, ns)().Spec.Containers[0].Name, Command: []string{"test", "-e", defaults.LocalRepository + "/org/apache/camel/k"}, Stdin: false, Stdout: true, @@ -101,35 +102,35 @@ func TestBasicInstallation(t *testing.T) { }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestAlternativeImageInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--olm=false", "--operator-image", "x/y:latest")).To(Succeed()) - g.Eventually(OperatorImage(t, ns)).Should(Equal("x/y:latest")) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--olm=false", "--operator-image", "x/y:latest")).To(Succeed()) + g.Eventually(OperatorImage(t, ctx, ns)).Should(Equal("x/y:latest")) }) } func TestKitMainInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Expect(Kamel(t, "kit", "create", "timer", "-d", "camel:timer", "-x", operatorID, "-n", ns).Execute()).To(Succeed()) - g.Eventually(Build(t, ns, "timer"), TestTimeoutMedium).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Expect(Kamel(t, ctx, "kit", "create", "timer", "-d", "camel:timer", "-x", operatorID, "-n", ns).Execute()).To(Succeed()) + g.Eventually(Build(t, ctx, ns, "timer"), TestTimeoutMedium).ShouldNot(BeNil()) }) } func TestMavenRepositoryInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--maven-repository", "https://my.repo.org/public/")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--maven-repository", "https://my.repo.org/public/")).To(Succeed()) configmapName := fmt.Sprintf("%s-maven-settings", operatorID) - g.Eventually(Configmap(t, ns, configmapName)).Should(Not(BeNil())) + g.Eventually(Configmap(t, ctx, ns, configmapName)).Should(Not(BeNil())) g.Eventually(func() string { - return Configmap(t, ns, configmapName)().Data["settings.xml"] + return Configmap(t, ctx, ns, configmapName)().Data["settings.xml"] }).Should(ContainSubstring("https://my.repo.org/public/")) }) } @@ -139,12 +140,12 @@ func TestMavenRepositoryInstallation(t *testing.T) { * so the Platform will have an empty Registry structure */ func TestSkipRegistryInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--skip-registry-setup")).To(Succeed()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--skip-registry-setup")).To(Succeed()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) g.Eventually(func() v1.RegistrySpec { - return Platform(t, ns)().Spec.Build.Registry + return Platform(t, ctx, ns)().Spec.Build.Registry }, TestTimeoutMedium).Should(Equal(v1.RegistrySpec{})) }) } @@ -173,18 +174,18 @@ func TestConsoleCliDownload(t *testing.T) { templt, err := template.New("downloadLink").Parse(downloadUrlTemplate) require.NoError(t, err) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // make sure there is no preinstalled CliDownload resource - cliDownload := ConsoleCLIDownload(t, name)() + cliDownload := ConsoleCLIDownload(t, ctx, name)() if cliDownload != nil { - g.Expect(TestClient(t).Delete(TestContext, cliDownload)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, cliDownload)).To(Succeed()) } operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(ConsoleCLIDownload(t, name), TestTimeoutMedium).Should(Not(BeNil())) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(ConsoleCLIDownload(t, ctx, name), TestTimeoutMedium).Should(Not(BeNil())) - cliDownload = ConsoleCLIDownload(t, name)() + cliDownload = ConsoleCLIDownload(t, ctx, name)() links := cliDownload.Spec.Links for _, link := range links { @@ -204,19 +205,19 @@ func TestConsoleCliDownload(t *testing.T) { } func TestInstallSkipDefaultKameletsInstallation(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operatorID, ns, "--skip-default-kamelets-setup")).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Expect(KameletList(t, ns)()).Should(BeEmpty()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operatorID, ns, "--skip-default-kamelets-setup")).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Expect(KameletList(t, ctx, ns)()).Should(BeEmpty()) }) } func TestInstallDebugLogging(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "-z", "debug")).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "-z", "debug")).To(Succeed()) - g.Eventually(OperatorEnvVarValue(t, ns, "LOG_LEVEL"), TestTimeoutLong).Should(Equal("debug")) + g.Eventually(OperatorEnvVarValue(t, ctx, ns, "LOG_LEVEL"), TestTimeoutLong).Should(Equal("debug")) }) } diff --git a/e2e/install/cli/maven_ca_secret_test.go b/e2e/install/cli/maven_ca_secret_test.go index 595b4c3316..fceb53c3ee 100644 --- a/e2e/install/cli/maven_ca_secret_test.go +++ b/e2e/install/cli/maven_ca_secret_test.go @@ -25,6 +25,7 @@ package cli import ( "bufio" "bytes" + "context" "crypto/rand" "crypto/rsa" "crypto/x509" @@ -56,7 +57,7 @@ import ( ) func TestMavenCASecret(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { hostname := fmt.Sprintf("%s.%s.svc", "nexus", ns) tlsMountPath := "/etc/tls/private" @@ -111,7 +112,7 @@ func TestMavenCASecret(t *testing.T) { corev1.TLSPrivateKeyKey: privateKeyPem, }, } - g.Expect(TestClient(t).Create(TestContext, secret)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, secret)).To(Succeed()) // HTTPD configuration config := &corev1.ConfigMap{ @@ -179,7 +180,7 @@ ProxyPreserveHost On ), }, } - g.Expect(TestClient(t).Create(TestContext, config)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, config)).To(Succeed()) // Deploy Nexus // https://help.sonatype.com/repomanager3/installation/run-behind-a-reverse-proxy @@ -296,7 +297,7 @@ ProxyPreserveHost On }, }, } - g.Expect(TestClient(t).Create(TestContext, deployment)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, deployment)).To(Succeed()) service := &corev1.Service{ TypeMeta: metav1.TypeMeta{ @@ -318,10 +319,10 @@ ProxyPreserveHost On }, }, } - g.Expect(TestClient(t).Create(TestContext, service)).To(Succeed()) + g.Expect(TestClient(t).Create(ctx, service)).To(Succeed()) // Wait for the Deployment to become ready - g.Eventually(Deployment(t, ns, deployment.Name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, + g.Eventually(Deployment(t, ctx, ns, deployment.Name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, Fields{ "Status": MatchFields(IgnoreExtras, Fields{ @@ -337,7 +338,7 @@ ProxyPreserveHost On APIVersion: corev1.SchemeGroupVersion.String(), }, } - g.Expect(TestClient(t).List(TestContext, pods, + g.Expect(TestClient(t).List(ctx, pods, ctrl.InNamespace(ns), ctrl.MatchingLabels{"camel-k": "maven-test-nexus"}, )).To(Succeed()) @@ -421,40 +422,34 @@ ProxyPreserveHost On // Install Camel K with the Maven Central Nexus proxy and the corresponding Maven CA secret operatorID := "camel-k-maven-ca-secret" - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--maven-repository", fmt.Sprintf(`https://%s/repository/maven-public/@id=central-internal@mirrorOf=central`, hostname), - "--maven-repository", fmt.Sprintf(`https://%s/repository/%s/%s`, hostname, stagingRepository.ID, strings.Join(getRepositoryAttributes(stagingRepository), "")), - "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey, - // Active batch mode to assert dependencies download - "--maven-cli-option", "--batch-mode", - )).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--maven-repository", fmt.Sprintf(`https://%s/repository/maven-public/@id=central-internal@mirrorOf=central`, hostname), "--maven-repository", fmt.Sprintf(`https://%s/repository/%s/%s`, hostname, stagingRepository.ID, strings.Join(getRepositoryAttributes(stagingRepository), "")), "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey, "--maven-cli-option", "--batch-mode")).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Run the Integration name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutLong).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutLong).Should(ContainSubstring("Magicstring!")) // Assert no dependencies have been downloaded from the Maven central repository // Note: this should be adapted for the Pod build strategy - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() g.Expect(pod).NotTo(BeNil()) // pod.Namespace could be different from ns if using global operator - logs := Logs(t, pod.Namespace, pod.Name, corev1.PodLogOptions{})() + logs := Logs(t, ctx, pod.Namespace, pod.Name, corev1.PodLogOptions{})() g.Expect(logs).NotTo(BeEmpty()) g.Expect(logs).NotTo(ContainSubstring("Downloaded from central:")) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, deployment)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, service)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, secret)).To(Succeed()) - g.Expect(TestClient(t).Delete(TestContext, config)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, deployment)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, service)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, secret)).To(Succeed()) + g.Expect(TestClient(t).Delete(ctx, config)).To(Succeed()) }) } diff --git a/e2e/install/cli/uninstall_test.go b/e2e/install/cli/uninstall_test.go index 5eb0ef0b1c..f50b8bbd3e 100644 --- a/e2e/install/cli/uninstall_test.go +++ b/e2e/install/cli/uninstall_test.go @@ -23,6 +23,7 @@ limitations under the License. package cli import ( + "context" "fmt" . "github.com/onsi/gomega" "testing" @@ -33,15 +34,15 @@ import ( ) func TestBasicUninstall(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(DefaultCamelCatalogPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(DefaultCamelCatalogPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) // should be completely removed on uninstall - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles").Execute()).To(Succeed()) // Roles only removed in non-olm use-case uninstallViaOLM := false @@ -52,105 +53,105 @@ func TestBasicUninstall(t *testing.T) { } if !uninstallViaOLM { - g.Eventually(Role(t, ns)).Should(BeNil()) - g.Eventually(RoleBinding(t, ns)).Should(BeNil()) - g.Eventually(ServiceAccount(t, ns, "camel-k-operator")).Should(BeNil()) + g.Eventually(Role(t, ctx, ns)).Should(BeNil()) + g.Eventually(RoleBinding(t, ctx, ns)).Should(BeNil()) + g.Eventually(ServiceAccount(t, ctx, ns, "camel-k-operator")).Should(BeNil()) } else { - g.Eventually(Role(t, ns)).ShouldNot(BeNil()) - g.Eventually(RoleBinding(t, ns)).ShouldNot(BeNil()) + g.Eventually(Role(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(RoleBinding(t, ctx, ns)).ShouldNot(BeNil()) } - g.Eventually(Configmap(t, ns, "camel-k-maven-settings")).Should(BeNil()) - g.Eventually(OperatorPod(t, ns), TestTimeoutMedium).Should(BeNil()) - g.Eventually(KameletList(t, ns), TestTimeoutMedium).Should(BeEmpty()) - g.Eventually(CamelCatalogList(t, ns), TestTimeoutMedium).Should(BeEmpty()) + g.Eventually(Configmap(t, ctx, ns, "camel-k-maven-settings")).Should(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns), TestTimeoutMedium).Should(BeNil()) + g.Eventually(KameletList(t, ctx, ns), TestTimeoutMedium).Should(BeEmpty()) + g.Eventually(CamelCatalogList(t, ctx, ns), TestTimeoutMedium).Should(BeEmpty()) }) } func TestUninstallSkipOperator(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // on uninstall it should remove everything except operator - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-operator").Execute()).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-operator").Execute()).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) }) } func TestUninstallSkipRole(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--olm=false")).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--olm=false")).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // on uninstall it should remove everything except roles - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-roles").Execute()).To(Succeed()) - g.Eventually(Role(t, ns)).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-roles").Execute()).To(Succeed()) + g.Eventually(Role(t, ctx, ns)).ShouldNot(BeNil()) }) } func TestUninstallSkipRoleBinding(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--olm=false")).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--olm=false")).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // on uninstall it should remove everything except role-bindings - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-role-bindings").Execute()).To(Succeed()) - g.Eventually(RoleBinding(t, ns)).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-role-bindings").Execute()).To(Succeed()) + g.Eventually(RoleBinding(t, ctx, ns)).ShouldNot(BeNil()) }) } func TestUninstallSkipServiceAccounts(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--olm=false")).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--olm=false")).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // on uninstall it should remove everything except cluster-roles - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-service-accounts").Execute()).To(Succeed()) - g.Eventually(ServiceAccount(t, ns, "camel-k-operator")).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-service-accounts").Execute()).To(Succeed()) + g.Eventually(ServiceAccount(t, ctx, ns, "camel-k-operator")).ShouldNot(BeNil()) }) } func TestUninstallSkipIntegrationPlatform(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // on uninstall it should remove everything except cluster-roles // NOTE: skip CRDs is also required in addition to skip integration platform - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-integration-platform").Execute()).To(Succeed()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-integration-platform").Execute()).To(Succeed()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) }) } func TestUninstallSkipKamelets(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(KameletList(t, ns)).ShouldNot(BeEmpty()) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(KameletList(t, ctx, ns)).ShouldNot(BeEmpty()) // on uninstall it should remove everything except kamelets - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-kamelets").Execute()).To(Succeed()) - g.Eventually(KameletList(t, ns)).ShouldNot(BeEmpty()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-kamelets").Execute()).To(Succeed()) + g.Eventually(KameletList(t, ctx, ns)).ShouldNot(BeEmpty()) }) } func TestUninstallSkipCamelCatalogs(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // a successful new installation operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(CamelCatalogList(t, ns)).ShouldNot(BeEmpty()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(CamelCatalogList(t, ctx, ns)).ShouldNot(BeEmpty()) // on uninstall it should remove everything except camel catalogs - g.Expect(Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-camel-catalogs").Execute()).To(Succeed()) - g.Eventually(CamelCatalogList(t, ns)).ShouldNot(BeEmpty()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-camel-catalogs").Execute()).To(Succeed()) + g.Eventually(CamelCatalogList(t, ctx, ns)).ShouldNot(BeEmpty()) }) } diff --git a/e2e/install/helm/setup_test.go b/e2e/install/helm/setup_test.go index 471afac44f..da06c13f6c 100644 --- a/e2e/install/helm/setup_test.go +++ b/e2e/install/helm/setup_test.go @@ -23,6 +23,7 @@ limitations under the License. package helm import ( + "context" "fmt" "os" "os/exec" @@ -42,7 +43,7 @@ func TestHelmInstallRunUninstall(t *testing.T) { os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../../") - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { ExpectExecSucceed(t, g, Make(t, fmt.Sprintf("CUSTOM_IMAGE=%s", customImage), "set-version")) ExpectExecSucceed(t, g, Make(t, "release-helm")) ExpectExecSucceed(t, g, @@ -60,10 +61,10 @@ func TestHelmInstallRunUninstall(t *testing.T) { ), ) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) // Check if restricted security context has been applyed - operatorPod := OperatorPod(t, ns)() + operatorPod := OperatorPod(t, ctx, ns)() g.Expect(operatorPod.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(Equal(kubernetes.DefaultOperatorSecurityContext().RunAsNonRoot)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.Capabilities).To(Equal(kubernetes.DefaultOperatorSecurityContext().Capabilities)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.SeccompProfile).To(Equal(kubernetes.DefaultOperatorSecurityContext().SeccompProfile)) @@ -72,9 +73,9 @@ func TestHelmInstallRunUninstall(t *testing.T) { //Test a simple route t.Run("simple route", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRun(t, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) ExpectExecSucceed(t, g, @@ -87,6 +88,6 @@ func TestHelmInstallRunUninstall(t *testing.T) { ), ) - g.Eventually(OperatorPod(t, ns)).Should(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) }) } diff --git a/e2e/install/kustomize/operator_test.go b/e2e/install/kustomize/operator_test.go index 03a23555ef..20997cf74a 100644 --- a/e2e/install/kustomize/operator_test.go +++ b/e2e/install/kustomize/operator_test.go @@ -23,6 +23,7 @@ limitations under the License. package kustomize import ( + "context" "fmt" "os" "testing" @@ -40,14 +41,16 @@ func TestOperatorBasic(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) + ctx := TestContext() + // Ensure no CRDs are already installed g := NewWithT(t) - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "setup", namespaceArg)) @@ -59,20 +62,20 @@ func TestOperatorBasic(t *testing.T) { // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Check if restricted security context has been applyed - operatorPod := OperatorPod(t, ns)() + operatorPod := OperatorPod(t, ctx, ns)() g.Expect(operatorPod.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(Equal(kubernetes.DefaultOperatorSecurityContext().RunAsNonRoot)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.Capabilities).To(Equal(kubernetes.DefaultOperatorSecurityContext().Capabilities)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.SeccompProfile).To(Equal(kubernetes.DefaultOperatorSecurityContext().SeccompProfile)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation).To(Equal(kubernetes.DefaultOperatorSecurityContext().AllowPrivilegeEscalation)) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) registry := os.Getenv("KIND_REGISTRY") if registry != "" { - platform := Platform(t, ns)() + platform := Platform(t, ctx, ns)() g.Expect(platform.Status.Build.Registry).ShouldNot(BeNil()) g.Expect(platform.Status.Build.Registry.Address).To(Equal(registry)) } @@ -84,14 +87,16 @@ func TestOperatorKustomizeAlternativeImage(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) + ctx := TestContext() + // Ensure no CRDs are already installed g := NewWithT(t) - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "setup", namespaceArg)) @@ -108,7 +113,7 @@ func TestOperatorKustomizeAlternativeImage(t *testing.T) { // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - g.Eventually(OperatorImage(t, ns)).Should(Equal(fmt.Sprintf("%s:%s", newImage, newTag))) + g.Eventually(OperatorImage(t, ctx, ns)).Should(Equal(fmt.Sprintf("%s:%s", newImage, newTag))) }) } @@ -116,14 +121,16 @@ func TestOperatorKustomizeGlobal(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) + ctx := TestContext() + // Ensure no CRDs are already installed g := NewWithT(t) - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "setup", namespaceArg, "GLOBAL=true")) @@ -137,9 +144,9 @@ func TestOperatorKustomizeGlobal(t *testing.T) { // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - podFunc := OperatorPod(t, ns) + podFunc := OperatorPod(t, ctx, ns) g.Eventually(podFunc).ShouldNot(BeNil()) - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) pod := podFunc() containers := pod.Spec.Containers @@ -158,6 +165,6 @@ func TestOperatorKustomizeGlobal(t *testing.T) { } g.Expect(found).To(BeTrue()) - g.Eventually(Platform(t, ns)).ShouldNot(BeNil()) + g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) }) } diff --git a/e2e/install/kustomize/setup_test.go b/e2e/install/kustomize/setup_test.go index 4ec9989ea4..79a2d1b723 100644 --- a/e2e/install/kustomize/setup_test.go +++ b/e2e/install/kustomize/setup_test.go @@ -23,6 +23,7 @@ limitations under the License. package kustomize import ( + "context" "fmt" "os" "testing" @@ -34,18 +35,19 @@ import ( ) func TestSetupKustomizeBasic(t *testing.T) { + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) // Ensure no CRDs are already installed - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) g.Eventually(CRDs(t)).Should(HaveLen(0)) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(defaults.Version))) @@ -54,14 +56,14 @@ func TestSetupKustomizeBasic(t *testing.T) { kpRoles := ExpectedKubePromoteRoles opRoles := kpRoles + ExpectedOSPromoteRoles - g.Eventually(Role(t, ns)).Should(Or(HaveLen(kpRoles), HaveLen(opRoles))) + g.Eventually(Role(t, ctx, ns)).Should(Or(HaveLen(kpRoles), HaveLen(opRoles))) kcRoles := ExpectedKubeClusterRoles ocRoles := kcRoles + ExpectedOSClusterRoles - g.Eventually(ClusterRole(t)).Should(Or(HaveLen(kcRoles), HaveLen(ocRoles))) + g.Eventually(ClusterRole(t, ctx)).Should(Or(HaveLen(kcRoles), HaveLen(ocRoles))) // Tidy up to ensure next test works - g.Expect(Kamel(t, "uninstall", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns).Execute()).To(Succeed()) }) } @@ -70,25 +72,27 @@ func TestSetupKustomizeGlobal(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) + ctx := TestContext() + // Ensure no CRDs are already installed g := NewWithT(t) - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) g.Eventually(CRDs(t)).Should(HaveLen(0)) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(defaults.Version))) ExpectExecSucceed(t, g, Make(t, "setup", "GLOBAL=true", namespaceArg)) - g.Eventually(Role(t, ns)).Should(HaveLen(0)) + g.Eventually(Role(t, ctx, ns)).Should(HaveLen(0)) kcpRoles := ExpectedKubeClusterRoles + ExpectedKubePromoteRoles ocpRoles := kcpRoles + ExpectedOSClusterRoles + ExpectedOSPromoteRoles - g.Eventually(ClusterRole(t)).Should(Or(HaveLen(kcpRoles), HaveLen(ocpRoles))) + g.Eventually(ClusterRole(t, ctx)).Should(Or(HaveLen(kcpRoles), HaveLen(ocpRoles))) }) } diff --git a/e2e/install/kustomize/uninstall_test.go b/e2e/install/kustomize/uninstall_test.go index 0da0af158c..305fa7512d 100644 --- a/e2e/install/kustomize/uninstall_test.go +++ b/e2e/install/kustomize/uninstall_test.go @@ -23,6 +23,7 @@ limitations under the License. package kustomize import ( + "context" "fmt" "os" "testing" @@ -36,26 +37,27 @@ import ( ) func TestKustomizeUninstallBasic(t *testing.T) { + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) // Ensure no CRDs are already installed - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) g.Eventually(CRDs(t)).Should(HaveLen(0)) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "setup", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "platform", namespaceArg)) // Skip default kamelets installation for faster test runs ExpectExecSucceed(t, g, Make(t, "operator", namespaceArg, "INSTALL_DEFAULT_KAMELETS=false")) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Do uninstall ExpectExecSucceed(t, g, Make(t, "uninstall", namespaceArg)) @@ -63,12 +65,12 @@ func TestKustomizeUninstallBasic(t *testing.T) { // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - g.Eventually(OperatorPod(t, ns)).Should(BeNil()) - g.Eventually(Platform(t, ns)).Should(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) + g.Eventually(Platform(t, ctx, ns)).Should(BeNil()) // The operator can dynamically create a for its builders // so, in case there is a build strategy "pod", expect this to have 1 role - g.Eventually(Role(t, ns)).Should(BeNil()) - g.Eventually(ClusterRole(t)).Should(BeNil()) + g.Eventually(Role(t, ctx, ns)).Should(BeNil()) + g.Eventually(ClusterRole(t, ctx)).Should(BeNil()) // CRDs should be still there g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(defaults.Version))) @@ -81,26 +83,27 @@ func TestKustomizeUninstallBasic(t *testing.T) { } func TestUninstallGlobal(t *testing.T) { + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) // Ensure no CRDs are already installed - g.Expect(UninstallAll(t)).To(Succeed()) + g.Expect(UninstallAll(t, ctx)).To(Succeed()) g.Eventually(CRDs(t)).Should(HaveLen(0)) // Return the cluster to previous state - defer Cleanup(t) + defer Cleanup(t, ctx) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns) ExpectExecSucceed(t, g, Make(t, "setup-cluster", namespaceArg)) ExpectExecSucceed(t, g, Make(t, "setup", namespaceArg, "GLOBAL=true")) ExpectExecSucceed(t, g, Make(t, "platform", namespaceArg)) // Skip default kamelets installation for faster test runs ExpectExecSucceed(t, g, Make(t, "operator", namespaceArg, "GLOBAL=true", "INSTALL_DEFAULT_KAMELETS=false")) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Do uninstall ExpectExecSucceed(t, g, Make(t, "uninstall", namespaceArg)) @@ -108,10 +111,10 @@ func TestUninstallGlobal(t *testing.T) { // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - g.Eventually(OperatorPod(t, ns)).Should(BeNil()) - g.Eventually(Platform(t, ns)).Should(BeNil()) - g.Eventually(Role(t, ns)).Should(BeNil()) - g.Eventually(ClusterRole(t)).Should(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) + g.Eventually(Platform(t, ctx, ns)).Should(BeNil()) + g.Eventually(Role(t, ctx, ns)).Should(BeNil()) + g.Eventually(ClusterRole(t, ctx)).Should(BeNil()) // CRDs should be still there g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(defaults.Version))) diff --git a/e2e/install/olm/olm_install_test.go b/e2e/install/olm/olm_install_test.go index 5f3c9b9e7f..01482b4f7d 100644 --- a/e2e/install/olm/olm_install_test.go +++ b/e2e/install/olm/olm_install_test.go @@ -23,6 +23,7 @@ limitations under the License. package olm import ( + "context" "fmt" "os" "testing" @@ -53,8 +54,8 @@ func TestOLMInstallation(t *testing.T) { t.Skip("OLM fresh install test requires the CAMEL_K_NEW_IIB environment variable") } - WithNewTestNamespace(t, func(g *WithT, ns string) { - g.Expect(CreateOrUpdateCatalogSource(t, ns, installCatalogSourceName, newIIB)).To(Succeed()) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + g.Expect(CreateOrUpdateCatalogSource(t, ctx, ns, installCatalogSourceName, newIIB)).To(Succeed()) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) @@ -63,11 +64,11 @@ func TestOLMInstallation(t *testing.T) { // Wait for pull secret to be created in namespace // eg. test-camel-k-source-dockercfg-zlltn secretPrefix := fmt.Sprintf("%s-dockercfg-", installCatalogSourceName) - g.Eventually(SecretByName(t, ns, secretPrefix), TestTimeoutLong).Should(Not(BeNil())) + g.Eventually(SecretByName(t, ctx, ns, secretPrefix), TestTimeoutLong).Should(Not(BeNil())) } - g.Eventually(CatalogSourcePodRunning(t, ns, installCatalogSourceName), TestTimeoutMedium).Should(BeNil()) - g.Eventually(CatalogSourcePhase(t, ns, installCatalogSourceName), TestTimeoutLong).Should(Equal("READY")) + g.Eventually(CatalogSourcePodRunning(t, ctx, ns, installCatalogSourceName), TestTimeoutMedium).Should(BeNil()) + g.Eventually(CatalogSourcePhase(t, ctx, ns, installCatalogSourceName), TestTimeoutLong).Should(Equal("READY")) args := []string{"install", "-n", ns, "--olm=true", "--olm-source", installCatalogSourceName, "--olm-source-namespace", ns} @@ -75,39 +76,39 @@ func TestOLMInstallation(t *testing.T) { args = append(args, "--olm-channel", newUpdateChannel) } - g.Expect(Kamel(t, args...).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, args...).Execute()).To(Succeed()) // Find the only one Camel K CSV noAdditionalConditions := func(csv olm.ClusterServiceVersion) bool { return true } - g.Eventually(ClusterServiceVersionPhase(t, noAdditionalConditions, ns), TestTimeoutMedium).Should(Equal(olm.CSVPhaseSucceeded)) + g.Eventually(ClusterServiceVersionPhase(t, ctx, noAdditionalConditions, ns), TestTimeoutMedium).Should(Equal(olm.CSVPhaseSucceeded)) // Refresh the test client to account for the newly installed CRDs RefreshClient(t) - csvVersion := ClusterServiceVersion(t, noAdditionalConditions, ns)().Spec.Version + csvVersion := ClusterServiceVersion(t, ctx, noAdditionalConditions, ns)().Spec.Version ipVersionPrefix := fmt.Sprintf("%d.%d", csvVersion.Version.Major, csvVersion.Version.Minor) t.Logf("CSV Version installed: %s", csvVersion.Version.String()) // Check the operator pod is running - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(OperatorImage(t, ns), TestTimeoutShort).Should(Equal(defaults.OperatorImage())) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorImage(t, ctx, ns), TestTimeoutShort).Should(Equal(defaults.OperatorImage())) // Check the IntegrationPlatform has been reconciled - g.Eventually(PlatformVersion(t, ns)).Should(ContainSubstring(ipVersionPrefix)) + g.Eventually(PlatformVersion(t, ctx, ns)).Should(ContainSubstring(ipVersionPrefix)) // Check if restricted security context has been applyed - operatorPod := OperatorPod(t, ns)() + operatorPod := OperatorPod(t, ctx, ns)() g.Expect(operatorPod.Spec.Containers[0].SecurityContext.RunAsNonRoot).To(Equal(kubernetes.DefaultOperatorSecurityContext().RunAsNonRoot)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.Capabilities).To(Equal(kubernetes.DefaultOperatorSecurityContext().Capabilities)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.SeccompProfile).To(Equal(kubernetes.DefaultOperatorSecurityContext().SeccompProfile)) g.Expect(operatorPod.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation).To(Equal(kubernetes.DefaultOperatorSecurityContext().AllowPrivilegeEscalation)) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(Kamel(t, "uninstall", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns).Execute()).To(Succeed()) // Clean up cluster-wide resources that are not removed by OLM - g.Expect(Kamel(t, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) }) } diff --git a/e2e/install/upgrade/cli_upgrade_test.go b/e2e/install/upgrade/cli_upgrade_test.go index 12c38f20ed..90da1cb5ab 100644 --- a/e2e/install/upgrade/cli_upgrade_test.go +++ b/e2e/install/upgrade/cli_upgrade_test.go @@ -23,6 +23,7 @@ limitations under the License. package upgrade import ( + "context" "os" "testing" "time" @@ -39,7 +40,7 @@ import ( // WARNING: this test is not OLM specific but needs certain setting we provide in OLM installation scenario func TestCLIOperatorUpgrade(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { version, ok := os.LookupEnv("KAMEL_K_TEST_RELEASE_VERSION") g.Expect(ok).To(BeTrue()) @@ -54,7 +55,7 @@ func TestCLIOperatorUpgrade(t *testing.T) { if len(CRDs(t)()) > 0 { // Clean up old installation - maybe leftover from another test - if err := UninstallAll(t); err != nil && !kerrors.IsNotFound(err) { + if err := UninstallAll(t, ctx); err != nil && !kerrors.IsNotFound(err) { t.Error(err) t.FailNow() } @@ -62,83 +63,74 @@ func TestCLIOperatorUpgrade(t *testing.T) { g.Eventually(CRDs(t)).Should(HaveLen(0)) // Should both install the CRDs and kamel in the given namespace - g.Expect(Kamel( - t, - "install", - "-n", - ns, - "--olm=false", - "--force", - "--base-image", - defaults.BaseImage(), - ).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "install", "-n", ns, "--olm=false", "--force", "--base-image", defaults.BaseImage()).Execute()).To(Succeed()) // Check the operator pod is running - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Refresh the test client to account for the newly installed CRDs RefreshClient(t) // Check the IntegrationPlatform has been reconciled - g.Eventually(PlatformVersion(t, ns), TestTimeoutMedium).Should(Equal(version)) + g.Eventually(PlatformVersion(t, ctx, ns), TestTimeoutMedium).Should(Equal(version)) // Run the Integration name := RandomizedSuffixName("yaml") - g.Expect(Kamel(t, "run", "-n", ns, "--name", name, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) + g.Expect(Kamel(t, ctx, "run", "-n", ns, "--name", name, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) // Check the Integration version - g.Eventually(IntegrationVersion(t, ns, name)).Should(Equal(version)) + g.Eventually(IntegrationVersion(t, ctx, ns, name)).Should(Equal(version)) // Clear the KAMEL_BIN environment variable so that the current version is used from now on g.Expect(os.Setenv("KAMEL_BIN", "")).To(Succeed()) // Upgrade the operator by installing the current version - g.Expect(Kamel(t, "install", "-n", ns, "--olm=false", "--skip-default-kamelets-setup", "--force", "--operator-image", image, "--base-image", defaults.BaseImage()).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "install", "-n", ns, "--olm=false", "--skip-default-kamelets-setup", "--force", "--operator-image", image, "--base-image", defaults.BaseImage()).Execute()).To(Succeed()) // Check the operator image is the current built one - g.Eventually(OperatorImage(t, ns)).Should(Equal(image)) + g.Eventually(OperatorImage(t, ctx, ns)).Should(Equal(image)) // Check the operator pod is running - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Check the IntegrationPlatform has been reconciled - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(PlatformVersion(t, ns), TestTimeoutMedium).Should(Equal(defaults.Version)) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformVersion(t, ctx, ns), TestTimeoutMedium).Should(Equal(defaults.Version)) // Check the Integration hasn't been upgraded - g.Consistently(IntegrationVersion(t, ns, name), 5*time.Second, 1*time.Second).Should(Equal(version)) + g.Consistently(IntegrationVersion(t, ctx, ns, name), 5*time.Second, 1*time.Second).Should(Equal(version)) // Force the Integration upgrade - g.Expect(Kamel(t, "rebuild", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "rebuild", name, "-n", ns).Execute()).To(Succeed()) // A catalog should be created with the new configuration - g.Eventually(DefaultCamelCatalogPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) + g.Eventually(DefaultCamelCatalogPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) // Check the Integration version has been upgraded - g.Eventually(IntegrationVersion(t, ns, name), TestTimeoutMedium).Should(Equal(defaults.Version)) + g.Eventually(IntegrationVersion(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(defaults.Version)) // Check the previous kit is not garbage collected - g.Eventually(Kits(t, ns, KitWithVersion(version))).Should(HaveLen(1)) + g.Eventually(Kits(t, ctx, ns, KitWithVersion(version))).Should(HaveLen(1)) // Check a new kit is created with the current version - g.Eventually(Kits(t, ns, KitWithVersion(defaults.Version))).Should(HaveLen(1)) + g.Eventually(Kits(t, ctx, ns, KitWithVersion(defaults.Version))).Should(HaveLen(1)) // Check the new kit is ready - g.Eventually(Kits(t, ns, KitWithVersion(defaults.Version), KitWithPhase(v1.IntegrationKitPhaseReady)), + g.Eventually(Kits(t, ctx, ns, KitWithVersion(defaults.Version), KitWithPhase(v1.IntegrationKitPhaseReady)), TestTimeoutMedium).Should(HaveLen(1)) - kit := Kits(t, ns, KitWithVersion(defaults.Version))()[0] + kit := Kits(t, ctx, ns, KitWithVersion(defaults.Version))()[0] // Check the Integration uses the new image - g.Eventually(IntegrationKit(t, ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) + g.Eventually(IntegrationKit(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) // Check the Integration Pod uses the new kit - g.Eventually(IntegrationPodImage(t, ns, name)).Should(Equal(kit.Status.Image)) + g.Eventually(IntegrationPodImage(t, ctx, ns, name)).Should(Equal(kit.Status.Image)) // Check the Integration runs correctly - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) // Delete Integration Platform as it does not get removed with uninstall and might cause next tests to fail - DeletePlatform(t, ns)() - g.Expect(Kamel(t, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) + DeletePlatform(t, ctx, ns)() + g.Expect(Kamel(t, ctx, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) }) } diff --git a/e2e/install/upgrade/helm_upgrade_test.go b/e2e/install/upgrade/helm_upgrade_test.go index 927b08bcb0..4b95bc59a4 100644 --- a/e2e/install/upgrade/helm_upgrade_test.go +++ b/e2e/install/upgrade/helm_upgrade_test.go @@ -23,6 +23,7 @@ limitations under the License. package upgrade import ( + "context" "errors" "fmt" "os" @@ -40,6 +41,7 @@ import ( // WARNING: this test is not OLM specific but needs certain setting we provide in OLM installation scenario func TestHelmOperatorUpgrade(t *testing.T) { + ctx := TestContext() g := NewWithT(t) KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") @@ -60,14 +62,14 @@ func TestHelmOperatorUpgrade(t *testing.T) { if len(CRDs(t)()) > 0 { // Clean up old installation - maybe leftover from another test - if err := UninstallAll(t); err != nil && !kerrors.IsNotFound(err) { + if err := UninstallAll(t, ctx); err != nil && !kerrors.IsNotFound(err) { t.Error(err) t.FailNow() } } g.Eventually(CRDs(t), TestTimeoutMedium).Should(HaveLen(0)) - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // Install operator in last released version ExpectExecSucceed(t, g, exec.Command( @@ -84,16 +86,16 @@ func TestHelmOperatorUpgrade(t *testing.T) { ), ) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(OperatorImage(t, ns)).Should(ContainSubstring(releaseVersion)) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorImage(t, ctx, ns)).Should(ContainSubstring(releaseVersion)) g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(releaseVersion))) // Test a simple route t.Run("simple route", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRun(t, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) // Delete CRDs with kustomize @@ -140,22 +142,22 @@ func TestHelmOperatorUpgrade(t *testing.T) { ), ) - g.Eventually(OperatorPod(t, ns)).ShouldNot(BeNil()) - g.Eventually(OperatorImage(t, ns)).Should(ContainSubstring(defaults.Version)) + g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + g.Eventually(OperatorImage(t, ctx, ns)).Should(ContainSubstring(defaults.Version)) // Test again a simple route t.Run("simple route upgraded", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRun(t, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) // Delete Integration Platform as it does not get removed with uninstall and might cause next tests to fail - DeletePlatform(t, ns)() + DeletePlatform(t, ctx, ns)() // Uninstall with helm ExpectExecSucceed(t, g, @@ -167,7 +169,7 @@ func TestHelmOperatorUpgrade(t *testing.T) { ns, ), ) - g.Eventually(OperatorPod(t, ns)).Should(BeNil()) + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) // helm does not remove the CRDs g.Eventually(CRDs(t)).Should(HaveLen(GetExpectedCRDs(defaults.Version))) diff --git a/e2e/install/upgrade/olm_upgrade_test.go b/e2e/install/upgrade/olm_upgrade_test.go index 40daa5fd59..ac8bcf4721 100644 --- a/e2e/install/upgrade/olm_upgrade_test.go +++ b/e2e/install/upgrade/olm_upgrade_test.go @@ -23,6 +23,7 @@ limitations under the License. package upgrade import ( + "context" "fmt" "os" "testing" @@ -65,9 +66,8 @@ func TestOLMOperatorUpgrade(t *testing.T) { t.Logf("Testing cross-OLM channel upgrade %s -> %s", prevUpdateChannel, newUpdateChannel) } - WithNewTestNamespace(t, func(g *WithT, ns string) { - - g.Expect(CreateOrUpdateCatalogSource(t, ns, catalogSourceName, prevIIB)).To(Succeed()) + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + g.Expect(CreateOrUpdateCatalogSource(t, ctx, ns, catalogSourceName, prevIIB)).To(Succeed()) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) @@ -75,18 +75,18 @@ func TestOLMOperatorUpgrade(t *testing.T) { // Wait for pull secret to be created in namespace // e.g. test-camel-k-source-dockercfg-zlltn secretPrefix := fmt.Sprintf("%s-dockercfg-", catalogSourceName) - g.Eventually(SecretByName(t, ns, secretPrefix), TestTimeoutLong).Should(Not(BeNil())) + g.Eventually(SecretByName(t, ctx, ns, secretPrefix), TestTimeoutLong).Should(Not(BeNil())) } - g.Eventually(CatalogSourcePodRunning(t, ns, catalogSourceName), TestTimeoutMedium).Should(BeNil()) - g.Eventually(CatalogSourcePhase(t, ns, catalogSourceName), TestTimeoutMedium).Should(Equal("READY")) + g.Eventually(CatalogSourcePodRunning(t, ctx, ns, catalogSourceName), TestTimeoutMedium).Should(BeNil()) + g.Eventually(CatalogSourcePhase(t, ctx, ns, catalogSourceName), TestTimeoutMedium).Should(Equal("READY")) // Set KAMEL_BIN only for this test - don't override the ENV variable for all tests g.Expect(os.Setenv("KAMEL_BIN", kamel)).To(Succeed()) if len(CRDs(t)()) > 0 { // Clean up old installation - maybe leftover from another test - if err := UninstallAll(t); err != nil && !kerrors.IsNotFound(err) { + if err := UninstallAll(t, ctx); err != nil && !kerrors.IsNotFound(err) { t.Error(err) t.FailNow() } @@ -106,13 +106,13 @@ func TestOLMOperatorUpgrade(t *testing.T) { args = append(args, "--olm-channel", prevUpdateChannel) } - g.Expect(Kamel(t, args...).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, args...).Execute()).To(Succeed()) // Find the only one Camel K CSV noAdditionalConditions := func(csv olm.ClusterServiceVersion) bool { return true } - g.Eventually(ClusterServiceVersionPhase(t, noAdditionalConditions, ns), TestTimeoutMedium). + g.Eventually(ClusterServiceVersionPhase(t, ctx, noAdditionalConditions, ns), TestTimeoutMedium). Should(Equal(olm.CSVPhaseSucceeded)) // Refresh the test client to account for the newly installed CRDs @@ -126,75 +126,75 @@ func TestOLMOperatorUpgrade(t *testing.T) { var prevIPVersionPrefix string var newIPVersionMajorMinorPatch string - prevCSVVersion = ClusterServiceVersion(t, noAdditionalConditions, ns)().Spec.Version + prevCSVVersion = ClusterServiceVersion(t, ctx, noAdditionalConditions, ns)().Spec.Version prevIPVersionPrefix = fmt.Sprintf("%d.%d", prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor) t.Logf("Using Previous CSV Version: %s", prevCSVVersion.Version.String()) // Check the operator pod is running - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Check the IntegrationPlatform has been reconciled - g.Eventually(PlatformVersion(t, ns)).Should(ContainSubstring(prevIPVersionPrefix)) + g.Eventually(PlatformVersion(t, ctx, ns)).Should(ContainSubstring(prevIPVersionPrefix)) name := "yaml" - g.Expect(Kamel(t, "run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed()) kbindName := "timer-to-log" - g.Expect(KamelBind(t, ns, "timer-source?message=Hello", "log-sink", "--name", kbindName).Execute()).To(Succeed()) + g.Expect(KamelBind(t, ctx, ns, "timer-source?message=Hello", "log-sink", "--name", kbindName).Execute()).To(Succeed()) // Check the Integration runs correctly - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong). Should(Equal(corev1.ConditionTrue)) if prevCSVVersion.Version.String() >= "2" { // since 2.0 Pipe, previously KameletBinding - g.Eventually(PipeConditionStatus(t, ns, kbindName, v1.PipeConditionReady), TestTimeoutShort). + g.Eventually(PipeConditionStatus(t, ctx, ns, kbindName, v1.PipeConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) } - g.Eventually(IntegrationPodPhase(t, ns, kbindName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, kbindName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue)) // Check the Integration version matches that of the current operator - g.Expect(IntegrationVersion(t, ns, name)()).To(ContainSubstring(prevIPVersionPrefix)) - g.Expect(IntegrationVersion(t, ns, kbindName)()).To(ContainSubstring(prevIPVersionPrefix)) + g.Expect(IntegrationVersion(t, ctx, ns, name)()).To(ContainSubstring(prevIPVersionPrefix)) + g.Expect(IntegrationVersion(t, ctx, ns, kbindName)()).To(ContainSubstring(prevIPVersionPrefix)) t.Run("OLM upgrade", func(t *testing.T) { // Trigger Camel K operator upgrade by updating the CatalogSource with the new index image - g.Expect(CreateOrUpdateCatalogSource(t, ns, catalogSourceName, newIIB)).To(Succeed()) + g.Expect(CreateOrUpdateCatalogSource(t, ctx, ns, catalogSourceName, newIIB)).To(Succeed()) if crossChannelUpgrade { t.Log("Patching Camel K OLM subscription channel.") - subscription, err := GetSubscription(t, ns) + subscription, err := GetSubscription(t, ctx, ns) g.Expect(err).To(BeNil()) g.Expect(subscription).NotTo(BeNil()) // Patch the Subscription to avoid conflicts with concurrent updates performed by OLM patch := fmt.Sprintf("{\"spec\":{\"channel\":%q}}", newUpdateChannel) g.Expect( - TestClient(t).Patch(TestContext, subscription, ctrl.RawPatch(types.MergePatchType, []byte(patch))), + TestClient(t).Patch(ctx, subscription, ctrl.RawPatch(types.MergePatchType, []byte(patch))), ).To(Succeed()) // Assert the response back from the API server g.Expect(subscription.Spec.Channel).To(Equal(newUpdateChannel)) } // The new CSV is installed - g.Eventually(ClusterServiceVersionPhase(t, func(csv olm.ClusterServiceVersion) bool { + g.Eventually(ClusterServiceVersionPhase(t, ctx, func(csv olm.ClusterServiceVersion) bool { return csv.Spec.Version.Version.String() != prevCSVVersion.Version.String() }, ns), TestTimeoutMedium).Should(Equal(olm.CSVPhaseSucceeded)) // The old CSV is gone - g.Eventually(ClusterServiceVersion(t, func(csv olm.ClusterServiceVersion) bool { + g.Eventually(ClusterServiceVersion(t, ctx, func(csv olm.ClusterServiceVersion) bool { return csv.Spec.Version.Version.String() == prevCSVVersion.Version.String() }, ns), TestTimeoutMedium).Should(BeNil()) - newCSVVersion = ClusterServiceVersion(t, noAdditionalConditions, ns)().Spec.Version + newCSVVersion = ClusterServiceVersion(t, ctx, noAdditionalConditions, ns)().Spec.Version newIPVersionMajorMinorPatch = fmt.Sprintf("%d.%d.%d", newCSVVersion.Version.Major, newCSVVersion.Version.Minor, newCSVVersion.Version.Patch) g.Expect(prevCSVVersion.Version.String()).NotTo(Equal(newCSVVersion.Version.String())) - g.Eventually(OperatorPodPhase(t, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) - g.Eventually(OperatorImage(t, ns), TestTimeoutShort).Should(Equal(defaults.OperatorImage())) + g.Eventually(OperatorPodPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + g.Eventually(OperatorImage(t, ctx, ns), TestTimeoutShort).Should(Equal(defaults.OperatorImage())) // Check the IntegrationPlatform has been reconciled - g.Eventually(PlatformVersion(t, ns)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) + g.Eventually(PlatformVersion(t, ctx, ns)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) }) t.Run("Integration upgrade", func(t *testing.T) { @@ -202,60 +202,60 @@ func TestOLMOperatorUpgrade(t *testing.T) { g.Expect(os.Setenv("KAMEL_BIN", "")).To(Succeed()) // Check the Integration hasn't been upgraded - g.Consistently(IntegrationVersion(t, ns, name), 5*time.Second, 1*time.Second). + g.Consistently(IntegrationVersion(t, ctx, ns, name), 5*time.Second, 1*time.Second). Should(ContainSubstring(prevIPVersionPrefix)) // Rebuild the Integration - g.Expect(Kamel(t, "rebuild", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "rebuild", "--all", "-n", ns).Execute()).To(Succeed()) if prevCSVVersion.Version.String() >= "2" { - g.Eventually(PipeConditionStatus(t, ns, kbindName, v1.PipeConditionReady), TestTimeoutMedium). + g.Eventually(PipeConditionStatus(t, ctx, ns, kbindName, v1.PipeConditionReady), TestTimeoutMedium). Should(Equal(corev1.ConditionTrue)) } // Check the Integration runs correctly - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). Should(Equal(corev1.ConditionTrue)) // Check the Integration version has been upgraded - g.Eventually(IntegrationVersion(t, ns, name)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) - g.Eventually(IntegrationVersion(t, ns, kbindName)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) + g.Eventually(IntegrationVersion(t, ctx, ns, name)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) + g.Eventually(IntegrationVersion(t, ctx, ns, kbindName)).Should(ContainSubstring(newIPVersionMajorMinorPatch)) // Check the previous kit is not garbage collected (skip Build - present in case of respin) prevCSVVersionMajorMinorPatch := fmt.Sprintf("%d.%d.%d", prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor, prevCSVVersion.Version.Patch) - g.Eventually(Kits(t, ns, KitWithVersion(prevCSVVersionMajorMinorPatch))).Should(HaveLen(2)) + g.Eventually(Kits(t, ctx, ns, KitWithVersion(prevCSVVersionMajorMinorPatch))).Should(HaveLen(2)) // Check a new kit is created with the current version - g.Eventually(Kits(t, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch))).Should(HaveLen(2)) + g.Eventually(Kits(t, ctx, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch))).Should(HaveLen(2)) // Check the new kit is ready - g.Eventually(Kits(t, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithPhase(v1.IntegrationKitPhaseReady)), + g.Eventually(Kits(t, ctx, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithPhase(v1.IntegrationKitPhaseReady)), TestTimeoutMedium).Should(HaveLen(2)) - kit := Kits(t, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": name}))()[0] - kitKbind := Kits(t, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": kbindName}))()[0] + kit := Kits(t, ctx, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": name}))()[0] + kitKbind := Kits(t, ctx, ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": kbindName}))()[0] // Check the Integration uses the new kit - g.Eventually(IntegrationKit(t, ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) - g.Eventually(IntegrationKit(t, ns, kbindName), TestTimeoutMedium).Should(Equal(kitKbind.Name)) + g.Eventually(IntegrationKit(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) + g.Eventually(IntegrationKit(t, ctx, ns, kbindName), TestTimeoutMedium).Should(Equal(kitKbind.Name)) // Check the Integration Pod uses the new image - g.Eventually(IntegrationPodImage(t, ns, name)).Should(Equal(kit.Status.Image)) - g.Eventually(IntegrationPodImage(t, ns, kbindName)).Should(Equal(kitKbind.Status.Image)) + g.Eventually(IntegrationPodImage(t, ctx, ns, name)).Should(Equal(kit.Status.Image)) + g.Eventually(IntegrationPodImage(t, ctx, ns, kbindName)).Should(Equal(kitKbind.Status.Image)) // Check the Integration runs correctly - g.Eventually(IntegrationPodPhase(t, ns, name)).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, kbindName)).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutLong). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name)).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, kbindName)).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationConditionStatus(t, ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong). Should(Equal(corev1.ConditionTrue)) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) // Delete Integration Platform as it does not get removed with uninstall and might cause next tests to fail - DeletePlatform(t, ns)() - g.Expect(Kamel(t, "uninstall", "-n", ns).Execute()).To(Succeed()) + DeletePlatform(t, ctx, ns)() + g.Expect(Kamel(t, ctx, "uninstall", "-n", ns).Execute()).To(Succeed()) // Clean up cluster-wide resources that are not removed by OLM - g.Expect(Kamel(t, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed()) }) }) } diff --git a/e2e/knative/kamelet_test.go b/e2e/knative/kamelet_test.go index 50c76767b8..5a495f7330 100644 --- a/e2e/knative/kamelet_test.go +++ b/e2e/knative/kamelet_test.go @@ -38,58 +38,45 @@ import ( // Test that a Pipe can be changed and the changes are propagated to the Integration func TestKameletChange(t *testing.T) { + ctx := TestContext() g := NewWithT(t) timerPipe := "timer-binding" knChannel := "test-kamelet-messages" knChannelConf := fmt.Sprintf("%s:InMemoryChannel:%s", messaging.SchemeGroupVersion.String(), knChannel) timerSource := "my-timer-source" - g.Expect(CreateTimerKamelet(t, operatorID, ns, timerSource)()).To(Succeed()) - g.Expect(CreateKnativeChannel(t, ns, knChannel)()).To(Succeed()) + g.Expect(CreateTimerKamelet(t, ctx, operatorID, ns, timerSource)()).To(Succeed()) + g.Expect(CreateKnativeChannel(t, ctx, ns, knChannel)()).To(Succeed()) // Consumer route that will read from the KNative channel - g.Expect(KamelRunWithID(t, operatorID, ns, "files/test-kamelet-display.groovy", "-w").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "test-kamelet-display")).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/test-kamelet-display.groovy", "-w").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "test-kamelet-display")).Should(Equal(corev1.PodRunning)) // Create the Pipe - g.Expect(KamelBindWithID(t, operatorID, ns, - timerSource, - knChannelConf, - "-p", "source.message=HelloKNative!", - "--annotation", "trait.camel.apache.org/health.enabled=true", - "--annotation", "trait.camel.apache.org/health.readiness-initial-delay=10", - "--name", timerPipe, - ).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, timerPipe)).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, timerPipe, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, timerSource, knChannelConf, "-p", "source.message=HelloKNative!", "--annotation", "trait.camel.apache.org/health.enabled=true", "--annotation", "trait.camel.apache.org/health.readiness-initial-delay=10", "--name", timerPipe).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, timerPipe)).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, timerPipe, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Consume the message - g.Eventually(IntegrationLogs(t, ns, "test-kamelet-display"), TestTimeoutShort).Should(ContainSubstring("HelloKNative!")) + g.Eventually(IntegrationLogs(t, ctx, ns, "test-kamelet-display"), TestTimeoutShort).Should(ContainSubstring("HelloKNative!")) - g.Eventually(PipeCondition(t, ns, timerPipe, v1.PipeConditionReady), TestTimeoutMedium).Should(And( + g.Eventually(PipeCondition(t, ctx, ns, timerPipe, v1.PipeConditionReady), TestTimeoutMedium).Should(And( WithTransform(PipeConditionStatusExtract, Equal(corev1.ConditionTrue)), WithTransform(PipeConditionReason, Equal(v1.IntegrationConditionDeploymentReadyReason)), WithTransform(PipeConditionMessage, Equal(fmt.Sprintf("1/1 ready replicas"))), )) // Update the Pipe - g.Expect(KamelBindWithID(t, operatorID, ns, - timerSource, - knChannelConf, - "-p", "source.message=message is Hi", - "--annotation", "trait.camel.apache.org/health.enabled=true", - "--annotation", "trait.camel.apache.org/health.readiness-initial-delay=10", - "--name", timerPipe, - ).Execute()).To(Succeed()) - - g.Eventually(IntegrationPodPhase(t, ns, timerPipe), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, timerPipe, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "test-kamelet-display"), TestTimeoutShort).Should(ContainSubstring("message is Hi")) - - g.Eventually(PipeCondition(t, ns, timerPipe, v1.PipeConditionReady), TestTimeoutMedium). + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, timerSource, knChannelConf, "-p", "source.message=message is Hi", "--annotation", "trait.camel.apache.org/health.enabled=true", "--annotation", "trait.camel.apache.org/health.readiness-initial-delay=10", "--name", timerPipe).Execute()).To(Succeed()) + + g.Eventually(IntegrationPodPhase(t, ctx, ns, timerPipe), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, timerPipe, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "test-kamelet-display"), TestTimeoutShort).Should(ContainSubstring("message is Hi")) + + g.Eventually(PipeCondition(t, ctx, ns, timerPipe, v1.PipeConditionReady), TestTimeoutMedium). Should(And( WithTransform(PipeConditionStatusExtract, Equal(corev1.ConditionTrue)), WithTransform(PipeConditionReason, Equal(v1.IntegrationConditionDeploymentReadyReason)), WithTransform(PipeConditionMessage, Equal("1/1 ready replicas")), )) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) } diff --git a/e2e/knative/knative_platform_test.go b/e2e/knative/knative_platform_test.go index 743332f7b6..a6223495ee 100644 --- a/e2e/knative/knative_platform_test.go +++ b/e2e/knative/knative_platform_test.go @@ -23,6 +23,7 @@ limitations under the License. package knative import ( + "context" "strings" "testing" @@ -47,21 +48,21 @@ func TestKnativePlatformDetection(t *testing.T) { t.FailNow() } - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-knative" // Install without profile (should automatically detect the presence of Knative) - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(PlatformProfile(t, ns), TestTimeoutShort).Should(Equal(v1.TraitProfile(""))) - cluster := Platform(t, ns)().Status.Cluster + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Eventually(PlatformProfile(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.TraitProfile(""))) + cluster := Platform(t, ctx, ns)().Status.Cluster t.Run("run yaml on cluster profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--profile", string(cluster)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationTraitProfile(t, ns, "yaml"), TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster)))) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--profile", string(cluster)).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationTraitProfile(t, ctx, ns, "yaml"), TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster)))) // Change something in the integration to produce a redeployment - g.Expect(UpdateIntegration(t, ns, "yaml", func(it *v1.Integration) { + g.Expect(UpdateIntegration(t, ctx, ns, "yaml", func(it *v1.Integration) { it.Spec.Profile = "" content, err := dsl.ToYamlDSL(it.Spec.Flows) require.NoError(t, err) @@ -71,21 +72,21 @@ func TestKnativePlatformDetection(t *testing.T) { it.Spec.Flows = newFlows })).To(Succeed()) // Spec profile should be reset by "kamel run" - g.Eventually(IntegrationSpecProfile(t, ns, "yaml")).Should(Equal(v1.TraitProfile(""))) + g.Eventually(IntegrationSpecProfile(t, ctx, ns, "yaml")).Should(Equal(v1.TraitProfile(""))) // When integration is running again ... - g.Eventually(IntegrationPhase(t, ns, "yaml")).Should(Equal(v1.IntegrationPhaseRunning)) - g.Eventually(IntegrationLogs(t, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!!!")) + g.Eventually(IntegrationPhase(t, ctx, ns, "yaml")).Should(Equal(v1.IntegrationPhaseRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!!!")) // It should keep the old profile saved in status - g.Eventually(IntegrationTraitProfile(t, ns, "yaml"), TestTimeoutMedium).Should(Equal(v1.TraitProfile(cluster))) + g.Eventually(IntegrationTraitProfile(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(v1.TraitProfile(cluster))) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("run yaml on automatic profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationTraitProfile(t, ns, "yaml"), TestTimeoutShort).Should(Equal(v1.TraitProfileKnative)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationTraitProfile(t, ctx, ns, "yaml"), TestTimeoutShort).Should(Equal(v1.TraitProfileKnative)) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) } diff --git a/e2e/knative/knative_test.go b/e2e/knative/knative_test.go index e35b44ed2d..8cb1e624fa 100644 --- a/e2e/knative/knative_test.go +++ b/e2e/knative/knative_test.go @@ -23,6 +23,7 @@ limitations under the License. package knative import ( + "context" "fmt" "testing" "time" @@ -36,120 +37,120 @@ import ( ) func TestKnative(t *testing.T) { + ctx := TestContext() g := NewWithT(t) knChannelMessages := "messages" knChannelWords := "words" - g.Expect(CreateKnativeChannel(t, ns, knChannelMessages)()).To(Succeed()) - g.Expect(CreateKnativeChannel(t, ns, knChannelWords)()).To(Succeed()) + g.Expect(CreateKnativeChannel(t, ctx, ns, knChannelMessages)()).To(Succeed()) + g.Expect(CreateKnativeChannel(t, ctx, ns, knChannelWords)()).To(Succeed()) t.Run("Service combo", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knative2.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knative2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "knative2", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knative3.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knative3"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "knative3", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knative1.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knative1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "knative1", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative2.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knative2", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative3.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative3"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knative3", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative1.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knative1", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) // Correct logs - g.Eventually(IntegrationLogs(t, ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 2: Hello from knative2")) - g.Eventually(IntegrationLogs(t, ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 3: Hello from knative3")) + g.Eventually(IntegrationLogs(t, ctx, ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 2: Hello from knative2")) + g.Eventually(IntegrationLogs(t, ctx, ns, "knative1"), TestTimeoutMedium).Should(ContainSubstring("Received from 3: Hello from knative3")) // Incorrect logs - g.Consistently(IntegrationLogs(t, ns, "knative1"), 10*time.Second).ShouldNot(ContainSubstring("Received from 2: Hello from knative3")) - g.Consistently(IntegrationLogs(t, ns, "knative1"), 10*time.Second).ShouldNot(ContainSubstring("Received from 3: Hello from knative2")) + g.Consistently(IntegrationLogs(t, ctx, ns, "knative1"), 10*time.Second).ShouldNot(ContainSubstring("Received from 2: Hello from knative3")) + g.Consistently(IntegrationLogs(t, ctx, ns, "knative1"), 10*time.Second).ShouldNot(ContainSubstring("Received from 3: Hello from knative2")) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Channel combo v1beta1", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativech2.groovy").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativech1.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knativech2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "knativech1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "knativech2"), TestTimeoutMedium).Should(ContainSubstring("Received: Hello from knativech1")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativech2.groovy").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativech1.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativech2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativech1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativech2"), TestTimeoutMedium).Should(ContainSubstring("Received: Hello from knativech1")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Channel combo get to post", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativegetpost2.groovy").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativegetpost1.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knativegetpost2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "knativegetpost1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "knativegetpost2"), TestTimeoutMedium).Should(ContainSubstring(`Received ""`)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativegetpost2.groovy").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativegetpost1.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativegetpost2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativegetpost1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativegetpost2"), TestTimeoutMedium).Should(ContainSubstring(`Received ""`)) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Multi channel chain", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativemultihop3.groovy").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativemultihop2.groovy").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativemultihop1.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knativemultihop3"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "knativemultihop2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "knativemultihop1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From messages: message`)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From words: word`)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From words: transformed message`)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From messages: word`)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From words: message`)) - g.Eventually(IntegrationLogs(t, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From messages: transformed message`)) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativemultihop3.groovy").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativemultihop2.groovy").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativemultihop1.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativemultihop3"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativemultihop2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativemultihop1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From messages: message`)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From words: word`)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), TestTimeoutMedium).Should(ContainSubstring(`From words: transformed message`)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From messages: word`)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From words: message`)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativemultihop3"), 10*time.Second).ShouldNot(ContainSubstring(`From messages: transformed message`)) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Flow", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/flow.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "flow"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "flow", camelv1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(v1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/flow.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "flow"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "flow", camelv1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(v1.ConditionTrue)) t.Run("Scale to zero", func(t *testing.T) { - g.Eventually(IntegrationPod(t, ns, "flow"), TestTimeoutLong).Should(BeNil()) + g.Eventually(IntegrationPod(t, ctx, ns, "flow"), TestTimeoutLong).Should(BeNil()) }) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Knative-service disabled", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/http_out.groovy", "-t", "knative-service.enabled=false").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "http-out"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(Service(t, ns, "http-out"), TestTimeoutShort).ShouldNot(BeNil()) - g.Consistently(KnativeService(t, ns, "http-out"), TestTimeoutShort).Should(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/http_out.groovy", "-t", "knative-service.enabled=false").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "http-out"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(Service(t, ctx, ns, "http-out"), TestTimeoutShort).ShouldNot(BeNil()) + g.Consistently(KnativeService(t, ctx, ns, "http-out"), TestTimeoutShort).Should(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Knative-service priority", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/http_out.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "http-out"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(KnativeService(t, ns, "http-out"), TestTimeoutShort).ShouldNot(BeNil()) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/http_out.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "http-out"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(KnativeService(t, ctx, ns, "http-out"), TestTimeoutShort).ShouldNot(BeNil()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Knative-service annotation", func(t *testing.T) { - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knative2.groovy", - "-t", "knative-service.annotations.'haproxy.router.openshift.io/balance'=roundrobin").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knative2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(KnativeService(t, ns, "knative2"), TestTimeoutShort).ShouldNot(BeNil()) - ks := KnativeService(t, ns, "knative2")() + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative2.groovy", "-t", "knative-service.annotations.'haproxy.router.openshift.io/balance'=roundrobin").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(KnativeService(t, ctx, ns, "knative2"), TestTimeoutShort).ShouldNot(BeNil()) + ks := KnativeService(t, ctx, ns, "knative2")() annotations := ks.ObjectMeta.Annotations g.Expect(annotations["haproxy.router.openshift.io/balance"]).To(Equal("roundrobin")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRunBroker(t *testing.T) { - WithNewTestNamespaceWithKnativeBroker(t, func(g *WithT, ns string) { + WithNewTestNamespaceWithKnativeBroker(t, func(ctx context.Context, g *WithT, ns string) { operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, operatorID, ns, "--trait-profile", "knative")).To(Succeed()) - - g.Eventually(SelectedPlatformPhase(t, ns, operatorID), TestTimeoutMedium).Should(Equal(camelv1.IntegrationPlatformPhaseReady)) - - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativeevt1.groovy").Execute()).To(Succeed()) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/knativeevt2.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "knativeevt1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationPodPhase(t, ns, "knativeevt2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "knativeevt2"), TestTimeoutMedium).Should(ContainSubstring("Received 1: Hello 1")) - g.Eventually(IntegrationLogs(t, ns, "knativeevt2"), TestTimeoutMedium).Should(ContainSubstring("Received 2: Hello 2")) - g.Eventually(IntegrationLogs(t, ns, "knativeevt2")).ShouldNot(ContainSubstring("Received 1: Hello 2")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--trait-profile", "knative")).To(Succeed()) + + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(camelv1.IntegrationPlatformPhaseReady)) + + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativeevt1.groovy").Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativeevt2.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeevt1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeevt2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativeevt2"), TestTimeoutMedium).Should(ContainSubstring("Received 1: Hello 1")) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativeevt2"), TestTimeoutMedium).Should(ContainSubstring("Received 2: Hello 2")) + g.Eventually(IntegrationLogs(t, ctx, ns, "knativeevt2")).ShouldNot(ContainSubstring("Received 1: Hello 2")) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/knative/openapi_test.go b/e2e/knative/openapi_test.go index 106dc41159..a8f8457187 100644 --- a/e2e/knative/openapi_test.go +++ b/e2e/knative/openapi_test.go @@ -32,29 +32,26 @@ import ( ) func TestOpenAPIService(t *testing.T) { + ctx := TestContext() g := NewWithT(t) openapiContent, err := ioutil.ReadFile("./files/petstore-api.yaml") require.NoError(t, err) var cmDataProps = make(map[string]string) cmDataProps["petstore-api.yaml"] = string(openapiContent) - CreatePlainTextConfigmap(t, ns, "my-openapi-knative", cmDataProps) + CreatePlainTextConfigmap(t, ctx, ns, "my-openapi-knative", cmDataProps) - g.Expect(KamelRunWithID(t, operatorID, ns, - "--name", "petstore", - "--open-api", "configmap:my-openapi-knative", - "files/petstore.groovy", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "petstore", "--open-api", "configmap:my-openapi-knative", "files/petstore.groovy").Execute()).To(Succeed()) - g.Eventually(KnativeService(t, ns, "petstore"), TestTimeoutLong). + g.Eventually(KnativeService(t, ctx, ns, "petstore"), TestTimeoutLong). Should(Not(BeNil())) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started listPets (rest://get:/v1:/pets)")) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started createPets (rest://post:/v1:/pets)")) - g.Eventually(IntegrationLogs(t, ns, "petstore"), TestTimeoutMedium). + g.Eventually(IntegrationLogs(t, ctx, ns, "petstore"), TestTimeoutMedium). Should(ContainSubstring("Started showPetById (rest://get:/v1:/pets/%7BpetId%7D)")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) } diff --git a/e2e/knative/pod_test.go b/e2e/knative/pod_test.go index a1af88624f..de84434d45 100644 --- a/e2e/knative/pod_test.go +++ b/e2e/knative/pod_test.go @@ -34,16 +34,16 @@ import ( ) func TestPodTraitWithKnative(t *testing.T) { + ctx := TestContext() g := NewWithT(t) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/podtest-knative2.groovy", - "--pod-template", "files/template-knative.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "podtest-knative2"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "podtest-knative2", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Expect(KamelRunWithID(t, operatorID, ns, "files/podtest-knative1.groovy").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "podtest-knative1"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ns, "podtest-knative1", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, "podtest-knative1"), TestTimeoutShort).Should(ContainSubstring("hello from the template")) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/podtest-knative2.groovy", "--pod-template", "files/template-knative.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "podtest-knative2"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "podtest-knative2", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/podtest-knative1.groovy").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "podtest-knative1"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "podtest-knative1", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "podtest-knative1"), TestTimeoutShort).Should(ContainSubstring("hello from the template")) - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) } diff --git a/e2e/native/native_binding_test.go b/e2e/native/native_binding_test.go index 7bf2ea840e..b4af7a4b2c 100644 --- a/e2e/native/native_binding_test.go +++ b/e2e/native/native_binding_test.go @@ -23,6 +23,7 @@ limitations under the License. package native import ( + "context" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" . "github.com/onsi/gomega" @@ -31,44 +32,34 @@ import ( ) func TestNativeBinding(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-native-binding" - g.Expect(KamelInstallWithIDAndKameletCatalog(t, operatorID, ns, - "--build-timeout", "90m0s", - "--maven-cli-option", "-Dquarkus.native.native-image-xmx=6g", - )).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operatorID, ns, "--build-timeout", "90m0s", "--maven-cli-option", "-Dquarkus.native.native-image-xmx=6g")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) message := "Magicstring!" t.Run("binding with native build", func(t *testing.T) { bindingName := "native-binding" - g.Expect(KamelBindWithID(t, operatorID, ns, - "timer-source", - "log-sink", - "-p", "source.message="+message, - "--annotation", "trait.camel.apache.org/quarkus.build-mode=native", - "--annotation", "trait.camel.apache.org/builder.tasks-limit-memory=quarkus-native:6.5Gi", - "--name", bindingName, - ).Execute()).To(Succeed()) + g.Expect(KamelBindWithID(t, ctx, operatorID, ns, "timer-source", "log-sink", "-p", "source.message="+message, "--annotation", "trait.camel.apache.org/quarkus.build-mode=native", "--annotation", "trait.camel.apache.org/builder.tasks-limit-memory=quarkus-native:6.5Gi", "--name", bindingName).Execute()).To(Succeed()) // ==================================== // !!! THE MOST TIME-CONSUMING PART !!! // ==================================== - g.Eventually(Kits(t, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), + g.Eventually(Kits(t, ctx, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), TestTimeoutVeryLong).Should(HaveLen(1)) - nativeKit := Kits(t, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] - g.Eventually(IntegrationKit(t, ns, bindingName), TestTimeoutShort).Should(Equal(nativeKit.Name)) + nativeKit := Kits(t, ctx, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] + g.Eventually(IntegrationKit(t, ctx, ns, bindingName), TestTimeoutShort).Should(Equal(nativeKit.Name)) - g.Eventually(IntegrationPodPhase(t, ns, bindingName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, bindingName), TestTimeoutShort).Should(ContainSubstring(message)) + g.Eventually(IntegrationPodPhase(t, ctx, ns, bindingName), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, bindingName), TestTimeoutShort).Should(ContainSubstring(message)) - g.Eventually(IntegrationPod(t, ns, bindingName), TestTimeoutShort). + g.Eventually(IntegrationPod(t, ctx, ns, bindingName), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) // Clean up - g.Expect(Kamel(t, "delete", bindingName, "-n", ns).Execute()).To(Succeed()) - g.Expect(DeleteKits(t, ns)).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", bindingName, "-n", ns).Execute()).To(Succeed()) + g.Expect(DeleteKits(t, ctx, ns)).To(Succeed()) }) }) } diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go index 9f04bbf82d..ac726c04fc 100644 --- a/e2e/native/native_test.go +++ b/e2e/native/native_test.go @@ -23,6 +23,7 @@ limitations under the License. package native import ( + "context" "testing" . "github.com/onsi/gomega" @@ -35,130 +36,114 @@ import ( ) func TestNativeIntegrations(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-quarkus-native" - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--build-timeout", "90m0s", - "--maven-cli-option", "-Dquarkus.native.native-image-xmx=6g", - )).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--build-timeout", "90m0s", "--maven-cli-option", "-Dquarkus.native.native-image-xmx=6g")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("unsupported integration source language", func(t *testing.T) { name := RandomizedSuffixName("unsupported-js") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/JavaScript.js", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/JavaScript.js", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPhase(t, ns, name)).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionKitAvailable)). + g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionKitAvailable)). Should(Equal(corev1.ConditionFalse)) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, name)).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, name)() + g.Eventually(UnstructuredIntegration(t, ctx, ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, name)() quarkusTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "quarkus") g.Expect(quarkusTrait).ToNot(BeNil()) g.Expect(len(quarkusTrait)).To(Equal(1)) g.Expect(quarkusTrait["buildMode"]).ToNot(BeNil()) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) t.Run("xml native support", func(t *testing.T) { name := RandomizedSuffixName("xml-native") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Xml.xml", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Xml.xml", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("XML Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("XML Magicstring!")) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) t.Run("automatic rollout deployment from jvm to native kit", func(t *testing.T) { // Let's make sure we start from a clean state - g.Expect(DeleteKits(t, ns)).To(Succeed()) + g.Expect(DeleteKits(t, ctx, ns)).To(Succeed()) name := RandomizedSuffixName("yaml-native") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml.yaml", "--name", name, - "-t", "quarkus.build-mode=jvm", - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name, "-t", "quarkus.build-mode=jvm", "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi").Execute()).To(Succeed()) // Check that two Kits are created with distinct layout - g.Eventually(Kits(t, ns, withFastJarLayout)).Should(HaveLen(1)) - g.Eventually(Kits(t, ns, withNativeLayout)).Should(HaveLen(1)) + g.Eventually(Kits(t, ctx, ns, withFastJarLayout)).Should(HaveLen(1)) + g.Eventually(Kits(t, ctx, ns, withNativeLayout)).Should(HaveLen(1)) // Check the fast-jar Kit is ready - g.Eventually(Kits(t, ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), + g.Eventually(Kits(t, ctx, ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), TestTimeoutLong).Should(HaveLen(1)) - fastJarKit := Kits(t, ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] + fastJarKit := Kits(t, ctx, ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] // Check the Integration uses the fast-jar Kit - g.Eventually(IntegrationKit(t, ns, name), TestTimeoutShort).Should(Equal(fastJarKit.Name)) + g.Eventually(IntegrationKit(t, ctx, ns, name), TestTimeoutShort).Should(Equal(fastJarKit.Name)) // Check the Integration Pod uses the fast-jar Kit - g.Eventually(IntegrationPodImage(t, ns, name)).Should(Equal(fastJarKit.Status.Image)) + g.Eventually(IntegrationPodImage(t, ctx, ns, name)).Should(Equal(fastJarKit.Status.Image)) // Check the Integration is ready - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), ContainSubstring("java"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) // ==================================== // !!! THE MOST TIME-CONSUMING PART !!! // ==================================== // Check the native Kit is ready - g.Eventually(Kits(t, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), + g.Eventually(Kits(t, ctx, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady)), TestTimeoutVeryLong).Should(HaveLen(1)) - nativeKit := Kits(t, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] + nativeKit := Kits(t, ctx, ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0] // Check the Integration uses the native Kit - g.Eventually(IntegrationKit(t, ns, name), TestTimeoutShort).Should(Equal(nativeKit.Name)) + g.Eventually(IntegrationKit(t, ctx, ns, name), TestTimeoutShort).Should(Equal(nativeKit.Name)) // Check the Integration Pod uses the native Kit - g.Eventually(IntegrationPodImage(t, ns, name)).Should(Equal(nativeKit.Status.Image)) + g.Eventually(IntegrationPodImage(t, ctx, ns, name)).Should(Equal(nativeKit.Status.Image)) // Check the Integration is still ready - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) t.Run("yaml native should not rebuild", func(t *testing.T) { name := RandomizedSuffixName("yaml-native-2") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/yaml2.yaml", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml2.yaml", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:6.5Gi").Execute()).To(Succeed()) // This one should run quickly as it suppose to reuse an IntegrationKit - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2")) - g.Eventually(IntegrationKit(t, ns, "yaml-native-2")).Should(Equal(IntegrationKit(t, ns, "yaml-native")())) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2")) + g.Eventually(IntegrationKit(t, ctx, ns, "yaml-native-2")).Should(Equal(IntegrationKit(t, ctx, ns, "yaml-native")())) }) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) }) diff --git a/e2e/native/native_with_sources_test.go b/e2e/native/native_with_sources_test.go index ac6e49e79b..989f612c19 100644 --- a/e2e/native/native_with_sources_test.go +++ b/e2e/native/native_with_sources_test.go @@ -23,6 +23,7 @@ limitations under the License. package native import ( + "context" "testing" . "github.com/onsi/gomega" @@ -33,13 +34,10 @@ import ( ) func TestNativeHighMemoryIntegrations(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-quarkus-high-memory-native" - g.Expect(KamelInstallWithID(t, operatorID, ns, - "--build-timeout", "90m0s", - "--maven-cli-option", "-Dquarkus.native.native-image-xmx=9g", - )).To(Succeed()) - g.Eventually(PlatformPhase(t, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--build-timeout", "90m0s", "--maven-cli-option", "-Dquarkus.native.native-image-xmx=9g")).To(Succeed()) + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) javaNativeName := RandomizedSuffixName("java-native") javaNativeCloneName := RandomizedSuffixName("java-native-clone") @@ -47,91 +45,76 @@ func TestNativeHighMemoryIntegrations(t *testing.T) { t.Run("java native support", func(t *testing.T) { name := javaNativeName - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!")) t.Run("java native same should not rebuild", func(t *testing.T) { name := javaNativeCloneName - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java.java", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi").Execute()).To(Succeed()) // This one should run quickly as it suppose to reuse an IntegrationKit - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!")) - g.Eventually(IntegrationKit(t, ns, javaNativeCloneName)).Should(Equal(IntegrationKit(t, ns, javaNativeName)())) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!")) + g.Eventually(IntegrationKit(t, ctx, ns, javaNativeCloneName)).Should(Equal(IntegrationKit(t, ctx, ns, javaNativeName)())) }) t.Run("java native should rebuild", func(t *testing.T) { name := javaNative2Name - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Java2.java", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java2.java", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!")) - g.Eventually(IntegrationKit(t, ns, javaNative2Name)).ShouldNot(Equal(IntegrationKit(t, ns, javaNativeName)())) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!")) + g.Eventually(IntegrationKit(t, ctx, ns, javaNative2Name)).ShouldNot(Equal(IntegrationKit(t, ctx, ns, javaNativeName)())) }) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) t.Run("groovy native support", func(t *testing.T) { name := RandomizedSuffixName("groovy-native") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Groovy.groovy", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Groovy.groovy", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Groovy Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Groovy Magicstring!")) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) t.Run("kotlin native support", func(t *testing.T) { name := RandomizedSuffixName("kotlin-native") - g.Expect(KamelRunWithID(t, operatorID, ns, "files/Kotlin.kts", "--name", name, - "-t", "quarkus.build-mode=native", - "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi", - ).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Kotlin.kts", "--name", name, "-t", "quarkus.build-mode=native", "-t", "builder.tasks-limit-memory=quarkus-native:9.5Gi").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationPod(t, ns, name), TestTimeoutShort). + g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationPod(t, ctx, ns, name), TestTimeoutShort). Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*"))) - g.Eventually(IntegrationConditionStatus(t, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ns, name), TestTimeoutShort).Should(ContainSubstring("Kotlin Magicstring!")) + g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Kotlin Magicstring!")) // Clean up - g.Expect(Kamel(t, "delete", name, "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", name, "-n", ns).Execute()).To(Succeed()) }) }) } diff --git a/e2e/support/csv.go b/e2e/support/csv.go index 714596d862..c4bb04eae4 100644 --- a/e2e/support/csv.go +++ b/e2e/support/csv.go @@ -23,6 +23,7 @@ limitations under the License. package support import ( + "context" "fmt" "strings" "testing" @@ -41,10 +42,10 @@ import ( "github.com/apache/camel-k/v2/pkg/util/log" ) -func ClusterServiceVersion(t *testing.T, conditions func(olm.ClusterServiceVersion) bool, ns string) func() *olm.ClusterServiceVersion { +func ClusterServiceVersion(t *testing.T, ctx context.Context, conditions func(olm.ClusterServiceVersion) bool, ns string) func() *olm.ClusterServiceVersion { return func() *olm.ClusterServiceVersion { lst := olm.ClusterServiceVersionList{} - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { panic(err) } for _, s := range lst.Items { @@ -56,16 +57,16 @@ func ClusterServiceVersion(t *testing.T, conditions func(olm.ClusterServiceVersi } } -func ClusterServiceVersionPhase(t *testing.T, conditions func(olm.ClusterServiceVersion) bool, ns string) func() olm.ClusterServiceVersionPhase { +func ClusterServiceVersionPhase(t *testing.T, ctx context.Context, conditions func(olm.ClusterServiceVersion) bool, ns string) func() olm.ClusterServiceVersionPhase { return func() olm.ClusterServiceVersionPhase { - if csv := ClusterServiceVersion(t, conditions, ns)(); csv != nil && unsafe.Sizeof(csv.Status) > 0 { + if csv := ClusterServiceVersion(t, ctx, conditions, ns)(); csv != nil && unsafe.Sizeof(csv.Status) > 0 { return csv.Status.Phase } return "" } } -func CreateOrUpdateCatalogSource(t *testing.T, ns, name, image string) error { +func CreateOrUpdateCatalogSource(t *testing.T, ctx context.Context, ns, name, image string) error { catalogSource := &olm.CatalogSource{ ObjectMeta: metav1.ObjectMeta{ Namespace: ns, @@ -73,7 +74,7 @@ func CreateOrUpdateCatalogSource(t *testing.T, ns, name, image string) error { }, } - _, err := ctrlutil.CreateOrUpdate(TestContext, TestClient(t), catalogSource, func() error { + _, err := ctrlutil.CreateOrUpdate(ctx, TestClient(t), catalogSource, func() error { catalogSource.Spec = olm.CatalogSourceSpec{ Image: image, SourceType: "grpc", @@ -86,7 +87,7 @@ func CreateOrUpdateCatalogSource(t *testing.T, ns, name, image string) error { return err } -func CatalogSource(t *testing.T, ns, name string) func() *olm.CatalogSource { +func CatalogSource(t *testing.T, ctx context.Context, ns, name string) func() *olm.CatalogSource { return func() *olm.CatalogSource { cs := &olm.CatalogSource{ TypeMeta: metav1.TypeMeta{ @@ -98,7 +99,7 @@ func CatalogSource(t *testing.T, ns, name string) func() *olm.CatalogSource { Name: name, }, } - if err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(cs), cs); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(cs), cs); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Errorf(err, "Error while retrieving CatalogSource %s", name) @@ -108,18 +109,18 @@ func CatalogSource(t *testing.T, ns, name string) func() *olm.CatalogSource { } } -func CatalogSourcePhase(t *testing.T, ns, name string) func() string { +func CatalogSourcePhase(t *testing.T, ctx context.Context, ns, name string) func() string { return func() string { - if source := CatalogSource(t, ns, name)(); source != nil && source.Status.GRPCConnectionState != nil { - return CatalogSource(t, ns, name)().Status.GRPCConnectionState.LastObservedState + if source := CatalogSource(t, ctx, ns, name)(); source != nil && source.Status.GRPCConnectionState != nil { + return CatalogSource(t, ctx, ns, name)().Status.GRPCConnectionState.LastObservedState } return "" } } -func CatalogSourcePod(t *testing.T, ns, csName string) func() *corev1.Pod { +func CatalogSourcePod(t *testing.T, ctx context.Context, ns, csName string) func() *corev1.Pod { return func() *corev1.Pod { - podList, err := TestClient(t).CoreV1().Pods(ns).List(TestContext, metav1.ListOptions{}) + podList, err := TestClient(t).CoreV1().Pods(ns).List(ctx, metav1.ListOptions{}) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -140,8 +141,8 @@ func CatalogSourcePod(t *testing.T, ns, csName string) func() *corev1.Pod { } } -func CatalogSourcePodRunning(t *testing.T, ns, csName string) error { - podFunc := CatalogSourcePod(t, ns, csName) +func CatalogSourcePodRunning(t *testing.T, ctx context.Context, ns, csName string) error { + podFunc := CatalogSourcePod(t, ctx, ns, csName) for i := 1; i < 5; i++ { csPod := podFunc() @@ -151,7 +152,7 @@ func CatalogSourcePodRunning(t *testing.T, ns, csName string) error { if i == 2 { fmt.Println("Catalog Source Pod still not ready so delete & allow it to be redeployed ...") - if err := TestClient(t).Delete(TestContext, csPod); err != nil { + if err := TestClient(t).Delete(ctx, csPod); err != nil { return err } } @@ -163,9 +164,9 @@ func CatalogSourcePodRunning(t *testing.T, ns, csName string) error { return fmt.Errorf("Catalog Source Pod failed to reach a 'running' state") } -func GetSubscription(t *testing.T, ns string) (*olm.Subscription, error) { +func GetSubscription(t *testing.T, ctx context.Context, ns string) (*olm.Subscription, error) { lst := olm.SubscriptionList{} - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { return nil, err } for _, s := range lst.Items { diff --git a/e2e/support/test_nexus_hooks.go b/e2e/support/test_nexus_hooks.go index 87edb5c73e..83dbde5753 100644 --- a/e2e/support/test_nexus_hooks.go +++ b/e2e/support/test_nexus_hooks.go @@ -53,7 +53,7 @@ func init() { Name: nexusService, } - if err := TestClient(nil).Get(TestContext, key, &svc); err != nil { + if err := TestClient(nil).Get(TestContext(), key, &svc); err != nil { svcExists = false } svcChecked = true diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index cce80567d6..4f527a3eed 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -136,7 +136,7 @@ var TestTimeoutVeryLong = 60 * time.Minute var NoOlmOperatorImage string -var TestContext context.Context +var testContext = context.TODO() var testClient client.Client var clientMutex = sync.Mutex{} @@ -156,6 +156,10 @@ func failTest(t *testing.T, err error) { } } +func TestContext() context.Context { + return testContext +} + func TestClient(t *testing.T) client.Client { clientMutex.Lock() defer clientMutex.Unlock() @@ -181,6 +185,7 @@ func RefreshClient(t *testing.T) client.Client { if err != nil { failTest(t, err) } + testContext = context.TODO() return testClient } @@ -203,7 +208,6 @@ func init() { client.FastMapperAllowedAPIGroups["policy"] = true var err error - TestContext = context.TODO() // Defaults for testing imageName := os.Getenv("CAMEL_K_TEST_IMAGE_NAME") @@ -259,20 +263,20 @@ func NewTestClient() (client.Client, error) { return client.NewOutOfClusterClient(os.Getenv(kubeConfigEnvVar)) } -func Kamel(t *testing.T, args ...string) *cobra.Command { - return KamelWithContext(t, TestContext, args...) +func Kamel(t *testing.T, ctx context.Context, args ...string) *cobra.Command { + return KamelWithContext(t, ctx, args...) } -func KamelInstall(t *testing.T, namespace string, args ...string) error { - return KamelInstallWithID(t, platform.DefaultPlatformName, namespace, args...) +func KamelInstall(t *testing.T, ctx context.Context, namespace string, args ...string) error { + return KamelInstallWithID(t, ctx, platform.DefaultPlatformName, namespace, args...) } -func KamelInstallWithID(t *testing.T, operatorID string, namespace string, args ...string) error { - return kamelInstallWithContext(t, TestContext, operatorID, namespace, true, args...) +func KamelInstallWithID(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) error { + return kamelInstallWithContext(t, ctx, operatorID, namespace, true, args...) } -func KamelInstallWithIDAndKameletCatalog(t *testing.T, operatorID string, namespace string, args ...string) error { - return kamelInstallWithContext(t, TestContext, operatorID, namespace, false, args...) +func KamelInstallWithIDAndKameletCatalog(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) error { + return kamelInstallWithContext(t, ctx, operatorID, namespace, false, args...) } func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID string, namespace string, skipKameletCatalog bool, args ...string) error { @@ -308,6 +312,16 @@ func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID strin } } + runtimeVersion := os.Getenv("CAMEL_K_TEST_RUNTIME_VERSION") + if runtimeVersion != "" { + fmt.Printf("Setting runtime version to %s\n", runtimeVersion) + installArgs = append(installArgs, "--runtime-version", runtimeVersion) + } + baseImage := os.Getenv("CAMEL_K_TEST_BASE_IMAGE") + if baseImage != "" { + fmt.Printf("Setting base image to %s\n", baseImage) + installArgs = append(installArgs, "--base-image", baseImage) + } opImage := os.Getenv("CAMEL_K_TEST_OPERATOR_IMAGE") if opImage != "" { fmt.Printf("Setting operator image to %s\n", opImage) @@ -324,24 +338,24 @@ func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID strin return installCommand.Execute() } -func KamelRun(t *testing.T, namespace string, args ...string) *cobra.Command { - return KamelRunWithID(t, platform.DefaultPlatformName, namespace, args...) +func KamelRun(t *testing.T, ctx context.Context, namespace string, args ...string) *cobra.Command { + return KamelRunWithID(t, ctx, platform.DefaultPlatformName, namespace, args...) } -func KamelRunWithID(t *testing.T, operatorID string, namespace string, args ...string) *cobra.Command { - return KamelRunWithContext(t, TestContext, operatorID, namespace, args...) +func KamelRunWithID(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) *cobra.Command { + return KamelRunWithContext(t, ctx, operatorID, namespace, args...) } func KamelRunWithContext(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) *cobra.Command { return KamelCommandWithContext(t, ctx, "run", operatorID, namespace, args...) } -func KamelBind(t *testing.T, namespace string, args ...string) *cobra.Command { - return KamelBindWithID(t, platform.DefaultPlatformName, namespace, args...) +func KamelBind(t *testing.T, ctx context.Context, namespace string, args ...string) *cobra.Command { + return KamelBindWithID(t, ctx, platform.DefaultPlatformName, namespace, args...) } -func KamelBindWithID(t *testing.T, operatorID string, namespace string, args ...string) *cobra.Command { - return KamelBindWithContext(t, TestContext, operatorID, namespace, args...) +func KamelBindWithID(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) *cobra.Command { + return KamelBindWithContext(t, ctx, operatorID, namespace, args...) } func KamelBindWithContext(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) *cobra.Command { @@ -466,9 +480,9 @@ func KubectlWithContext(args ...string) *exec.Cmd { // Curried utility functions for testing // ============================================================================= -func IntegrationLogs(t *testing.T, ns, name string) func() string { +func IntegrationLogs(t *testing.T, ctx context.Context, ns, name string) func() string { return func() string { - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() if pod == nil { return "" } @@ -477,28 +491,35 @@ func IntegrationLogs(t *testing.T, ns, name string) func() string { TailLines: pointer.Int64(100), } + for _, container := range pod.Status.ContainerStatuses { + if !container.Ready || container.State.Waiting != nil { + // avoid logs watch fail due to container creating state + return "" + } + } + if len(pod.Spec.Containers) > 1 { options.Container = pod.Spec.Containers[0].Name } - return Logs(t, ns, pod.Name, options)() + return Logs(t, ctx, ns, pod.Name, options)() } } -// Retrieve the Logs from the Pod defined by its name in the given namespace ns. The number of lines numLines from the end of the logs to show. -func TailedLogs(t *testing.T, ns, name string, numLines int64) func() string { +// TailedLogs Retrieve the Logs from the Pod defined by its name in the given namespace ns. The number of lines numLines from the end of the logs to show. +func TailedLogs(t *testing.T, ctx context.Context, ns, name string, numLines int64) func() string { return func() string { options := corev1.PodLogOptions{ TailLines: pointer.Int64(numLines), } - return Logs(t, ns, name, options)() + return Logs(t, ctx, ns, name, options)() } } -func Logs(t *testing.T, ns, podName string, options corev1.PodLogOptions) func() string { +func Logs(t *testing.T, ctx context.Context, ns, podName string, options corev1.PodLogOptions) func() string { return func() string { - byteReader, err := TestClient(t).CoreV1().Pods(ns).GetLogs(podName, &options).Stream(TestContext) + byteReader, err := TestClient(t).CoreV1().Pods(ns).GetLogs(podName, &options).Stream(ctx) if err != nil { log.Error(err, "Error while reading container logs") return "" @@ -509,18 +530,18 @@ func Logs(t *testing.T, ns, podName string, options corev1.PodLogOptions) func() } }() - bytes, err := io.ReadAll(byteReader) + logBytes, err := io.ReadAll(byteReader) if err != nil { log.Error(err, "Error while reading container logs") return "" } - return string(bytes) + return string(logBytes) } } -func StructuredLogs(t *testing.T, ns, podName string, options *corev1.PodLogOptions, ignoreParseErrors bool) ([]util.LogEntry, error) { +func StructuredLogs(t *testing.T, ctx context.Context, ns, podName string, options *corev1.PodLogOptions, ignoreParseErrors bool) ([]util.LogEntry, error) { - stream, err := TestClient(t).CoreV1().Pods(ns).GetLogs(podName, options).Stream(TestContext) + stream, err := TestClient(t).CoreV1().Pods(ns).GetLogs(podName, options).Stream(ctx) if err != nil { msg := "Error while reading container logs" log.Error(err, msg) @@ -567,9 +588,9 @@ func StructuredLogs(t *testing.T, ns, podName string, options *corev1.PodLogOpti return entries, nil } -func IntegrationPodPhase(t *testing.T, ns string, name string) func() corev1.PodPhase { +func IntegrationPodPhase(t *testing.T, ctx context.Context, ns string, name string) func() corev1.PodPhase { return func() corev1.PodPhase { - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() if pod == nil { return "" } @@ -577,9 +598,9 @@ func IntegrationPodPhase(t *testing.T, ns string, name string) func() corev1.Pod } } -func IntegrationPodImage(t *testing.T, ns string, name string) func() string { +func IntegrationPodImage(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() if pod == nil || len(pod.Spec.Containers) == 0 { return "" } @@ -587,9 +608,9 @@ func IntegrationPodImage(t *testing.T, ns string, name string) func() string { } } -func IntegrationPod(t *testing.T, ns string, name string) func() *corev1.Pod { +func IntegrationPod(t *testing.T, ctx context.Context, ns string, name string) func() *corev1.Pod { return func() *corev1.Pod { - pods := IntegrationPods(t, ns, name)() + pods := IntegrationPods(t, ctx, ns, name)() if len(pods) == 0 { return nil } @@ -597,9 +618,9 @@ func IntegrationPod(t *testing.T, ns string, name string) func() *corev1.Pod { } } -func IntegrationPodHas(t *testing.T, ns string, name string, predicate func(pod *corev1.Pod) bool) func() bool { +func IntegrationPodHas(t *testing.T, ctx context.Context, ns string, name string, predicate func(pod *corev1.Pod) bool) func() bool { return func() bool { - pod := IntegrationPod(t, ns, name)() + pod := IntegrationPod(t, ctx, ns, name)() if pod == nil { return false } @@ -607,7 +628,7 @@ func IntegrationPodHas(t *testing.T, ns string, name string, predicate func(pod } } -func IntegrationPods(t *testing.T, ns string, name string) func() []corev1.Pod { +func IntegrationPods(t *testing.T, ctx context.Context, ns string, name string) func() []corev1.Pod { return func() []corev1.Pod { lst := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -615,7 +636,7 @@ func IntegrationPods(t *testing.T, ns string, name string) func() []corev1.Pod { APIVersion: corev1.SchemeGroupVersion.String(), }, } - err := TestClient(t).List(TestContext, &lst, + err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ v1.IntegrationLabel: name, @@ -627,16 +648,16 @@ func IntegrationPods(t *testing.T, ns string, name string) func() []corev1.Pod { } } -func IntegrationPodsNumbers(t *testing.T, ns string, name string) func() *int32 { +func IntegrationPodsNumbers(t *testing.T, ctx context.Context, ns string, name string) func() *int32 { return func() *int32 { - i := int32(len(IntegrationPods(t, ns, name)())) + i := int32(len(IntegrationPods(t, ctx, ns, name)())) return &i } } -func IntegrationSpecReplicas(t *testing.T, ns string, name string) func() *int32 { +func IntegrationSpecReplicas(t *testing.T, ctx context.Context, ns string, name string) func() *int32 { return func() *int32 { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return nil } @@ -644,9 +665,9 @@ func IntegrationSpecReplicas(t *testing.T, ns string, name string) func() *int32 } } -func IntegrationGeneration(t *testing.T, ns string, name string) func() *int64 { +func IntegrationGeneration(t *testing.T, ctx context.Context, ns string, name string) func() *int64 { return func() *int64 { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return nil } @@ -654,9 +675,9 @@ func IntegrationGeneration(t *testing.T, ns string, name string) func() *int64 { } } -func IntegrationObservedGeneration(t *testing.T, ns string, name string) func() *int64 { +func IntegrationObservedGeneration(t *testing.T, ctx context.Context, ns string, name string) func() *int64 { return func() *int64 { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return nil } @@ -664,9 +685,9 @@ func IntegrationObservedGeneration(t *testing.T, ns string, name string) func() } } -func IntegrationStatusReplicas(t *testing.T, ns string, name string) func() *int32 { +func IntegrationStatusReplicas(t *testing.T, ctx context.Context, ns string, name string) func() *int32 { return func() *int32 { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return nil } @@ -674,9 +695,9 @@ func IntegrationStatusReplicas(t *testing.T, ns string, name string) func() *int } } -func IntegrationStatusImage(t *testing.T, ns string, name string) func() string { +func IntegrationStatusImage(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -684,9 +705,9 @@ func IntegrationStatusImage(t *testing.T, ns string, name string) func() string } } -func IntegrationAnnotations(t *testing.T, ns string, name string) func() map[string]string { +func IntegrationAnnotations(t *testing.T, ctx context.Context, ns string, name string) func() map[string]string { return func() map[string]string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return map[string]string{} } @@ -694,9 +715,9 @@ func IntegrationAnnotations(t *testing.T, ns string, name string) func() map[str } } -func IntegrationCondition(t *testing.T, ns string, name string, conditionType v1.IntegrationConditionType) func() *v1.IntegrationCondition { +func IntegrationCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.IntegrationConditionType) func() *v1.IntegrationCondition { return func() *v1.IntegrationCondition { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return nil } @@ -752,16 +773,16 @@ func HealthCheckData(r *v1.HealthCheckResponse) (map[string]interface{}, error) } var data map[string]interface{} - if err := json.Unmarshal(r.Data, data); err != nil { + if err := json.Unmarshal(r.Data, &data); err != nil { return nil, err } return data, nil } -func IntegrationConditionStatus(t *testing.T, ns string, name string, conditionType v1.IntegrationConditionType) func() corev1.ConditionStatus { +func IntegrationConditionStatus(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.IntegrationConditionType) func() corev1.ConditionStatus { return func() corev1.ConditionStatus { - c := IntegrationCondition(t, ns, name, conditionType)() + c := IntegrationCondition(t, ctx, ns, name, conditionType)() if c == nil { return "Unknown" } @@ -769,14 +790,14 @@ func IntegrationConditionStatus(t *testing.T, ns string, name string, conditionT } } -func AssignIntegrationToOperator(t *testing.T, ns, name, operator string) error { - it := Integration(t, ns, name)() +func AssignIntegrationToOperator(t *testing.T, ctx context.Context, ns, name, operator string) error { + it := Integration(t, ctx, ns, name)() if it == nil { return fmt.Errorf("cannot assign integration %q to operator: integration not found", name) } it.SetOperatorID(operator) - return TestClient(t).Update(TestContext, it) + return TestClient(t).Update(ctx, it) } func Annotations(object metav1.Object) map[string]string { @@ -787,14 +808,14 @@ func IntegrationSpec(it *v1.Integration) *v1.IntegrationSpec { return &it.Spec } -func Lease(t *testing.T, ns string, name string) func() *coordination.Lease { +func Lease(t *testing.T, ctx context.Context, ns string, name string) func() *coordination.Lease { return func() *coordination.Lease { lease := coordination.Lease{} key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - err := TestClient(t).Get(TestContext, key, &lease) + err := TestClient(t).Get(ctx, key, &lease) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -804,7 +825,7 @@ func Lease(t *testing.T, ns string, name string) func() *coordination.Lease { } } -func Nodes(t *testing.T) func() []corev1.Node { +func Nodes(t *testing.T, ctx context.Context) func() []corev1.Node { return func() []corev1.Node { nodes := &corev1.NodeList{ TypeMeta: metav1.TypeMeta{ @@ -812,14 +833,14 @@ func Nodes(t *testing.T) func() []corev1.Node { APIVersion: corev1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, nodes); err != nil { + if err := TestClient(t).List(ctx, nodes); err != nil { failTest(t, err) } return nodes.Items } } -func Node(t *testing.T, name string) func() *corev1.Node { +func Node(t *testing.T, ctx context.Context, name string) func() *corev1.Node { return func() *corev1.Node { node := &corev1.Node{ TypeMeta: metav1.TypeMeta{ @@ -830,7 +851,7 @@ func Node(t *testing.T, name string) func() *corev1.Node { Name: name, }, } - err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(node), node) + err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(node), node) if err != nil { failTest(t, err) } @@ -838,14 +859,14 @@ func Node(t *testing.T, name string) func() *corev1.Node { } } -func Service(t *testing.T, ns string, name string) func() *corev1.Service { +func Service(t *testing.T, ctx context.Context, ns string, name string) func() *corev1.Service { return func() *corev1.Service { svc := corev1.Service{} key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - err := TestClient(t).Get(TestContext, key, &svc) + err := TestClient(t).Get(ctx, key, &svc) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -855,9 +876,9 @@ func Service(t *testing.T, ns string, name string) func() *corev1.Service { } } -func ServiceType(t *testing.T, ns string, name string) func() corev1.ServiceType { +func ServiceType(t *testing.T, ctx context.Context, ns string, name string) func() corev1.ServiceType { return func() corev1.ServiceType { - svc := Service(t, ns, name)() + svc := Service(t, ctx, ns, name)() if svc == nil { return "" } @@ -865,12 +886,12 @@ func ServiceType(t *testing.T, ns string, name string) func() corev1.ServiceType } } -// Find the service in the given namespace with the given type -func ServicesByType(t *testing.T, ns string, svcType corev1.ServiceType) func() []corev1.Service { +// ServicesByType Find the service in the given namespace with the given type +func ServicesByType(t *testing.T, ctx context.Context, ns string, svcType corev1.ServiceType) func() []corev1.Service { return func() []corev1.Service { svcs := []corev1.Service{} - svcList, err := TestClient(t).CoreV1().Services(ns).List(TestContext, metav1.ListOptions{}) + svcList, err := TestClient(t).CoreV1().Services(ns).List(ctx, metav1.ListOptions{}) if err != nil && k8serrors.IsNotFound(err) { return svcs } else if err != nil { @@ -891,14 +912,14 @@ func ServicesByType(t *testing.T, ns string, svcType corev1.ServiceType) func() } } -func Route(t *testing.T, ns string, name string) func() *routev1.Route { +func Route(t *testing.T, ctx context.Context, ns string, name string) func() *routev1.Route { return func() *routev1.Route { route := routev1.Route{} key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - err := TestClient(t).Get(TestContext, key, &route) + err := TestClient(t).Get(ctx, key, &route) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -908,7 +929,7 @@ func Route(t *testing.T, ns string, name string) func() *routev1.Route { } } -func RouteFull(t *testing.T, ns string, name string) func() *routev1.Route { +func RouteFull(t *testing.T, ctx context.Context, ns string, name string) func() *routev1.Route { return func() *routev1.Route { answer := routev1.Route{ TypeMeta: metav1.TypeMeta{ @@ -924,7 +945,7 @@ func RouteFull(t *testing.T, ns string, name string) func() *routev1.Route { Namespace: ns, Name: name, } - err := TestClient(t).Get(TestContext, key, &answer) + err := TestClient(t).Get(ctx, key, &answer) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -934,9 +955,9 @@ func RouteFull(t *testing.T, ns string, name string) func() *routev1.Route { } } -func RouteStatus(t *testing.T, ns string, name string) func() string { +func RouteStatus(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - route := Route(t, ns, name)() + route := Route(t, ctx, ns, name)() if route == nil || len(route.Status.Ingress) == 0 { return "" } @@ -944,7 +965,7 @@ func RouteStatus(t *testing.T, ns string, name string) func() string { } } -func IntegrationCronJob(t *testing.T, ns string, name string) func() *batchv1.CronJob { +func IntegrationCronJob(t *testing.T, ctx context.Context, ns string, name string) func() *batchv1.CronJob { return func() *batchv1.CronJob { lst := batchv1.CronJobList{ TypeMeta: metav1.TypeMeta{ @@ -952,7 +973,7 @@ func IntegrationCronJob(t *testing.T, ns string, name string) func() *batchv1.Cr APIVersion: batchv1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "camel.apache.org/integration": name, @@ -966,10 +987,10 @@ func IntegrationCronJob(t *testing.T, ns string, name string) func() *batchv1.Cr } } -func Integrations(t *testing.T, ns string) func() *v1.IntegrationList { +func Integrations(t *testing.T, ctx context.Context, ns string) func() *v1.IntegrationList { return func() *v1.IntegrationList { lst := v1.NewIntegrationList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } @@ -977,21 +998,21 @@ func Integrations(t *testing.T, ns string) func() *v1.IntegrationList { } } -func NumIntegrations(t *testing.T, ns string) func() int { +func NumIntegrations(t *testing.T, ctx context.Context, ns string) func() int { return func() int { - lst := Integrations(t, ns)() + lst := Integrations(t, ctx, ns)() return len(lst.Items) } } -func Integration(t *testing.T, ns string, name string) func() *v1.Integration { +func Integration(t *testing.T, ctx context.Context, ns string, name string) func() *v1.Integration { return func() *v1.Integration { it := v1.NewIntegration(ns, name) key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &it); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &it); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -1000,20 +1021,20 @@ func Integration(t *testing.T, ns string, name string) func() *v1.Integration { } } -func UnstructuredIntegration(t *testing.T, ns string, name string) func() *unstructured.Unstructured { +func UnstructuredIntegration(t *testing.T, ctx context.Context, ns string, name string) func() *unstructured.Unstructured { return func() *unstructured.Unstructured { gvk := schema.GroupVersionKind{Group: v1.SchemeGroupVersion.Group, Version: v1.SchemeGroupVersion.Version, Kind: v1.IntegrationKind} - return UnstructuredObject(t, ns, name, gvk)() + return UnstructuredObject(t, ctx, ns, name, gvk)() } } -func UnstructuredObject(t *testing.T, ns string, name string, gvk schema.GroupVersionKind) func() *unstructured.Unstructured { +func UnstructuredObject(t *testing.T, ctx context.Context, ns string, name string, gvk schema.GroupVersionKind) func() *unstructured.Unstructured { return func() *unstructured.Unstructured { object := &unstructured.Unstructured{} object.SetNamespace(ns) object.SetName(name) object.SetGroupVersionKind(gvk) - if err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(object), object); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(object), object); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -1022,9 +1043,9 @@ func UnstructuredObject(t *testing.T, ns string, name string, gvk schema.GroupVe } } -func IntegrationVersion(t *testing.T, ns string, name string) func() string { +func IntegrationVersion(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1032,9 +1053,9 @@ func IntegrationVersion(t *testing.T, ns string, name string) func() string { } } -func IntegrationTraitProfile(t *testing.T, ns string, name string) func() v1.TraitProfile { +func IntegrationTraitProfile(t *testing.T, ctx context.Context, ns string, name string) func() v1.TraitProfile { return func() v1.TraitProfile { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1042,9 +1063,9 @@ func IntegrationTraitProfile(t *testing.T, ns string, name string) func() v1.Tra } } -func IntegrationPhase(t *testing.T, ns string, name string) func() v1.IntegrationPhase { +func IntegrationPhase(t *testing.T, ctx context.Context, ns string, name string) func() v1.IntegrationPhase { return func() v1.IntegrationPhase { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1052,9 +1073,9 @@ func IntegrationPhase(t *testing.T, ns string, name string) func() v1.Integratio } } -func IntegrationSpecProfile(t *testing.T, ns string, name string) func() v1.TraitProfile { +func IntegrationSpecProfile(t *testing.T, ctx context.Context, ns string, name string) func() v1.TraitProfile { return func() v1.TraitProfile { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1062,9 +1083,9 @@ func IntegrationSpecProfile(t *testing.T, ns string, name string) func() v1.Trai } } -func IntegrationStatusCapabilities(t *testing.T, ns string, name string) func() []string { +func IntegrationStatusCapabilities(t *testing.T, ctx context.Context, ns string, name string) func() []string { return func() []string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil || &it.Status == nil { return nil } @@ -1072,9 +1093,9 @@ func IntegrationStatusCapabilities(t *testing.T, ns string, name string) func() } } -func IntegrationSpecSA(t *testing.T, ns string, name string) func() string { +func IntegrationSpecSA(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1082,9 +1103,9 @@ func IntegrationSpecSA(t *testing.T, ns string, name string) func() string { } } -func IntegrationKit(t *testing.T, ns string, name string) func() string { +func IntegrationKit(t *testing.T, ctx context.Context, ns string, name string) func() string { return func() string { - it := Integration(t, ns, name)() + it := Integration(t, ctx, ns, name)() if it == nil { return "" } @@ -1095,9 +1116,9 @@ func IntegrationKit(t *testing.T, ns string, name string) func() string { } } -func IntegrationKitNamespace(t *testing.T, integrationNamespace string, name string) func() string { +func IntegrationKitNamespace(t *testing.T, ctx context.Context, integrationNamespace string, name string) func() string { return func() string { - it := Integration(t, integrationNamespace, name)() + it := Integration(t, ctx, integrationNamespace, name)() if it == nil { return "" } @@ -1108,10 +1129,10 @@ func IntegrationKitNamespace(t *testing.T, integrationNamespace string, name str } } -func Kit(t *testing.T, ns, name string) func() *v1.IntegrationKit { +func Kit(t *testing.T, ctx context.Context, ns, name string) func() *v1.IntegrationKit { return func() *v1.IntegrationKit { kit := v1.NewIntegrationKit(ns, name) - if err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(kit), kit); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(kit), kit); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -1120,9 +1141,9 @@ func Kit(t *testing.T, ns, name string) func() *v1.IntegrationKit { } } -func KitPhase(t *testing.T, ns, name string) func() v1.IntegrationKitPhase { +func KitPhase(t *testing.T, ctx context.Context, ns, name string) func() v1.IntegrationKitPhase { return func() v1.IntegrationKitPhase { - kit := Kit(t, ns, name)() + kit := Kit(t, ctx, ns, name)() if kit == nil { return v1.IntegrationKitPhaseNone } @@ -1130,9 +1151,9 @@ func KitPhase(t *testing.T, ns, name string) func() v1.IntegrationKitPhase { } } -func KitCondition(t *testing.T, ns string, name string, conditionType v1.IntegrationKitConditionType) func() *v1.IntegrationKitCondition { +func KitCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.IntegrationKitConditionType) func() *v1.IntegrationKitCondition { return func() *v1.IntegrationKitCondition { - kt := Kit(t, ns, name)() + kt := Kit(t, ctx, ns, name)() if kt == nil { return nil } @@ -1140,18 +1161,18 @@ func KitCondition(t *testing.T, ns string, name string, conditionType v1.Integra } } -func UpdateIntegration(t *testing.T, ns string, name string, mutate func(it *v1.Integration)) error { - it := Integration(t, ns, name)() +func UpdateIntegration(t *testing.T, ctx context.Context, ns string, name string, mutate func(it *v1.Integration)) error { + it := Integration(t, ctx, ns, name)() if it == nil { return fmt.Errorf("no integration named %s found", name) } target := it.DeepCopy() mutate(target) - return TestClient(t).Update(TestContext, target) + return TestClient(t).Update(ctx, target) } -func PatchIntegration(t *testing.T, ns string, name string, mutate func(it *v1.Integration)) error { - it := Integration(t, ns, name)() +func PatchIntegration(t *testing.T, ctx context.Context, ns string, name string, mutate func(it *v1.Integration)) error { + it := Integration(t, ctx, ns, name)() if it == nil { return fmt.Errorf("no integration named %s found", name) } @@ -1163,23 +1184,23 @@ func PatchIntegration(t *testing.T, ns string, name string, mutate func(it *v1.I } else if len(p) == 0 { return nil } - return TestClient(t).Patch(TestContext, target, ctrl.RawPatch(types.MergePatchType, p)) + return TestClient(t).Patch(ctx, target, ctrl.RawPatch(types.MergePatchType, p)) } -func ScaleIntegration(t *testing.T, ns string, name string, replicas int32) error { - return PatchIntegration(t, ns, name, func(it *v1.Integration) { +func ScaleIntegration(t *testing.T, ctx context.Context, ns string, name string, replicas int32) error { + return PatchIntegration(t, ctx, ns, name, func(it *v1.Integration) { it.Spec.Replicas = &replicas }) } -func Pipe(t *testing.T, ns string, name string) func() *v1.Pipe { +func Pipe(t *testing.T, ctx context.Context, ns string, name string) func() *v1.Pipe { return func() *v1.Pipe { klb := v1.NewPipe(ns, name) key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &klb); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &klb); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -1188,9 +1209,9 @@ func Pipe(t *testing.T, ns string, name string) func() *v1.Pipe { } } -func PipePhase(t *testing.T, ns string, name string) func() v1.PipePhase { +func PipePhase(t *testing.T, ctx context.Context, ns string, name string) func() v1.PipePhase { return func() v1.PipePhase { - klb := Pipe(t, ns, name)() + klb := Pipe(t, ctx, ns, name)() if klb == nil { return "" } @@ -1198,9 +1219,9 @@ func PipePhase(t *testing.T, ns string, name string) func() v1.PipePhase { } } -func PipeSpecReplicas(t *testing.T, ns string, name string) func() *int32 { +func PipeSpecReplicas(t *testing.T, ctx context.Context, ns string, name string) func() *int32 { return func() *int32 { - klb := Pipe(t, ns, name)() + klb := Pipe(t, ctx, ns, name)() if klb == nil { return nil } @@ -1208,9 +1229,9 @@ func PipeSpecReplicas(t *testing.T, ns string, name string) func() *int32 { } } -func PipeStatusReplicas(t *testing.T, ns string, name string) func() *int32 { +func PipeStatusReplicas(t *testing.T, ctx context.Context, ns string, name string) func() *int32 { return func() *int32 { - klb := Pipe(t, ns, name)() + klb := Pipe(t, ctx, ns, name)() if klb == nil { return nil } @@ -1218,9 +1239,9 @@ func PipeStatusReplicas(t *testing.T, ns string, name string) func() *int32 { } } -func PipeCondition(t *testing.T, ns string, name string, conditionType v1.PipeConditionType) func() *v1.PipeCondition { +func PipeCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.PipeConditionType) func() *v1.PipeCondition { return func() *v1.PipeCondition { - kb := Pipe(t, ns, name)() + kb := Pipe(t, ctx, ns, name)() if kb == nil { return nil } @@ -1253,9 +1274,9 @@ func PipeConditionMessage(c *v1.PipeCondition) string { return c.Message } -func PipeConditionStatus(t *testing.T, ns string, name string, conditionType v1.PipeConditionType) func() corev1.ConditionStatus { +func PipeConditionStatus(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.PipeConditionType) func() corev1.ConditionStatus { return func() corev1.ConditionStatus { - klb := Pipe(t, ns, name)() + klb := Pipe(t, ctx, ns, name)() if klb == nil { return "PipeMissing" } @@ -1267,8 +1288,8 @@ func PipeConditionStatus(t *testing.T, ns string, name string, conditionType v1. } } -func UpdatePipe(t *testing.T, ns string, name string, upd func(it *v1.Pipe)) error { - klb := Pipe(t, ns, name)() +func UpdatePipe(t *testing.T, ctx context.Context, ns string, name string, upd func(it *v1.Pipe)) error { + klb := Pipe(t, ctx, ns, name)() if klb == nil { return fmt.Errorf("no Pipe named %s found", name) } @@ -1281,23 +1302,23 @@ func UpdatePipe(t *testing.T, ns string, name string, upd func(it *v1.Pipe)) err } else if len(p) == 0 { return nil } - return TestClient(t).Patch(TestContext, target, ctrl.RawPatch(types.MergePatchType, p)) + return TestClient(t).Patch(ctx, target, ctrl.RawPatch(types.MergePatchType, p)) } -func ScalePipe(t *testing.T, ns string, name string, replicas int32) error { - return UpdatePipe(t, ns, name, func(klb *v1.Pipe) { +func ScalePipe(t *testing.T, ctx context.Context, ns string, name string, replicas int32) error { + return UpdatePipe(t, ctx, ns, name, func(klb *v1.Pipe) { klb.Spec.Replicas = &replicas }) } -func AssignPipeToOperator(t *testing.T, ns, name, operator string) error { - klb := Pipe(t, ns, name)() +func AssignPipeToOperator(t *testing.T, ctx context.Context, ns, name, operator string) error { + klb := Pipe(t, ctx, ns, name)() if klb == nil { return fmt.Errorf("cannot assign Pipe %q to operator:Pipe not found", name) } klb.SetOperatorID(operator) - return TestClient(t).Update(TestContext, klb) + return TestClient(t).Update(ctx, klb) } type KitFilter interface { @@ -1342,7 +1363,7 @@ func (f *kitFilter) Match(kit *v1.IntegrationKit) bool { return f.filter(kit) } -func Kits(t *testing.T, ns string, options ...interface{}) func() []v1.IntegrationKit { +func Kits(t *testing.T, ctx context.Context, ns string, options ...interface{}) func() []v1.IntegrationKit { filters := make([]KitFilter, 0) listOptions := []ctrl.ListOption{ctrl.InNamespace(ns)} for _, option := range options { @@ -1358,7 +1379,7 @@ func Kits(t *testing.T, ns string, options ...interface{}) func() []v1.Integrati return func() []v1.IntegrationKit { list := v1.NewIntegrationKitList() - if err := TestClient(t).List(TestContext, &list, listOptions...); err != nil { + if err := TestClient(t).List(ctx, &list, listOptions...); err != nil { failTest(t, err) } @@ -1377,13 +1398,13 @@ func Kits(t *testing.T, ns string, options ...interface{}) func() []v1.Integrati } } -func DeleteKits(t *testing.T, ns string) error { - kits := Kits(t, ns)() +func DeleteKits(t *testing.T, ctx context.Context, ns string) error { + kits := Kits(t, ctx, ns)() if len(kits) == 0 { return nil } for _, kit := range kits { - if err := TestClient(t).Delete(TestContext, &kit); err != nil { + if err := TestClient(t).Delete(ctx, &kit); err != nil { return err } } @@ -1391,24 +1412,24 @@ func DeleteKits(t *testing.T, ns string) error { return nil } -func DeleteIntegrations(t *testing.T, ns string) func() (int, error) { +func DeleteIntegrations(t *testing.T, ctx context.Context, ns string) func() (int, error) { return func() (int, error) { - integrations := Integrations(t, ns)() + integrations := Integrations(t, ctx, ns)() if len(integrations.Items) == 0 { return 0, nil } - if err := Kamel(t, "delete", "--all", "-n", ns).Execute(); err != nil { + if err := Kamel(t, ctx, "delete", "--all", "-n", ns).Execute(); err != nil { return 0, err } - return NumIntegrations(t, ns)(), nil + return NumIntegrations(t, ctx, ns)(), nil } } -func OperatorImage(t *testing.T, ns string) func() string { +func OperatorImage(t *testing.T, ctx context.Context, ns string) func() string { return func() string { - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() if pod != nil { if len(pod.Spec.Containers) > 0 { return pod.Spec.Containers[0].Image @@ -1418,9 +1439,9 @@ func OperatorImage(t *testing.T, ns string) func() string { } } -func OperatorPodSecurityContext(t *testing.T, ns string) func() *corev1.SecurityContext { +func OperatorPodSecurityContext(t *testing.T, ctx context.Context, ns string) func() *corev1.SecurityContext { return func() *corev1.SecurityContext { - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() if pod == nil || pod.Spec.Containers == nil || len(pod.Spec.Containers) == 0 { return nil } @@ -1428,9 +1449,9 @@ func OperatorPodSecurityContext(t *testing.T, ns string) func() *corev1.Security } } -func OperatorPodHas(t *testing.T, ns string, predicate func(pod *corev1.Pod) bool) func() bool { +func OperatorPodHas(t *testing.T, ctx context.Context, ns string, predicate func(pod *corev1.Pod) bool) func() bool { return func() bool { - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() if pod == nil { return false } @@ -1438,9 +1459,9 @@ func OperatorPodHas(t *testing.T, ns string, predicate func(pod *corev1.Pod) boo } } -func OperatorPodPhase(t *testing.T, ns string) func() corev1.PodPhase { +func OperatorPodPhase(t *testing.T, ctx context.Context, ns string) func() corev1.PodPhase { return func() corev1.PodPhase { - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() if pod == nil { return "" } @@ -1448,9 +1469,9 @@ func OperatorPodPhase(t *testing.T, ns string) func() corev1.PodPhase { } } -func OperatorEnvVarValue(t *testing.T, ns string, key string) func() string { +func OperatorEnvVarValue(t *testing.T, ctx context.Context, ns string, key string) func() string { return func() string { - pod := OperatorPod(t, ns)() + pod := OperatorPod(t, ctx, ns)() if pod == nil || len(pod.Spec.Containers) == 0 { return "" } @@ -1465,7 +1486,7 @@ func OperatorEnvVarValue(t *testing.T, ns string, key string) func() string { } } -func Configmap(t *testing.T, ns string, name string) func() *corev1.ConfigMap { +func Configmap(t *testing.T, ctx context.Context, ns string, name string) func() *corev1.ConfigMap { return func() *corev1.ConfigMap { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ @@ -1481,7 +1502,7 @@ func Configmap(t *testing.T, ns string, name string) func() *corev1.ConfigMap { Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &cm); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &cm); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Error(err, "Error while retrieving configmap "+name) @@ -1491,7 +1512,7 @@ func Configmap(t *testing.T, ns string, name string) func() *corev1.ConfigMap { } } -func BuilderPod(t *testing.T, ns string, name string) func() *corev1.Pod { +func BuilderPod(t *testing.T, ctx context.Context, ns string, name string) func() *corev1.Pod { return func() *corev1.Pod { pod := corev1.Pod{ TypeMeta: metav1.TypeMeta{ @@ -1507,7 +1528,7 @@ func BuilderPod(t *testing.T, ns string, name string) func() *corev1.Pod { Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &pod); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &pod); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Error(err, "Error while retrieving pod "+name) @@ -1517,9 +1538,9 @@ func BuilderPod(t *testing.T, ns string, name string) func() *corev1.Pod { } } -func BuilderPodPhase(t *testing.T, ns string, name string) func() corev1.PodPhase { +func BuilderPodPhase(t *testing.T, ctx context.Context, ns string, name string) func() corev1.PodPhase { return func() corev1.PodPhase { - pod := BuilderPod(t, ns, name)() + pod := BuilderPod(t, ctx, ns, name)() if pod == nil { return "" } @@ -1527,7 +1548,7 @@ func BuilderPodPhase(t *testing.T, ns string, name string) func() corev1.PodPhas } } -func BuilderPodsCount(t *testing.T, ns string) func() int { +func BuilderPodsCount(t *testing.T, ctx context.Context, ns string) func() int { return func() int { lst := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -1535,7 +1556,7 @@ func BuilderPodsCount(t *testing.T, ns string) func() int { APIVersion: corev1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "camel.apache.org/component": "builder", @@ -1546,7 +1567,7 @@ func BuilderPodsCount(t *testing.T, ns string) func() int { } } -func AutogeneratedConfigmapsCount(t *testing.T, ns string) func() int { +func AutogeneratedConfigmapsCount(t *testing.T, ctx context.Context, ns string) func() int { return func() int { lst := corev1.ConfigMapList{ TypeMeta: metav1.TypeMeta{ @@ -1554,7 +1575,7 @@ func AutogeneratedConfigmapsCount(t *testing.T, ns string) func() int { APIVersion: corev1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ kubernetes.ConfigMapAutogenLabel: "true", @@ -1565,11 +1586,11 @@ func AutogeneratedConfigmapsCount(t *testing.T, ns string) func() int { } } -func CreatePlainTextConfigmap(t *testing.T, ns string, name string, data map[string]string) error { - return CreatePlainTextConfigmapWithLabels(t, ns, name, data, map[string]string{}) +func CreatePlainTextConfigmap(t *testing.T, ctx context.Context, ns string, name string, data map[string]string) error { + return CreatePlainTextConfigmapWithLabels(t, ctx, ns, name, data, map[string]string{}) } -func CreatePlainTextConfigmapWithLabels(t *testing.T, ns string, name string, data map[string]string, labels map[string]string) error { +func CreatePlainTextConfigmapWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, labels map[string]string) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", @@ -1582,10 +1603,10 @@ func CreatePlainTextConfigmapWithLabels(t *testing.T, ns string, name string, da }, Data: data, } - return TestClient(t).Create(TestContext, &cm) + return TestClient(t).Create(ctx, &cm) } -func CreatePlainTextConfigmapWithOwnerRefWithLabels(t *testing.T, ns string, name string, data map[string]string, orname string, uid types.UID, labels map[string]string) error { +func CreatePlainTextConfigmapWithOwnerRefWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, orname string, uid types.UID, labels map[string]string) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", @@ -1607,14 +1628,14 @@ func CreatePlainTextConfigmapWithOwnerRefWithLabels(t *testing.T, ns string, nam }, Data: data, } - return TestClient(t).Create(TestContext, &cm) + return TestClient(t).Create(ctx, &cm) } -func UpdatePlainTextConfigmap(t *testing.T, ns string, name string, data map[string]string) error { - return UpdatePlainTextConfigmapWithLabels(t, ns, name, data, nil) +func UpdatePlainTextConfigmap(t *testing.T, ctx context.Context, ns string, name string, data map[string]string) error { + return UpdatePlainTextConfigmapWithLabels(t, ctx, ns, name, data, nil) } -func UpdatePlainTextConfigmapWithLabels(t *testing.T, ns string, name string, data map[string]string, labels map[string]string) error { +func UpdatePlainTextConfigmapWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, labels map[string]string) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", @@ -1627,10 +1648,10 @@ func UpdatePlainTextConfigmapWithLabels(t *testing.T, ns string, name string, da }, Data: data, } - return TestClient(t).Update(TestContext, &cm) + return TestClient(t).Update(ctx, &cm) } -func CreateBinaryConfigmap(t *testing.T, ns string, name string, data map[string][]byte) error { +func CreateBinaryConfigmap(t *testing.T, ctx context.Context, ns string, name string, data map[string][]byte) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", @@ -1642,10 +1663,10 @@ func CreateBinaryConfigmap(t *testing.T, ns string, name string, data map[string }, BinaryData: data, } - return TestClient(t).Create(TestContext, &cm) + return TestClient(t).Create(ctx, &cm) } -func DeleteConfigmap(t *testing.T, ns string, name string) error { +func DeleteConfigmap(t *testing.T, ctx context.Context, ns string, name string) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ Kind: "ConfigMap", @@ -1656,18 +1677,18 @@ func DeleteConfigmap(t *testing.T, ns string, name string) error { Name: name, }, } - return TestClient(t).Delete(TestContext, &cm) + return TestClient(t).Delete(ctx, &cm) } -func CreatePlainTextSecret(t *testing.T, ns string, name string, data map[string]string) error { - return CreatePlainTextSecretWithLabels(t, ns, name, data, map[string]string{}) +func CreatePlainTextSecret(t *testing.T, ctx context.Context, ns string, name string, data map[string]string) error { + return CreatePlainTextSecretWithLabels(t, ctx, ns, name, data, map[string]string{}) } -func UpdatePlainTextSecret(t *testing.T, ns string, name string, data map[string]string) error { - return UpdatePlainTextSecretWithLabels(t, ns, name, data, nil) +func UpdatePlainTextSecret(t *testing.T, ctx context.Context, ns string, name string, data map[string]string) error { + return UpdatePlainTextSecretWithLabels(t, ctx, ns, name, data, nil) } -func UpdatePlainTextSecretWithLabels(t *testing.T, ns string, name string, data map[string]string, labels map[string]string) error { +func UpdatePlainTextSecretWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, labels map[string]string) error { sec := corev1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -1680,10 +1701,10 @@ func UpdatePlainTextSecretWithLabels(t *testing.T, ns string, name string, data }, StringData: data, } - return TestClient(t).Update(TestContext, &sec) + return TestClient(t).Update(ctx, &sec) } -func CreatePlainTextSecretWithLabels(t *testing.T, ns string, name string, data map[string]string, labels map[string]string) error { +func CreatePlainTextSecretWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, labels map[string]string) error { sec := corev1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -1696,13 +1717,13 @@ func CreatePlainTextSecretWithLabels(t *testing.T, ns string, name string, data }, StringData: data, } - return TestClient(t).Create(TestContext, &sec) + return TestClient(t).Create(ctx, &sec) } // SecretByName Finds a secret in the given namespace by name or prefix of name -func SecretByName(t *testing.T, ns string, prefix string) func() *corev1.Secret { +func SecretByName(t *testing.T, ctx context.Context, ns string, prefix string) func() *corev1.Secret { return func() *corev1.Secret { - secretList, err := TestClient(t).CoreV1().Secrets(ns).List(TestContext, metav1.ListOptions{}) + secretList, err := TestClient(t).CoreV1().Secrets(ns).List(ctx, metav1.ListOptions{}) if err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { @@ -1723,7 +1744,7 @@ func SecretByName(t *testing.T, ns string, prefix string) func() *corev1.Secret } } -func DeleteSecret(t *testing.T, ns string, name string) error { +func DeleteSecret(t *testing.T, ctx context.Context, ns string, name string) error { sec := corev1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -1734,10 +1755,10 @@ func DeleteSecret(t *testing.T, ns string, name string) error { Name: name, }, } - return TestClient(t).Delete(TestContext, &sec) + return TestClient(t).Delete(ctx, &sec) } -func KnativeService(t *testing.T, ns string, name string) func() *servingv1.Service { +func KnativeService(t *testing.T, ctx context.Context, ns string, name string) func() *servingv1.Service { return func() *servingv1.Service { answer := servingv1.Service{ TypeMeta: metav1.TypeMeta{ @@ -1753,7 +1774,7 @@ func KnativeService(t *testing.T, ns string, name string) func() *servingv1.Serv Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &answer); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &answer); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Errorf(err, "Error while retrieving knative service %s", name) @@ -1762,7 +1783,7 @@ func KnativeService(t *testing.T, ns string, name string) func() *servingv1.Serv return &answer } } -func DeploymentWithIntegrationLabel(t *testing.T, ns string, label string) func() *appsv1.Deployment { +func DeploymentWithIntegrationLabel(t *testing.T, ctx context.Context, ns string, label string) func() *appsv1.Deployment { return func() *appsv1.Deployment { lst := appsv1.DeploymentList{ TypeMeta: metav1.TypeMeta{ @@ -1770,7 +1791,7 @@ func DeploymentWithIntegrationLabel(t *testing.T, ns string, label string) func( APIVersion: appsv1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{v1.IntegrationLabel: label}); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{v1.IntegrationLabel: label}); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Errorf(err, "Error while retrieving deployment %s", label) @@ -1783,7 +1804,7 @@ func DeploymentWithIntegrationLabel(t *testing.T, ns string, label string) func( } } -func Deployment(t *testing.T, ns string, name string) func() *appsv1.Deployment { +func Deployment(t *testing.T, ctx context.Context, ns string, name string) func() *appsv1.Deployment { return func() *appsv1.Deployment { answer := appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ @@ -1799,7 +1820,7 @@ func Deployment(t *testing.T, ns string, name string) func() *appsv1.Deployment Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &answer); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &answer); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Errorf(err, "Error while retrieving deployment %s", name) @@ -1809,9 +1830,9 @@ func Deployment(t *testing.T, ns string, name string) func() *appsv1.Deployment } } -func DeploymentCondition(t *testing.T, ns string, name string, conditionType appsv1.DeploymentConditionType) func() appsv1.DeploymentCondition { +func DeploymentCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType appsv1.DeploymentConditionType) func() appsv1.DeploymentCondition { return func() appsv1.DeploymentCondition { - deployment := Deployment(t, ns, name)() + deployment := Deployment(t, ctx, ns, name)() condition := appsv1.DeploymentCondition{ Status: corev1.ConditionUnknown, @@ -1828,10 +1849,10 @@ func DeploymentCondition(t *testing.T, ns string, name string, conditionType app } } -func Build(t *testing.T, ns, name string) func() *v1.Build { +func Build(t *testing.T, ctx context.Context, ns, name string) func() *v1.Build { return func() *v1.Build { build := v1.NewBuild(ns, name) - if err := TestClient(t).Get(TestContext, ctrl.ObjectKeyFromObject(build), build); err != nil && k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, ctrl.ObjectKeyFromObject(build), build); err != nil && k8serrors.IsNotFound(err) { return nil } else if err != nil { log.Error(err, "Error while retrieving build "+name) @@ -1841,9 +1862,9 @@ func Build(t *testing.T, ns, name string) func() *v1.Build { } } -func BuildConfig(t *testing.T, ns, name string) func() v1.BuildConfiguration { +func BuildConfig(t *testing.T, ctx context.Context, ns, name string) func() v1.BuildConfiguration { return func() v1.BuildConfiguration { - build := Build(t, ns, name)() + build := Build(t, ctx, ns, name)() if build != nil { return *build.BuilderConfiguration() } @@ -1851,9 +1872,9 @@ func BuildConfig(t *testing.T, ns, name string) func() v1.BuildConfiguration { } } -func BuildPhase(t *testing.T, ns, name string) func() v1.BuildPhase { +func BuildPhase(t *testing.T, ctx context.Context, ns, name string) func() v1.BuildPhase { return func() v1.BuildPhase { - build := Build(t, ns, name)() + build := Build(t, ctx, ns, name)() if build != nil { return build.Status.Phase } @@ -1861,9 +1882,9 @@ func BuildPhase(t *testing.T, ns, name string) func() v1.BuildPhase { } } -func BuildConditions(t *testing.T, ns, name string) func() []v1.BuildCondition { +func BuildConditions(t *testing.T, ctx context.Context, ns, name string) func() []v1.BuildCondition { return func() []v1.BuildCondition { - build := Build(t, ns, name)() + build := Build(t, ctx, ns, name)() if build != nil && &build.Status != nil && build.Status.Conditions != nil { return build.Status.Conditions } @@ -1871,9 +1892,9 @@ func BuildConditions(t *testing.T, ns, name string) func() []v1.BuildCondition { } } -func BuildCondition(t *testing.T, ns string, name string, conditionType v1.BuildConditionType) func() *v1.BuildCondition { +func BuildCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.BuildConditionType) func() *v1.BuildCondition { return func() *v1.BuildCondition { - build := Build(t, ns, name)() + build := Build(t, ctx, ns, name)() if build != nil && &build.Status != nil && build.Status.Conditions != nil { return build.Status.GetCondition(conditionType) } @@ -1881,9 +1902,9 @@ func BuildCondition(t *testing.T, ns string, name string, conditionType v1.Build } } -func BuildFailureRecovery(t *testing.T, ns, name string) func() int { +func BuildFailureRecovery(t *testing.T, ctx context.Context, ns, name string) func() int { return func() int { - build := Build(t, ns, name)() + build := Build(t, ctx, ns, name)() if build != nil { return build.Status.Failure.Recovery.Attempt } @@ -1903,20 +1924,20 @@ func BuildsRunning(predicates ...func() v1.BuildPhase) func() int { } } -func HasPlatform(t *testing.T, ns string) func() bool { +func HasPlatform(t *testing.T, ctx context.Context, ns string) func() bool { return func() bool { lst := v1.NewIntegrationPlatformList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { return false } return len(lst.Items) > 0 } } -func Platform(t *testing.T, ns string) func() *v1.IntegrationPlatform { +func Platform(t *testing.T, ctx context.Context, ns string) func() *v1.IntegrationPlatform { return func() *v1.IntegrationPlatform { lst := v1.NewIntegrationPlatformList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } if len(lst.Items) == 0 { @@ -1929,10 +1950,10 @@ func Platform(t *testing.T, ns string) func() *v1.IntegrationPlatform { } } -func PlatformByName(t *testing.T, ns string, name string) func() *v1.IntegrationPlatform { +func PlatformByName(t *testing.T, ctx context.Context, ns string, name string) func() *v1.IntegrationPlatform { return func() *v1.IntegrationPlatform { lst := v1.NewIntegrationPlatformList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } for _, p := range lst.Items { @@ -1944,11 +1965,11 @@ func PlatformByName(t *testing.T, ns string, name string) func() *v1.Integration } } -func CopyIntegrationKits(t *testing.T, ns, operatorID string) error { +func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID string) error { opns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) lst := v1.NewIntegrationKitList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(opns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(opns)); err != nil { failTest(t, err) } for _, kit := range lst.Items { @@ -1970,7 +1991,7 @@ func CopyIntegrationKits(t *testing.T, ns, operatorID string) error { v1.SetAnnotation(©Kit.ObjectMeta, v1.OperatorIDAnnotation, operatorID) fmt.Printf("Copy integration kit %s from namespace %s\n", kit.Name, opns) - if err := CreateIntegrationKit(t, ©Kit)(); err != nil { + if err := CreateIntegrationKit(t, ctx, ©Kit)(); err != nil { return err } } @@ -1979,11 +2000,11 @@ func CopyIntegrationKits(t *testing.T, ns, operatorID string) error { return nil } -func CopyCamelCatalog(t *testing.T, ns, operatorID string) error { +func CopyCamelCatalog(t *testing.T, ctx context.Context, ns, operatorID string) error { catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion)) opns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - defaultCatalog := CamelCatalog(t, opns, catalogName)() + defaultCatalog := CamelCatalog(t, ctx, opns, catalogName)() if defaultCatalog != nil { fmt.Printf("Copy catalog %s from namespace %s\n", catalogName, opns) catalog := v1.CamelCatalog{ @@ -1994,16 +2015,16 @@ func CopyCamelCatalog(t *testing.T, ns, operatorID string) error { Spec: *defaultCatalog.Spec.DeepCopy(), } v1.SetAnnotation(&catalog.ObjectMeta, v1.OperatorIDAnnotation, operatorID) - return CreateCamelCatalog(t, &catalog)() + return CreateCamelCatalog(t, ctx, &catalog)() } return nil } -func IntegrationProfileByName(t *testing.T, ns string, name string) func() *v1.IntegrationProfile { +func IntegrationProfileByName(t *testing.T, ctx context.Context, ns string, name string) func() *v1.IntegrationProfile { return func() *v1.IntegrationProfile { lst := v1.NewIntegrationProfileList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } for _, pc := range lst.Items { @@ -2015,14 +2036,14 @@ func IntegrationProfileByName(t *testing.T, ns string, name string) func() *v1.I } } -func CamelCatalog(t *testing.T, ns, name string) func() *v1.CamelCatalog { +func CamelCatalog(t *testing.T, ctx context.Context, ns, name string) func() *v1.CamelCatalog { return func() *v1.CamelCatalog { cat := v1.CamelCatalog{} key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &cat); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &cat); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -2031,10 +2052,10 @@ func CamelCatalog(t *testing.T, ns, name string) func() *v1.CamelCatalog { } } -func IntegrationProfile(t *testing.T, ns string) func() *v1.IntegrationProfile { +func IntegrationProfile(t *testing.T, ctx context.Context, ns string) func() *v1.IntegrationProfile { return func() *v1.IntegrationProfile { lst := v1.NewIntegrationProfileList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } if len(lst.Items) == 0 { @@ -2047,12 +2068,12 @@ func IntegrationProfile(t *testing.T, ns string) func() *v1.IntegrationProfile { } } -func CreateIntegrationProfile(t *testing.T, profile *v1.IntegrationProfile) error { - return TestClient(t).Create(TestContext, profile) +func CreateIntegrationProfile(t *testing.T, ctx context.Context, profile *v1.IntegrationProfile) error { + return TestClient(t).Create(ctx, profile) } -func UpdateIntegrationProfile(t *testing.T, ns string, upd func(ipr *v1.IntegrationProfile)) error { - ipr := IntegrationProfile(t, ns)() +func UpdateIntegrationProfile(t *testing.T, ctx context.Context, ns string, upd func(ipr *v1.IntegrationProfile)) error { + ipr := IntegrationProfile(t, ctx, ns)() if ipr == nil { return fmt.Errorf("unable to locate Integration Profile in %s", ns) } @@ -2065,42 +2086,42 @@ func UpdateIntegrationProfile(t *testing.T, ns string, upd func(ipr *v1.Integrat } else if len(p) == 0 { return nil } - return TestClient(t).Patch(TestContext, target, ctrl.RawPatch(types.MergePatchType, p)) + return TestClient(t).Patch(ctx, target, ctrl.RawPatch(types.MergePatchType, p)) } -func CreateCamelCatalog(t *testing.T, catalog *v1.CamelCatalog) func() error { +func CreateCamelCatalog(t *testing.T, ctx context.Context, catalog *v1.CamelCatalog) func() error { return func() error { testSetupMutex.Lock() defer testSetupMutex.Unlock() - return TestClient(t).Create(TestContext, catalog) + return TestClient(t).Create(ctx, catalog) } } -func CreateIntegrationKit(t *testing.T, kit *v1.IntegrationKit) func() error { +func CreateIntegrationKit(t *testing.T, ctx context.Context, kit *v1.IntegrationKit) func() error { return func() error { testSetupMutex.Lock() defer testSetupMutex.Unlock() - return TestClient(t).Create(TestContext, kit) + return TestClient(t).Create(ctx, kit) } } -func DeleteCamelCatalog(t *testing.T, ns, name string) func() bool { +func DeleteCamelCatalog(t *testing.T, ctx context.Context, ns, name string) func() bool { return func() bool { - cat := CamelCatalog(t, ns, name)() + cat := CamelCatalog(t, ctx, ns, name)() if cat == nil { return true } - if err := TestClient(t).Delete(TestContext, cat); err != nil { + if err := TestClient(t).Delete(ctx, cat); err != nil { log.Error(err, "Got error while deleting the catalog") } return true } } -func DefaultCamelCatalogPhase(t *testing.T, ns string) func() v1.CamelCatalogPhase { +func DefaultCamelCatalogPhase(t *testing.T, ctx context.Context, ns string) func() v1.CamelCatalogPhase { return func() v1.CamelCatalogPhase { catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion)) - c := CamelCatalog(t, ns, catalogName)() + c := CamelCatalog(t, ctx, ns, catalogName)() if c == nil { return "" } @@ -2108,9 +2129,9 @@ func DefaultCamelCatalogPhase(t *testing.T, ns string) func() v1.CamelCatalogPha } } -func CamelCatalogPhase(t *testing.T, ns, name string) func() v1.CamelCatalogPhase { +func CamelCatalogPhase(t *testing.T, ctx context.Context, ns, name string) func() v1.CamelCatalogPhase { return func() v1.CamelCatalogPhase { - c := CamelCatalog(t, ns, name)() + c := CamelCatalog(t, ctx, ns, name)() if c == nil { return "" } @@ -2118,9 +2139,9 @@ func CamelCatalogPhase(t *testing.T, ns, name string) func() v1.CamelCatalogPhas } } -func CamelCatalogCondition(t *testing.T, ns, name string, conditionType v1.CamelCatalogConditionType) func() *v1.CamelCatalogCondition { +func CamelCatalogCondition(t *testing.T, ctx context.Context, ns, name string, conditionType v1.CamelCatalogConditionType) func() *v1.CamelCatalogCondition { return func() *v1.CamelCatalogCondition { - c := CamelCatalog(t, ns, name)() + c := CamelCatalog(t, ctx, ns, name)() if c == nil { return nil } @@ -2133,9 +2154,9 @@ func CamelCatalogCondition(t *testing.T, ns, name string, conditionType v1.Camel } } -func CamelCatalogImage(t *testing.T, ns, name string) func() string { +func CamelCatalogImage(t *testing.T, ctx context.Context, ns, name string) func() string { return func() string { - c := CamelCatalog(t, ns, name)() + c := CamelCatalog(t, ctx, ns, name)() if c == nil { return "" } @@ -2143,31 +2164,31 @@ func CamelCatalogImage(t *testing.T, ns, name string) func() string { } } -func CamelCatalogList(t *testing.T, ns string) func() []v1.CamelCatalog { +func CamelCatalogList(t *testing.T, ctx context.Context, ns string) func() []v1.CamelCatalog { return func() []v1.CamelCatalog { lst := v1.NewCamelCatalogList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } return lst.Items } } -func DeletePlatform(t *testing.T, ns string) func() bool { +func DeletePlatform(t *testing.T, ctx context.Context, ns string) func() bool { return func() bool { - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() if pl == nil { return true } - if err := TestClient(t).Delete(TestContext, pl); err != nil { + if err := TestClient(t).Delete(ctx, pl); err != nil { log.Error(err, "Got error while deleting the platform") } return false } } -func UpdatePlatform(t *testing.T, ns string, name string, upd func(ip *v1.IntegrationPlatform)) error { - ip := PlatformByName(t, ns, name)() +func UpdatePlatform(t *testing.T, ctx context.Context, ns string, name string, upd func(ip *v1.IntegrationPlatform)) error { + ip := PlatformByName(t, ctx, ns, name)() if ip == nil { return fmt.Errorf("unable to locate Integration Platform %s in %s", name, ns) } @@ -2180,12 +2201,12 @@ func UpdatePlatform(t *testing.T, ns string, name string, upd func(ip *v1.Integr } else if len(p) == 0 { return nil } - return TestClient(t).Patch(TestContext, target, ctrl.RawPatch(types.MergePatchType, p)) + return TestClient(t).Patch(ctx, target, ctrl.RawPatch(types.MergePatchType, p)) } -func PlatformVersion(t *testing.T, ns string) func() string { +func PlatformVersion(t *testing.T, ctx context.Context, ns string) func() string { return func() string { - p := Platform(t, ns)() + p := Platform(t, ctx, ns)() if p == nil { return "" } @@ -2193,9 +2214,9 @@ func PlatformVersion(t *testing.T, ns string) func() string { } } -func PlatformPhase(t *testing.T, ns string) func() v1.IntegrationPlatformPhase { +func PlatformPhase(t *testing.T, ctx context.Context, ns string) func() v1.IntegrationPlatformPhase { return func() v1.IntegrationPlatformPhase { - p := Platform(t, ns)() + p := Platform(t, ctx, ns)() if p == nil { return "" } @@ -2203,9 +2224,9 @@ func PlatformPhase(t *testing.T, ns string) func() v1.IntegrationPlatformPhase { } } -func SelectedPlatformPhase(t *testing.T, ns string, name string) func() v1.IntegrationPlatformPhase { +func SelectedPlatformPhase(t *testing.T, ctx context.Context, ns string, name string) func() v1.IntegrationPlatformPhase { return func() v1.IntegrationPlatformPhase { - p := PlatformByName(t, ns, name)() + p := PlatformByName(t, ctx, ns, name)() if p == nil { return "" } @@ -2213,9 +2234,9 @@ func SelectedPlatformPhase(t *testing.T, ns string, name string) func() v1.Integ } } -func SelectedIntegrationProfilePhase(t *testing.T, ns string, name string) func() v1.IntegrationProfilePhase { +func SelectedIntegrationProfilePhase(t *testing.T, ctx context.Context, ns string, name string) func() v1.IntegrationProfilePhase { return func() v1.IntegrationProfilePhase { - pc := IntegrationProfileByName(t, ns, name)() + pc := IntegrationProfileByName(t, ctx, ns, name)() if pc == nil { return "" } @@ -2223,9 +2244,9 @@ func SelectedIntegrationProfilePhase(t *testing.T, ns string, name string) func( } } -func PlatformHas(t *testing.T, ns string, predicate func(pl *v1.IntegrationPlatform) bool) func() bool { +func PlatformHas(t *testing.T, ctx context.Context, ns string, predicate func(pl *v1.IntegrationPlatform) bool) func() bool { return func() bool { - pl := Platform(t, ns)() + pl := Platform(t, ctx, ns)() if pl == nil { return false } @@ -2233,13 +2254,9 @@ func PlatformHas(t *testing.T, ns string, predicate func(pl *v1.IntegrationPlatf } } -func PlatformCondition( - t *testing.T, - ns string, - conditionType v1.IntegrationPlatformConditionType, -) func() *v1.IntegrationPlatformCondition { +func PlatformCondition(t *testing.T, ctx context.Context, ns string, conditionType v1.IntegrationPlatformConditionType) func() *v1.IntegrationPlatformCondition { return func() *v1.IntegrationPlatformCondition { - p := Platform(t, ns)() + p := Platform(t, ctx, ns)() if p == nil { return nil } @@ -2247,13 +2264,9 @@ func PlatformCondition( } } -func PlatformConditionStatus( - t *testing.T, - ns string, - conditionType v1.IntegrationPlatformConditionType, -) func() corev1.ConditionStatus { +func PlatformConditionStatus(t *testing.T, ctx context.Context, ns string, conditionType v1.IntegrationPlatformConditionType) func() corev1.ConditionStatus { return func() corev1.ConditionStatus { - c := PlatformCondition(t, ns, conditionType)() + c := PlatformCondition(t, ctx, ns, conditionType)() if c == nil { return "Unknown" } @@ -2261,9 +2274,9 @@ func PlatformConditionStatus( } } -func PlatformProfile(t *testing.T, ns string) func() v1.TraitProfile { +func PlatformProfile(t *testing.T, ctx context.Context, ns string) func() v1.TraitProfile { return func() v1.TraitProfile { - p := Platform(t, ns)() + p := Platform(t, ctx, ns)() if p == nil { return "" } @@ -2271,9 +2284,9 @@ func PlatformProfile(t *testing.T, ns string) func() v1.TraitProfile { } } -func PlatformTimeout(t *testing.T, ns string) func() *metav1.Duration { +func PlatformTimeout(t *testing.T, ctx context.Context, ns string) func() *metav1.Duration { return func() *metav1.Duration { - p := Platform(t, ns)() + p := Platform(t, ctx, ns)() if p == nil { return &metav1.Duration{} } @@ -2281,14 +2294,14 @@ func PlatformTimeout(t *testing.T, ns string) func() *metav1.Duration { } } -func AssignPlatformToOperator(t *testing.T, ns, operator string) error { - pl := Platform(t, ns)() +func AssignPlatformToOperator(t *testing.T, ctx context.Context, ns, operator string) error { + pl := Platform(t, ctx, ns)() if pl == nil { return errors.New("cannot assign platform to operator: no platform found") } pl.SetOperatorID(operator) - return TestClient(t).Update(TestContext, pl) + return TestClient(t).Update(ctx, pl) } func GetExpectedCRDs(releaseVersion string) int { @@ -2344,10 +2357,10 @@ func CRDs(t *testing.T) func() []metav1.APIResource { } } -func ConsoleCLIDownload(t *testing.T, name string) func() *consoleV1.ConsoleCLIDownload { +func ConsoleCLIDownload(t *testing.T, ctx context.Context, name string) func() *consoleV1.ConsoleCLIDownload { return func() *consoleV1.ConsoleCLIDownload { cliDownload := consoleV1.ConsoleCLIDownload{} - if err := TestClient(t).Get(TestContext, ctrl.ObjectKey{Name: name}, &cliDownload); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, ctrl.ObjectKey{Name: name}, &cliDownload); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -2356,7 +2369,7 @@ func ConsoleCLIDownload(t *testing.T, name string) func() *consoleV1.ConsoleCLID } } -func OperatorPod(t *testing.T, ns string) func() *corev1.Pod { +func OperatorPod(t *testing.T, ctx context.Context, ns string) func() *corev1.Pod { return func() *corev1.Pod { lst := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -2364,7 +2377,7 @@ func OperatorPod(t *testing.T, ns string) func() *corev1.Pod { APIVersion: v1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "camel.apache.org/component": "operator", @@ -2379,7 +2392,7 @@ func OperatorPod(t *testing.T, ns string) func() *corev1.Pod { } // Pod Find one pod filtered by namespace ns and label app.kubernetes.io/name value appName. -func Pod(t *testing.T, ns string, appName string) func() (*corev1.Pod, error) { +func Pod(t *testing.T, ctx context.Context, ns string, appName string) func() (*corev1.Pod, error) { return func() (*corev1.Pod, error) { lst := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -2387,7 +2400,7 @@ func Pod(t *testing.T, ns string, appName string) func() (*corev1.Pod, error) { APIVersion: v1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "app.kubernetes.io/name": appName, @@ -2401,34 +2414,34 @@ func Pod(t *testing.T, ns string, appName string) func() (*corev1.Pod, error) { } } -func OperatorTryPodForceKill(t *testing.T, ns string, timeSeconds int) { - pod := OperatorPod(t, ns)() +func OperatorTryPodForceKill(t *testing.T, ctx context.Context, ns string, timeSeconds int) { + pod := OperatorPod(t, ctx, ns)() if pod != nil { - if err := TestClient(t).Delete(TestContext, pod, ctrl.GracePeriodSeconds(timeSeconds)); err != nil { + if err := TestClient(t).Delete(ctx, pod, ctrl.GracePeriodSeconds(timeSeconds)); err != nil { log.Error(err, "cannot forcefully kill the pod") } } } -func ScaleOperator(t *testing.T, ns string, replicas int32) error { - operator, err := TestClient(t).AppsV1().Deployments(ns).Get(TestContext, "camel-k-operator", metav1.GetOptions{}) +func ScaleOperator(t *testing.T, ctx context.Context, ns string, replicas int32) error { + operator, err := TestClient(t).AppsV1().Deployments(ns).Get(ctx, "camel-k-operator", metav1.GetOptions{}) if err != nil { return err } operator.Spec.Replicas = &replicas - _, err = TestClient(t).AppsV1().Deployments(ns).Update(TestContext, operator, metav1.UpdateOptions{}) + _, err = TestClient(t).AppsV1().Deployments(ns).Update(ctx, operator, metav1.UpdateOptions{}) if err != nil { return err } if replicas == 0 { // speedup scale down by killing the pod - OperatorTryPodForceKill(t, ns, 10) + OperatorTryPodForceKill(t, ctx, ns, 10) } return nil } -func ClusterRole(t *testing.T) func() []rbacv1.ClusterRole { +func ClusterRole(t *testing.T, ctx context.Context) func() []rbacv1.ClusterRole { return func() []rbacv1.ClusterRole { lst := rbacv1.ClusterRoleList{ TypeMeta: metav1.TypeMeta{ @@ -2436,7 +2449,7 @@ func ClusterRole(t *testing.T) func() []rbacv1.ClusterRole { APIVersion: rbacv1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.MatchingLabels{ "app": "camel-k", }); err != nil { @@ -2449,7 +2462,7 @@ func ClusterRole(t *testing.T) func() []rbacv1.ClusterRole { } } -func Role(t *testing.T, ns string) func() []rbacv1.Role { +func Role(t *testing.T, ctx context.Context, ns string) func() []rbacv1.Role { return func() []rbacv1.Role { lst := rbacv1.RoleList{ TypeMeta: metav1.TypeMeta{ @@ -2457,7 +2470,7 @@ func Role(t *testing.T, ns string) func() []rbacv1.Role { APIVersion: rbacv1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "app": "camel-k", @@ -2471,7 +2484,7 @@ func Role(t *testing.T, ns string) func() []rbacv1.Role { } } -func RoleBinding(t *testing.T, ns string) func() *rbacv1.RoleBinding { +func RoleBinding(t *testing.T, ctx context.Context, ns string) func() *rbacv1.RoleBinding { return func() *rbacv1.RoleBinding { lst := rbacv1.RoleBindingList{ TypeMeta: metav1.TypeMeta{ @@ -2479,7 +2492,7 @@ func RoleBinding(t *testing.T, ns string) func() *rbacv1.RoleBinding { APIVersion: metav1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "app": "camel-k", @@ -2493,7 +2506,7 @@ func RoleBinding(t *testing.T, ns string) func() *rbacv1.RoleBinding { } } -func ServiceAccount(t *testing.T, ns, name string) func() *corev1.ServiceAccount { +func ServiceAccount(t *testing.T, ctx context.Context, ns, name string) func() *corev1.ServiceAccount { return func() *corev1.ServiceAccount { lst := corev1.ServiceAccountList{ TypeMeta: metav1.TypeMeta{ @@ -2501,7 +2514,7 @@ func ServiceAccount(t *testing.T, ns, name string) func() *corev1.ServiceAccount APIVersion: corev1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns), ctrl.MatchingLabels{ "app": "camel-k", @@ -2515,24 +2528,24 @@ func ServiceAccount(t *testing.T, ns, name string) func() *corev1.ServiceAccount } } -func KameletList(t *testing.T, ns string) func() []v1.Kamelet { +func KameletList(t *testing.T, ctx context.Context, ns string) func() []v1.Kamelet { return func() []v1.Kamelet { lst := v1.NewKameletList() - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { failTest(t, err) } return lst.Items } } -func Kamelet(t *testing.T, name string, ns string) func() *v1.Kamelet { +func Kamelet(t *testing.T, ctx context.Context, name string, ns string) func() *v1.Kamelet { return func() *v1.Kamelet { it := v1.NewKamelet(ns, name) key := ctrl.ObjectKey{ Namespace: ns, Name: name, } - if err := TestClient(t).Get(TestContext, key, &it); err != nil && !k8serrors.IsNotFound(err) { + if err := TestClient(t).Get(ctx, key, &it); err != nil && !k8serrors.IsNotFound(err) { failTest(t, err) } else if err != nil && k8serrors.IsNotFound(err) { return nil @@ -2548,12 +2561,12 @@ func KameletLabels(kamelet *v1.Kamelet) map[string]string { return kamelet.GetLabels() } -func ClusterDomainName(t *testing.T) (string, error) { +func ClusterDomainName(t *testing.T, ctx context.Context) (string, error) { dns := configv1.DNS{} key := ctrl.ObjectKey{ Name: "cluster", } - err := TestClient(t).Get(TestContext, key, &dns) + err := TestClient(t).Get(ctx, key, &dns) if err != nil { return "", err } @@ -2564,11 +2577,11 @@ func ClusterDomainName(t *testing.T) (string, error) { Tekton */ -func CreateOperatorServiceAccount(t *testing.T, ns string) error { - return install.Resource(TestContext, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/manager/operator-service-account.yaml") +func CreateOperatorServiceAccount(t *testing.T, ctx context.Context, ns string) error { + return install.Resource(ctx, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/manager/operator-service-account.yaml") } -func CreateOperatorRole(t *testing.T, ns string) (err error) { +func CreateOperatorRole(t *testing.T, ctx context.Context, ns string) (err error) { oc, err := openshift.IsOpenShift(TestClient(t)) if err != nil { failTest(t, err) @@ -2579,32 +2592,32 @@ func CreateOperatorRole(t *testing.T, ns string) (err error) { // This should ideally be removed from the common RBAC manifest. customizer = install.RemoveIngressRoleCustomizer } - err = install.Resource(TestContext, TestClient(t), ns, true, customizer, "/config/rbac/namespaced/operator-role.yaml") + err = install.Resource(ctx, TestClient(t), ns, true, customizer, "/config/rbac/namespaced/operator-role.yaml") if err != nil { return err } if oc { - return install.Resource(TestContext, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/openshift/namespaced/operator-role-openshift.yaml") + return install.Resource(ctx, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/openshift/namespaced/operator-role-openshift.yaml") } return nil } -func CreateOperatorRoleBinding(t *testing.T, ns string) error { +func CreateOperatorRoleBinding(t *testing.T, ctx context.Context, ns string) error { oc, err := openshift.IsOpenShift(TestClient(t)) if err != nil { failTest(t, err) } - err = install.Resource(TestContext, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/namespaced/operator-role-binding.yaml") + err = install.Resource(ctx, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/namespaced/operator-role-binding.yaml") if err != nil { return err } if oc { - return install.Resource(TestContext, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/openshift/namespaced/operator-role-binding-openshift.yaml") + return install.Resource(ctx, TestClient(t), ns, true, install.IdentityResourceCustomizer, "/config/rbac/openshift/namespaced/operator-role-binding-openshift.yaml") } return nil } -func CreateKamelPod(t *testing.T, ns string, name string, command ...string) error { +func CreateKamelPod(t *testing.T, ctx context.Context, ns string, name string, command ...string) error { args := command for _, hook := range KamelHooks { args = hook(args) @@ -2630,14 +2643,14 @@ func CreateKamelPod(t *testing.T, ns string, name string, command ...string) err }, }, } - return TestClient(t).Create(TestContext, &pod) + return TestClient(t).Create(ctx, &pod) } /* Knative */ -func CreateKnativeChannel(t *testing.T, ns string, name string) func() error { +func CreateKnativeChannel(t *testing.T, ctx context.Context, ns string, name string) func() error { return func() error { channel := messaging.InMemoryChannel{ TypeMeta: metav1.TypeMeta{ @@ -2649,11 +2662,11 @@ func CreateKnativeChannel(t *testing.T, ns string, name string) func() error { Name: name, }, } - return TestClient(t).Create(TestContext, &channel) + return TestClient(t).Create(ctx, &channel) } } -func CreateKnativeBroker(t *testing.T, ns string, name string) func() error { +func CreateKnativeBroker(t *testing.T, ctx context.Context, ns string, name string) func() error { return func() error { broker := eventing.Broker{ TypeMeta: metav1.TypeMeta{ @@ -2665,7 +2678,7 @@ func CreateKnativeBroker(t *testing.T, ns string, name string) func() error { Name: name, }, } - return TestClient(t).Create(TestContext, &broker) + return TestClient(t).Create(ctx, &broker) } } @@ -2673,7 +2686,7 @@ func CreateKnativeBroker(t *testing.T, ns string, name string) func() error { Kamelets */ -func CreateKamelet(t *testing.T, operatorID string, ns string, name string, template map[string]interface{}, properties map[string]v1.JSONSchemaProp, labels map[string]string) func() error { +func CreateKamelet(t *testing.T, operatorID string, ctx context.Context, ns string, name string, template map[string]interface{}, properties map[string]v1.JSONSchemaProp, labels map[string]string) func() error { return func() error { kamelet := v1.Kamelet{ ObjectMeta: metav1.ObjectMeta{ @@ -2690,11 +2703,11 @@ func CreateKamelet(t *testing.T, operatorID string, ns string, name string, temp } kamelet.SetOperatorID(operatorID) - return TestClient(t).Create(TestContext, &kamelet) + return TestClient(t).Create(ctx, &kamelet) } } -func CreateTimerKamelet(t *testing.T, operatorID string, ns string, name string) func() error { +func CreateTimerKamelet(t *testing.T, ctx context.Context, operatorID string, ns string, name string) func() error { props := map[string]v1.JSONSchemaProp{ "message": { Type: "string", @@ -2717,17 +2730,17 @@ func CreateTimerKamelet(t *testing.T, operatorID string, ns string, name string) }, } - return CreateKamelet(t, operatorID, ns, name, flow, props, nil) + return CreateKamelet(t, operatorID, ctx, ns, name, flow, props, nil) } -func DeleteKamelet(t *testing.T, ns string, name string) error { +func DeleteKamelet(t *testing.T, ctx context.Context, ns string, name string) error { kamelet := v1.Kamelet{ ObjectMeta: metav1.ObjectMeta{ Namespace: ns, Name: name, }, } - return TestClient(t).Delete(TestContext, &kamelet) + return TestClient(t).Delete(ctx, &kamelet) } func asTemplate(t *testing.T, source map[string]interface{}) *v1.Template { @@ -2755,7 +2768,7 @@ func AsTraitConfiguration(t *testing.T, props map[string]string) *traitv1.Config Namespace testing functions */ -func Pods(t *testing.T, ns string) func() []corev1.Pod { +func Pods(t *testing.T, ctx context.Context, ns string) func() []corev1.Pod { return func() []corev1.Pod { lst := corev1.PodList{ TypeMeta: metav1.TypeMeta{ @@ -2763,7 +2776,7 @@ func Pods(t *testing.T, ns string) func() []corev1.Pod { APIVersion: v1.SchemeGroupVersion.String(), }, } - if err := TestClient(t).List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(ns)); err != nil { if !k8serrors.IsUnauthorized(err) { log.Error(err, "Error while listing the pods") } @@ -2773,33 +2786,33 @@ func Pods(t *testing.T, ns string) func() []corev1.Pod { } } -func WithNewTestNamespace(t *testing.T, doRun func(*gomega.WithT, string)) { - ns := NewTestNamespace(t, false) - defer deleteTestNamespace(t, ns) +func WithNewTestNamespace(t *testing.T, doRun func(context.Context, *gomega.WithT, string)) { + ns := NewTestNamespace(t, testContext, false) + defer deleteTestNamespace(t, testContext, ns) defer userCleanup(t) - invokeUserTestCode(t, ns.GetName(), doRun) + invokeUserTestCode(t, testContext, ns.GetName(), doRun) } -func WithGlobalOperatorNamespace(t *testing.T, test func(*gomega.WithT, string)) { +func WithGlobalOperatorNamespace(t *testing.T, test func(context.Context, *gomega.WithT, string)) { ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) if ocp { // global operators are always installed in the openshift-operators namespace - invokeUserTestCode(t, "openshift-operators", test) + invokeUserTestCode(t, testContext, "openshift-operators", test) } else { // create new namespace for the global operator WithNewTestNamespace(t, test) } } -func WithNewTestNamespaceWithKnativeBroker(t *testing.T, doRun func(*gomega.WithT, string)) { - ns := NewTestNamespace(t, true) - defer deleteTestNamespace(t, ns) - defer deleteKnativeBroker(t, ns) +func WithNewTestNamespaceWithKnativeBroker(t *testing.T, doRun func(context.Context, *gomega.WithT, string)) { + ns := NewTestNamespace(t, testContext, true) + defer deleteTestNamespace(t, testContext, ns) + defer deleteKnativeBroker(t, testContext, ns) defer userCleanup(t) - invokeUserTestCode(t, ns.GetName(), doRun) + invokeUserTestCode(t, testContext, ns.GetName(), doRun) } func userCleanup(t *testing.T) { @@ -2818,17 +2831,17 @@ func userCleanup(t *testing.T) { } } -func invokeUserTestCode(t *testing.T, ns string, doRun func(*gomega.WithT, string)) { +func invokeUserTestCode(t *testing.T, ctx context.Context, ns string, doRun func(context.Context, *gomega.WithT, string)) { defer func() { - DumpNamespace(t, ns) + DumpNamespace(t, ctx, ns) osns := os.Getenv("CAMEL_K_GLOBAL_OPERATOR_NS") // Try to clean up namespace - if ns != osns && HasPlatform(t, ns)() { + if ns != osns && HasPlatform(t, ctx, ns)() { t.Logf("Clean up test namespace: %s", ns) - if err := Kamel(t, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles").Execute(); err != nil { + if err := Kamel(t, ctx, "uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles").Execute(); err != nil { t.Logf("Error while cleaning up namespace %s: %v\n", ns, err) } @@ -2837,10 +2850,10 @@ func invokeUserTestCode(t *testing.T, ns string, doRun func(*gomega.WithT, strin }() g := gomega.NewWithT(t) - doRun(g, ns) + doRun(ctx, g, ns) } -func deleteKnativeBroker(t *testing.T, ns metav1.Object) { +func deleteKnativeBroker(t *testing.T, ctx context.Context, ns metav1.Object) { nsRef := corev1.Namespace{ TypeMeta: metav1.TypeMeta{ APIVersion: v1.SchemeGroupVersion.String(), @@ -2851,12 +2864,12 @@ func deleteKnativeBroker(t *testing.T, ns metav1.Object) { }, } nsKey := ctrl.ObjectKeyFromObject(&nsRef) - if err := TestClient(t).Get(TestContext, nsKey, &nsRef); err != nil { + if err := TestClient(t).Get(ctx, nsKey, &nsRef); err != nil { failTest(t, err) } nsRef.SetLabels(make(map[string]string, 0)) - if err := TestClient(t).Update(TestContext, &nsRef); err != nil { + if err := TestClient(t).Update(ctx, &nsRef); err != nil { failTest(t, err) } broker := eventing.Broker{ @@ -2869,12 +2882,12 @@ func deleteKnativeBroker(t *testing.T, ns metav1.Object) { Name: TestDefaultNamespace, }, } - if err := TestClient(t).Delete(TestContext, &broker); err != nil { + if err := TestClient(t).Delete(ctx, &broker); err != nil { failTest(t, err) } } -func deleteTestNamespace(t *testing.T, ns ctrl.Object) { +func deleteTestNamespace(t *testing.T, ctx context.Context, ns ctrl.Object) { value, saveNS := os.LookupEnv("CAMEL_K_TEST_SAVE_FAILED_TEST_NAMESPACE") if t != nil && t.Failed() && saveNS && value == "true" { t.Logf("Warning: retaining failed test project %q", ns.GetName()) @@ -2895,20 +2908,20 @@ func deleteTestNamespace(t *testing.T, ns ctrl.Object) { Name: ns.GetName(), }, } - if err := TestClient(t).Delete(TestContext, prj); err != nil { + if err := TestClient(t).Delete(ctx, prj); err != nil { t.Logf("Warning: cannot delete test project %q", prj.Name) } } else { - if err := TestClient(t).Delete(TestContext, ns); err != nil { + if err := TestClient(t).Delete(ctx, ns); err != nil { t.Logf("Warning: cannot delete test namespace %q", ns.GetName()) } } // Wait for all pods to be deleted - pods := Pods(t, ns.GetName())() + pods := Pods(t, ctx, ns.GetName())() for i := 0; len(pods) > 0 && i < 60; i++ { time.Sleep(1 * time.Second) - pods = Pods(t, ns.GetName())() + pods = Pods(t, ctx, ns.GetName())() } if len(pods) > 0 { names := []string{} @@ -2920,8 +2933,8 @@ func deleteTestNamespace(t *testing.T, ns ctrl.Object) { } } -func testNamespaceExists(t *testing.T, ns string) (bool, error) { - _, err := TestClient(t).CoreV1().Namespaces().Get(TestContext, ns, metav1.GetOptions{}) +func testNamespaceExists(t *testing.T, ctx context.Context, ns string) (bool, error) { + _, err := TestClient(t).CoreV1().Namespaces().Get(ctx, ns, metav1.GetOptions{}) if err != nil { if k8serrors.IsNotFound(err) { return false, nil @@ -2933,42 +2946,42 @@ func testNamespaceExists(t *testing.T, ns string) (bool, error) { return true, nil } -func DumpNamespace(t *testing.T, ns string) { +func DumpNamespace(t *testing.T, ctx context.Context, ns string) { if t.Failed() { - if err := util.Dump(TestContext, TestClient(t), ns, t); err != nil { + if err := util.Dump(ctx, TestClient(t), ns, t); err != nil { t.Logf("Error while dumping namespace %s: %v\n", ns, err) } } } -func DeleteNamespace(t *testing.T, ns string) error { - nsObj, err := TestClient(t).CoreV1().Namespaces().Get(TestContext, ns, metav1.GetOptions{}) +func DeleteNamespace(t *testing.T, ctx context.Context, ns string) error { + nsObj, err := TestClient(t).CoreV1().Namespaces().Get(ctx, ns, metav1.GetOptions{}) if err != nil { return err } - deleteTestNamespace(t, nsObj) + deleteTestNamespace(t, ctx, nsObj) return nil } -func NewTestNamespace(t *testing.T, injectKnativeBroker bool) ctrl.Object { +func NewTestNamespace(t *testing.T, ctx context.Context, injectKnativeBroker bool) ctrl.Object { name := os.Getenv("CAMEL_K_TEST_NS") if name == "" { name = "test-" + uuid.New().String() } - if exists, err := testNamespaceExists(t, name); err != nil { + if exists, err := testNamespaceExists(t, ctx, name); err != nil { failTest(t, err) } else if exists { fmt.Println("Warning: namespace ", name, " already exists so using different namespace name") name = fmt.Sprintf("%s-%d", name, time.Now().Second()) } - return NewNamedTestNamespace(t, name, injectKnativeBroker) + return NewNamedTestNamespace(t, ctx, name, injectKnativeBroker) } -func NewNamedTestNamespace(t *testing.T, name string, injectKnativeBroker bool) ctrl.Object { +func NewNamedTestNamespace(t *testing.T, ctx context.Context, name string, injectKnativeBroker bool) ctrl.Object { brokerLabel := "eventing.knative.dev/injection" c := TestClient(t) @@ -3003,7 +3016,7 @@ func NewNamedTestNamespace(t *testing.T, name string, injectKnativeBroker bool) err = rest.Post(). Resource("projectrequests"). Body(request). - Do(TestContext). + Do(ctx). Into(project) if err != nil { failTest(t, err) @@ -3011,14 +3024,14 @@ func NewNamedTestNamespace(t *testing.T, name string, injectKnativeBroker bool) // workaround https://github.com/openshift/origin/issues/3819 if injectKnativeBroker { // use Kubernetes API - https://access.redhat.com/solutions/2677921 - if namespace, err := TestClient(t).CoreV1().Namespaces().Get(TestContext, name, metav1.GetOptions{}); err != nil { + if namespace, err := TestClient(t).CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{}); err != nil { failTest(t, err) } else { if _, ok := namespace.GetLabels()[brokerLabel]; !ok { namespace.SetLabels(map[string]string{ brokerLabel: "enabled", }) - if err = TestClient(t).Update(TestContext, namespace); err != nil { + if err = TestClient(t).Update(ctx, namespace); err != nil { failTest(t, errors.New("Unable to label project with knative-eventing-injection. This operation needs update permission on the project.")) } } @@ -3040,7 +3053,7 @@ func NewNamedTestNamespace(t *testing.T, name string, injectKnativeBroker bool) brokerLabel: "enabled", }) } - if err := TestClient(t).Create(TestContext, namespace); err != nil { + if err := TestClient(t).Create(ctx, namespace); err != nil { failTest(t, err) } return namespace @@ -3070,7 +3083,7 @@ func GetOutputStringAsync(cmd *cobra.Command) func() string { } } -func CreateLogKamelet(t *testing.T, operatorID string, ns string, name string) func() error { +func CreateLogKamelet(t *testing.T, ctx context.Context, operatorID string, ns string, name string) func() error { flow := map[string]interface{}{ "from": map[string]interface{}{ "uri": "kamelet:source", @@ -3088,7 +3101,7 @@ func CreateLogKamelet(t *testing.T, operatorID string, ns string, name string) f }, } - return CreateKamelet(t, operatorID, ns, name, flow, props, nil) + return CreateKamelet(t, operatorID, ctx, ns, name, flow, props, nil) } func GetCIProcessID() string { diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go index 4973a2599f..d110c34f81 100644 --- a/e2e/support/test_util.go +++ b/e2e/support/test_util.go @@ -23,6 +23,7 @@ limitations under the License. package support import ( + "context" "github.com/apache/camel-k/v2/pkg/util/log" "os" "os/exec" @@ -101,24 +102,24 @@ func ExpectExecError(t *testing.T, g *WithT, command *exec.Cmd) { } // Cleanup Clean up the cluster ready for the next set of tests -func Cleanup(t *testing.T) { +func Cleanup(t *testing.T, ctx context.Context) { // Remove the locally installed operator - if err := UninstallAll(t); err != nil { + if err := UninstallAll(t, ctx); err != nil { log.Error(err, "Failed to uninstall Camel K") } // Ensure the CRDs & ClusterRoles are reinstalled if not already - if err := Kamel(t, "install", "--olm=false", "--cluster-setup").Execute(); err != nil { + if err := Kamel(t, ctx, "install", "--olm=false", "--cluster-setup").Execute(); err != nil { log.Error(err, "Failed to perform Camel K cluster setup") } } // UninstallAll Removes all items -func UninstallAll(t *testing.T) error { - return Kamel(t, "uninstall", "--olm=false", "--all").Execute() +func UninstallAll(t *testing.T, ctx context.Context) error { + return Kamel(t, ctx, "uninstall", "--olm=false", "--all").Execute() } // UninstallFromNamespace Removes operator from given namespace -func UninstallFromNamespace(t *testing.T, ns string) error { - return Kamel(t, "uninstall", "--olm=false", "-n", ns).Execute() +func UninstallFromNamespace(t *testing.T, ctx context.Context, ns string) error { + return Kamel(t, ctx, "uninstall", "--olm=false", "-n", ns).Execute() } diff --git a/e2e/telemetry/telemetry_test.go b/e2e/telemetry/telemetry_test.go index cb93fcf841..ec3d494c26 100644 --- a/e2e/telemetry/telemetry_test.go +++ b/e2e/telemetry/telemetry_test.go @@ -23,6 +23,7 @@ limitations under the License. package telemetry import ( + "context" "fmt" "testing" @@ -35,42 +36,36 @@ import ( ) func TestTelemetryTrait(t *testing.T) { - WithNewTestNamespace(t, func(g *WithT, ns string) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-trait-telemetry" - g.Expect(KamelInstallWithID(t, operatorID, ns)).To(Succeed()) + g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) // Check service is available - g.Eventually(ServicesByType(t, "otlp", corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) + g.Eventually(ServicesByType(t, ctx, "otlp", corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) // Create integration and activate traces by telemetry trait - g.Expect(KamelRunWithID(t, operatorID, ns, "files/rest-consumer.yaml", - "--name", "rest-consumer", - "-t", "telemetry.enabled=true", - "-t", "telemetry.endpoint=http://opentelemetrycollector.otlp.svc.cluster.local:4317").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "rest-consumer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-consumer.yaml", "--name", "rest-consumer", "-t", "telemetry.enabled=true", "-t", "telemetry.endpoint=http://opentelemetrycollector.otlp.svc.cluster.local:4317").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) name := "Bob" - g.Expect(KamelRunWithID(t, operatorID, ns, "files/rest-producer.yaml", - "-p", "serviceName=rest-consumer", - "-p", "name="+name, - "--name", "rest-producer").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ns, "rest-producer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ns, "rest-consumer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name))) - g.Eventually(IntegrationLogs(t, ns, "rest-producer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-producer.yaml", "-p", "serviceName=rest-consumer", "-p", "name="+name, "--name", "rest-producer").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name))) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) // Find opentelemetry collector pod : the exporter is configured to log traces with detailed verbosity. - pod, err := Pod(t, "otlp", "opentelemetrycollector")() + pod, err := Pod(t, ctx, "otlp", "opentelemetrycollector")() g.Expect(err).To(BeNil()) g.Expect(pod).NotTo(BeNil()) // Ensured logs in opentelemetry collector pod are present - g.Eventually(TailedLogs(t, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.target: Str(/customers/%s)", name))) - g.Eventually(TailedLogs(t, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.url: Str(http://rest-consumer/customers/%s)", name))) + g.Eventually(TailedLogs(t, ctx, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.target: Str(/customers/%s)", name))) + g.Eventually(TailedLogs(t, ctx, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.url: Str(http://rest-consumer/customers/%s)", name))) // check integration schema does not contains unwanted default trait value. - g.Eventually(UnstructuredIntegration(t, ns, "rest-consumer")).ShouldNot(BeNil()) - unstructuredIntegration := UnstructuredIntegration(t, ns, "rest-consumer")() + g.Eventually(UnstructuredIntegration(t, ctx, ns, "rest-consumer")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, "rest-consumer")() builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "addons", "telemetry") g.Expect(builderTrait).NotTo(BeNil()) g.Expect(len(builderTrait)).To(Equal(2)) @@ -78,6 +73,6 @@ func TestTelemetryTrait(t *testing.T) { g.Expect(builderTrait["endpoint"]).To(Equal("http://opentelemetrycollector.otlp.svc.cluster.local:4317")) // Clean up - g.Expect(Kamel(t, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/helm/camel-k/crds/crd-integration-kit.yaml b/helm/camel-k/crds/crd-integration-kit.yaml index 28880c09cb..29bf85c966 100644 --- a/helm/camel-k/crds/crd-integration-kit.yaml +++ b/helm/camel-k/crds/crd-integration-kit.yaml @@ -88,6 +88,11 @@ spec: spec: description: the desired configuration properties: + capabilities: + description: features offered by the IntegrationKit + items: + type: string + type: array configuration: description: 'Deprecated: Use camel trait (camel.properties) to manage properties Use mount trait (mount.configs) to manage configs Use diff --git a/pkg/apis/camel/v1/integrationkit_types.go b/pkg/apis/camel/v1/integrationkit_types.go index 8763237319..d8b0864c4a 100644 --- a/pkg/apis/camel/v1/integrationkit_types.go +++ b/pkg/apis/camel/v1/integrationkit_types.go @@ -74,6 +74,8 @@ type IntegrationKitSpec struct { Repositories []string `json:"repositories,omitempty"` // the sources to add at build time Sources []SourceSpec `json:"sources,omitempty"` + // features offered by the IntegrationKit + Capabilities []string `json:"capabilities,omitempty"` } // IntegrationKitTraits defines traits assigned to an `IntegrationKit`. diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index 96f5e5fc6e..6ca63f75fe 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -1248,6 +1248,11 @@ func (in *IntegrationKitSpec) DeepCopyInto(out *IntegrationKitSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Capabilities != nil { + in, out := &in.Capabilities, &out.Capabilities + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationKitSpec. diff --git a/pkg/client/camel/applyconfiguration/camel/v1/integrationkitspec.go b/pkg/client/camel/applyconfiguration/camel/v1/integrationkitspec.go index 19bd2e613c..9d85a68297 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/integrationkitspec.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/integrationkitspec.go @@ -33,6 +33,7 @@ type IntegrationKitSpecApplyConfiguration struct { Configuration []ConfigurationSpecApplyConfiguration `json:"configuration,omitempty"` Repositories []string `json:"repositories,omitempty"` Sources []SourceSpecApplyConfiguration `json:"sources,omitempty"` + Capabilities []string `json:"capabilities,omitempty"` } // IntegrationKitSpecApplyConfiguration constructs an declarative configuration of the IntegrationKitSpec type for use with @@ -110,3 +111,13 @@ func (b *IntegrationKitSpecApplyConfiguration) WithSources(values ...*SourceSpec } return b } + +// WithCapabilities adds the given value to the Capabilities field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Capabilities field. +func (b *IntegrationKitSpecApplyConfiguration) WithCapabilities(values ...string) *IntegrationKitSpecApplyConfiguration { + for i := range values { + b.Capabilities = append(b.Capabilities, values[i]) + } + return b +} diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go index 20df5c682e..22adf0f039 100644 --- a/pkg/controller/integration/kits.go +++ b/pkg/controller/integration/kits.go @@ -19,8 +19,6 @@ package integration import ( "context" - "fmt" - "reflect" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" @@ -132,7 +130,7 @@ func integrationMatches(ctx context.Context, c client.Client, integration *v1.In return false, err } - if match, err := hasMatchingTraits(itc, ikc); !match || err != nil { + if match, err := trait.HasMatchingTraits(itc, ikc); !match || err != nil { ilog.Debug("Integration and integration-kit traits do not match", "integration", integration.Name, "integration-kit", kit.Name, "namespace", integration.Namespace) return false, err } @@ -195,7 +193,7 @@ func kitMatches(kit *v1.IntegrationKit, target *v1.IntegrationKit) (bool, error) return false, err } - if match, err := hasMatchingTraits(c1, c2); !match || err != nil { + if match, err := trait.HasMatchingTraits(c1, c2); !match || err != nil { return false, err } if !util.StringSliceContains(kit.Spec.Dependencies, target.Spec.Dependencies) { @@ -205,67 +203,6 @@ func kitMatches(kit *v1.IntegrationKit, target *v1.IntegrationKit) (bool, error) return true, nil } -func hasMatchingTraits(traitMap trait.Options, kitTraitMap trait.Options) (bool, error) { - catalog := trait.NewCatalog(nil) - - for _, t := range catalog.AllTraits() { - if t == nil { - continue - } - - id := string(t.ID()) - it, ok1 := traitMap.Get(id) - kt, ok2 := kitTraitMap.Get(id) - - if !ok1 && !ok2 { - continue - } - - if t.InfluencesKit() && t.InfluencesBuild(it, kt) { - if ct, ok := t.(trait.ComparableTrait); ok { - // if it's match trait use its matches method to determine the match - if match, err := matchesComparableTrait(ct, it, kt); !match || err != nil { - return false, err - } - } else { - if !matchesTrait(it, kt) { - return false, nil - } - } - } - } - - return true, nil -} - -func matchesComparableTrait(ct trait.ComparableTrait, it map[string]interface{}, kt map[string]interface{}) (bool, error) { - t1 := reflect.New(reflect.TypeOf(ct).Elem()).Interface() - if err := trait.ToTrait(it, &t1); err != nil { - return false, err - } - - t2 := reflect.New(reflect.TypeOf(ct).Elem()).Interface() - if err := trait.ToTrait(kt, &t2); err != nil { - return false, err - } - - ct2, ok := t2.(trait.ComparableTrait) - if !ok { - return false, fmt.Errorf("type assertion failed: %v", t2) - } - tt1, ok := t1.(trait.Trait) - if !ok { - return false, fmt.Errorf("type assertion failed: %v", t1) - } - - return ct2.Matches(tt1), nil -} - -func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool { - // perform exact match on the two trait maps - return reflect.DeepEqual(it, kt) -} - func hasMatchingSourcesForNative(it *v1.Integration, kit *v1.IntegrationKit) bool { if len(it.UserDefinedSources()) != len(kit.Spec.Sources) { return false diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go index 685f5d0e01..1f946aa350 100644 --- a/pkg/controller/integration/kits_test.go +++ b/pkg/controller/integration/kits_test.go @@ -27,7 +27,6 @@ import ( traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/trait" - "github.com/apache/camel-k/v2/pkg/util/log" "github.com/apache/camel-k/v2/pkg/util/test" "github.com/stretchr/testify/assert" @@ -94,10 +93,6 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) { require.NoError(t, err) - a := buildKitAction{} - a.InjectLogger(log.Log) - a.InjectClient(c) - kits, err := lookupKitsForIntegration(context.TODO(), c, &v1.Integration{ TypeMeta: metav1.TypeMeta{ APIVersion: v1.SchemeGroupVersion.String(), @@ -221,10 +216,6 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T) require.NoError(t, err) - a := buildKitAction{} - a.InjectLogger(log.Log) - a.InjectClient(c) - kits, err := lookupKitsForIntegration(context.TODO(), c, &v1.Integration{ TypeMeta: metav1.TypeMeta{ APIVersion: v1.SchemeGroupVersion.String(), @@ -288,9 +279,6 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) { }, } - a := buildKitAction{} - a.InjectLogger(log.Log) - ok, err := integrationAndKitHaveSameTraits(integration, kit) require.NoError(t, err) assert.False(t, ok) @@ -339,9 +327,6 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) { }, } - a := buildKitAction{} - a.InjectLogger(log.Log) - ok, err := integrationAndKitHaveSameTraits(integration, kit) require.NoError(t, err) assert.True(t, ok) diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go index 4bd465bebd..2c526be948 100644 --- a/pkg/controller/integration/monitor.go +++ b/pkg/controller/integration/monitor.go @@ -237,7 +237,7 @@ func (action *monitorAction) checkDigestAndRebuild(ctx context.Context, integrat } if hash != integration.Status.Digest { - action.L.Info("Integration %s digest has changed: resetting its status. Will check if it needs to be rebuilt and restarted.", integration.Name) + action.L.Infof("Integration %s digest has changed: resetting its status. Will check if it needs to be rebuilt and restarted.", integration.Name) if isIntegrationKitResetRequired(integration, kit) { integration.SetIntegrationKit(nil) } diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml index 28880c09cb..29bf85c966 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml @@ -88,6 +88,11 @@ spec: spec: description: the desired configuration properties: + capabilities: + description: features offered by the IntegrationKit + items: + type: string + type: array configuration: description: 'Deprecated: Use camel trait (camel.properties) to manage properties Use mount trait (mount.configs) to manage configs Use diff --git a/pkg/resources/config/samples/bases/camel_v1alpha1_kamelet.yaml b/pkg/resources/config/samples/bases/camel_v1alpha1_kamelet.yaml new file mode 100644 index 0000000000..b44a4ea45f --- /dev/null +++ b/pkg/resources/config/samples/bases/camel_v1alpha1_kamelet.yaml @@ -0,0 +1,46 @@ +# --------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# --------------------------------------------------------------------------- + +apiVersion: camel.apache.org/v1alpha1 +kind: Kamelet +metadata: + name: example-source +spec: + definition: + description: Produces periodic events with a custom payload + properties: + message: + description: The message to generate + title: Message + type: string + period: + default: 1000 + description: The time interval between two events + title: Period + type: integer + required: + - message + title: Example Timer + template: + from: + uri: timer:tick + parameters: + period: "#property:period" + steps: + - setBody: + constant: "#property:message" + - to: kamelet:sink diff --git a/pkg/resources/config/samples/kustomization.yaml b/pkg/resources/config/samples/kustomization.yaml index e973532e24..cda69fdad6 100644 --- a/pkg/resources/config/samples/kustomization.yaml +++ b/pkg/resources/config/samples/kustomization.yaml @@ -29,6 +29,7 @@ resources: - bases/camel_v1_build.yaml - bases/camel_v1_kamelet.yaml - bases/camel_v1_pipe.yaml +- bases/camel_v1alpha1_kamelet.yaml - bases/camel_v1alpha1_kameletbinding.yaml patchesStrategicMerge: diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index 6b93751262..8c6a8d790f 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -20,6 +20,7 @@ package trait import ( "fmt" "regexp" + "slices" "sort" "strconv" "strings" @@ -56,9 +57,33 @@ func (t *builderTrait) InfluencesKit() bool { return true } -// InfluencesBuild overrides base class method. -func (t *builderTrait) InfluencesBuild(this, prev map[string]interface{}) bool { - return true +func (t *builderTrait) Matches(trait Trait) bool { + otherTrait, ok := trait.(*builderTrait) + if !ok { + return false + } + if t.BaseImage != otherTrait.BaseImage || len(t.Properties) != len(otherTrait.Properties) || len(t.Tasks) != len(otherTrait.Tasks) { + return false + } + // More sofisticated check if len is the same. Sort and compare via slices equal func. + // Although the Matches func is used as a support for comparison, it makes sense + // to copy the properties and avoid possible inconsistencies caused by the sorting operation. + srtThisProps := make([]string, len(t.Properties)) + srtOtheProps := make([]string, len(otherTrait.Properties)) + copy(srtThisProps, t.Properties) + copy(srtOtheProps, otherTrait.Properties) + slices.Sort(srtThisProps) + slices.Sort(srtOtheProps) + if !slices.Equal(srtThisProps, srtOtheProps) { + return false + } + srtThisTasks := make([]string, len(t.Tasks)) + srtOtheTasks := make([]string, len(otherTrait.Tasks)) + copy(srtThisTasks, t.Tasks) + copy(srtOtheTasks, otherTrait.Tasks) + slices.Sort(srtThisTasks) + slices.Sort(srtOtheTasks) + return slices.Equal(srtThisTasks, srtOtheTasks) } func (t *builderTrait) Configure(e *Environment) (bool, *TraitCondition, error) { diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go index 2448a28778..7b37567193 100644 --- a/pkg/trait/builder_test.go +++ b/pkg/trait/builder_test.go @@ -28,6 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/kubernetes" @@ -603,3 +604,53 @@ func tasksByName(tasks []v1.Task) []string { } return pipelineTasks } + +func TestBuilderMatches(t *testing.T) { + t1 := builderTrait{ + BasePlatformTrait: NewBasePlatformTrait("builder", 600), + BuilderTrait: traitv1.BuilderTrait{ + OrderStrategy: "dependencies", + }, + } + t2 := builderTrait{ + BasePlatformTrait: NewBasePlatformTrait("builder", 600), + BuilderTrait: traitv1.BuilderTrait{ + OrderStrategy: "dependencies", + }, + } + assert.True(t, t1.Matches(&t2)) + // This is a property that does not influence the build + t2.OrderStrategy = "fifo" + assert.True(t, t1.Matches(&t2)) + // Changing properties which influences build + t1.Properties = []string{"hello=world"} + assert.False(t, t1.Matches(&t2)) + t2.Properties = []string{"hello=world"} + assert.True(t, t1.Matches(&t2)) + t1.Properties = []string{"hello=world", "weare=theworld"} + assert.False(t, t1.Matches(&t2)) + // should detect swap + t2.Properties = []string{"weare=theworld", "hello=world"} + assert.True(t, t1.Matches(&t2)) +} + +func TestBuilderMatchesTasks(t *testing.T) { + t1 := builderTrait{ + BasePlatformTrait: NewBasePlatformTrait("builder", 600), + BuilderTrait: traitv1.BuilderTrait{}, + } + t2 := builderTrait{ + BasePlatformTrait: NewBasePlatformTrait("builder", 600), + BuilderTrait: traitv1.BuilderTrait{ + Tasks: []string{"task1;my-task;do-something"}, + }, + } + t3 := builderTrait{ + BasePlatformTrait: NewBasePlatformTrait("builder", 600), + BuilderTrait: traitv1.BuilderTrait{ + Tasks: []string{"task1;my-task;do-something-else"}, + }, + } + assert.False(t, t1.Matches(&t2)) + assert.False(t, t2.Matches(&t3)) +} diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go index f56c2bd1f5..3d2a991d8d 100644 --- a/pkg/trait/camel.go +++ b/pkg/trait/camel.go @@ -53,9 +53,13 @@ func (t *camelTrait) InfluencesKit() bool { return true } -// InfluencesBuild only when the runtime has changed. -func (t *camelTrait) InfluencesBuild(this, prev map[string]interface{}) bool { - return this["runtimeVersion"] != prev["runtimeVersion"] +func (t *camelTrait) Matches(trait Trait) bool { + otherTrait, ok := trait.(*camelTrait) + if !ok { + return false + } + + return otherTrait.RuntimeVersion == t.RuntimeVersion } func (t *camelTrait) Configure(e *Environment) (bool, *TraitCondition, error) { diff --git a/pkg/trait/camel_test.go b/pkg/trait/camel_test.go index e60e7cf994..a3fc3688d6 100644 --- a/pkg/trait/camel_test.go +++ b/pkg/trait/camel_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -208,3 +209,24 @@ func TestApplyCamelTraitWithSources(t *testing.T) { "content": "XML Source Code", }, sourceCm.Data) } + +func TestCamelMatches(t *testing.T) { + t1 := camelTrait{ + BasePlatformTrait: NewBasePlatformTrait("camel", 600), + CamelTrait: traitv1.CamelTrait{ + RuntimeVersion: "1.2.3", + }, + } + t2 := camelTrait{ + BasePlatformTrait: NewBasePlatformTrait("camel", 600), + CamelTrait: traitv1.CamelTrait{ + RuntimeVersion: "1.2.3", + }, + } + + assert.True(t, t1.Matches(&t2)) + t1.Properties = []string{"hello=world"} + assert.True(t, t1.Matches(&t2)) + t2.RuntimeVersion = "3.2.1" + assert.False(t, t1.Matches(&t2)) +} diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index bf7fdcc684..6b75d4b97d 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -109,23 +109,14 @@ func (t *quarkusTrait) InfluencesKit() bool { return true } -// InfluencesBuild overrides base class method. -func (t *quarkusTrait) InfluencesBuild(this, prev map[string]interface{}) bool { - return true -} - -var _ ComparableTrait = &quarkusTrait{} - func (t *quarkusTrait) Matches(trait Trait) bool { qt, ok := trait.(*quarkusTrait) if !ok { return false } - if len(t.Modes) == 0 && len(qt.Modes) != 0 && !qt.containsMode(traitv1.JvmQuarkusMode) { return false } - for _, md := range t.Modes { if md == traitv1.JvmQuarkusMode && len(qt.Modes) == 0 { continue @@ -135,8 +126,17 @@ func (t *quarkusTrait) Matches(trait Trait) bool { } return false } + // We need to check if the native base image used is the same + thisNativeBaseImage := t.NativeBaseImage + if thisNativeBaseImage == "" { + thisNativeBaseImage = QuarkusNativeDefaultBaseImageName + } + otherNativeBaseImage := qt.NativeBaseImage + if otherNativeBaseImage == "" { + otherNativeBaseImage = QuarkusNativeDefaultBaseImageName + } - return true + return thisNativeBaseImage == otherNativeBaseImage } func (t *quarkusTrait) Configure(e *Environment) (bool, *TraitCondition, error) { @@ -273,27 +273,26 @@ func (t *quarkusTrait) newIntegrationKit(e *Environment, packageType quarkusPack v1.SetAnnotation(&kit.ObjectMeta, v1.IntegrationProfileNamespaceAnnotation, e.Integration.Namespace) } } - for k, v := range integration.Annotations { if strings.HasPrefix(k, v1.TraitAnnotationPrefix) { v1.SetAnnotation(&kit.ObjectMeta, k, v) } } - operatorID := defaults.OperatorID() if operatorID != "" { kit.SetOperatorID(operatorID) } - kit.Spec = v1.IntegrationKitSpec{ Dependencies: e.Integration.Status.Dependencies, Repositories: e.Integration.Spec.Repositories, Traits: propagateKitTraits(e), } - if packageType == nativeSourcesPackageType { kit.Spec.Sources = propagateSourcesRequiredAtBuildTime(e) } + if e.Integration.Status.Capabilities != nil { + kit.Spec.Capabilities = e.Integration.Status.Capabilities + } return kit } diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go index 752e57fc02..5d681a3097 100644 --- a/pkg/trait/quarkus_test.go +++ b/pkg/trait/quarkus_test.go @@ -225,3 +225,31 @@ func TestGetLanguageSettingsWithLoaders(t *testing.T) { assert.Equal(t, languageSettings{native: false, sourcesRequiredAtBuildTime: true}, getLanguageSettings(environment, v1.LanguageKotlin)) assert.Equal(t, languageSettings{native: true, sourcesRequiredAtBuildTime: false}, getLanguageSettings(environment, v1.LanguageJavaShell)) } + +func TestQuarkusMatches(t *testing.T) { + qt := quarkusTrait{ + BasePlatformTrait: NewBasePlatformTrait("quarkus", 600), + QuarkusTrait: traitv1.QuarkusTrait{ + Modes: []traitv1.QuarkusMode{traitv1.JvmQuarkusMode}, + }, + } + qt2 := quarkusTrait{ + BasePlatformTrait: NewBasePlatformTrait("quarkus", 600), + QuarkusTrait: traitv1.QuarkusTrait{ + Modes: []traitv1.QuarkusMode{traitv1.JvmQuarkusMode}, + NativeBaseImage: QuarkusNativeDefaultBaseImageName, + }, + } + + assert.True(t, qt.Matches(&qt2)) + qt2.Modes = append(qt2.Modes, traitv1.NativeQuarkusMode) + assert.True(t, qt.Matches(&qt2)) + qt2.Modes = []traitv1.QuarkusMode{traitv1.NativeQuarkusMode} + assert.False(t, qt.Matches(&qt2)) + qt2.Modes = nil + assert.True(t, qt.Matches(&qt2)) + qt2.Modes = []traitv1.QuarkusMode{} + assert.True(t, qt.Matches(&qt2)) + qt2.NativeBaseImage = "docker.io/my-new-native-base" + assert.False(t, qt.Matches(&qt2)) +} diff --git a/pkg/trait/registry.go b/pkg/trait/registry.go index 98d9f88e2e..906e6f7fa9 100644 --- a/pkg/trait/registry.go +++ b/pkg/trait/registry.go @@ -54,11 +54,6 @@ func (t *registryTrait) InfluencesKit() bool { return true } -// InfluencesBuild overrides base class method. -func (t *registryTrait) InfluencesBuild(this, prev map[string]interface{}) bool { - return true -} - func (t *registryTrait) Configure(e *Environment) (bool, *TraitCondition, error) { // disabled by default if e.IntegrationKit == nil || !pointer.BoolDeref(t.Enabled, false) { diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go index 1d41da6320..85d152e47a 100644 --- a/pkg/trait/trait_types.go +++ b/pkg/trait/trait_types.go @@ -73,11 +73,6 @@ type Trait interface { // InfluencesKit determines if the trait has any influence on Integration Kits InfluencesKit() bool - // InfluencesBuild defines a low level of granularity for those traits which influences the build. - // The trait can specify if any particular trait configuration influences a build or not. - // Note: You must override this method if you override `InfluencesKit()` - InfluencesBuild(this, prev map[string]interface{}) bool - // IsPlatformTrait marks all fundamental traits that allow the platform to work IsPlatformTrait() bool @@ -91,10 +86,12 @@ type Trait interface { Order() int } +// Comparable is the interface exposing comparable funcs. type Comparable interface { Matches(trait Trait) bool } +// ComparableTrait is the interface used to compare two traits between them. type ComparableTrait interface { Trait Comparable @@ -154,12 +151,6 @@ func (trait *BaseTrait) InfluencesKit() bool { return false } -// InfluencesBuild defines a low level of granularity for those traits which influences the build. -// The trait can specify if any particular trait configuration influences a build or not. -func (trait *BaseTrait) InfluencesBuild(this, prev map[string]interface{}) bool { - return false -} - // IsPlatformTrait marks all fundamental traits that allow the platform to work. func (trait *BaseTrait) IsPlatformTrait() bool { return false diff --git a/pkg/trait/util.go b/pkg/trait/util.go index fe1190ea65..374d90e48b 100644 --- a/pkg/trait/util.go +++ b/pkg/trait/util.go @@ -533,7 +533,6 @@ func NewTraitsOptionsForKameletBinding(kb *v1alpha1.KameletBinding) (Options, er func FromAnnotations(meta *metav1.ObjectMeta) (Options, error) { options := make(Options) - for k, v := range meta.Annotations { if strings.HasPrefix(k, v1.TraitAnnotationPrefix) { configKey := strings.TrimPrefix(k, v1.TraitAnnotationPrefix) @@ -544,22 +543,7 @@ func FromAnnotations(meta *metav1.ObjectMeta) (Options, error) { if _, ok := options[id]; !ok { options[id] = make(map[string]interface{}) } - - propParts := util.ConfigTreePropertySplit(prop) - var current = options[id] - if len(propParts) > 1 { - c, err := util.NavigateConfigTree(current, propParts[0:len(propParts)-1]) - if err != nil { - return options, err - } - if cc, ok := c.(map[string]interface{}); ok { - current = cc - } else { - return options, errors.New(`invalid array specification: to set an array value use the ["v1", "v2"] format`) - } - } - current[prop] = v - + options[id][prop] = stringOrSlice(v) } else { return options, fmt.Errorf("wrong format for trait annotation %q: missing trait ID", k) } @@ -569,6 +553,24 @@ func FromAnnotations(meta *metav1.ObjectMeta) (Options, error) { return options, nil } +// stringOrSlice returns either a string or a slice with trimmed values when the input is +// represented as an array style (ie, [a,b,c]). +func stringOrSlice(val string) interface{} { + if val == "[]" { + // empty array + return []string{} + } + if strings.HasPrefix(val, "[") && strings.HasSuffix(val, "]") { + slice := strings.Split(val[1:len(val)-1], ",") + for i := range slice { + slice[i] = strings.Trim(slice[i], " ") + } + return slice + } else { + return val + } +} + // verify if the integration in the Environment contains an endpoint. func containsEndpoint(name string, e *Environment, c client.Client) (bool, error) { sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, c, e.Integration, e.Resources) @@ -593,3 +595,56 @@ func containsEndpoint(name string, e *Environment, c client.Client) (bool, error } return hasKnativeEndpoint, nil } + +// HasMatchingTraits verifies if two traits options match. +func HasMatchingTraits(traitMap Options, kitTraitMap Options) (bool, error) { + catalog := NewCatalog(nil) + + for _, t := range catalog.AllTraits() { + if t == nil || !t.InfluencesKit() { + // We don't store the trait configuration if the trait cannot influence the kit behavior + continue + } + id := string(t.ID()) + it, _ := traitMap.Get(id) + kt, _ := kitTraitMap.Get(id) + if ct, ok := t.(ComparableTrait); ok { + // if it's match trait use its matches method to determine the match + if match, err := matchesComparableTrait(ct, it, kt); !match || err != nil { + return false, err + } + } else { + if !matchesTrait(it, kt) { + return false, nil + } + } + } + + return true, nil +} + +func matchesComparableTrait(ct ComparableTrait, it map[string]interface{}, kt map[string]interface{}) (bool, error) { + t1 := reflect.New(reflect.TypeOf(ct).Elem()).Interface() + if err := ToTrait(it, &t1); err != nil { + return false, err + } + t2 := reflect.New(reflect.TypeOf(ct).Elem()).Interface() + if err := ToTrait(kt, &t2); err != nil { + return false, err + } + ct2, ok := t2.(ComparableTrait) + if !ok { + return false, fmt.Errorf("type assertion failed: %v", t2) + } + tt1, ok := t1.(Trait) + if !ok { + return false, fmt.Errorf("type assertion failed: %v", t1) + } + + return ct2.Matches(tt1), nil +} + +func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool { + // perform exact match on the two trait maps + return reflect.DeepEqual(it, kt) +} diff --git a/pkg/trait/util_test.go b/pkg/trait/util_test.go index 69767785b1..d89262bbf9 100644 --- a/pkg/trait/util_test.go +++ b/pkg/trait/util_test.go @@ -345,3 +345,93 @@ func TestSameTraits(t *testing.T) { assert.False(t, ok) }) } + +func TestHasMathchingTraitsEmpty(t *testing.T) { + opt1 := Options{ + "builder": {}, + "camel": { + "runtimeVersion": "1.2.3", + }, + "quarkus": {}, + } + opt2 := Options{ + "camel": { + "runtimeVersion": "1.2.3", + }, + } + opt3 := Options{ + "camel": { + "runtimeVersion": "1.2.3", + }, + } + opt4 := Options{ + "camel": { + "runtimeVersion": "3.2.1", + }, + } + b1, err := HasMatchingTraits(opt1, opt2) + assert.Nil(t, err) + assert.True(t, b1) + b2, err := HasMatchingTraits(opt1, opt4) + assert.Nil(t, err) + assert.False(t, b2) + b3, err := HasMatchingTraits(opt2, opt3) + assert.Nil(t, err) + assert.True(t, b3) +} + +func TestHasMathchingTraitsMissing(t *testing.T) { + opt1 := Options{} + opt2 := Options{ + "camel": { + "properties": []string{"a=1"}, + }, + } + b1, err := HasMatchingTraits(opt1, opt2) + assert.Nil(t, err) + assert.True(t, b1) +} + +func TestFromAnnotationsPlain(t *testing.T) { + meta := metav1.ObjectMeta{ + Annotations: map[string]string{ + "trait.camel.apache.org/trait.prop1": "hello1", + "trait.camel.apache.org/trait.prop2": "hello2", + }, + } + opt, err := FromAnnotations(&meta) + require.NoError(t, err) + tt, ok := opt.Get("trait") + assert.True(t, ok) + assert.Equal(t, "hello1", tt["prop1"]) + assert.Equal(t, "hello2", tt["prop2"]) +} + +func TestFromAnnotationsArray(t *testing.T) { + meta := metav1.ObjectMeta{ + Annotations: map[string]string{ + "trait.camel.apache.org/trait.prop1": "[hello,world]", + // The func should trim empty spaces as well + "trait.camel.apache.org/trait.prop2": "[\"hello=1\", \"world=2\"]", + }, + } + opt, err := FromAnnotations(&meta) + require.NoError(t, err) + tt, ok := opt.Get("trait") + assert.True(t, ok) + assert.Equal(t, []string{"hello", "world"}, tt["prop1"]) + assert.Equal(t, []string{"\"hello=1\"", "\"world=2\""}, tt["prop2"]) +} + +func TestFromAnnotationsArrayEmpty(t *testing.T) { + meta := metav1.ObjectMeta{ + Annotations: map[string]string{ + "trait.camel.apache.org/trait.prop": "[]", + }, + } + opt, err := FromAnnotations(&meta) + require.NoError(t, err) + tt, ok := opt.Get("trait") + assert.True(t, ok) + assert.Equal(t, []string{}, tt["prop"]) +} diff --git a/script/Makefile b/script/Makefile index f281adcdc8..32e515ac91 100644 --- a/script/Makefile +++ b/script/Makefile @@ -32,8 +32,8 @@ OPM_VERSION := v1.24.0 BASE_IMAGE := eclipse-temurin:17 LOCAL_REPOSITORY := /etc/maven/m2 IMAGE_NAME ?= docker.io/apache/camel-k -# Default value, change to your architecture accordingly -IMAGE_ARCH ?= amd64 +# Test for arm64, fall back to amd64 +IMAGE_ARCH ?= $(if $(filter arm64,$(shell uname -m)),arm64,amd64) # # Situations when user wants to override # the image name and version @@ -240,9 +240,15 @@ ifeq (, $(shell command -v gotestfmt 2> /dev/null)) go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest endif +# Build images without running unit tests +# NOTEST=1 make images test: do-build +ifndef NOTEST @echo "####### Running unit test..." go test ./... $(COVERAGE_OPTS) +else + @echo "####### Skipping unit test..." +endif # # Common tests that do not require any customized operator setting. They can leverage a unique namespaced operator installation to reduce @@ -342,8 +348,8 @@ test-quarkus-native-high-memory: do-build go test -timeout 180m -v ./e2e/native -tags=integration,high_memory $(TEST_QUARKUS_RUN) $(GOTESTFMT) build-kamel: - @echo "####### Building kamel CLI for $(GOOS) $(IMAGE_ARCH) architecture..." - CGO_ENABLED=0 GOARCH=$(IMAGE_ARCH) go build $(GOFLAGS) -o build/_output/bin/kamel-$(IMAGE_ARCH) ./cmd/kamel/*.go + @echo "####### Building kamel CLI for linux/$(IMAGE_ARCH) architecture..." + CGO_ENABLED=0 GOOS=linux GOARCH=$(IMAGE_ARCH) go build $(GOFLAGS) -o build/_output/bin/kamel-$(IMAGE_ARCH) ./cmd/kamel/*.go # Symbolic link to a local CLI ln -sf build/_output/bin/kamel-$(IMAGE_ARCH) ./kamel @@ -362,7 +368,7 @@ endif build-compile-integration-tests: @echo "####### Compiling integration tests..." - export CAMEL_K_E2E_JUST_COMPILE="true" ;\ + export CAMEL_K_E2E_JUST_COMPILE="true"; \ go test -run nope -tags="integration" ./e2e/... clean: @@ -416,57 +422,54 @@ maven-overlay: mkdir -p build/_maven_overlay ./script/maven_overlay.sh build/_maven_overlay -kamel-overlay: - mkdir -p build/_output/bin -ifeq ($(shell uname -s 2>/dev/null || echo Unknown),Linux) - @echo "####### Copying Linux platform arch $(IMAGE_ARCH) CLI into output build directory..." -else - @echo "####### (Re)Building a Linux platform arch $(IMAGE_ARCH) CLI " - @echo "####### Likely you're on a non Linux host, so I need to build a Linux CLI to bundle in the container image" - GOOS=linux GOARCH=$(IMAGE_ARCH) go build $(GOFLAGS) -o build/_output/bin/kamel-$(IMAGE_ARCH) ./cmd/kamel/*.go -endif - cp build/_output/bin/kamel-$(IMAGE_ARCH) build/_output/bin/kamel - TARGET_STAGE := base ifeq ($(DEBUG_MODE),true) TARGET_STAGE := debug CUSTOM_IMAGE := $(CUSTOM_IMAGE)-debug endif -DOCKER_TAG := $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -ifneq ($(IMAGE_ARCH), amd64) - DOCKER_TAG := $(DOCKER_TAG)-$(IMAGE_ARCH) -endif +DOCKER_TAG := $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-$(IMAGE_ARCH) -images: build kamel-overlay maven-overlay bundle-kamelets +images: build maven-overlay bundle-kamelets ifneq (,$(findstring SNAPSHOT,$(DEFAULT_RUNTIME_VERSION))) ./script/package_maven_artifacts.sh -s "$(STAGING_RUNTIME_REPO)" -d "$(CAMEL_K_RUNTIME_DIR)" $(DEFAULT_RUNTIME_VERSION) endif @echo "####### Building Camel K operator arch $(IMAGE_ARCH) container image..." mkdir -p build/_maven_output - docker buildx build --target $(TARGET_STAGE) --platform=linux/$(IMAGE_ARCH) -t $(DOCKER_TAG) -f build/Dockerfile . + docker buildx build --target $(TARGET_STAGE) --platform=linux/$(IMAGE_ARCH) --build-arg IMAGE_ARCH=$(IMAGE_ARCH) --load -t $(DOCKER_TAG) -f build/Dockerfile . + docker tag $(DOCKER_TAG) $(CUSTOM_IMAGE):$(CUSTOM_VERSION) # Mainly used for internal CI purposes image-push: docker push $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -images-all: images +# Make sure the current docker builder must supports the wanted platform list, which may not be the case for the default builder +# +# docker buildx inspect +# ... +# Platforms: linux/amd64*, linux/arm64* +# +# +# docker buildx create --name mybuilder --platform linux/amd64,linux/arm64 +# docker buildx use mybuilder +images-all: make IMAGE_ARCH=arm64 images - -images-push: - docker push $(CUSTOM_IMAGE):$(CUSTOM_VERSION) - docker push $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 + make IMAGE_ARCH=amd64 images images-push-staging: - docker tag $(CUSTOM_IMAGE):$(CUSTOM_VERSION) $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION) - docker tag $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-arm64 + docker tag $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-amd64 $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-amd64 + docker tag $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-amd64 $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION) + docker push $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-amd64 docker push $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION) - docker push $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-arm64 - # TODO: we can evaluate the usage of manifest and try the following - # docker manifest create $(CUSTOM_IMAGE):$(CUSTOM_VERSION) \ - # --amend $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-amd64 \ - # --amend $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 - # docker manifest push --purge $(CUSTOM_IMAGE):$(CUSTOM_VERSION) + @if docker inspect $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 &> /dev/null; then \ + echo "Image $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 exists, building the multiarch manifest"; \ + docker tag $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-arm64; \ + docker push $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-arm64; \ + docker manifest create $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION) --amend $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-amd64 --amend $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION)-arm64; \ + docker manifest push --purge $(STAGING_IMAGE_NAME):$(CUSTOM_VERSION); \ + else \ + echo "Image $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-arm64 does not exist"; \ + fi get-image: @echo $(CUSTOM_IMAGE)