Skip to content

Commit

Permalink
fix(e2e): let test install global operators
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Jun 28, 2024
1 parent e8e350f commit 9f1659b
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 159 deletions.
48 changes: 26 additions & 22 deletions e2e/advanced/build_max_pipelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ package advanced

import (
"context"
"errors"
"fmt"
"testing"
"time"

Expand All @@ -41,10 +39,11 @@ type kitOptions struct {
traits []string
}

func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, buildOrderStrategy v1.BuildOrderStrategy) {
func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, condition func(runningBuilds int) bool, buildOrderStrategy v1.BuildOrderStrategy) {
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
InstallOperator(t, ctx, g, ns)

g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.IntegrationPlatformPhaseReady))
pl := Platform(t, ctx, ns)()
// set maximum number of running builds and order strategy
pl.Spec.Build.MaxRunningBuilds = maxRunningBuilds
Expand All @@ -53,6 +52,10 @@ func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, buildOrderStrategy v
t.Error(err)
t.FailNow()
}
g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.IntegrationPlatformPhaseReady))
g.Eventually(PlatformHas(t, ctx, ns, func(pl *v1.IntegrationPlatform) bool {
return pl.Status.Build.MaxRunningBuilds == maxRunningBuilds
}), TestTimeoutShort).Should(BeTrue())

buildA := "integration-a"
buildB := "integration-b"
Expand Down Expand Up @@ -85,22 +88,11 @@ func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, buildOrderStrategy v
},
}, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone)

var notExceedsMaxBuildLimit = func(runningBuilds int) bool {
return runningBuilds <= 2
}

limit := 0
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, 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, ctx, ns, buildA)(), buildA)))
t.FailNow()
}
g.Consistently(BuildsRunning(
BuildPhase(t, ctx, ns, buildA),
BuildPhase(t, ctx, ns, buildB),
BuildPhase(t, ctx, ns, buildC),
), TestTimeoutShort, 10*time.Second).Should(Satisfy(condition))

// verify that all builds are successful
g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded))
Expand All @@ -113,15 +105,27 @@ func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, buildOrderStrategy v
}

func TestKitMaxBuildLimitSequential(t *testing.T) {
kitMaxBuildLimit(t, 2, v1.BuildOrderStrategySequential)
// We must verify we have at least 1 build at a time
var condition = func(runningBuilds int) bool {
return runningBuilds <= 1
}
kitMaxBuildLimit(t, 2, condition, v1.BuildOrderStrategySequential)
}

func TestKitMaxBuildLimitFIFO(t *testing.T) {
kitMaxBuildLimit(t, 2, v1.BuildOrderStrategyFIFO)
// We may have up to 2 parallel builds
var condition = func(runningBuilds int) bool {
return runningBuilds <= 2
}
kitMaxBuildLimit(t, 2, condition, v1.BuildOrderStrategyFIFO)
}

func TestKitMaxBuildLimitDependencies(t *testing.T) {
kitMaxBuildLimit(t, 2, v1.BuildOrderStrategyDependencies)
// We may have up to 2 parallel builds
var condition = func(runningBuilds int) bool {
return runningBuilds <= 2
}
kitMaxBuildLimit(t, 2, condition, v1.BuildOrderStrategyDependencies)
}

