Skip to content

Commit

Permalink
chore(e2e-tests): Improve E2E tests
Browse files Browse the repository at this point in the history
- Rename E2E tests commonwithcustominstall to advanced
- Install global Camel K operator when running tests on Kind cluster (operator namespace = default)
- E2E tests are still able to install custom Camel K operators with different operator ID
- Gain test execution speed by copying the CamelCatalog from default namespace instead of recreating it every time a new operator is installed into a temp test namespace
  • Loading branch information
christophd committed Feb 22, 2024
1 parent 6dbc035 commit 53c2b77
Show file tree
Hide file tree
Showing 45 changed files with 109 additions and 237 deletions.
4 changes: 2 additions & 2 deletions .github/actions/e2e-builder/exec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export CAMEL_K_TEST_IMAGE_VERSION=${CUSTOM_VERSION}
export CAMEL_K_TEST_SAVE_FAILED_TEST_NAMESPACE=${SAVE_FAILED_TEST_NS}

if [ -n "${GLOBAL_OPERATOR_NAMESPACE}" ]; then
echo "Info: Tests being run using global operator"
export CAMEL_K_FORCE_GLOBAL_TEST=true
export CAMEL_K_GLOBAL_OPERATOR_NS="${GLOBAL_OPERATOR_NAMESPACE}"
else
export CAMEL_K_GLOBAL_OPERATOR_NS="default"
fi

# Then run integration tests
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/e2e-common/exec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export CAMEL_K_TEST_IMAGE_VERSION=${CUSTOM_VERSION}
export CAMEL_K_TEST_SAVE_FAILED_TEST_NAMESPACE=${SAVE_FAILED_TEST_NS}

if [ -n "${GLOBAL_OPERATOR_NAMESPACE}" ]; then
echo "Info: Tests being run using global operator"
export CAMEL_K_FORCE_GLOBAL_TEST=true
export CAMEL_K_GLOBAL_OPERATOR_NS="${GLOBAL_OPERATOR_NAMESPACE}"
else
export CAMEL_K_GLOBAL_OPERATOR_NS="default"
fi

# Then run all integration tests rather than ending on first failure
Expand All @@ -143,7 +143,7 @@ exit_code=0
if [ "${SMOKE_TEST_ONLY}" == "true" ]; then
DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-smoke || exit_code=1
elif [ "${CUSTOM_INSTALL_TEST}" == "true" ]; then
DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-common-with-custom-install || exit_code=1
DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-advanced || exit_code=1
else
DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-common || exit_code=1
fi
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/e2e-knative/exec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export CAMEL_K_TEST_SAVE_FAILED_TEST_NAMESPACE=${SAVE_FAILED_TEST_NS}
export KAMEL_INSTALL_OPERATOR_ENV_VARS=KAMEL_INSTALL_DEFAULT_KAMELETS=false

if [ -n "${GLOBAL_OPERATOR_NAMESPACE}" ]; then
echo "Info: Tests being run using global operator"
export CAMEL_K_FORCE_GLOBAL_TEST=true
export CAMEL_K_GLOBAL_OPERATOR_NS="${GLOBAL_OPERATOR_NAMESPACE}"
else
export CAMEL_K_GLOBAL_OPERATOR_NS="default"
fi

# Then run integration tests
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/e2e-telemetry/exec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export CAMEL_K_TEST_IMAGE_VERSION=${CUSTOM_VERSION}
export CAMEL_K_TEST_SAVE_FAILED_TEST_NAMESPACE=${SAVE_FAILED_TEST_NS}

if [ -n "${GLOBAL_OPERATOR_NAMESPACE}" ]; then
echo "Info: Tests being run using global operator"
export CAMEL_K_FORCE_GLOBAL_TEST=true
export CAMEL_K_GLOBAL_OPERATOR_NS="${GLOBAL_OPERATOR_NAMESPACE}"
else
export CAMEL_K_GLOBAL_OPERATOR_NS="default"
fi

# Then run all integration telemetry test rather than ending on first failure
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/kamel-config-cluster-custom/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# ---------------------------------------------------------------------------

name: kamel-config-cluster-custom
description: 'Provides configuration for acessing a custom kubernetes cluster'
description: 'Provides configuration for accessing a custom kubernetes cluster'

