Skip to content

Commit

Permalink
fix: Consistent integration platform settings hierarchy (backport #4317)
Browse files Browse the repository at this point in the history
- Make sure to apply global integration platform settings when creating namespace local platform
- Always derive local platform from operator global platform settings
- Global platform settings resist when the setting is not explicitly overwritten in the given user namespaced integration platform
  • Loading branch information
christophd authored and squakez committed May 11, 2023
1 parent b9d9283 commit b479dbe
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 4 deletions.
103 changes: 103 additions & 0 deletions e2e/global/common/local_platform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//go:build integration
// +build integration

// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"

/*
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.
*/

package common

import (
"testing"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"

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

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

pl := Platform(ns)()
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
if err := TestClient().Update(TestContext, pl); err != nil {
t.Error(err)
t.FailNow()
}

Eventually(PlatformHas(ns, func(pl *v1.IntegrationPlatform) bool {
return pl.Status.Build.MaxRunningBuilds == 1
}), TestTimeoutMedium).Should(BeTrue())

WithNewTestNamespace(t, func(ns1 string) {
localPlatform := v1.NewIntegrationPlatform(ns1, operatorID)
localPlatform.Spec.Build.Maven.Properties = make(map[string]string)
localPlatform.Spec.Build.Maven.Properties["build-local-prop1"] = "build-local-value1"
localPlatform.SetOperatorID(operatorID)

localPlatform.Spec.Traits.Container = &traitv1.ContainerTrait{
LimitCPU: "0.1",
}

if err := TestClient().Create(TestContext, &localPlatform); err != nil {
t.Error(err)
t.FailNow()
}
Eventually(PlatformPhase(ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
Eventually(PlatformHas(ns1, func(pl *v1.IntegrationPlatform) bool {
return pl.Status.Cluster != ""
}), TestTimeoutShort).Should(BeTrue())

Eventually(PlatformHas(ns1, func(pl *v1.IntegrationPlatform) bool {
return pl.Status.Build.MaxRunningBuilds == 1
}), TestTimeoutShort).Should(BeTrue())

local := Platform(ns1)()
Expect(local.Status.Build.PublishStrategy).To(Equal(pl.Status.Build.PublishStrategy))
Expect(local.Status.Build.BuildStrategy).To(Equal(pl.Status.Build.BuildStrategy))
Expect(local.Status.Build.Maven.LocalRepository).To(Equal(pl.Status.Build.Maven.LocalRepository))
Expect(local.Status.Build.Maven.CLIOptions).To(ContainElements(pl.Status.Build.Maven.CLIOptions))
Expect(local.Status.Build.Maven.Extension).To(BeEmpty())
Expect(local.Status.Build.Maven.Properties).To(HaveLen(2))
Expect(local.Status.Build.Maven.Properties["build-global-prop1"]).To(Equal("build-global-value1"))
Expect(local.Status.Build.Maven.Properties["build-local-prop1"]).To(Equal("build-local-value1"))

Expect(KamelRunWithID(operatorID, ns1, "--name", "local-integration", "files/yaml.yaml").Execute()).To(Succeed())
Eventually(IntegrationPod(ns1, "local-integration"), TestTimeoutMedium).Should(Not(BeNil()))
Eventually(IntegrationPodHas(ns1, "local-integration", 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())

// Clean up
Expect(Kamel("delete", "--all", "-n", ns1).Execute()).To(Succeed())
})
})
}
20 changes: 16 additions & 4 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const kubeConfigEnvVar = "KUBECONFIG"

var TestTimeoutShort = 1 * time.Minute
var TestTimeoutMedium = 5 * time.Minute
var TestTimeoutLong = 10 * time.Minute
var TestTimeoutLong = 15 * time.Minute

// TestTimeoutVeryLong should be used only for testing native builds.
var TestTimeoutVeryLong = 60 * time.Minute
Expand All @@ -112,6 +112,7 @@ func setTestLocus(t *testing.T) {
// using the test locus to error out and fail now.
func failTest(err error) {
if testLocus != nil {
testLocus.Helper()
testLocus.Error(err)
testLocus.FailNow()
} else {
Expand Down Expand Up @@ -390,9 +391,9 @@ func MakeWithContext(ctx context.Context, rule string, args ...string) *exec.Cmd
return exec.Command("make", args...)
}

/*
Curryied utility functions for testing
*/
// =============================================================================
// Curried utility functions for testing
// =============================================================================

func IntegrationLogs(ns, name string) func() string {
return func() string {
Expand Down Expand Up @@ -455,6 +456,7 @@ func StructuredLogs(ns, podName string, options corev1.PodLogOptions, ignorePars
err := json.Unmarshal([]byte(t), &entry)
if err != nil {
if ignoreParseErrors {
fmt.Printf("Warning: Ignoring parse error for logging line: %q\n", t)
continue
} else {
log.Errorf(err, "Unable to parse structured content: %s", t)
Expand Down Expand Up @@ -1432,6 +1434,16 @@ func PlatformPhase(ns string) func() v1.IntegrationPlatformPhase {
}
}

func PlatformHas(ns string, predicate func(pl *v1.IntegrationPlatform) bool) func() bool {
return func() bool {
pl := Platform(ns)()
if pl == nil {
return false
}
return predicate(pl)
}
}

func PlatformProfile(ns string) func() v1.TraitProfile {
return func() v1.TraitProfile {
p := Platform(ns)()
Expand Down
Loading

0 comments on commit b479dbe

Please sign in to comment.