func TestMaxBuildLimitWaitingBuilds(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/advanced/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestHTTPProxy(t *testing.T) {
}

// Install Camel K with the HTTP proxy environment variable
InstallOperatorWithConf(t, ctx, g, ns, "",
InstallOperatorWithConf(t, ctx, g, ns, "", false,
map[string]string{
"HTTP_PROXY": httpProxy,
"NO_PROXY": strings.Join(noProxy, ","),
Expand Down
6 changes: 3 additions & 3 deletions e2e/advanced/integration_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestIntegrationProfile(t *testing.T) {

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
operatorID := "camel-k-integration-profile"
InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil)
InstallOperatorWithConf(t, ctx, g, ns, operatorID, true, nil)

integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global")
integrationProfile.SetOperatorID(operatorID)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) {

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
operatorID := "camel-k-ipr-kit"
InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil)
InstallOperatorWithConf(t, ctx, g, ns, operatorID, false, nil)

integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global")
integrationProfile.SetOperatorID(operatorID)
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) {

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
operatorID := "camel-k-ipr-changes"
InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil)
InstallOperatorWithConf(t, ctx, g, ns, operatorID, false, nil)

integrationProfile := v1.NewIntegrationProfile(ns, "debug-profile")
integrationProfile.SetOperatorID(operatorID)
Expand Down
4 changes: 3 additions & 1 deletion e2e/advanced/kamelet_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
corev1 "k8s.io/api/core/v1"

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
)

func TestKameletFromCustomRepository(t *testing.T) {
Expand All @@ -41,10 +42,11 @@ func TestKameletFromCustomRepository(t *testing.T) {
kameletName := "timer-custom-source"
removeKamelet(t, ctx, kameletName, ns)
g.Eventually(Kamelet(t, ctx, kameletName, ns)).Should(BeNil())
g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.IntegrationPlatformPhaseReady))
// Add the custom repository
g.Expect(Kamel(t, ctx, "kamelet", "add-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns).Execute()).To(Succeed())
g.Expect(KamelRun(t, ctx, ns, "files/TimerCustomKameletIntegration.java").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-custom-kamelet-integration"), TestTimeoutLong).
g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-custom-kamelet-integration"), TestTimeoutMedium).
Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns, "timer-custom-kamelet-integration")).Should(ContainSubstring("hello world"))

Expand Down
107 changes: 0 additions & 107 deletions e2e/advanced/local_platform_test.go

This file was deleted.

19 changes: 13 additions & 6 deletions e2e/advanced/maven_http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ func TestMavenProxy(t *testing.T) {
}
noProxy = append(noProxy, svc.Spec.ClusterIPs...)

InstallOperator(t, ctx, g, ns)

InstallOperatorWithConf(t, ctx, g, ns, "", false,
map[string]string{
"HTTP_PROXY": fmt.Sprintf("http://%s", hostname),
"NO_PROXY": strings.Join(noProxy, ","),
},
)
// Check that operator pod has env_vars
g.Eventually(OperatorPodHas(t, ctx, ns, func(op *corev1.Pod) bool {
if envVar := envvar.Get(op.Spec.Containers[0].Env, "HTTP_PROXY"); envVar != nil {
Expand Down Expand Up @@ -186,7 +190,7 @@ func TestMavenProxyNotPresent(t *testing.T) {
t.Parallel()

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
//hostname := fmt.Sprintf("%s.%s.svc", "proxy-fake", ns)
hostname := fmt.Sprintf("%s.%s.svc", "proxy-fake", ns)
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
Expand All @@ -197,9 +201,12 @@ func TestMavenProxyNotPresent(t *testing.T) {
}
noProxy = append(noProxy, svc.Spec.ClusterIPs...)

InstallOperator(t, ctx, g, ns)
//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())

InstallOperatorWithConf(t, ctx, g, ns, "", false,
map[string]string{
"HTTP_PROXY": fmt.Sprintf("http://%s", hostname),
"NO_PROXY": strings.Join(noProxy, ","),
},
)
// Run the Integration
name := RandomizedSuffixName("java")
g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed())
Expand Down
4 changes: 2 additions & 2 deletions e2e/advanced/operator_id_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func TestOperatorIDFiltering(t *testing.T) {
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop1 string) {
operator1 := "operator-1"
InstallOperatorWithConf(t, ctx, g, nsop1, operator1, nil)
InstallOperatorWithConf(t, ctx, g, nsop1, operator1, true, nil)
g.Eventually(PlatformPhase(t, ctx, nsop1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop2 string) {
operator2 := "operator-2"
InstallOperatorWithConf(t, ctx, g, nsop2, operator2, nil)
InstallOperatorWithConf(t, ctx, g, nsop2, operator2, true, nil)
g.Eventually(PlatformPhase(t, ctx, nsop2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

t.Run("Operators ignore non-scoped integrations", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/advanced/operator_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestMetrics(t *testing.T) {

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
// Install Camel K with the log debug enabled
InstallOperatorWithConf(t, ctx, g, ns, "",
InstallOperatorWithConf(t, ctx, g, ns, "", false,
map[string]string{
"LOG_LEVEL": "debug",
},
Expand Down
4 changes: 2 additions & 2 deletions e2e/advanced/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestKamelCLIPromote(t *testing.T) {
// Dev environment namespace
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsDev string) {
operatorDevID := "camel-k-cli-promote-dev"
InstallOperatorWithConf(t, ctx, g, nsDev, operatorDevID, nil)
InstallOperatorWithConf(t, ctx, g, nsDev, operatorDevID, false, nil)
g.Eventually(SelectedPlatformPhase(t, ctx, nsDev, operatorDevID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

// Dev content configmap
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestKamelCLIPromote(t *testing.T) {
// Prod environment namespace
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsProd string) {
operatorProdID := "camel-k-cli-promote-prod"
InstallOperatorWithConf(t, ctx, g, nsProd, operatorProdID, nil)
InstallOperatorWithConf(t, ctx, g, nsProd, operatorProdID, false, nil)
g.Eventually(PlatformPhase(t, ctx, nsProd), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

t.Run("no configmap in destination", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/advanced/synthetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestSyntheticIntegrationFromDeployment(t *testing.T) {

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
// Install Camel K with the proper configuration support
InstallOperatorWithConf(t, ctx, g, ns, "",
InstallOperatorWithConf(t, ctx, g, ns, "", false,
map[string]string{
"CAMEL_K_SYNTHETIC_INTEGRATIONS": "true",
},
Expand Down
6 changes: 0 additions & 6 deletions e2e/install/olm/olm_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,5 @@ func TestOLMInstallation(t *testing.T) {
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, 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, ctx, "uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed())
})
}
2 changes: 1 addition & 1 deletion e2e/knative/knative_pipes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestRunBroker(t *testing.T) {
WithNewTestNamespaceWithKnativeBroker(t, func(ctx context.Context, g *WithT, ns string) {
// This test require an adhoc operator to run properly
operatorID := fmt.Sprintf("camel-k-%s", ns)
InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil)
InstallOperatorWithConf(t, ctx, g, ns, operatorID, false, nil)
g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(camelv1.IntegrationPlatformPhaseReady))

g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativeevt1.yaml").Execute()).To(Succeed())
Expand Down
10 changes: 7 additions & 3 deletions e2e/support/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func GetEnvOrDefault(key string, deflt string) string {
// InstallOperator is in charge to install a namespaced operator. The func must be
// executed in a critical section as there may be concurrent access to it.
func InstallOperator(t *testing.T, ctx context.Context, g *WithT, ns string) {
InstallOperatorWithConf(t, ctx, g, ns, "", nil)
InstallOperatorWithConf(t, ctx, g, ns, "", false, nil)
}

// InstallOperatorWithConf is in charge to install a namespaced operator with additional configurations.
func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, operatorID string, envs map[string]string) {
func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, operatorID string, global bool, envs map[string]string) {
lock.Lock()
defer lock.Unlock()
KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY")
Expand All @@ -96,9 +96,13 @@ func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, op
args = append(args, fmt.Sprintf("ENV=%s", joinedArgs))
}
}
makeRule := "install-k8s-ns"
if global {
makeRule = "install-k8s-global"
}
os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../")
ExpectExecSucceed(t, g,
Make(t, "install-k8s-ns", args...),
Make(t, makeRule, args...),
)
// Let's make sure the operator has been deployed
g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil())
Expand Down
Loading

0 comments on commit 9f1659b

Please sign in to comment.