inputs:
cluster-config-data:
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/kamel-config-cluster-kind/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ outputs:
cluster-has-olm:
description: "Does the cluster have OLM"
value: ${{ steps.extract-config.outputs.cluster-has-olm }}
cluster-global-operator-namespace:
description: "Namespace to install a global operator"
value: ${{ steps.extract-config.outputs.cluster-global-operator-namespace}}
2 changes: 2 additions & 0 deletions .github/actions/kamel-config-cluster-kind/extract-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ echo "cluster-image-registry-push-host=${KIND_REGISTRY}" >> $GITHUB_OUTPUT
echo "cluster-image-registry-pull-host=${KIND_REGISTRY}" >> $GITHUB_OUTPUT
echo "cluster-image-registry-insecure=$(echo true)" >> $GITHUB_OUTPUT

echo "cluster-global-operator-namespace=$(echo default)" >> $GITHUB_OUTPUT

#
# Export the context used for admin and user
# Since kind has no rbac switched on then these can be the same
Expand Down
1 change: 1 addition & 0 deletions .github/actions/kamel-config-cluster/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ runs:
# Does not require global operator name or namespace ... yet
./.github/actions/kamel-config-cluster/output-config.sh \
-a "${{ steps.execute-kind.outputs.cluster-kube-admin-user-ctx }}" \
-g "${{ steps.execute-kind.outputs.cluster-global-operator-namespace }}" \
-n "${{ steps.execute-kind.outputs.cluster-image-namespace }}" \
-o "${{ steps.execute-kind.outputs.cluster-has-olm }}" \
-p "${{ steps.execute-kind.outputs.cluster-image-registry-push-host }}" \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ concurrency:
cancel-in-progress: true

jobs:
common-it-single-operator-installation:
common-it:
runs-on: ubuntu-latest

steps:
Expand All @@ -96,7 +96,7 @@ jobs:
cluster-config-data: ${{ secrets.E2E_CLUSTER_CONFIG }}
cluster-kube-config-data: ${{ secrets.E2E_KUBE_CONFIG }}

common-it-custom-operator-installation:
common-it-advanced:
runs-on: ubuntu-latest

steps:
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/contributing/e2e.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ make test-smoke
The test script will install the operators needed in a random namespace, execute all expected tests and clean themselves. Cleaning may not be performed if the execution of tests fails or the test process is interrupted. In that case you can look for any namespace similar to `test-29ed8147-c9fc-4c04-9c29-744eaf4750c6` and remove it manually.

[[testing-e2e-structure]]
== End To End tests structure
== End-To-End tests structure

We have several kind of end to end tests. Most of them will only require the installation of Camel K operator, but, others need some particular configuration. This is the reason why they may not work out of the box on your cluster. The main goal of the test is to run in a CI environment, so, all requirements are scripted accordingly. If you want to run a test in your cluster, make sure to provide the configuration as expected by the test suite.
We have several kind of end-to-end tests. Most of them will only require the installation of Camel K operator, but, others need some particular configuration. This is the reason why they may not work out of the box on your cluster. The main goal of the test is to run in a CI environment, so, all requirements are scripted accordingly. If you want to run a test in your cluster, make sure to provide the configuration as expected by the test suite.

This is the list of the groups we are using (please, notice that they can slightly change in the future):

* builder (`make test-builder`)
* common (`make test-common`)
* commonwithcustominstall (`make test-common-with-custom-install`)
* advanced (`make test-advanced`)
* install (`make test-install`, `make test-install-olm` and `make test-install-upgrade`)
* knative (`make test-knative`)
* native (`make test-quarkus-native` and `make test-quarkus-native-high-memory`)
* telemetry (`make test-telemetry`)

Each group tests a specific feature of Camel K. Typically any new test should be falling under the `common` group, unless it belongs to any other category or it requires some particular customization. As an example, `telemetry` requires the configuration of an OTLP Collector, reason why it requires its own group. If the test still is a common one but needs to perform customization on the Camel K Operator, then, it should be developed under `commonwithcustominstall`: as an example, we have there tests which requires the configuration of a Maven proxy.
Each group tests a specific feature of Camel K. Typically any new test should be falling under the `common` group, unless it belongs to any other category or it requires some particular customization. As an example, `telemetry` requires the configuration of an OTLP Collector, reason why it requires its own group. If the test still is a common one but needs to perform customization on the Camel K Operator, then, it should be developed under `advanced`: as an example, we have there tests which requires the configuration of a Maven proxy.

It's important to know that a subset of `common` named `test-smoke` is used as smoke test in the nightly release process. We want to keep this group of test as fast as possible.

Expand Down
4 changes: 2 additions & 2 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NOTE: dear contributor, please, keep this organization as clean as you can, upda

* builder
* common
* commonwithcustominstall
* advanced
* install
* knative
* native
Expand All @@ -23,7 +23,7 @@ Contains a basic set of tests required to validate each builder strategy we offe

Full set of test to validate the main project feature. This test will assume the presence of a namespaced operator (installation provided by the same test execution suite). Insert here any test that has to validate any new feature required.

### Commonwithcustominstall
### Advanced

Additional set of test that cover the main common features but that requires some particular operator configuration. In this test suite you must take care of installing the operator as well.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"testing"
Expand All @@ -37,6 +37,7 @@ import (
func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-build-order-deps"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns, "--build-order-strategy", string(v1.BuildOrderStrategyDependencies)).Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

Expand Down Expand Up @@ -119,6 +120,7 @@ func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) {
func TestRunBuildOrderStrategyFIFO(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-build-order-fifo"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns, "--build-order-strategy", string(v1.BuildOrderStrategyFIFO)).Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand All @@ -38,6 +38,7 @@ import (
func TestBuilderTimeout(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
Eventually(Platform(ns)).ShouldNot(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand All @@ -39,6 +39,7 @@ func TestCamelCatalogBuilder(t *testing.T) {

WithNewTestNamespace(t, func(ns string) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
Eventually(Platform(ns)).ShouldNot(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"context"
Expand All @@ -39,6 +39,7 @@ func TestKamelCLIDebug(t *testing.T) {

WithNewTestNamespace(t, func(ns string) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

t.Run("debug local default port check", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"testing"
Expand All @@ -35,9 +35,10 @@ import (

func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
op := "camel-k-failing-deploy"
operatorID := "camel-k-failing-deploy"
nsRestr := "restr"
Expect(KamelInstallWithID(op, ns, "--global", "--force").Execute()).To(Succeed())
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns, "--global", "--force").Execute()).To(Succeed())
// Create restricted namespace
ExpectExecSucceed(t,
exec.Command(
Expand All @@ -64,7 +65,7 @@ func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) {
)
// Create an Integration into a restricted namespace
name := RandomizedSuffixName("java-fail")
Expect(KamelRunWithID(op, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed())
Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed())
// Check the error is reported into the Integration
Eventually(IntegrationPhase(nsRestr, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError))
Eventually(IntegrationCondition(nsRestr, name, v1.IntegrationConditionReady)().Status).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand All @@ -46,6 +46,7 @@ func TestKamelCLIDump(t *testing.T) {

t.Run("dump non-empty namespace", func(t *testing.T) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand Down Expand Up @@ -65,6 +65,7 @@ func TestEnvironmentTrait(t *testing.T) {

// Install Camel K with the HTTP proxy environment variable
operatorID := "camel-k-trait-environment"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns,
"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy),
"--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand All @@ -38,6 +38,7 @@ import (
func TestRunIncrementalBuildRoutine(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-incremental-build"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

name := RandomizedSuffixName("java")
Expand Down Expand Up @@ -89,6 +90,7 @@ func TestRunIncrementalBuildRoutine(t *testing.T) {
func TestRunIncrementalBuildPod(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-incremental-build"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

name := RandomizedSuffixName("java")
Expand Down Expand Up @@ -146,6 +148,7 @@ func TestRunIncrementalBuildPod(t *testing.T) {
func TestRunIncrementalBuildOff(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-standard-build"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

name := RandomizedSuffixName("java")
Expand Down Expand Up @@ -194,6 +197,7 @@ func TestRunIncrementalBuildOff(t *testing.T) {
func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-standard-build"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

name := RandomizedSuffixName("java")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"fmt"
Expand All @@ -38,6 +38,7 @@ func TestKameletFromCustomRepository(t *testing.T) {

WithNewTestNamespace(t, func(ns string) {
operatorID := fmt.Sprintf("camel-k-%s", ns)
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"testing"
Expand All @@ -36,6 +36,7 @@ import (
func TestLocalPlatform(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
operatorID := "camel-k-platform-local"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
Expect(KamelInstallWithID(operatorID, ns, "--global", "--force").Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package commonwithcustominstall
package advanced

import (
"crypto/rand"
Expand Down Expand Up @@ -148,6 +148,7 @@ func TestMavenProxy(t *testing.T) {

// Install Camel K with the HTTP proxy
operatorID := "camel-k-maven-proxy"
Expect(CopyCamelCatalog(ns, operatorID)).To(Succeed())
olm, olmErr := olm.IsAPIAvailable(TestContext, TestClient(), ns)
installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name())
permission, pErr := kubernetes.CheckPermission(TestContext, TestClient(), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit")
Expand Down
Loading

0 comments on commit 53c2b77

Please sign in to comment.