You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/09/09 09:52:39 UTC
[camel-k] branch main updated (a8e6810 -> 49c0903)
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from a8e6810 Updated CHANGELOG.md
new 41b7ccf feat: Switch on Quarkus native build
new 34956df chore(s2i): Use tar.gz archive to preserve file permissions
new 62513d5 chore(native): Move to quarkus-distroless-image base image for native builds
new 446f2d2 feat(native): Use Mandrel as operator/builder image
new aec61ef feat(native): Configure Integration runtime depending on Quarkus packaging type
new 41581b0 feat(native): Configure Build depending on Quarkus packaging type
new fb3d1fe feat(native): Split builder task Dockerfile JVM/native steps
new e6d13fa chore(native): Set working directory in JVM trait
new 622dbdd feat(native): Preserve file permissions when copying image context
new 8b130dd feat(native): Exclude native kits from incremental base image lookup
new eff1b4f chore(native): No need to compute transitive dependencies for native builds
new 5bb3b26 chore(native): Report the native runner as the only image artifact
new 3dd8cc3 chore(native): Upgrade Maven to version 3.8.2
new a53c5bf feat(native): Enable builds to run concurrently
new b456c98 feat(native): Support native build with Spectrum strategy
new 546759f chore(native): Remove unused IntegrationPhaseResolvingKit phase
new b35a9b3 chore(native): Simplify integration transition out of kit building phase
new 7840bf6 fix(native): Only evaluate Quarkus packaging for JVM trait active phases
new 8fded21 feat(native): Add multi-kit support with prioritization
new 6d20fb0 chore(native): Pass current kit to evaluate traits for running Integrations
new 2bbbba1 chore(native): Polish build kit logic
new d2cb79c fix(native): Do not add default Quarkus trait configuration to kit
new aecb231 chore(trait): Remove trait context and the InjectContext interface
new 0176e13 feat(native): Add type label to build metrics
new d7384cf fix(native): Fix comparable trait configuration unmarshaling
new 48525da feat(native): Automatic rollout to highest priority kit
new 6430399 feat(native): Lenient trait matching
new 50edc77 chore(native): Polish native checks logic
new 3a8d5c5 chore(e2e): Remove redundant Quarkus trait e2e test
new a9242cf feat(native): Add builder native e2e test
new d6500f7 fix(e2e): Increase build timeout for native tests
new 55f8525 fix(cli): Do not skip dependencies in kit create command
new 95af8de feat(native): Automatic rollout deployment to native kit e2e test
new eef9d5f chore(native): Rebuild resources
new 2e4eaac feat(native): Increase native build timeout to sensible default
new fe6b24c test(native): Add memory limits to build e2e tests
new 49c0903 doc(native): Add automatic rollout to native integration example
The 37 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/workflows/kubernetes.yml | 3 +-
addons/master/master.go | 4 +-
addons/tracing/tracing.go | 2 +-
build/Dockerfile | 19 +-
cmd/util/doc-gen/generators/traitdocgen.go | 12 +-
deploy/traits.yaml | 22 +-
docs/modules/traits/pages/deployer.adoc | 4 +-
docs/modules/traits/pages/quarkus.adoc | 33 ++-
e2e/builder/build_test.go | 60 ++++-
e2e/builder/global_test.go | 20 +-
e2e/common/languages/yaml_test.go | 9 -
e2e/common/operator_metrics_test.go | 5 +
e2e/native/native_test.go | 93 +++++++
e2e/{upgrade/files => native}/yaml.yaml | 0
e2e/support/test_support.go | 120 ++++++---
e2e/upgrade/cli_upgrade_test.go | 16 +-
e2e/upgrade/olm_upgrade_test.go | 8 +-
pkg/apis/camel/v1/build_types_support.go | 16 +-
pkg/apis/camel/v1/integration_types.go | 5 +-
pkg/apis/camel/v1/integrationkit_types.go | 16 +-
pkg/apis/camel/v1/integrationkit_types_support.go | 36 +--
pkg/builder/builder.go | 13 +-
pkg/builder/image.go | 111 ++++++--
pkg/builder/image_test.go | 4 +-
pkg/builder/project.go | 29 +-
pkg/builder/project_test.go | 4 +-
pkg/builder/quarkus.go | 31 +--
pkg/builder/s2i.go | 72 ++++-
pkg/builder/spectrum.go | 21 +-
pkg/builder/steps.go | 12 +
pkg/cmd/completion_bash.go | 9 +-
pkg/cmd/describe_kit.go | 8 +-
pkg/cmd/kit_create.go | 32 +--
pkg/cmd/kit_delete.go | 33 ++-
pkg/cmd/kit_get.go | 2 +-
pkg/cmd/run.go | 2 +-
pkg/cmd/run_test.go | 2 +-
pkg/cmd/trait_help.go | 4 +-
pkg/controller/build/metrics.go | 24 +-
pkg/controller/build/schedule.go | 38 ++-
pkg/controller/integration/build_kit.go | 293 ++++-----------------
pkg/controller/integration/build_kit_test.go | 38 ++-
pkg/controller/integration/initialize.go | 2 +-
.../integration/integration_controller.go | 66 ++---
pkg/controller/integration/kits.go | 266 +++++++++++++++++++
pkg/controller/integration/monitor.go | 75 +++++-
pkg/controller/integrationkit/build.go | 16 +-
.../integrationkit/integrationkit_controller.go | 2 +-
pkg/resources/resources.go | 4 +-
pkg/trait/builder.go | 11 +-
pkg/trait/builder_test.go | 6 +-
pkg/trait/camel.go | 6 +-
pkg/trait/camel_test.go | 2 +-
pkg/trait/container.go | 6 +-
pkg/trait/container_test.go | 16 +-
pkg/trait/cron.go | 2 +-
pkg/trait/cron_test.go | 21 +-
pkg/trait/dependencies.go | 2 +-
pkg/trait/deployer.go | 77 +++---
pkg/trait/deployer_test.go | 13 +-
pkg/trait/deployment_test.go | 5 +-
pkg/trait/environment_test.go | 9 +-
pkg/trait/gc.go | 13 +-
pkg/trait/gc_test.go | 3 +-
pkg/trait/ingress_test.go | 3 +-
pkg/trait/jolokia_test.go | 3 +-
pkg/trait/jvm.go | 25 +-
pkg/trait/jvm_test.go | 6 +-
pkg/trait/kamelets.go | 8 +-
pkg/trait/kamelets_test.go | 4 +-
pkg/trait/knative.go | 16 +-
pkg/trait/knative_service.go | 4 +-
pkg/trait/knative_service_test.go | 7 +-
pkg/trait/knative_test.go | 15 +-
pkg/trait/logging_test.go | 6 +-
pkg/trait/openapi.go | 10 +-
pkg/trait/platform.go | 2 +-
pkg/trait/prometheus_test.go | 5 +-
pkg/trait/pull_secret.go | 4 +-
pkg/trait/pull_secret_test.go | 4 +-
pkg/trait/quarkus.go | 260 +++++++++++++++++-
pkg/trait/quarkus_test.go | 38 ++-
pkg/trait/route_test.go | 3 +-
pkg/trait/service.go | 2 +-
pkg/trait/service_binding.go | 2 +-
pkg/trait/service_test.go | 11 +-
pkg/trait/trait.go | 4 +-
pkg/trait/trait_catalog.go | 16 +-
pkg/trait/trait_configure.go | 5 +-
pkg/trait/trait_configure_test.go | 17 +-
pkg/trait/trait_test.go | 11 +-
pkg/trait/trait_types.go | 75 +++---
pkg/trait/util.go | 8 +-
pkg/util/controller/util.go | 45 ----
pkg/util/kubernetes/client.go | 78 ++----
pkg/util/maven/maven_command.go | 7 +-
pkg/util/util.go | 88 +++----
pkg/util/zip/zip.go | 64 -----
script/Makefile | 28 +-
99 files changed, 1681 insertions(+), 1111 deletions(-)
create mode 100644 e2e/native/native_test.go
copy e2e/{upgrade/files => native}/yaml.yaml (100%)
create mode 100644 pkg/controller/integration/kits.go
delete mode 100644 pkg/util/controller/util.go
delete mode 100644 pkg/util/zip/zip.go
[camel-k] 02/37: chore(s2i): Use tar.gz archive to preserve file
permissions
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 34956df3c99cb0d86f11483dc881596940fb1178
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jul 29 11:36:41 2021 +0200
chore(s2i): Use tar.gz archive to preserve file permissions
---
pkg/builder/s2i.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++----
pkg/util/zip/zip.go | 64 -----------------------------------------------
2 files changed, 67 insertions(+), 69 deletions(-)
diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index 428901a..6ce99b6 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -18,10 +18,16 @@ limitations under the License.
package builder
import (
+ "archive/tar"
+ "compress/gzip"
"context"
+ "fmt"
+ "io"
"io/ioutil"
"os"
"path"
+ "path/filepath"
+ "strings"
"time"
"github.com/pkg/errors"
@@ -42,7 +48,6 @@ import (
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/util/kubernetes/customclient"
"github.com/apache/camel-k/pkg/util/log"
- "github.com/apache/camel-k/pkg/util/zip"
)
type s2iTask struct {
@@ -140,7 +145,7 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
if err != nil {
return status.Failed(err)
}
- archive := path.Join(tmpDir, "archive.zip")
+ archive := path.Join(tmpDir, "archive.tar.gz")
defer os.RemoveAll(tmpDir)
contextDir := t.task.ContextDir
@@ -156,14 +161,19 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
contextDir = path.Join(pwd, ContextDir)
}
- err = zip.Directory(contextDir, archive)
+ archiveFile, err := os.Create(archive)
if err != nil {
- return status.Failed(errors.Wrap(err, "cannot zip context directory"))
+ return status.Failed(errors.Wrap(err, "cannot create tar archive"))
+ }
+
+ err = tarDir(contextDir, archiveFile)
+ if err != nil {
+ return status.Failed(errors.Wrap(err, "cannot tar context directory"))
}
resource, err := ioutil.ReadFile(archive)
if err != nil {
- return status.Failed(errors.Wrap(err, "cannot fully read zip file "+archive))
+ return status.Failed(errors.Wrap(err, "cannot read tar file "+archive))
}
restClient, err := customclient.GetClientFor(t.c, "build.openshift.io", "v1")
@@ -275,3 +285,55 @@ func (t *s2iTask) cancelBuild(ctx context.Context, build *buildv1.Build) error {
*build = *target
return nil
}
+
+func tarDir(src string, writers ...io.Writer) error {
+ // ensure the src actually exists before trying to tar it
+ if _, err := os.Stat(src); err != nil {
+ return fmt.Errorf("unable to tar files - %v", err.Error())
+ }
+
+ mw := io.MultiWriter(writers...)
+
+ gzw := gzip.NewWriter(mw)
+ defer gzw.Close()
+
+ tw := tar.NewWriter(gzw)
+ defer tw.Close()
+
+ return filepath.Walk(src, func(file string, fi os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if !fi.Mode().IsRegular() {
+ return nil
+ }
+
+ header, err := tar.FileInfoHeader(fi, fi.Name())
+ if err != nil {
+ return err
+ }
+
+ // update the name to correctly reflect the desired destination when un-taring
+ header.Name = strings.TrimPrefix(strings.Replace(file, src, "", -1), string(filepath.Separator))
+
+ if err := tw.WriteHeader(header); err != nil {
+ return err
+ }
+
+ f, err := os.Open(file)
+ if err != nil {
+ return err
+ }
+
+ if _, err := io.Copy(tw, f); err != nil {
+ return err
+ }
+
+ // manually close here after each file operation; deferring would cause each file close
+ // to wait until all operations have completed.
+ f.Close()
+
+ return nil
+ })
+}
diff --git a/pkg/util/zip/zip.go b/pkg/util/zip/zip.go
deleted file mode 100644
index a5f59de..0000000
--- a/pkg/util/zip/zip.go
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-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 zip
-
-import (
- "archive/zip"
- "io"
- "os"
- "path/filepath"
- "strings"
-)
-
-func Directory(pathToZip, destinationPath string) error {
- destinationFile, err := os.Create(destinationPath)
- if err != nil {
- return err
- }
- myZip := zip.NewWriter(destinationFile)
- err = filepath.Walk(pathToZip, func(filePath string, info os.FileInfo, err error) error {
- if info.IsDir() {
- return nil
- }
- if err != nil {
- return err
- }
- relPath := strings.TrimPrefix(filePath, pathToZip)
- zipFile, err := myZip.Create(relPath)
- if err != nil {
- return err
- }
- fsFile, err := os.Open(filePath)
- if err != nil {
- return err
- }
- _, err = io.Copy(zipFile, fsFile)
- if err != nil {
- return err
- }
- return nil
- })
- if err != nil {
- return err
- }
- err = myZip.Close()
- if err != nil {
- return err
- }
- return nil
-}
[camel-k] 24/37: feat(native): Add type label to build metrics
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 0176e135c1e1bcf5cce960e1cf3fca23610d59b9
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 27 11:37:16 2021 +0200
feat(native): Add type label to build metrics
---
e2e/common/operator_metrics_test.go | 5 +++++
pkg/controller/build/metrics.go | 24 ++++++++++++++++++++----
pkg/controller/build/schedule.go | 3 +--
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/e2e/common/operator_metrics_test.go b/e2e/common/operator_metrics_test.go
index abb92b3..dc10029 100644
--- a/e2e/common/operator_metrics_test.go
+++ b/e2e/common/operator_metrics_test.go
@@ -115,6 +115,7 @@ func TestMetrics(t *testing.T) {
{
Label: []*prometheus.LabelPair{
label("result", "Succeeded"),
+ label("type", "fast-jar"),
},
Histogram: &prometheus.Histogram{
SampleCount: uint64P(1),
@@ -151,6 +152,7 @@ func TestMetrics(t *testing.T) {
{
Label: []*prometheus.LabelPair{
label("result", "Succeeded"),
+ label("type", "fast-jar"),
},
Histogram: &prometheus.Histogram{
SampleCount: uint64P(1),
@@ -367,6 +369,9 @@ func TestMetrics(t *testing.T) {
Type: metricTypeP(prometheus.MetricType_HISTOGRAM),
Metric: []*prometheus.Metric{
{
+ Label: []*prometheus.LabelPair{
+ label("type", "fast-jar"),
+ },
Histogram: &prometheus.Histogram{
SampleCount: uint64P(1),
SampleSum: histogram.SampleSum,
diff --git a/pkg/controller/build/metrics.go b/pkg/controller/build/metrics.go
index 16fd330..387f117 100644
--- a/pkg/controller/build/metrics.go
+++ b/pkg/controller/build/metrics.go
@@ -28,7 +28,10 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
)
-const buildResultLabel = "result"
+const (
+ buildResultLabel = "result"
+ buildTypeLabel = "type"
+)
var (
buildDuration = prometheus.NewHistogramVec(
@@ -46,6 +49,7 @@ var (
},
[]string{
buildResultLabel,
+ buildTypeLabel,
},
)
@@ -57,10 +61,11 @@ var (
},
[]string{
buildResultLabel,
+ buildTypeLabel,
},
)
- queueDuration = prometheus.NewHistogram(
+ queueDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "camel_k_build_queue_duration_seconds",
Help: "Camel K build queue duration",
@@ -72,6 +77,9 @@ var (
5 * time.Minute.Seconds(),
},
},
+ []string{
+ buildTypeLabel,
+ },
)
)
@@ -80,6 +88,11 @@ func init() {
metrics.Registry.MustRegister(buildDuration, buildRecovery, queueDuration)
}
+func observeBuildQueueDuration(build *v1.Build) {
+ queueDuration.WithLabelValues(build.Labels[v1.IntegrationKitLayoutLabel]).
+ Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
+}
+
func observeBuildResult(build *v1.Build, phase v1.BuildPhase, duration time.Duration) {
attempt, attemptMax := getBuildAttemptFor(build)
@@ -89,8 +102,11 @@ func observeBuildResult(build *v1.Build, phase v1.BuildPhase, duration time.Dura
phase = v1.BuildPhaseError
}
- buildRecovery.WithLabelValues(phase.String()).Observe(float64(attempt))
- buildDuration.WithLabelValues(phase.String()).Observe(duration.Seconds())
+ resultLabel := phase.String()
+ typeLabel := build.Labels[v1.IntegrationKitLayoutLabel]
+
+ buildRecovery.WithLabelValues(resultLabel, typeLabel).Observe(float64(attempt))
+ buildDuration.WithLabelValues(resultLabel, typeLabel).Observe(duration.Seconds())
}
func getBuildAttemptFor(build *v1.Build) (int, int) {
diff --git a/pkg/controller/build/schedule.go b/pkg/controller/build/schedule.go
index c49b904..93cffd9 100644
--- a/pkg/controller/build/schedule.go
+++ b/pkg/controller/build/schedule.go
@@ -20,7 +20,6 @@ package build
import (
"context"
"sync"
- "time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@@ -119,7 +118,7 @@ func (action *scheduleAction) toPendingPhase(ctx context.Context, build *v1.Buil
}
// Report the duration the Build has been waiting in the build queue
- queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
+ observeBuildQueueDuration(build)
return nil
}
[camel-k] 07/37: feat(native): Split builder task Dockerfile
JVM/native steps
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fb3d1fe58b326d02ef3dbd3af8b262aa1d4d73d1
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Aug 16 15:36:35 2021 +0200
feat(native): Split builder task Dockerfile JVM/native steps
---
pkg/builder/image.go | 45 +++++++++++++++++++++++++++++++++------------
pkg/builder/project.go | 4 ++++
pkg/trait/quarkus.go | 4 ++--
pkg/trait/quarkus_test.go | 2 +-
4 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 4a35be5..8aca5a6 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -57,6 +57,23 @@ func nativeImageContext(ctx *builderContext) error {
})
}
+func executableDockerfile(ctx *builderContext) error {
+ // #nosec G202
+ dockerfile := []byte(`
+ FROM ` + ctx.BaseImage + `
+ WORKDIR ` + DeploymentDir + `
+ COPY --chown=nonroot:root . ` + DeploymentDir + `
+ USER nonroot
+ `)
+
+ err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0777)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
func standardImageContext(ctx *builderContext) error {
return imageContext(ctx, func(ctx *builderContext) error {
ctx.SelectedArtifacts = ctx.Artifacts
@@ -65,6 +82,22 @@ func standardImageContext(ctx *builderContext) error {
})
}
+func jvmDockerfile(ctx *builderContext) error {
+ // #nosec G202
+ dockerfile := []byte(`
+ FROM ` + ctx.BaseImage + `
+ ADD . ` + DeploymentDir + `
+ USER 1000
+ `)
+
+ err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0777)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
func incrementalImageContext(ctx *builderContext) error {
if ctx.Build.BaseImage != "" {
// If the build requires a specific image, don't try to determine the
@@ -129,18 +162,6 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
}
}
- // #nosec G202
- dockerfile := []byte(`
- FROM ` + ctx.BaseImage + `
- COPY --chown=nonroot:root . ` + DeploymentDir + `
- USER nonroot
- `)
-
- err = ioutil.WriteFile(path.Join(contextDir, "Dockerfile"), dockerfile, 0777)
- if err != nil {
- return err
- }
-
return nil
}
diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index 6cb8a0b..517e879 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -38,6 +38,8 @@ type steps struct {
IncrementalImageContext Step
NativeImageContext Step
StandardImageContext Step
+ ExecutableDockerfile Step
+ JvmDockerfile Step
}
var Steps = steps{
@@ -49,6 +51,8 @@ var Steps = steps{
IncrementalImageContext: NewStep(ApplicationPackagePhase, incrementalImageContext),
NativeImageContext: NewStep(ApplicationPackagePhase, nativeImageContext),
StandardImageContext: NewStep(ApplicationPackagePhase, standardImageContext),
+ ExecutableDockerfile: NewStep(ApplicationPackagePhase+1, executableDockerfile),
+ JvmDockerfile: NewStep(ApplicationPackagePhase+1, jvmDockerfile),
}
var DefaultSteps = []Step{
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 47f1f95..b43e045 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -87,10 +87,10 @@ func (t *quarkusTrait) Apply(e *Environment) error {
if t.isNativePackageType() {
build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
- steps = append(steps, builder.Steps.NativeImageContext)
+ steps = append(steps, builder.Steps.NativeImageContext, builder.Steps.ExecutableDockerfile)
} else {
build.Maven.Properties["quarkus.package.type"] = string(fastJarPackageType)
- steps = append(steps, builder.Steps.IncrementalImageContext)
+ steps = append(steps, builder.Steps.IncrementalImageContext, builder.Steps.JvmDockerfile)
}
// Sort steps by phase
diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go
index 688194a..7f4d970 100644
--- a/pkg/trait/quarkus_test.go
+++ b/pkg/trait/quarkus_test.go
@@ -42,7 +42,7 @@ func TestConfigureQuarkusTraitBuildSubmitted(t *testing.T) {
build := getBuilderTask(environment.BuildTasks)
assert.NotNil(t, t, build)
- assert.Len(t, build.Steps, len(builder.QuarkusSteps)+1)
+ assert.Len(t, build.Steps, len(builder.QuarkusSteps)+2)
}
func TestConfigureDisabledQuarkusTraitShouldFail(t *testing.T) {
[camel-k] 36/37: test(native): Add memory limits to build e2e tests
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fe6b24c49eeb0a0aa3e81c1c2e343f3c0d1dc717
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Sep 8 12:06:49 2021 +0200
test(native): Add memory limits to build e2e tests
---
e2e/builder/build_test.go | 25 ++++++++++++++++++++-----
e2e/native/native_test.go | 5 ++++-
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go
index 1e4bfe6..3d350f6 100644
--- a/e2e/builder/build_test.go
+++ b/e2e/builder/build_test.go
@@ -22,6 +22,7 @@ limitations under the License.
package builder
import (
+ "os"
"testing"
"time"
@@ -29,6 +30,7 @@ import (
. "github.com/apache/camel-k/e2e/support"
"github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/pkg/util/openshift"
)
type kitOptions struct {
@@ -37,7 +39,7 @@ type kitOptions struct {
}
func TestKitTimerToLogFullBuild(t *testing.T) {
- doKitFullBuild(t, "timer-to-log", "5m0s", TestTimeoutLong, kitOptions{
+ doKitFullBuild(t, "timer-to-log", "300Mi", "5m0s", TestTimeoutLong, kitOptions{
dependencies: []string{
"camel:timer", "camel:log",
},
@@ -45,7 +47,7 @@ func TestKitTimerToLogFullBuild(t *testing.T) {
}
func TestKitKnativeFullBuild(t *testing.T) {
- doKitFullBuild(t, "knative", "5m0s", TestTimeoutLong, kitOptions{
+ doKitFullBuild(t, "knative", "300mi", "5m0s", TestTimeoutLong, kitOptions{
dependencies: []string{
"camel-k-knative",
},
@@ -53,7 +55,7 @@ func TestKitKnativeFullBuild(t *testing.T) {
}
func TestKitTimerToLogFullNativeBuild(t *testing.T) {
- doKitFullBuild(t, "timer-to-log", "15m0s", 2*TestTimeoutLong, kitOptions{
+ doKitFullBuild(t, "timer-to-log", "4Gi", "15m0s", 2*TestTimeoutLong, kitOptions{
dependencies: []string{
"camel:timer", "camel:log",
},
@@ -63,9 +65,21 @@ func TestKitTimerToLogFullNativeBuild(t *testing.T) {
})
}
-func doKitFullBuild(t *testing.T, name string, buildTimeout string, testTimeout time.Duration, options kitOptions) {
+func doKitFullBuild(t *testing.T, name string, memoryLimit string, buildTimeout string, testTimeout time.Duration, options kitOptions) {
WithNewTestNamespace(t, func(ns string) {
- Expect(Kamel("install", "-n", ns, "--build-timeout", buildTimeout).Execute()).To(Succeed())
+ strategy := os.Getenv("KAMEL_INSTALL_BUILD_PUBLISH_STRATEGY")
+ ocp, err := openshift.IsOpenShift(TestClient())
+ Expect(err).To(Succeed())
+
+ args := []string{"install", "-n", ns}
+ args = append(args, "--build-timeout", buildTimeout)
+ // TODO: configure build Pod resources if applicable
+ if strategy == "Spectrum" || ocp {
+ args = append(args, "--operator-resources", "limits.memory="+memoryLimit)
+ }
+
+ Expect(Kamel(args...).Execute()).To(Succeed())
+
buildKitArgs := []string{"kit", "create", name, "-n", ns}
for _, dependency := range options.dependencies {
buildKitArgs = append(buildKitArgs, "-d", dependency)
@@ -74,6 +88,7 @@ func doKitFullBuild(t *testing.T, name string, buildTimeout string, testTimeout
buildKitArgs = append(buildKitArgs, "-t", trait)
}
Expect(Kamel(buildKitArgs...).Execute()).To(Succeed())
+
Eventually(Build(ns, name)).ShouldNot(BeNil())
Eventually(BuildPhase(ns, name), testTimeout).Should(Equal(v1.BuildPhaseSucceeded))
Eventually(KitPhase(ns, name), testTimeout).Should(Equal(v1.IntegrationKitPhaseReady))
diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
index e3fd7ca..a1ea20b 100644
--- a/e2e/native/native_test.go
+++ b/e2e/native/native_test.go
@@ -39,7 +39,10 @@ var (
func TestAutomaticRolloutDeploymentFromFastJarToNativeKit(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
- Expect(Kamel("install", "-n", ns, "--build-timeout", "15m0s").Execute()).To(Succeed())
+ Expect(Kamel("install", "-n", ns,
+ "--build-timeout", "15m0s",
+ "--operator-resources", "limits.memory=4Gi",
+ ).Execute()).To(Succeed())
Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
name := "jvm-to-native"
[camel-k] 27/37: feat(native): Lenient trait matching
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 6430399d143ff45dde5b584e90571f5fd2ee5a47
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Aug 31 12:27:18 2021 +0200
feat(native): Lenient trait matching
---
pkg/controller/integration/build_kit.go | 37 +-------
pkg/controller/integration/build_kit_test.go | 14 +--
pkg/controller/integration/kits.go | 122 ++++++++++++++++-----------
pkg/trait/quarkus.go | 24 ++++--
pkg/trait/trait_catalog.go | 10 +--
pkg/trait/trait_test.go | 6 +-
6 files changed, 104 insertions(+), 109 deletions(-)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index a0fee46..aab2ba2 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -24,8 +24,6 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/trait"
- "github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/kubernetes"
)
@@ -97,7 +95,7 @@ kits:
for _, kit := range env.IntegrationKits {
kit := kit
for i, k := range existingKits {
- match, err := action.kitMatches(&kit, &k)
+ match, err := kitMatches(&kit, &k)
if err != nil {
return nil, err
}
@@ -128,36 +126,3 @@ kits:
return integration, nil
}
-
-
-// kitMatches returns whether the v1.IntegrationKit match
-func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.IntegrationKit) (bool, error) {
- version := k1.Status.Version
- if version == "" {
- // Defaults with the version that is going to be set during the kit initialization
- version = defaults.Version
- }
- if version != k2.Status.Version {
- return false, nil
- }
- if len(k1.Spec.Dependencies) != len(k2.Spec.Dependencies) {
- return false, nil
- }
- if len(k1.Spec.Traits) != len(k2.Spec.Traits) {
- return false, nil
- }
- for name, kt1 := range k1.Spec.Traits {
- kt2, ok := k2.Spec.Traits[name]
- if !ok {
- return false, nil
- }
- match, err := hasMatchingTrait(&kt1, &kt2)
- if !match || err != nil {
- return false, err
- }
- }
- if !util.StringSliceContains(k1.Spec.Dependencies, k2.Spec.Dependencies) {
- return false, nil
- }
- return true, nil
-}
diff --git a/pkg/controller/integration/build_kit_test.go b/pkg/controller/integration/build_kit_test.go
index 430dc38..8c9f749 100644
--- a/pkg/controller/integration/build_kit_test.go
+++ b/pkg/controller/integration/build_kit_test.go
@@ -109,9 +109,7 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T) {
c, err := test.NewFakeClient(
- //
// Should be discarded because it does not contain the required traits
- //
&v1.IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
@@ -134,10 +132,8 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
Phase: v1.IntegrationKitPhaseReady,
},
},
- //
// Should be discarded because it contains a subset of the required traits but
// with different configuration value
- //
&v1.IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
@@ -165,10 +161,8 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
Phase: v1.IntegrationKitPhaseReady,
},
},
- //
// Should NOT be discarded because it contains a subset of the required traits and
// same configuration values
- //
&v1.IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
@@ -259,7 +253,7 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) {
},
}
- integrationKitSpec := &v1.IntegrationKit{
+ kit := &v1.IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKitKind,
@@ -276,7 +270,7 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := hasMatchingTraits(integration, integrationKitSpec)
+ ok, err := hasMatchingTraits(integration.Spec.Traits, kit.Spec.Traits)
assert.Nil(t, err)
assert.False(t, ok)
}
@@ -303,7 +297,7 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) {
},
}
- integrationKitSpec := &v1.IntegrationKit{
+ kit := &v1.IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKitKind,
@@ -327,7 +321,7 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := hasMatchingTraits(integration, integrationKitSpec)
+ ok, err := hasMatchingTraits(integration.Spec.Traits, kit.Spec.Traits)
assert.Nil(t, err)
assert.True(t, ok)
}
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index 2a7eab0..49927da 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -22,7 +22,7 @@ import (
"encoding/json"
"reflect"
- k8serrors "k8s.io/apimachinery/pkg/api/errors"
+ "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
@@ -32,11 +32,12 @@ import (
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
+ "github.com/apache/camel-k/pkg/util/defaults"
)
func lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration, options ...ctrl.ListOption) ([]v1.IntegrationKit, error) {
pl, err := platform.GetCurrent(ctx, c, integration.Namespace)
- if err != nil && !k8serrors.IsNotFound(err) {
+ if err != nil && !errors.IsNotFound(err) {
return nil, err
}
@@ -106,7 +107,7 @@ func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bo
//
// A kit can be used only if it contains a subset of the traits and related configurations
// declared on integration.
- if match, err := hasMatchingTraits(integration, kit); !match || err != nil {
+ if match, err := hasMatchingTraits(integration.Spec.Traits, kit.Spec.Traits); !match || err != nil {
return false, err
}
if !util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies) {
@@ -115,89 +116,110 @@ func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bo
return true, nil
}
-// hasMatchingTraits compares the traits defined on the v1.Integration with those defined on the v1.IntegrationKit
-func hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
- catalog := trait.NewCatalog(nil)
+// kitMatches returns whether the two v1.IntegrationKit match
+func kitMatches(kit1 *v1.IntegrationKit, kit2 *v1.IntegrationKit) (bool, error) {
+ version := kit1.Status.Version
+ if version == "" {
+ // Defaults with the version that is going to be set during the kit initialization
+ version = defaults.Version
+ }
+ if version != kit2.Status.Version {
+ return false, nil
+ }
+ if len(kit1.Spec.Dependencies) != len(kit2.Spec.Dependencies) {
+ return false, nil
+ }
+ if match, err := hasMatchingTraits(kit1.Spec.Traits, kit2.Spec.Traits); !match || err != nil {
+ return false, err
+ }
+ if !util.StringSliceContains(kit1.Spec.Dependencies, kit2.Spec.Dependencies) {
+ return false, nil
+ }
+ return true, nil
+}
- traitCount := 0
- for name, itTrait := range integration.Spec.Traits {
- t := catalog.GetTrait(name)
+func hasMatchingTraits(traits1 map[string]v1.TraitSpec, traits2 map[string]v1.TraitSpec) (bool, error) {
+ catalog := trait.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
}
- traitCount++
- kitTrait, ok := kit.Spec.Traits[name]
- if !ok {
- // skip it because trait configured on integration is not defined on kit
- return false, nil
+ id := string(t.ID())
+ t1, ok1 := traits1[id]
+ t2, ok2 := traits2[id]
+
+ if !ok1 && !ok2 {
+ continue
}
if ct, ok := t.(trait.ComparableTrait); ok {
- comparable, err := hasComparableTrait(ct, &itTrait, &kitTrait)
- if !comparable || err != nil {
+ if comparable, err := hasComparableTrait(ct, &t1, &t2); err != nil {
return false, err
+ } else if comparable {
+ continue
}
- } else {
- match, err := hasMatchingTrait(&itTrait, &kitTrait)
- if !match || err != nil {
+ } else if ok1 && ok2 {
+ if match, err := hasMatchingTrait(&t1, &t2); err != nil {
return false, err
+ } else if match {
+ continue
}
}
- }
-
- // Check the number of influencing traits matches
- if len(kit.Spec.Traits) != traitCount {
return false, nil
}
return true, nil
}
-func hasComparableTrait(c trait.ComparableTrait, itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
- it := reflect.New(reflect.TypeOf(c).Elem()).Interface()
- data, err := json.Marshal(itTrait.Configuration)
- if err != nil {
- return false, err
- }
- err = json.Unmarshal(data, &it)
- if err != nil {
- return false, err
+func hasComparableTrait(t trait.ComparableTrait, ts1 *v1.TraitSpec, ts2 *v1.TraitSpec) (bool, error) {
+ t1 := reflect.New(reflect.TypeOf(t).Elem()).Interface()
+ if ts1.Configuration.RawMessage != nil {
+ data, err := json.Marshal(ts1.Configuration)
+ if err != nil {
+ return false, err
+ }
+ err = json.Unmarshal(data, &t1)
+ if err != nil {
+ return false, err
+ }
}
- kt := reflect.New(reflect.TypeOf(c).Elem()).Interface()
- data, err = json.Marshal(kitTrait.Configuration)
- if err != nil {
- return false, err
- }
- err = json.Unmarshal(data, &kt)
- if err != nil {
- return false, err
+ t2 := reflect.New(reflect.TypeOf(t).Elem()).Interface()
+ if ts2.Configuration.RawMessage != nil {
+ data, err := json.Marshal(ts2.Configuration)
+ if err != nil {
+ return false, err
+ }
+ err = json.Unmarshal(data, &t2)
+ if err != nil {
+ return false, err
+ }
}
- return kt.(trait.ComparableTrait).Matches(it.(trait.Trait)), nil
+ return t2.(trait.ComparableTrait).Matches(t1.(trait.Trait)), nil
}
-func hasMatchingTrait(itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
- data, err := json.Marshal(itTrait.Configuration)
+func hasMatchingTrait(ts1 *v1.TraitSpec, ts2 *v1.TraitSpec) (bool, error) {
+ data, err := json.Marshal(ts1.Configuration)
if err != nil {
return false, err
}
- itConf := make(map[string]interface{})
- err = json.Unmarshal(data, &itConf)
+ t1 := make(map[string]interface{})
+ err = json.Unmarshal(data, &t1)
if err != nil {
return false, err
}
- data, err = json.Marshal(kitTrait.Configuration)
+ data, err = json.Marshal(ts2.Configuration)
if err != nil {
return false, err
}
- kitConf := make(map[string]interface{})
- err = json.Unmarshal(data, &kitConf)
+ t2 := make(map[string]interface{})
+ err = json.Unmarshal(data, &t2)
if err != nil {
return false, err
}
- for ck, cv := range kitConf {
- iv, ok := itConf[ck]
+ for ck, cv := range t2 {
+ iv, ok := t1[ck]
if !ok {
// skip it because trait configured on kit has a value that is not defined
// in integration trait
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 138d3a1..629ba82 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -88,16 +88,30 @@ func (t *quarkusTrait) Matches(trait Trait) bool {
return false
}
-types:
- for _, p1 := range t.PackageTypes {
- for _, p2 := range qt.PackageTypes {
- if p1 == p2 {
- continue types
+ contains := func(types []quarkusPackageType, t quarkusPackageType) bool {
+ for _, ti := range qt.PackageTypes {
+ if t == ti {
+ return true
}
}
return false
}
+ if len(t.PackageTypes) == 0 && len(qt.PackageTypes) != 0 && !contains(qt.PackageTypes, fastJarPackageType) {
+ return false
+ }
+
+types:
+ for _, pt := range t.PackageTypes {
+ if pt == fastJarPackageType && len(qt.PackageTypes) == 0 {
+ continue
+ }
+ if contains(qt.PackageTypes, pt) {
+ continue types
+ }
+ return false
+ }
+
return true
}
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index f3c31c5..3f3d3ac 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -54,7 +54,7 @@ func NewCatalog(c client.Client) *Catalog {
traits: traitList,
}
- for _, t := range catalog.allTraits() {
+ for _, t := range catalog.AllTraits() {
if c != nil {
t.InjectClient(c)
}
@@ -62,7 +62,7 @@ func NewCatalog(c client.Client) *Catalog {
return &catalog
}
-func (c *Catalog) allTraits() []Trait {
+func (c *Catalog) AllTraits() []Trait {
return append([]Trait(nil), c.traits...)
}
@@ -79,7 +79,7 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
// so care must be taken while changing the lists order.
func (c *Catalog) TraitsForProfile(profile v1.TraitProfile) []Trait {
var res []Trait
- for _, t := range c.allTraits() {
+ for _, t := range c.AllTraits() {
if t.IsAllowedInProfile(profile) {
res = append(res, t)
}
@@ -142,7 +142,7 @@ func (c *Catalog) apply(environment *Environment) error {
// GetTrait returns the trait with the given ID
func (c *Catalog) GetTrait(id string) Trait {
- for _, t := range c.allTraits() {
+ for _, t := range c.AllTraits() {
if t.ID() == ID(id) {
return t
}
@@ -153,7 +153,7 @@ func (c *Catalog) GetTrait(id string) Trait {
// ComputeTraitsProperties returns all key/value configuration properties that can be used to configure traits
func (c *Catalog) ComputeTraitsProperties() []string {
results := make([]string, 0)
- for _, trait := range c.allTraits() {
+ for _, trait := range c.AllTraits() {
trait := trait // pin
c.processFields(structs.Fields(trait), func(name string) {
results = append(results, string(trait.ID())+"."+name)
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 6eb0261..e423830 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -497,7 +497,7 @@ func TestOnlySomeTraitsInfluenceBuild(t *testing.T) {
c := NewTraitTestCatalog()
buildTraits := []string{"builder", "quarkus"}
- for _, trait := range c.allTraits() {
+ for _, trait := range c.AllTraits() {
if trait.InfluencesKit() {
assert.Contains(t, buildTraits, string(trait.ID()))
} else {
@@ -510,7 +510,7 @@ func TestOnlySomeTraitsArePlatform(t *testing.T) {
c := NewTraitTestCatalog()
platformTraits := []string{"builder", "camel", "jvm", "container", "dependencies", "deployer", "deployment", "environment", "error-handler", "kamelets", "openapi", "owner", "platform", "quarkus"}
- for _, trait := range c.allTraits() {
+ for _, trait := range c.AllTraits() {
if trait.IsPlatformTrait() {
assert.Contains(t, platformTraits, string(trait.ID()))
} else {
@@ -523,7 +523,7 @@ func TestOnlySomeTraitsDoNotRequireIntegrationPlatform(t *testing.T) {
c := NewTraitTestCatalog()
doNotRequirePlatformTraits := []string{"deployer", "platform"}
- for _, trait := range c.allTraits() {
+ for _, trait := range c.AllTraits() {
if !trait.RequiresIntegrationPlatform() {
assert.Contains(t, doNotRequirePlatformTraits, string(trait.ID()))
} else {
[camel-k] 19/37: feat(native): Add multi-kit support with
prioritization
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 8fded214097f40819c872e71964f09b64b45c397
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 26 16:28:01 2021 +0200
feat(native): Add multi-kit support with prioritization
---
pkg/apis/camel/v1/integrationkit_types.go | 3 +
pkg/apis/camel/v1/integrationkit_types_support.go | 18 ++
pkg/controller/integration/build_kit.go | 362 ++++++++++++----------
pkg/controller/integration/build_kit_test.go | 18 +-
pkg/controller/integrationkit/build.go | 2 +-
pkg/trait/quarkus.go | 150 +++++++--
pkg/trait/quarkus_test.go | 4 +-
pkg/trait/trait_configure.go | 5 +-
pkg/trait/trait_types.go | 45 +--
9 files changed, 388 insertions(+), 219 deletions(-)
diff --git a/pkg/apis/camel/v1/integrationkit_types.go b/pkg/apis/camel/v1/integrationkit_types.go
index 0fae093..17203c5 100644
--- a/pkg/apis/camel/v1/integrationkit_types.go
+++ b/pkg/apis/camel/v1/integrationkit_types.go
@@ -105,6 +105,9 @@ const (
// IntegrationKitLayoutNative labels a kit using the Quarkus native packaging
IntegrationKitLayoutNative = "native"
+ // IntegrationKitPriorityLabel labels the kit priority
+ IntegrationKitPriorityLabel = "camel.apache.org/kit.priority"
+
// IntegrationKitPhaseNone --
IntegrationKitPhaseNone IntegrationKitPhase = ""
// IntegrationKitPhaseInitialization --
diff --git a/pkg/apis/camel/v1/integrationkit_types_support.go b/pkg/apis/camel/v1/integrationkit_types_support.go
index a9c894e..408a884 100644
--- a/pkg/apis/camel/v1/integrationkit_types_support.go
+++ b/pkg/apis/camel/v1/integrationkit_types_support.go
@@ -18,6 +18,8 @@ limitations under the License.
package v1
import (
+ "strconv"
+
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -76,6 +78,22 @@ func (in *IntegrationKit) SetIntegrationPlatform(platform *IntegrationPlatform)
in.Status.Platform = platform.Name
}
+func (in *IntegrationKit) HasHigherPriorityThan(kit *IntegrationKit) bool {
+ p1 := 0
+ p2 := 0
+ if l, ok := in.Labels[IntegrationKitPriorityLabel]; ok {
+ if p, err := strconv.Atoi(l); err == nil {
+ p1 = p
+ }
+ }
+ if l, ok := kit.Labels[IntegrationKitPriorityLabel]; ok {
+ if p, err := strconv.Atoi(l); err == nil {
+ p2 = p
+ }
+ }
+ return p1 > p2
+}
+
// GetCondition returns the condition with the provided type.
func (in *IntegrationKitStatus) GetCondition(condType IntegrationKitConditionType) *IntegrationKitCondition {
for i := range in.Conditions {
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index 348d3a5..3187512 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -20,10 +20,9 @@ package integration
import (
"context"
"encoding/json"
- "fmt"
+ "reflect"
"github.com/pkg/errors"
- "github.com/rs/xid"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
@@ -35,6 +34,7 @@ import (
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
+ "github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/kubernetes"
)
@@ -55,38 +55,32 @@ func (action *buildKitAction) CanHandle(integration *v1.Integration) bool {
}
func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integration) (*v1.Integration, error) {
- kit, err := action.lookupKitForIntegration(ctx, action.client, integration)
- if err != nil {
- // TODO: we may need to add a wait strategy, i.e give up after some time
- return nil, err
- }
-
- if kit != nil {
- if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
- // This is a platform kit and as it is auto generated it may get
- // out of sync if the integration that has generated it, has been
- // amended to add/remove dependencies
+ // TODO: we may need to add a timeout strategy, i.e give up after some time in case of an unrecoverable error.
- versionMatch := kit.Status.Version == integration.Status.Version
-
- // TODO: this is a very simple check, we may need to provide a deps comparison strategy
- dependenciesMatch := util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies)
+ if integration.Status.IntegrationKit != nil {
+ kit, err := kubernetes.GetIntegrationKit(ctx, action.client, integration.Status.IntegrationKit.Name, integration.Status.IntegrationKit.Namespace)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to find integration kit %s/%s, %s", integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err)
+ }
- if !dependenciesMatch || !versionMatch {
- // We need to re-generate a kit or search for a new one that
- // satisfies integrations needs so let's remove the association
- // with a kit
+ if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
+ match, err := action.integrationMatches(integration, kit)
+ if err != nil {
+ return nil, err
+ } else if !match {
+ // We need to re-generate a kit, or search for a new one that
+ // matches the integration, so let's remove the association
+ // with the kit.
integration.SetIntegrationKit(&v1.IntegrationKit{})
-
return integration, nil
}
+
}
if kit.Status.Phase == v1.IntegrationKitPhaseError {
integration.Status.Image = kit.Status.Image
integration.Status.Phase = v1.IntegrationPhaseError
integration.SetIntegrationKit(kit)
-
return integration, nil
}
@@ -94,87 +88,59 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
integration.Status.Image = kit.Status.Image
integration.Status.Phase = v1.IntegrationPhaseDeploying
integration.SetIntegrationKit(kit)
-
- return integration, nil
- }
-
- if integration.Status.IntegrationKit == nil || integration.Status.IntegrationKit.Name == "" {
- integration.SetIntegrationKit(kit)
-
return integration, nil
}
return nil, nil
}
- pl, err := platform.GetCurrent(ctx, action.client, integration.Namespace)
- if err != nil && !k8serrors.IsNotFound(err) {
+ existingKits, err := action.lookupKitsForIntegration(ctx, action.client, integration)
+ if err != nil {
return nil, err
}
- kit = v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(pl), fmt.Sprintf("kit-%s", xid.New()))
-
- // Add some information for post-processing, this may need to be refactored
- // to a proper data structure
- kit.Labels = map[string]string{
- v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
- "camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
- "camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
- kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
- kubernetes.CamelCreatorLabelName: integration.Name,
- kubernetes.CamelCreatorLabelNamespace: integration.Namespace,
- kubernetes.CamelCreatorLabelVersion: integration.ResourceVersion,
- }
-
- // Set the kit to have the same characteristics as the integrations
- kit.Spec = v1.IntegrationKitSpec{
- Dependencies: integration.Status.Dependencies,
- Repositories: integration.Spec.Repositories,
- Traits: action.filterKitTraits(ctx, integration.Spec.Traits),
- }
-
- if _, err := trait.Apply(ctx, action.client, integration, kit); err != nil {
+ env, err := trait.Apply(ctx, action.client, integration, nil)
+ if err != nil {
return nil, err
}
- if err := action.client.Create(ctx, kit); err != nil {
- return nil, err
+ var integrationKit *v1.IntegrationKit
+kits:
+ for i, kit := range env.IntegrationKits {
+ for j, k := range existingKits {
+ match, err := action.kitMatches(&kit, &k)
+ if err != nil {
+ return nil, err
+ }
+ if match {
+ if integrationKit == nil ||
+ integrationKit.Status.Phase != v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady ||
+ integrationKit.Status.Phase == v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady && k.HasHigherPriorityThan(integrationKit) {
+ integrationKit = &existingKits[j]
+ }
+ continue kits
+ }
+ }
+ if err := action.client.Create(ctx, &kit); err != nil {
+ return nil, err
+ }
+ if integrationKit == nil {
+ integrationKit = &env.IntegrationKits[i]
+ }
}
// Set the kit name so the next handle loop, will fall through the
// same path as integration with a user defined kit
- integration.SetIntegrationKit(kit)
+ if integrationKit.Status.Phase == v1.IntegrationKitPhaseReady {
+ integration.Status.Image = integrationKit.Status.Image
+ integration.Status.Phase = v1.IntegrationPhaseDeploying
+ }
+ integration.SetIntegrationKit(integrationKit)
return integration, nil
}
-func (action *buildKitAction) filterKitTraits(ctx context.Context, in map[string]v1.TraitSpec) map[string]v1.TraitSpec {
- if len(in) == 0 {
- return in
- }
- catalog := trait.NewCatalog(ctx, action.client)
- out := make(map[string]v1.TraitSpec)
- for name, conf := range in {
- t := catalog.GetTrait(name)
- if t != nil && !t.InfluencesKit() {
- // We don't store the trait configuration if the trait cannot influence the kit behavior
- continue
- }
- out[name] = conf
- }
- return out
-}
-
-func (action *buildKitAction) lookupKitForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration) (*v1.IntegrationKit, error) {
- if integration.Status.IntegrationKit != nil {
- kit, err := kubernetes.GetIntegrationKit(ctx, c, integration.Status.IntegrationKit.Name, integration.Status.IntegrationKit.Namespace)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to find integration kit %s/%s, %s", integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err)
- }
-
- return kit, nil
- }
-
+func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration) ([]v1.IntegrationKit, error) {
pl, err := platform.GetCurrent(ctx, c, integration.Namespace)
if err != nil && !k8serrors.IsNotFound(err) {
return nil, err
@@ -199,111 +165,181 @@ func (action *buildKitAction) lookupKitForIntegration(ctx context.Context, c ctr
},
}
- kits := v1.NewIntegrationKitList()
- if err := c.List(ctx, &kits, options...); err != nil {
+ list := v1.NewIntegrationKitList()
+ if err := c.List(ctx, &list, options...); err != nil {
return nil, err
}
- for _, kit := range kits.Items {
- kit := kit // pin
-
- if kit.Status.Phase == v1.IntegrationKitPhaseError {
- continue
- }
-
- /*
- TODO: moved to label selector
- if kit.Status.RuntimeVersion != integration.Status.RuntimeVersion {
- continue
- }
- if kit.Status.RuntimeProvider != integration.Status.RuntimeProvider {
- continue
- }
- */
-
- if kit.Status.Version != integration.Status.Version {
- continue
- }
-
- ideps := len(integration.Status.Dependencies)
- cdeps := len(kit.Spec.Dependencies)
-
- if ideps != cdeps {
- continue
- }
-
- // When a platform kit is created it inherits the traits from the integrations and as
- // some traits may influence the build thus the artifacts present on the container image,
- // we need to take traits into account when looking up for compatible kits.
- //
- // It could also happen that an integration is updated and a trait is modified, if we do
- // not include traits in the lookup, we may use a kit that does not have all the
- // characteristics required by the integration.
- //
- // A kit can be used only if it contains a subset of the traits and related configurations
- // declared on integration.
- match, err := action.hasMatchingTraits(ctx, &kit, integration)
+ kits := make([]v1.IntegrationKit, 0)
+ for _, kit := range list.Items {
+ match, err := action.integrationMatches(integration, &kit)
if err != nil {
return nil, err
- }
- if !match {
+ } else if !match {
continue
}
- if util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies) {
- return &kit, nil
- }
+ kits = append(kits, kit)
}
- return nil, nil
+ return kits, nil
}
-// hasMatchingTraits compares traits defined on kit against those defined on integration
-func (action *buildKitAction) hasMatchingTraits(ctx context.Context, kit *v1.IntegrationKit, integration *v1.Integration) (bool, error) {
- traits := action.filterKitTraits(ctx, integration.Spec.Traits)
+// integrationMatches returns whether the v1.IntegrationKit meets the requirements of the v1.Integration
+func (action *buildKitAction) integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
+ if kit.Status.Phase == v1.IntegrationKitPhaseError {
+ return false, nil
+ }
+ if kit.Status.Version != integration.Status.Version {
+ return false, nil
+ }
+ if len(integration.Status.Dependencies) != len(kit.Spec.Dependencies) {
+ return false, nil
+ }
+ // When a platform kit is created it inherits the traits from the integrations and as
+ // some traits may influence the build thus the artifacts present on the container image,
+ // we need to take traits into account when looking up for compatible kits.
+ //
+ // It could also happen that an integration is updated and a trait is modified, if we do
+ // not include traits in the lookup, we may use a kit that does not have all the
+ // characteristics required by the integration.
+ //
+ // A kit can be used only if it contains a subset of the traits and related configurations
+ // declared on integration.
+ if match, err := action.hasMatchingTraits(integration, kit); !match || err != nil {
+ return false, err
+ }
+ if !util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies) {
+ return false, nil
+ }
+ return true, nil
+}
- // The kit has no trait, but the integration need some
- if len(kit.Spec.Traits) == 0 && len(traits) > 0 {
+// kitMatches returns whether the v1.IntegrationKit match
+func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.IntegrationKit) (bool, error) {
+ version := k1.Status.Version
+ if version == "" {
+ // Defaults with the version that is going to be set during the kit initialization
+ version = defaults.Version
+ }
+ if version != k2.Status.Version {
+ return false, nil
+ }
+ if len(k1.Spec.Dependencies) != len(k2.Spec.Dependencies) {
return false, nil
}
- for name, kitTrait := range kit.Spec.Traits {
- itTrait, ok := traits[name]
+ if len(k1.Spec.Traits) != len(k2.Spec.Traits) {
+ return false, nil
+ }
+ for name, kt1 := range k1.Spec.Traits {
+ kt2, ok := k2.Spec.Traits[name]
if !ok {
- // skip it because trait configured on kit is not defined on integration
return false, nil
}
- data, err := json.Marshal(itTrait.Configuration)
- if err != nil {
+ match, err := action.hasMatchingTrait(&kt1, &kt2)
+ if !match || err != nil {
return false, err
}
- itConf := make(map[string]interface{})
- err = json.Unmarshal(data, &itConf)
- if err != nil {
- return false, err
- }
- data, err = json.Marshal(kitTrait.Configuration)
- if err != nil {
- return false, err
+ }
+ if !util.StringSliceContains(k1.Spec.Dependencies, k2.Spec.Dependencies) {
+ return false, nil
+ }
+ return true, nil
+}
+
+// hasMatchingTraits compares the traits defined on the v1.Integration with those defined on the v1.IntegrationKit
+func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
+ catalog := trait.NewCatalog(context.TODO(), action.client)
+
+ traitCount := 0
+ for name, itTrait := range integration.Spec.Traits {
+ t := catalog.GetTrait(name)
+ if t != nil && !t.InfluencesKit() {
+ // We don't store the trait configuration if the trait cannot influence the kit behavior
+ continue
}
- kitConf := make(map[string]interface{})
- err = json.Unmarshal(data, &kitConf)
- if err != nil {
- return false, err
+ traitCount++
+ kitTrait, ok := kit.Spec.Traits[name]
+ if !ok {
+ // skip it because trait configured on integration is not defined on kit
+ return false, nil
}
- for ck, cv := range kitConf {
- iv, ok := itConf[ck]
- if !ok {
- // skip it because trait configured on kit has a value that is not defined
- // in integration trait
- return false, nil
+ if ct, ok := t.(trait.ComparableTrait); ok {
+ comparable, err := action.hasComparableTrait(ct, &itTrait, &kitTrait)
+ if !comparable || err != nil {
+ return false, err
}
- if !equal(iv, cv) {
- // skip it because trait configured on kit has a value that differs from
- // the one configured on integration
- return false, nil
+ } else {
+ match, err := action.hasMatchingTrait(&itTrait, &kitTrait)
+ if !match || err != nil {
+ return false, err
}
}
}
+ // Check the number of influencing traits matches
+ if len(kit.Spec.Traits) != traitCount {
+ return false, nil
+ }
+
+ return true, nil
+}
+
+func (action *buildKitAction) hasComparableTrait(c trait.ComparableTrait, itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
+ it := reflect.New(reflect.TypeOf(c).Elem()).Interface()
+ data, err := json.Marshal(itTrait.Configuration)
+ if err != nil {
+ return false, err
+ }
+ err = json.Unmarshal(data, &it)
+ if err != nil {
+ return false, err
+ }
+
+ kt := reflect.New(reflect.TypeOf(c).Elem()).Interface()
+ data, err = json.Marshal(kitTrait.Configuration)
+ if err != nil {
+ return false, err
+ }
+ err = json.Unmarshal(data, &it)
+ if err != nil {
+ return false, err
+ }
+
+ return kt.(trait.ComparableTrait).Matches(it.(trait.Trait)), nil
+}
+
+func (action *buildKitAction) hasMatchingTrait(itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
+ data, err := json.Marshal(itTrait.Configuration)
+ if err != nil {
+ return false, err
+ }
+ itConf := make(map[string]interface{})
+ err = json.Unmarshal(data, &itConf)
+ if err != nil {
+ return false, err
+ }
+ data, err = json.Marshal(kitTrait.Configuration)
+ if err != nil {
+ return false, err
+ }
+ kitConf := make(map[string]interface{})
+ err = json.Unmarshal(data, &kitConf)
+ if err != nil {
+ return false, err
+ }
+ for ck, cv := range kitConf {
+ iv, ok := itConf[ck]
+ if !ok {
+ // skip it because trait configured on kit has a value that is not defined
+ // in integration trait
+ return false, nil
+ }
+ if !equal(iv, cv) {
+ // skip it because trait configured on kit has a value that differs from
+ // the one configured on integration
+ return false, nil
+ }
+ }
return true, nil
}
diff --git a/pkg/controller/integration/build_kit_test.go b/pkg/controller/integration/build_kit_test.go
index fa3df64..a1538e3 100644
--- a/pkg/controller/integration/build_kit_test.go
+++ b/pkg/controller/integration/build_kit_test.go
@@ -84,7 +84,7 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
a.InjectLogger(log.Log)
a.InjectClient(c)
- i, err := a.lookupKitForIntegration(context.TODO(), c, &v1.Integration{
+ kits, err := a.lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKind,
@@ -102,8 +102,9 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
})
assert.Nil(t, err)
- assert.NotNil(t, i)
- assert.Equal(t, "my-kit-2", i.Name)
+ assert.NotNil(t, kits)
+ assert.Len(t, kits, 1)
+ assert.Equal(t, "my-kit-2", kits[0].Name)
}
func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T) {
@@ -206,7 +207,7 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
a.InjectLogger(log.Log)
a.InjectClient(c)
- i, err := a.lookupKitForIntegration(context.TODO(), c, &v1.Integration{
+ kits, err := a.lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKind,
@@ -234,8 +235,9 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
})
assert.Nil(t, err)
- assert.NotNil(t, i)
- assert.Equal(t, "my-kit-3", i.Name)
+ assert.NotNil(t, kits)
+ assert.Len(t, kits, 1)
+ assert.Equal(t, "my-kit-3", kits[0].Name)
}
func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) {
@@ -274,7 +276,7 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := a.hasMatchingTraits(context.TODO(), integrationKitSpec, integration)
+ ok, err := a.hasMatchingTraits(integration, integrationKitSpec)
assert.Nil(t, err)
assert.False(t, ok)
}
@@ -325,7 +327,7 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := a.hasMatchingTraits(context.TODO(), integrationKitSpec, integration)
+ ok, err := a.hasMatchingTraits(integration, integrationKitSpec)
assert.Nil(t, err)
assert.True(t, ok)
}
diff --git a/pkg/controller/integrationkit/build.go b/pkg/controller/integrationkit/build.go
index 62b6820..9a8c390 100644
--- a/pkg/controller/integrationkit/build.go
+++ b/pkg/controller/integrationkit/build.go
@@ -44,7 +44,7 @@ type buildAction struct {
}
func (action *buildAction) Name() string {
- return "build-submitted"
+ return "build"
}
func (action *buildAction) CanHandle(kit *v1.IntegrationKit) bool {
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index bb38039..2e47f5b 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -18,12 +18,16 @@ limitations under the License.
package trait
import (
+ "encoding/json"
"fmt"
"sort"
+ "github.com/rs/xid"
+
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/util/defaults"
+ "github.com/apache/camel-k/pkg/util/kubernetes"
)
type quarkusPackageType string
@@ -35,6 +39,11 @@ const (
nativePackageType quarkusPackageType = "native"
)
+var kitPriority = map[quarkusPackageType]string{
+ fastJarPackageType: "1000",
+ nativePackageType: "2000",
+}
+
// The Quarkus trait configures the Quarkus runtime.
//
// It's enabled by default.
@@ -42,8 +51,13 @@ const (
// +camel-k:trait=quarkus
type quarkusTrait struct {
BaseTrait `property:",squash"`
- // The Quarkus package type, either `fast-jar` or `native` (default `fast-jar`)
- PackageType *quarkusPackageType `property:"package-type" json:"packageType,omitempty"`
+ // The Quarkus package types, either `fast-jar` or `native` (default `fast-jar`).
+ // In case both `fast-jar` and `native` are specified, two IntegrationKits are created,
+ // with the `native` kit having precedence over the `fast-jar' one once ready.
+ // The order influences the resolution of the current IntegrationKit for the Integration.
+ // The IntegrationKit corresponding to the first package type will be assigned to the
+ // Integration in case no existing IntegrationKit that matches the Integration exists.
+ PackageTypes []quarkusPackageType `property:"package-type" json:"packageTypes,omitempty"`
}
func newQuarkusTrait() Trait {
@@ -52,30 +66,109 @@ func newQuarkusTrait() Trait {
}
}
+// IsPlatformTrait overrides base class method
+func (t *quarkusTrait) IsPlatformTrait() bool {
+ return true
+}
+
+// InfluencesKit overrides base class method
+func (t *quarkusTrait) InfluencesKit() bool {
+ return true
+}
+
+var _ ComparableTrait = &quarkusTrait{}
+
+func (t *quarkusTrait) Matches(trait Trait) bool {
+ qt, ok := trait.(*quarkusTrait)
+ if !ok {
+ return false
+ }
+
+ if IsNilOrTrue(t.Enabled) && IsFalse(qt.Enabled) {
+ return false
+ }
+
+types:
+ for _, p1 := range t.PackageTypes {
+ for _, p2 := range qt.PackageTypes {
+ if p1 == p2 {
+ continue types
+ }
+ }
+ return false
+ }
+
+ return true
+}
+
func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
if IsFalse(t.Enabled) {
return false, nil
}
- if t.PackageType == nil {
- packageType := fastJarPackageType
- t.PackageType = &packageType
+ if len(t.PackageTypes) == 0 {
+ t.PackageTypes = []quarkusPackageType{fastJarPackageType}
}
- return e.IntegrationKitInPhase(v1.IntegrationKitPhaseNone, v1.IntegrationKitPhaseBuildSubmitted) ||
+ return e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) ||
+ e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning),
nil
}
func (t *quarkusTrait) Apply(e *Environment) error {
- switch e.IntegrationKit.Status.Phase {
+ if e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) {
+ integration := e.Integration
+
+ for _, packageType := range t.PackageTypes {
+ kit := v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(e.Platform), fmt.Sprintf("kit-%s", xid.New()))
+
+ kit.Labels = map[string]string{
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
+ "camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
+ "camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
+ v1.IntegrationKitLayoutLabel: string(packageType),
+ v1.IntegrationKitPriorityLabel: kitPriority[packageType],
+ kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
+ kubernetes.CamelCreatorLabelName: integration.Name,
+ kubernetes.CamelCreatorLabelNamespace: integration.Namespace,
+ kubernetes.CamelCreatorLabelVersion: integration.ResourceVersion,
+ }
- case v1.IntegrationKitPhaseNone:
- if e.IntegrationKit.Labels == nil {
- e.IntegrationKit.Labels = make(map[string]string)
+ traits := t.getKitTraits(e)
+ data, err := json.Marshal(traits[quarkusTraitId].Configuration)
+ if err != nil {
+ return err
+ }
+ trait := quarkusTrait{}
+ err = json.Unmarshal(data, &trait)
+ if err != nil {
+ return err
+ }
+ trait.PackageTypes = []quarkusPackageType{packageType}
+ data, err = json.Marshal(trait)
+ if err != nil {
+ return err
+ }
+ traits[quarkusTraitId] = v1.TraitSpec{
+ Configuration: v1.TraitConfiguration{
+ RawMessage: data,
+ },
+ }
+ kit.Spec = v1.IntegrationKitSpec{
+ Dependencies: e.Integration.Status.Dependencies,
+ Repositories: e.Integration.Spec.Repositories,
+ Traits: traits,
+ }
+
+ e.IntegrationKits = append(e.IntegrationKits, *kit)
}
- e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] = string(*t.PackageType)
+
+ return nil
+ }
+
+ switch e.IntegrationKit.Status.Phase {
case v1.IntegrationKitPhaseBuildSubmitted:
build := getBuilderTask(e.BuildTasks)
@@ -94,7 +187,7 @@ func (t *quarkusTrait) Apply(e *Environment) error {
steps = append(steps, builder.Quarkus.CommonSteps...)
- if t.isNativePackageType() {
+ if t.hasNativePackageType(e) {
build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
steps = append(steps, builder.Image.NativeImageContext)
// Spectrum does not rely on Dockerfile to assemble the image
@@ -118,7 +211,7 @@ func (t *quarkusTrait) Apply(e *Environment) error {
build.Steps = builder.StepIDsFor(steps...)
case v1.IntegrationKitPhaseReady:
- if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) && t.isNativePackageType() {
+ if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) && t.hasNativePackageType(e) {
container := e.getIntegrationContainer()
if container == nil {
return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
@@ -132,18 +225,29 @@ func (t *quarkusTrait) Apply(e *Environment) error {
return nil
}
-// IsPlatformTrait overrides base class method
-func (t *quarkusTrait) IsPlatformTrait() bool {
- return true
-}
-
-// InfluencesKit overrides base class method
-func (t *quarkusTrait) InfluencesKit() bool {
- return true
+func (t *quarkusTrait) getKitTraits(e *Environment) map[string]v1.TraitSpec {
+ traits := make(map[string]v1.TraitSpec)
+ for name, spec := range e.Integration.Spec.Traits {
+ t := e.Catalog.GetTrait(name)
+ if t != nil && !t.InfluencesKit() {
+ continue
+ }
+ traits[name] = spec
+ }
+ return traits
}
-func (t *quarkusTrait) isNativePackageType() bool {
- return t.PackageType != nil && *t.PackageType == nativePackageType
+func (t *quarkusTrait) hasNativePackageType(e *Environment) bool {
+ switch types := t.PackageTypes; len(types) {
+ case 0:
+ return false
+ case 1:
+ return types[0] == nativePackageType
+ default:
+ // The Integration has more than one package types.
+ // Let's rely on the current IntegrationKit to resolve it.
+ return e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] == v1.IntegrationKitLayoutNative
+ }
}
func getBuilderTask(tasks []v1.Task) *v1.BuilderTask {
diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go
index e09cc2b..f7c60d3 100644
--- a/pkg/trait/quarkus_test.go
+++ b/pkg/trait/quarkus_test.go
@@ -57,6 +57,7 @@ func TestConfigureDisabledQuarkusTraitShouldFail(t *testing.T) {
func TestApplyQuarkusTraitDefaultKitLayout(t *testing.T) {
quarkusTrait, environment := createNominalQuarkusTest()
+ environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
configured, err := quarkusTrait.Configure(environment)
assert.True(t, configured)
@@ -64,7 +65,8 @@ func TestApplyQuarkusTraitDefaultKitLayout(t *testing.T) {
err = quarkusTrait.Apply(environment)
assert.Nil(t, err)
- assert.Equal(t, environment.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel], v1.IntegrationKitLayoutFastJar)
+ assert.Len(t, environment.IntegrationKits, 1)
+ assert.Equal(t, environment.IntegrationKits[0].Labels[v1.IntegrationKitLayoutLabel], v1.IntegrationKitLayoutFastJar)
}
func createNominalQuarkusTest() (*quarkusTrait, *Environment) {
diff --git a/pkg/trait/trait_configure.go b/pkg/trait/trait_configure.go
index f255053..952a96c 100644
--- a/pkg/trait/trait_configure.go
+++ b/pkg/trait/trait_configure.go
@@ -23,9 +23,10 @@ import (
"reflect"
"strings"
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
)
func (c *Catalog) configure(env *Environment) error {
@@ -149,7 +150,7 @@ func configureTrait(id string, config map[string]string, trait interface{}) erro
)
if err != nil {
- return errors.Wrapf(err, "error while decoding trait configuration from annotations on trait %q", id)
+ return errors.Wrapf(err, "error while decoding trait configuration %q", id)
}
return decoder.Decode(config)
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index fc6d0f0..2ab9296 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -97,6 +97,15 @@ type Trait interface {
Order() int
}
+type Comparable interface {
+ Matches(Trait) bool
+}
+
+type ComparableTrait interface {
+ Trait
+ Comparable
+}
+
// A list of named orders, useful for correctly binding addons
const (
// TraitOrderBeforeControllerCreation can be used to inject configuration such as properties and environment variables
@@ -110,9 +119,6 @@ const (
TraitOrderPostProcessResources = 2450
)
-/* Base trait */
-
-// NewBaseTrait --
func NewBaseTrait(id string, order int) BaseTrait {
return BaseTrait{
TraitID: ID(id),
@@ -173,8 +179,6 @@ func (trait *BaseTrait) Order() int {
return trait.ExecutionOrder
}
-/* ControllerStrategySelector */
-
// ControllerStrategySelector is the interface for traits that can determine the kind of controller that will run the integration.
type ControllerStrategySelector interface {
// SelectControllerStrategy tells if the trait with current configuration can select a specific controller to use
@@ -183,18 +187,22 @@ type ControllerStrategySelector interface {
ControllerStrategySelectorOrder() int
}
-/* Environment */
-
-// A Environment provides the context where the trait is executed
+// An Environment provides the context for the execution of the traits
type Environment struct {
- CamelCatalog *camel.RuntimeCatalog
- RuntimeVersion string
- Catalog *Catalog
- C context.Context
- Client client.Client
- Platform *v1.IntegrationPlatform
- IntegrationKit *v1.IntegrationKit
- Integration *v1.Integration
+ CamelCatalog *camel.RuntimeCatalog
+ RuntimeVersion string
+ Catalog *Catalog
+ C context.Context
+ Client client.Client
+ // The active Platform
+ Platform *v1.IntegrationPlatform
+ // The current Integration
+ Integration *v1.Integration
+ // The IntegrationKit associated to the Integration
+ IntegrationKit *v1.IntegrationKit
+ // The IntegrationKits to be created for the Integration
+ IntegrationKits []v1.IntegrationKit
+ // The resources owned by the Integration that are applied to the API server
Resources *kubernetes.Collection
PostActions []func(*Environment) error
PostStepProcessors []func(*Environment) error
@@ -220,7 +228,6 @@ const (
DefaultControllerStrategy = ControllerStrategyDeployment
)
-// GetTrait --
func (e *Environment) GetTrait(id ID) Trait {
for _, t := range e.ExecutedTraits {
if t.ID() == id {
@@ -231,7 +238,6 @@ func (e *Environment) GetTrait(id ID) Trait {
return nil
}
-// IntegrationInPhase --
func (e *Environment) IntegrationInPhase(phases ...v1.IntegrationPhase) bool {
if e.Integration == nil {
return false
@@ -246,7 +252,6 @@ func (e *Environment) IntegrationInPhase(phases ...v1.IntegrationPhase) bool {
return false
}
-// IntegrationKitInPhase --
func (e *Environment) IntegrationKitInPhase(phases ...v1.IntegrationKitPhase) bool {
if e.IntegrationKit == nil {
return false
@@ -261,7 +266,6 @@ func (e *Environment) IntegrationKitInPhase(phases ...v1.IntegrationKitPhase) bo
return false
}
-// InPhase --
func (e *Environment) InPhase(c v1.IntegrationKitPhase, i v1.IntegrationPhase) bool {
return e.IntegrationKitInPhase(c) && e.IntegrationInPhase(i)
}
@@ -346,7 +350,6 @@ func (e *Environment) GetIntegrationPodSpec() *corev1.PodSpec {
return nil
}
-// DetermineCatalogNamespace --
func (e *Environment) DetermineCatalogNamespace() string {
// Catalog is expected to be together with the platform
if e.Platform != nil && e.Platform.Namespace != "" {
[camel-k] 12/37: chore(native): Report the native runner as the
only image artifact
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 5bb3b267ca1315d6b7e28da85eeaa240c7207b70
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Aug 18 14:58:46 2021 +0200
chore(native): Report the native runner as the only image artifact
---
pkg/builder/image.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index ac33a6f..637ca97 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -66,12 +66,14 @@ func nativeImageContext(ctx *builderContext) error {
runner := "camel-k-integration-" + defaults.Version + "-runner"
ctx.BaseImage = "quay.io/quarkus/quarkus-distroless-image:1.0"
- ctx.SelectedArtifacts = []v1.Artifact{
+ ctx.Artifacts = []v1.Artifact{
{
+ ID: runner,
Location: path.Join(ctx.Path, "maven", "target", runner),
Target: runner,
},
}
+ ctx.SelectedArtifacts = ctx.Artifacts
return nil
})
[camel-k] 28/37: chore(native): Polish native checks logic
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 50edc77a320759eff4ca2440b15e4bf1fad40d13
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Aug 31 12:48:38 2021 +0200
chore(native): Polish native checks logic
---
pkg/trait/jvm.go | 3 ++-
pkg/trait/quarkus.go | 21 +++++++++++++--------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 8d17bcc..60e853b 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -77,7 +77,8 @@ func (t *jvmTrait) Configure(e *Environment) (bool, error) {
}
if trait := e.Catalog.GetTrait(quarkusTraitId); trait != nil {
- if quarkus := trait.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.hasNativePackageType(e) {
+ // The JVM trait must be disabled in case the current IntegrationKit corresponds to a native build
+ if quarkus := trait.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativeIntegration(e) {
return false, nil
}
}
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 629ba82..49a180e 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -186,7 +186,9 @@ func (t *quarkusTrait) Apply(e *Environment) error {
steps = append(steps, builder.Quarkus.CommonSteps...)
- if t.hasNativePackageType(e) {
+ if native, err := t.isNativeKit(e); err != nil {
+ return err
+ } else if native {
build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
steps = append(steps, builder.Image.NativeImageContext)
// Spectrum does not rely on Dockerfile to assemble the image
@@ -210,7 +212,7 @@ func (t *quarkusTrait) Apply(e *Environment) error {
build.Steps = builder.StepIDsFor(steps...)
case v1.IntegrationKitPhaseReady:
- if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) && t.hasNativePackageType(e) {
+ if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) && t.isNativeIntegration(e) {
container := e.getIntegrationContainer()
if container == nil {
return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
@@ -263,19 +265,22 @@ func (t *quarkusTrait) getKitTraits(e *Environment) map[string]v1.TraitSpec {
return traits
}
-func (t *quarkusTrait) hasNativePackageType(e *Environment) bool {
+func (t *quarkusTrait) isNativeKit(e *Environment) (bool, error) {
switch types := t.PackageTypes; len(types) {
case 0:
- return false
+ return false, nil
case 1:
- return types[0] == nativePackageType
+ return types[0] == nativePackageType, nil
default:
- // The Integration has more than one package types.
- // Let's rely on the current IntegrationKit to resolve it.
- return e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] == v1.IntegrationKitLayoutNative
+ return false, fmt.Errorf("kit %q has more than one package type", e.IntegrationKit.Name)
}
}
+func (t *quarkusTrait) isNativeIntegration(e *Environment) bool {
+ // The current IntegrationKit determines the Integration runtime type
+ return e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] == v1.IntegrationKitLayoutNative
+}
+
func getBuilderTask(tasks []v1.Task) *v1.BuilderTask {
for i, task := range tasks {
if task.Builder != nil {
[camel-k] 25/37: fix(native): Fix comparable trait configuration
unmarshaling
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d7384cfae775597b67e878f317a61d296ae5224c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Aug 30 16:39:38 2021 +0200
fix(native): Fix comparable trait configuration unmarshaling
---
pkg/controller/integration/build_kit.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index 8740cb0..ff396dd 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -298,7 +298,7 @@ func (action *buildKitAction) hasComparableTrait(c trait.ComparableTrait, itTrai
if err != nil {
return false, err
}
- err = json.Unmarshal(data, &it)
+ err = json.Unmarshal(data, &kt)
if err != nil {
return false, err
}
[camel-k] 08/37: chore(native): Set working directory in JVM trait
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e6d13fa7024783e9fc15e9a7c94d5a4a46dfe73a
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Aug 16 15:37:28 2021 +0200
chore(native): Set working directory in JVM trait
---
pkg/trait/jvm.go | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 8d9e3d3..1080de4 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -71,8 +71,8 @@ func (t *jvmTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
- if t := e.Catalog.GetTrait(quarkusTraitId); t != nil && t.(*quarkusTrait).isNativePackageType() {
- if quarkus := t.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativePackageType() {
+ if trait := e.Catalog.GetTrait(quarkusTraitId); trait != nil {
+ if quarkus := trait.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativePackageType() {
return false, nil
}
}
@@ -200,6 +200,8 @@ func (t *jvmTrait) Apply(e *Environment) error {
container.Args = args
}
+ container.WorkingDir = builder.DeploymentDir
+
return nil
}
[camel-k] 37/37: doc(native): Add automatic rollout to native
integration example
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 49c0903c1d30d349754ce853d35bc81123a97f20
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Sep 8 16:54:56 2021 +0200
doc(native): Add automatic rollout to native integration example
---
deploy/traits.yaml | 17 ++++++++++-------
docs/modules/traits/pages/quarkus.adoc | 30 ++++++++++++++++++++++--------
pkg/resources/resources.go | 4 ++--
pkg/trait/quarkus.go | 14 +++++++++-----
4 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/deploy/traits.yaml b/deploy/traits.yaml
index 073fff9..46bfcb1 100755
--- a/deploy/traits.yaml
+++ b/deploy/traits.yaml
@@ -808,7 +808,11 @@ traits:
- Kubernetes
- Knative
- OpenShift
- description: The Quarkus trait configures the Quarkus runtime. It's enabled by default.
+ description: 'The Quarkus trait configures the Quarkus runtime. It''s enabled by
+ default. NOTE: Compiling to a native executable, i.e. when using `package-type=native`,
+ requires at least 4GiB of memory. Make sure enough memory is available for the
+ Pod running the native build, that is either the operator Pod, or the build Pod,
+ depending on the build strategy configured for the platform.'
properties:
- name: enabled
type: bool
@@ -817,12 +821,11 @@ traits:
- name: package-type
type: '[]./pkg/trait.quarkusPackageType'
description: The Quarkus package types, either `fast-jar` or `native` (default
- `fast-jar`).In case both `fast-jar` and `native` are specified, two IntegrationKits
- are created,with the `native` kit having precedence over the `fast-jar' one
- once ready.The order influences the resolution of the current IntegrationKit
- for the Integration.The IntegrationKit corresponding to the first package type
- will be assigned to theIntegration in case no existing IntegrationKit that matches
- the Integration exists.
+ `fast-jar`).In case both `fast-jar` and `native` are specified, two `IntegrationKit`
+ resources are created,with the `native` kit having precedence over the `fast-jar`
+ one once ready.The order influences the resolution of the current kit for the
+ integration.The kit corresponding to the first package type will be assigned
+ to theintegration in case no existing kit that matches the integration exists.
- name: route
platform: false
profiles:
diff --git a/docs/modules/traits/pages/quarkus.adoc b/docs/modules/traits/pages/quarkus.adoc
index 5127c0d..d90ad66 100755
--- a/docs/modules/traits/pages/quarkus.adoc
+++ b/docs/modules/traits/pages/quarkus.adoc
@@ -5,6 +5,10 @@ The Quarkus trait configures the Quarkus runtime.
It's enabled by default.
+NOTE: Compiling to a native executable, i.e. when using `package-type=native`, requires at least 4GiB of memory.
+Make sure enough memory is available for the Pod running the native build, that is either the operator Pod, or
+the build Pod, depending on the build strategy configured for the platform.
+
This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.
@@ -32,11 +36,11 @@ The following configuration options are available:
| quarkus.package-type
| []./pkg/trait.quarkusPackageType
| The Quarkus package types, either `fast-jar` or `native` (default `fast-jar`).
-In case both `fast-jar` and `native` are specified, two IntegrationKits are created,
-with the `native` kit having precedence over the `fast-jar' one once ready.
-The order influences the resolution of the current IntegrationKit for the Integration.
-The IntegrationKit corresponding to the first package type will be assigned to the
-Integration in case no existing IntegrationKit that matches the Integration exists.
+In case both `fast-jar` and `native` are specified, two `IntegrationKit` resources are created,
+with the `native` kit having precedence over the `fast-jar` one once ready.
+The order influences the resolution of the current kit for the integration.
+The kit corresponding to the first package type will be assigned to the
+integration in case no existing kit that matches the integration exists.
|===
@@ -44,7 +48,17 @@ Integration in case no existing IntegrationKit that matches the Integration exis
== Supported Camel Components
-When running with Quarkus enabled, then Camel K only supports out of the box, those Camel components that
-are available as Camel Quarkus Extensions.
+Camel K only supports the Camel components that are available as Camel Quarkus Extensions out-of-the-box. These extensions are listed in the xref:2.0.0@camel-quarkus::reference/index.adoc[Camel Quarkus documentation].
+
+== Examples
+
+=== Automatic Rollout Deployment to Native Integration
+
+While the compilation to native executables produces integrations that start faster and consume less memory at runtime, the build process is resources intensive, and takes a longer time than the packaging to traditional Java applications.
+
+In order to combine the best of both worlds, it's possible to configure the Quarkus trait to run both traditional and native builds in parallel when running an integration, e.g.:
+
+[source,console]
+$ kamel run -t quarkus.package-type=fast-jar -t quarkus.package-type=native ...
-You can see the list of extensions from the xref:2.0.0@camel-quarkus::reference/index.adoc[Camel Quarkus documentation].
+The integration pod will run as soon as the `fast-jar` build completes, and a rollout deployment to the `native` image will be triggered, as soon as the `native` build completes, with no service interruption.
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index 815ff3b..0cd7ac2 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -467,9 +467,9 @@ var assets = func() http.FileSystem {
"/traits.yaml": &vfsgen۰CompressedFileInfo{
name: "traits.yaml",
modTime: time.Time{},
- uncompressedSize: 39715,
+ uncompressedSize: 40006,
- compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfb\x73\x24\xb7\xd1\xd8\xef\xf7\x57\xa0\xf8\xa5\x8a\x8f\xda\x1d\x52\x76\xec\x4f\x61\xa2\xb8\xe8\xbb\x93\x45\xe9\x1e\xcc\x91\x92\x2b\x75\x51\x79\xb1\x33\xbd\xbb\x38\x62\x80\x31\x80\x21\x6f\x9d\x2f\xff\x7b\x0a\xdd\x78\xcd\xec\x92\x5c\x9e\x44\x95\x98\x8a\xfd\x83\x8e\xe4\xa0\xd1\x68\x34\xfa\x8d\x86\x33\x5c\x38\x7b\xfa\x62\xca\x14\x6f\xe1\x94\xf1\xc5\x42\x28\xe1\xd6\x2f\x18\xeb\x24\x77\x0b\x6d\xda\x53\xb6\xe0\xd2\x [...]
+ compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfd\x73\x24\xb7\xb1\xd8\xef\xf7\x57\xa0\xf8\x52\x75\x24\x6b\x77\x78\xb2\x9f\x6d\x85\x89\xe2\xa2\xee\x4e\x16\xa5\xfb\x60\x8e\x94\x5c\x29\x45\xe5\xc5\xce\xf4\xee\xe2\x16\x03\x8c\x01\x0c\x79\xeb\xbc\xfc\xef\x29\x74\xe3\x6b\x76\x87\xe4\xf2\x24\xaa\xc4\xd4\xb3\x7f\xd0\x91\x1c\x00\x8d\x46\xa3\xbf\xbb\xe1\x0c\x17\xce\x9e\x3e\x9b\x32\xc5\x5b\x38\x65\x7c\xb1\x10\x4a\xb8\xcd\x33\xc6\x3a\xc9\xdd\x42\x9b\xf6\x94\x2d\xb8\x [...]
},
}
fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 49a180e..c4dd613 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -48,15 +48,19 @@ var kitPriority = map[quarkusPackageType]string{
//
// It's enabled by default.
//
+// NOTE: Compiling to a native executable, i.e. when using `package-type=native`, requires at least 4GiB of memory.
+// Make sure enough memory is available for the Pod running the native build, that is either the operator Pod, or
+// the build Pod, depending on the build strategy configured for the platform.
+//
// +camel-k:trait=quarkus
type quarkusTrait struct {
BaseTrait `property:",squash"`
// The Quarkus package types, either `fast-jar` or `native` (default `fast-jar`).
- // In case both `fast-jar` and `native` are specified, two IntegrationKits are created,
- // with the `native` kit having precedence over the `fast-jar' one once ready.
- // The order influences the resolution of the current IntegrationKit for the Integration.
- // The IntegrationKit corresponding to the first package type will be assigned to the
- // Integration in case no existing IntegrationKit that matches the Integration exists.
+ // In case both `fast-jar` and `native` are specified, two `IntegrationKit` resources are created,
+ // with the `native` kit having precedence over the `fast-jar` one once ready.
+ // The order influences the resolution of the current kit for the integration.
+ // The kit corresponding to the first package type will be assigned to the
+ // integration in case no existing kit that matches the integration exists.
PackageTypes []quarkusPackageType `property:"package-type" json:"packageTypes,omitempty"`
}
[camel-k] 15/37: feat(native): Support native build with Spectrum
strategy
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b456c988c42f1dbdac5724227719961a98413039
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 19 13:32:26 2021 +0200
feat(native): Support native build with Spectrum strategy
---
pkg/builder/spectrum.go | 21 +++++++++++++--------
pkg/trait/quarkus.go | 12 ++++++++++--
pkg/util/util.go | 14 ++++++++++++++
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index cb2134a..b719222 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -32,6 +32,7 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
+ "github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/log"
)
@@ -65,16 +66,20 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
contextDir = path.Join(pwd, ContextDir)
}
- libraryPath := path.Join(contextDir, DependenciesDir)
- _, err := os.Stat(libraryPath)
- if err != nil && os.IsNotExist(err) {
- // this can only indicate that there are no more libraries to add to the base image,
- // because transitive resolution is the same even if spec differs
+ exists, err := util.DirectoryExists(contextDir)
+ if err != nil {
+ return status.Failed(err)
+ }
+ empty, err := util.DirectoryEmpty(contextDir)
+ if err != nil {
+ return status.Failed(err)
+ }
+ if !exists || empty {
+ // this can only indicate that there are no more resources to add to the base image,
+ // because transitive resolution is the same even if spec differs.
log.Infof("No new image to build, reusing existing image %s", baseImage)
status.Image = baseImage
return status
- } else if err != nil {
- return status.Failed(err)
}
pullInsecure := t.task.Registry.Insecure // incremental build case
@@ -120,7 +125,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
}
go readSpectrumLogs(newStdR)
- digest, err := spectrum.Build(options, libraryPath+":"+path.Join(DeploymentDir, DependenciesDir))
+ digest, err := spectrum.Build(options, contextDir+":"+path.Join(DeploymentDir))
if err != nil {
return status.Failed(err)
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index d77b614..bb38039 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -96,10 +96,18 @@ func (t *quarkusTrait) Apply(e *Environment) error {
if t.isNativePackageType() {
build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
- steps = append(steps, builder.Image.NativeImageContext, builder.Image.ExecutableDockerfile)
+ steps = append(steps, builder.Image.NativeImageContext)
+ // Spectrum does not rely on Dockerfile to assemble the image
+ if e.Platform.Status.Build.PublishStrategy != v1.IntegrationPlatformBuildPublishStrategySpectrum {
+ steps = append(steps, builder.Image.ExecutableDockerfile)
+ }
} else {
build.Maven.Properties["quarkus.package.type"] = string(fastJarPackageType)
- steps = append(steps, builder.Quarkus.ComputeQuarkusDependencies, builder.Image.IncrementalImageContext, builder.Image.JvmDockerfile)
+ steps = append(steps, builder.Quarkus.ComputeQuarkusDependencies, builder.Image.IncrementalImageContext)
+ // Spectrum does not rely on Dockerfile to assemble the image
+ if e.Platform.Status.Build.PublishStrategy != v1.IntegrationPlatformBuildPublishStrategySpectrum {
+ steps = append(steps, builder.Image.JvmDockerfile)
+ }
}
// Sort steps by phase
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 8e61e97..40e559f 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -289,6 +289,20 @@ func DirectoryExists(directory string) (bool, error) {
return info.IsDir(), nil
}
+func DirectoryEmpty(directory string) (bool, error) {
+ f, err := os.Open(directory)
+ if err != nil {
+ return false, err
+ }
+ defer f.Close()
+
+ _, err = f.Readdirnames(1)
+ if err == io.EOF {
+ return true, nil
+ }
+ return false, err
+}
+
func CreateDirectory(directory string) error {
if directory != "" {
// If directory does not exist, create it
[camel-k] 33/37: feat(native): Automatic rollout deployment to
native kit e2e test
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 95af8de2ff394df265995b50ea014ebc2bc9aeb3
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Sep 7 12:44:46 2021 +0200
feat(native): Automatic rollout deployment to native kit e2e test
---
.github/workflows/kubernetes.yml | 3 +-
e2e/native/native_test.go | 90 ++++++++++++++++++++++++++++++++++++++++
e2e/native/yaml.yaml | 28 +++++++++++++
e2e/support/test_support.go | 62 ++++++++++++++++++++++-----
e2e/upgrade/cli_upgrade_test.go | 16 ++-----
e2e/upgrade/olm_upgrade_test.go | 8 ++--
script/Makefile | 28 +++++++------
7 files changed, 195 insertions(+), 40 deletions(-)
diff --git a/.github/workflows/kubernetes.yml b/.github/workflows/kubernetes.yml
index 6677360..33f7f01 100644
--- a/.github/workflows/kubernetes.yml
+++ b/.github/workflows/kubernetes.yml
@@ -131,4 +131,5 @@ jobs:
# Then run integration tests
make test-integration
- make test-service-binding
\ No newline at end of file
+ make test-service-binding
+ make test-quarkus-native
diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
new file mode 100644
index 0000000..e3fd7ca
--- /dev/null
+++ b/e2e/native/native_test.go
@@ -0,0 +1,90 @@
+// +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 native
+
+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"
+)
+
+var (
+ withFastJarLayout = KitWithLabels(map[string]string{v1.IntegrationKitLayoutLabel: v1.IntegrationKitLayoutFastJar})
+ withNativeLayout = KitWithLabels(map[string]string{v1.IntegrationKitLayoutLabel: v1.IntegrationKitLayoutNative})
+)
+
+func TestAutomaticRolloutDeploymentFromFastJarToNativeKit(t *testing.T) {
+ WithNewTestNamespace(t, func(ns string) {
+ Expect(Kamel("install", "-n", ns, "--build-timeout", "15m0s").Execute()).To(Succeed())
+ Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+
+ name := "jvm-to-native"
+ Expect(Kamel("run", "-n", ns, "yaml.yaml", "--name", name,
+ "-t", "quarkus.package-type=fast-jar",
+ "-t", "quarkus.package-type=native",
+ ).Execute()).To(Succeed())
+
+ // Check that two Kits are created with distinct layout
+ Eventually(Kits(ns, withFastJarLayout)).Should(HaveLen(1))
+ Eventually(Kits(ns, withNativeLayout)).Should(HaveLen(1))
+
+ // Check the fast-jar Kit is ready
+ Eventually(Kits(ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady)),
+ TestTimeoutMedium).Should(HaveLen(1))
+
+ fastJarKit := Kits(ns, withFastJarLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0]
+ // Check the Integration uses the fast-jar Kit
+ Eventually(IntegrationKit(ns, name), TestTimeoutShort).Should(Equal(fastJarKit.Name))
+ // Check the Integration Pod uses the fast-jar Kit
+ Eventually(IntegrationPodImage(ns, name)).Should(Equal(fastJarKit.Status.Image))
+
+ // Check the Integration is ready
+ Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+ Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+
+ Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+ // Check the native Kit is ready
+ Eventually(Kits(ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady)),
+ TestTimeoutLong).Should(HaveLen(1))
+
+ nativeKit := Kits(ns, withNativeLayout, KitWithPhase(v1.IntegrationKitPhaseReady))()[0]
+ // Check the Integration uses the native Kit
+ Eventually(IntegrationKit(ns, name), TestTimeoutShort).Should(Equal(nativeKit.Name))
+ // Check the Integration Pod uses the native Kit
+ Eventually(IntegrationPodImage(ns, name)).Should(Equal(nativeKit.Status.Image))
+
+ // Check the Integration is still ready
+ Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+ Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+
+ Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+ // Clean up
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+}
diff --git a/e2e/native/yaml.yaml b/e2e/native/yaml.yaml
new file mode 100644
index 0000000..9ccf652
--- /dev/null
+++ b/e2e/native/yaml.yaml
@@ -0,0 +1,28 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- from:
+ uri: "timer:yaml"
+ parameters:
+ period: "5000"
+ steps:
+ - set-header:
+ name: "m"
+ constant: "string!"
+ - set-body:
+ simple: "Magic${header.m}"
+ - to: "log:info"
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 6f29b22..096a1e9 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -46,6 +46,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
@@ -678,26 +679,65 @@ func ScaleKameletBinding(ns string, name string, replicas int32) error {
})
}
-func Kits(ns string, filters ...func(*v1.IntegrationKit) bool) func() []v1.IntegrationKit {
+type KitFilter interface {
+ Match(*v1.IntegrationKit) bool
+}
+
+func KitWithPhase(phase v1.IntegrationKitPhase) KitFilter {
+ return &kitFilter{
+ filter: func(kit *v1.IntegrationKit) bool {
+ return kit.Status.Phase == phase
+ },
+ }
+}
+
+func KitWithVersion(version string) KitFilter {
+ return &kitFilter{
+ filter: func(kit *v1.IntegrationKit) bool {
+ return kit.Status.Version == version
+ },
+ }
+}
+
+func KitWithLabels(kitLabels map[string]string) ctrl.ListOption {
+ return ctrl.MatchingLabelsSelector{
+ Selector: labels.Set(kitLabels).AsSelector(),
+ }
+}
+
+type kitFilter struct {
+ filter func(*v1.IntegrationKit) bool
+}
+
+func (f *kitFilter) Match(kit *v1.IntegrationKit) bool {
+ return f.filter(kit)
+}
+
+func Kits(ns string, options ...interface{}) func() []v1.IntegrationKit {
+ filters := make([]KitFilter, 0)
+ listOptions := []ctrl.ListOption{ctrl.InNamespace(ns)}
+ for _, option := range options {
+ switch o := option.(type) {
+ case KitFilter:
+ filters = append(filters, o)
+ case ctrl.ListOption:
+ listOptions = append(listOptions, o)
+ default:
+ panic(fmt.Errorf("unsupported kits option %q", o))
+ }
+ }
+
return func() []v1.IntegrationKit {
list := v1.NewIntegrationKitList()
- if err := TestClient().List(TestContext, &list, ctrl.InNamespace(ns)); err != nil {
+ if err := TestClient().List(TestContext, &list, listOptions...); err != nil {
panic(err)
}
- if len(filters) == 0 {
- filters = []func(*v1.IntegrationKit) bool{
- func(kit *v1.IntegrationKit) bool {
- return true
- },
- }
- }
-
var kits []v1.IntegrationKit
kits:
for _, kit := range list.Items {
for _, filter := range filters {
- if !filter(&kit) {
+ if !filter.Match(&kit) {
continue kits
}
}
diff --git a/e2e/upgrade/cli_upgrade_test.go b/e2e/upgrade/cli_upgrade_test.go
index b324633..313b18e 100644
--- a/e2e/upgrade/cli_upgrade_test.go
+++ b/e2e/upgrade/cli_upgrade_test.go
@@ -94,14 +94,14 @@ func TestOperatorUpgrade(t *testing.T) {
Eventually(IntegrationVersion(ns, name)).Should(Equal(defaults.Version))
// Check the previous kit is not garbage collected
- Eventually(Kits(ns, kitWithVersion(version))).Should(HaveLen(1))
+ Eventually(Kits(ns, KitWithVersion(version))).Should(HaveLen(1))
// Check a new kit is created with the current version
- Eventually(Kits(ns, kitWithVersion(defaults.Version))).Should(HaveLen(1))
+ Eventually(Kits(ns, KitWithVersion(defaults.Version))).Should(HaveLen(1))
// Check the new kit is ready
- Eventually(Kits(ns, kitWithVersion(defaults.Version), kitWithPhase(v1.IntegrationKitPhaseReady)),
+ Eventually(Kits(ns, KitWithVersion(defaults.Version), KitWithPhase(v1.IntegrationKitPhaseReady)),
TestTimeoutMedium).Should(HaveLen(1))
- kit := Kits(ns, kitWithVersion(defaults.Version))()[0]
+ kit := Kits(ns, KitWithVersion(defaults.Version))()[0]
// Check the Integration uses the new image
Eventually(IntegrationKit(ns, name), TestTimeoutMedium).Should(Equal(kit.Name))
@@ -117,11 +117,3 @@ func TestOperatorUpgrade(t *testing.T) {
Expect(Kamel("uninstall", "--all", "--olm=false").Execute()).To(Succeed())
})
}
-
-func kitWithVersion(version string) func(kit *v1.IntegrationKit) bool {
- return func(kit *v1.IntegrationKit) bool { return kit.Status.Version == version }
-}
-
-func kitWithPhase(phase v1.IntegrationKitPhase) func(kit *v1.IntegrationKit) bool {
- return func(kit *v1.IntegrationKit) bool { return kit.Status.Phase == phase }
-}
diff --git a/e2e/upgrade/olm_upgrade_test.go b/e2e/upgrade/olm_upgrade_test.go
index 5641959..7977c74 100644
--- a/e2e/upgrade/olm_upgrade_test.go
+++ b/e2e/upgrade/olm_upgrade_test.go
@@ -141,14 +141,14 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
Eventually(IntegrationVersion(ns, name)).Should(ContainSubstring(newIPVersionPrefix))
// Check the previous kit is not garbage collected
- Eventually(Kits(ns, kitWithVersion(prevCSVVersion.String()))).Should(HaveLen(1))
+ Eventually(Kits(ns, KitWithVersion(prevCSVVersion.String()))).Should(HaveLen(1))
// Check a new kit is created with the current version
- Eventually(Kits(ns, kitWithVersion(defaults.Version))).Should(HaveLen(1))
+ Eventually(Kits(ns, KitWithVersion(defaults.Version))).Should(HaveLen(1))
// Check the new kit is ready
- Eventually(Kits(ns, kitWithVersion(defaults.Version), kitWithPhase(v1.IntegrationKitPhaseReady)),
+ Eventually(Kits(ns, KitWithVersion(defaults.Version), KitWithPhase(v1.IntegrationKitPhaseReady)),
TestTimeoutMedium).Should(HaveLen(1))
- kit := Kits(ns, kitWithVersion(defaults.Version))()[0]
+ kit := Kits(ns, KitWithVersion(defaults.Version))()[0]
// Check the Integration uses the new kit
Eventually(IntegrationKit(ns, name), TestTimeoutMedium).Should(Equal(kit.Name))
diff --git a/script/Makefile b/script/Makefile
index e5fe4c6..4a74b79 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -161,28 +161,32 @@ test-integration: build
go test -timeout 60m -v ./e2e/common/traits -tags=integration
test-knative: build
- STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/knative -tags=integration
- #go test -timeout 60m -v ./e2e/knative -tags=integration
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/knative -tags=integration
test-builder: build
- STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/builder -tags=integration
- #go test -timeout 60m -v ./e2e/builder -tags=integration
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/builder -tags=integration
test-local: build
- STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/local -tags=integration
- #go test -timeout 60m -v ./e2e/local -tags=integration
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/local -tags=integration
test-kamel-cli: build
- STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/common/cli -tags=integration
- #go test -timeout 60m -v ./e2e/common/cli -tags=integration
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/common/cli -tags=integration
-test-upgrade: build
+test-quarkus-native: build
STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
- go test -timeout 60m -v ./e2e/upgrade -tags=integration
+ go test -timeout 60m -v ./e2e/native -tags=integration
test-service-binding: build
- STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/service-binding -tags=integration
- #go test -timeout 60m -v ./e2e/service-binding -tags=integration
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/service-binding -tags=integration
+
+test-upgrade: build
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \
+ go test -timeout 60m -v ./e2e/upgrade -tags=integration
build-kamel:
# Ensure the binary is statically linked when building on Linux due to ABI changes in newer glibc 2.32, otherwise
[camel-k] 10/37: feat(native): Exclude native kits from incremental
base image lookup
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 8b130dd6e53f991beeff0455885b1155840a33f8
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Aug 17 14:44:09 2021 +0200
feat(native): Exclude native kits from incremental base image lookup
---
e2e/builder/global_test.go | 20 +++---
e2e/support/test_support.go | 8 +--
pkg/apis/camel/v1/build_types_support.go | 16 +----
pkg/apis/camel/v1/integrationkit_types.go | 13 +++-
pkg/apis/camel/v1/integrationkit_types_support.go | 18 +----
pkg/builder/image.go | 18 +++--
pkg/builder/image_test.go | 4 +-
pkg/cmd/describe_kit.go | 8 +--
pkg/cmd/kit_create.go | 22 +++---
pkg/cmd/kit_delete.go | 33 +++++----
pkg/cmd/kit_get.go | 2 +-
pkg/controller/integration/build_kit.go | 36 ++++++----
pkg/controller/integration/build_kit_test.go | 10 +--
pkg/controller/integration/initialize.go | 2 +-
.../integrationkit/integrationkit_controller.go | 2 +-
pkg/trait/container.go | 6 +-
pkg/trait/gc.go | 13 ++--
pkg/trait/jvm.go | 10 +--
pkg/trait/jvm_test.go | 2 +-
pkg/trait/quarkus.go | 23 ++++---
pkg/trait/quarkus_test.go | 8 ++-
pkg/trait/util.go | 8 +--
pkg/util/controller/util.go | 45 -------------
pkg/util/kubernetes/client.go | 78 ++++++++--------------
24 files changed, 170 insertions(+), 235 deletions(-)
diff --git a/e2e/builder/global_test.go b/e2e/builder/global_test.go
index a8b676e..d2b408a 100644
--- a/e2e/builder/global_test.go
+++ b/e2e/builder/global_test.go
@@ -28,11 +28,11 @@ import (
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
- v1 "k8s.io/api/core/v1"
+ corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
. "github.com/apache/camel-k/e2e/support"
- camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/util/openshift"
)
@@ -57,7 +57,7 @@ func TestRunGlobalInstall(t *testing.T) {
Expect(Kamel("install", "-n", ns2, "--skip-operator-setup", "--olm=false").Execute()).To(Succeed())
Expect(Kamel("run", "-n", ns2, "files/Java.java").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns2, "java"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationPodPhase(ns2, "java"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns2, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", "--all", "-n", ns2).Execute()).To(Succeed())
Expect(Kits(ns2)()).Should(HaveLen(1))
@@ -72,7 +72,7 @@ func TestRunGlobalInstall(t *testing.T) {
Expect(Kamel("install", "-n", ns3, "--olm=false").Execute()).To(Succeed())
Expect(Kamel("run", "-n", ns3, "files/Java.java").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns3, "java"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationPodPhase(ns3, "java"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns3, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", "--all", "-n", ns3).Execute()).To(Succeed())
@@ -85,7 +85,7 @@ func TestRunGlobalInstall(t *testing.T) {
t.Run("Global test on namespace without platform", func(t *testing.T) {
WithNewTestNamespace(t, func(ns4 string) {
Expect(Kamel("run", "-n", ns4, "files/Java.java").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns4, "java"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationPodPhase(ns4, "java"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns4, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", "--all", "-n", ns4).Execute()).To(Succeed())
Expect(Kits(ns4)()).Should(HaveLen(0))
@@ -98,7 +98,7 @@ func TestRunGlobalInstall(t *testing.T) {
t.Run("Global test on namespace without platform with external kit", func(t *testing.T) {
WithNewTestNamespace(t, func(ns5 string) {
Expect(Kamel("run", "-n", ns5, "files/Java.java").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns5, "java"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationPodPhase(ns5, "java"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns5, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", "--all", "-n", ns5).Execute()).To(Succeed())
Expect(Kits(ns5)()).Should(HaveLen(0))
@@ -107,22 +107,22 @@ func TestRunGlobalInstall(t *testing.T) {
if len(globalKits) == 1 {
kit := globalKits[0]
// external kit mirroring the global one
- externalKit := camelv1.IntegrationKit{
+ externalKit := v1.IntegrationKit{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns5,
Name: "external",
Labels: map[string]string{
- "camel.apache.org/kit.type": camelv1.IntegrationKitTypeExternal,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeExternal,
},
},
- Spec: camelv1.IntegrationKitSpec{
+ Spec: v1.IntegrationKitSpec{
Image: kit.Status.Image,
},
}
Expect(TestClient().Create(TestContext, &externalKit)).Should(BeNil())
Expect(Kamel("run", "-n", ns5, "files/Java.java", "--name", "ext", "--kit", "external").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns5, "ext"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationPodPhase(ns5, "ext"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns5, "ext"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(IntegrationKit(ns5, "ext")()).Should(Equal("external"))
Expect(Kamel("delete", "--all", "-n", ns5).Execute()).To(Succeed())
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 323362e..a85b0d4 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -854,17 +854,13 @@ func DeploymentCondition(ns string, name string, conditionType appsv1.Deployment
func Build(ns string, name string) func() *v1.Build {
return func() *v1.Build {
build := v1.NewBuild(ns, name)
- key := ctrl.ObjectKey{
- Namespace: ns,
- Name: name,
- }
- if err := TestClient().Get(TestContext, key, &build); err != nil && k8serrors.IsNotFound(err) {
+ if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(build), build); err != nil && k8serrors.IsNotFound(err) {
return nil
} else if err != nil {
log.Error(err, "Error while retrieving build "+name)
return nil
}
- return &build
+ return build
}
}
diff --git a/pkg/apis/camel/v1/build_types_support.go b/pkg/apis/camel/v1/build_types_support.go
index 9b5c332..31fc668 100644
--- a/pkg/apis/camel/v1/build_types_support.go
+++ b/pkg/apis/camel/v1/build_types_support.go
@@ -22,9 +22,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
-// NewBuild --
-func NewBuild(namespace string, name string) Build {
- return Build{
+func NewBuild(namespace string, name string) *Build {
+ return &Build{
TypeMeta: metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: BuildKind,
@@ -36,7 +35,6 @@ func NewBuild(namespace string, name string) Build {
}
}
-// NewBuildList --
func NewBuildList() BuildList {
return BuildList{
TypeMeta: metav1.TypeMeta{
@@ -50,7 +48,6 @@ func (buildPhase *BuildPhase) String() string {
return string(*buildPhase)
}
-// SetIntegrationPlatform --
func (in *Build) SetIntegrationPlatform(platform *IntegrationPlatform) {
cs := corev1.ConditionTrue
@@ -79,7 +76,6 @@ func (in *BuildStatus) Failed(err error) BuildStatus {
return *in
}
-// SetCondition --
func (in *BuildStatus) SetCondition(condType BuildConditionType, status corev1.ConditionStatus, reason string, message string) {
in.SetConditions(BuildCondition{
Type: condType,
@@ -91,7 +87,6 @@ func (in *BuildStatus) SetCondition(condType BuildConditionType, status corev1.C
})
}
-// SetErrorCondition --
func (in *BuildStatus) SetErrorCondition(condType BuildConditionType, reason string, err error) {
in.SetConditions(BuildCondition{
Type: condType,
@@ -145,7 +140,6 @@ func (in *BuildStatus) RemoveCondition(condType BuildConditionType) {
var _ ResourceCondition = BuildCondition{}
-// GetConditions --
func (in *BuildStatus) GetConditions() []ResourceCondition {
res := make([]ResourceCondition, 0, len(in.Conditions))
for _, c := range in.Conditions {
@@ -154,32 +148,26 @@ func (in *BuildStatus) GetConditions() []ResourceCondition {
return res
}
-// GetType --
func (c BuildCondition) GetType() string {
return string(c.Type)
}
-// GetStatus --
func (c BuildCondition) GetStatus() corev1.ConditionStatus {
return c.Status
}
-// GetLastUpdateTime --
func (c BuildCondition) GetLastUpdateTime() metav1.Time {
return c.LastUpdateTime
}
-// GetLastTransitionTime --
func (c BuildCondition) GetLastTransitionTime() metav1.Time {
return c.LastTransitionTime
}
-// GetReason --
func (c BuildCondition) GetReason() string {
return c.Reason
}
-// GetMessage --
func (c BuildCondition) GetMessage() string {
return c.Message
}
diff --git a/pkg/apis/camel/v1/integrationkit_types.go b/pkg/apis/camel/v1/integrationkit_types.go
index 46ebdf2..0fae093 100644
--- a/pkg/apis/camel/v1/integrationkit_types.go
+++ b/pkg/apis/camel/v1/integrationkit_types.go
@@ -87,15 +87,24 @@ const (
// IntegrationKitKind --
IntegrationKitKind string = "IntegrationKit"
+ // IntegrationKitTypeLabel labels the kit type
+ IntegrationKitTypeLabel = "camel.apache.org/kit.type"
+
// IntegrationKitTypePlatform --
IntegrationKitTypePlatform = "platform"
-
// IntegrationKitTypeUser --
IntegrationKitTypeUser = "user"
-
// IntegrationKitTypeExternal --
IntegrationKitTypeExternal = "external"
+ // IntegrationKitLayoutLabel labels the kit layout
+ IntegrationKitLayoutLabel = "camel.apache.org/kit.layout"
+
+ // IntegrationKitLayoutFastJar labels a kit using the Quarkus fast-jar packaging
+ IntegrationKitLayoutFastJar = "fast-jar"
+ // IntegrationKitLayoutNative labels a kit using the Quarkus native packaging
+ IntegrationKitLayoutNative = "native"
+
// IntegrationKitPhaseNone --
IntegrationKitPhaseNone IntegrationKitPhase = ""
// IntegrationKitPhaseInitialization --
diff --git a/pkg/apis/camel/v1/integrationkit_types_support.go b/pkg/apis/camel/v1/integrationkit_types_support.go
index fb310df..a9c894e 100644
--- a/pkg/apis/camel/v1/integrationkit_types_support.go
+++ b/pkg/apis/camel/v1/integrationkit_types_support.go
@@ -22,9 +22,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
-// NewIntegrationKit --
-func NewIntegrationKit(namespace string, name string) IntegrationKit {
- return IntegrationKit{
+func NewIntegrationKit(namespace string, name string) *IntegrationKit {
+ return &IntegrationKit{
TypeMeta: metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: IntegrationKitKind,
@@ -36,7 +35,6 @@ func NewIntegrationKit(namespace string, name string) IntegrationKit {
}
}
-// NewIntegrationKitList --
func NewIntegrationKitList() IntegrationKitList {
return IntegrationKitList{
TypeMeta: metav1.TypeMeta{
@@ -46,7 +44,6 @@ func NewIntegrationKitList() IntegrationKitList {
}
}
-// Configurations --
func (in *IntegrationKitSpec) Configurations() []ConfigurationSpec {
if in == nil {
return []ConfigurationSpec{}
@@ -55,7 +52,6 @@ func (in *IntegrationKitSpec) Configurations() []ConfigurationSpec {
return in.Configuration
}
-// Configurations --
func (in *IntegrationKit) Configurations() []ConfigurationSpec {
if in == nil {
return []ConfigurationSpec{}
@@ -64,7 +60,6 @@ func (in *IntegrationKit) Configurations() []ConfigurationSpec {
return in.Spec.Configuration
}
-// SetIntegrationPlatform --
func (in *IntegrationKit) SetIntegrationPlatform(platform *IntegrationPlatform) {
cs := corev1.ConditionTrue
@@ -92,7 +87,6 @@ func (in *IntegrationKitStatus) GetCondition(condType IntegrationKitConditionTyp
return nil
}
-// SetCondition --
func (in *IntegrationKitStatus) SetCondition(condType IntegrationKitConditionType, status corev1.ConditionStatus, reason string, message string) {
in.SetConditions(IntegrationKitCondition{
Type: condType,
@@ -104,7 +98,6 @@ func (in *IntegrationKitStatus) SetCondition(condType IntegrationKitConditionTyp
})
}
-// SetErrorCondition --
func (in *IntegrationKitStatus) SetErrorCondition(condType IntegrationKitConditionType, reason string, err error) {
in.SetConditions(IntegrationKitCondition{
Type: condType,
@@ -158,7 +151,6 @@ func (in *IntegrationKitStatus) RemoveCondition(condType IntegrationKitCondition
var _ ResourceCondition = IntegrationKitCondition{}
-// GetConditions --
func (in *IntegrationKitStatus) GetConditions() []ResourceCondition {
res := make([]ResourceCondition, 0, len(in.Conditions))
for _, c := range in.Conditions {
@@ -167,32 +159,26 @@ func (in *IntegrationKitStatus) GetConditions() []ResourceCondition {
return res
}
-// GetType --
func (c IntegrationKitCondition) GetType() string {
return string(c.Type)
}
-// GetStatus --
func (c IntegrationKitCondition) GetStatus() corev1.ConditionStatus {
return c.Status
}
-// GetLastUpdateTime --
func (c IntegrationKitCondition) GetLastUpdateTime() metav1.Time {
return c.LastUpdateTime
}
-// GetLastTransitionTime --
func (c IntegrationKitCondition) GetLastTransitionTime() metav1.Time {
return c.LastTransitionTime
}
-// GetReason --
func (c IntegrationKitCondition) GetReason() string {
return c.Reason
}
-// GetMessage --
func (c IntegrationKitCondition) GetMessage() string {
return c.Message
}
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 8aca5a6..da702bc 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -22,6 +22,7 @@ import (
"os"
"path"
+ "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,7 +30,6 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/controller"
"github.com/apache/camel-k/pkg/util/defaults"
)
@@ -166,19 +166,27 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
}
func listPublishedImages(context *builderContext) ([]v1.IntegrationKitStatus, error) {
+ excludeNativeImages, err := labels.NewRequirement(v1.IntegrationKitLayoutLabel, selection.NotEquals, []string{
+ v1.IntegrationKitLayoutNative,
+ })
+ if err != nil {
+ return nil, err
+ }
+
options := []ctrl.ListOption{
ctrl.InNamespace(context.Namespace),
ctrl.MatchingLabels{
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
"camel.apache.org/runtime.version": context.Catalog.Runtime.Version,
"camel.apache.org/runtime.provider": string(context.Catalog.Runtime.Provider),
},
- controller.NewLabelSelector("camel.apache.org/kit.type", selection.Equals, []string{
- v1.IntegrationKitTypePlatform,
- }),
+ ctrl.MatchingLabelsSelector{
+ Selector: labels.NewSelector().Add(*excludeNativeImages),
+ },
}
list := v1.NewIntegrationKitList()
- err := context.Client.List(context.C, &list, options...)
+ err = context.Client.List(context.C, &list, options...)
if err != nil {
return nil, err
}
diff --git a/pkg/builder/image_test.go b/pkg/builder/image_test.go
index b858288..eafd6d1 100644
--- a/pkg/builder/image_test.go
+++ b/pkg/builder/image_test.go
@@ -44,7 +44,7 @@ func TestListPublishedImages(t *testing.T) {
Namespace: "ns",
Name: "my-kit-1",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
"camel.apache.org/runtime.version": catalog.Runtime.Version,
"camel.apache.org/runtime.provider": string(catalog.Runtime.Provider),
},
@@ -65,7 +65,7 @@ func TestListPublishedImages(t *testing.T) {
Namespace: "ns",
Name: "my-kit-2",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
"camel.apache.org/runtime.version": catalog.Runtime.Version,
"camel.apache.org/runtime.provider": string(catalog.Runtime.Provider),
},
diff --git a/pkg/cmd/describe_kit.go b/pkg/cmd/describe_kit.go
index 2040352..7e3a33e 100644
--- a/pkg/cmd/describe_kit.go
+++ b/pkg/cmd/describe_kit.go
@@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra"
- k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/indentedwriter"
@@ -74,12 +74,12 @@ func (command *describeKitCommandOptions) run(args []string) error {
}
kit := v1.NewIntegrationKit(command.Namespace, args[0])
- kitKey := k8sclient.ObjectKey{
+ kitKey := ctrl.ObjectKey{
Namespace: command.Namespace,
Name: args[0],
}
- if err := c.Get(command.Context, kitKey, &kit); err == nil {
+ if err := c.Get(command.Context, kitKey, kit); err == nil {
if desc, err := command.describeIntegrationKit(kit); err == nil {
fmt.Print(desc)
} else {
@@ -92,7 +92,7 @@ func (command *describeKitCommandOptions) run(args []string) error {
return nil
}
-func (command *describeKitCommandOptions) describeIntegrationKit(kit v1.IntegrationKit) (string, error) {
+func (command *describeKitCommandOptions) describeIntegrationKit(kit *v1.IntegrationKit) (string, error) {
return indentedwriter.IndentedString(func(out io.Writer) error {
w := indentedwriter.NewWriter(out)
diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go
index 63ab0ea..ebf547f 100644
--- a/pkg/cmd/kit_create.go
+++ b/pkg/cmd/kit_create.go
@@ -23,8 +23,10 @@ import (
"strings"
"github.com/spf13/cobra"
+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
- k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/trait"
@@ -98,15 +100,15 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
}
kit := v1.NewIntegrationKit(command.Namespace, args[0])
- key := k8sclient.ObjectKey{
+ key := ctrl.ObjectKey{
Namespace: command.Namespace,
Name: args[0],
}
- if err := c.Get(command.Context, key, &kit); err == nil {
+ if err := c.Get(command.Context, key, kit); err == nil {
// the integration kit already exists, let's check that it is
// not a platform one which is supposed to be "read only"
- if kit.Labels["camel.apache.org/kit.type"] == v1.IntegrationKitTypePlatform {
+ if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
fmt.Printf("integration kit \"%s\" is not editable\n", kit.Name)
return nil
}
@@ -114,7 +116,7 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
kit = v1.NewIntegrationKit(command.Namespace, kubernetes.SanitizeName(args[0]))
kit.Labels = map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypeUser,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeUser,
}
kit.Spec = v1.IntegrationKitSpec{
Dependencies: make([]string, 0, len(command.Dependencies)),
@@ -126,7 +128,7 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
// if the Image is set, the kit do not require any build but
// is be marked as external as the information about the classpath
// is missing so it cannot be used as base for other Kits
- kit.Labels["camel.apache.org/kit.type"] = v1.IntegrationKitTypeExternal
+ kit.Labels[v1.IntegrationKitTypeLabel] = v1.IntegrationKitTypeExternal
// Set the Image to be used by the kit
kit.Spec.Image = command.Image
@@ -162,22 +164,22 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
Value: item,
})
}
- if err := command.configureTraits(&kit, command.Traits, catalog); err != nil {
+ if err := command.configureTraits(kit, command.Traits, catalog); err != nil {
return nil
}
existed := false
- err = c.Create(command.Context, &kit)
+ err = c.Create(command.Context, kit)
if err != nil && k8serrors.IsAlreadyExists(err) {
existed = true
existing := v1.NewIntegrationKit(kit.Namespace, kit.Name)
- err = c.Get(command.Context, key, &existing)
+ err = c.Get(command.Context, key, existing)
if err != nil {
fmt.Print(err.Error())
return nil
}
kit.ResourceVersion = existing.ResourceVersion
- err = c.Update(command.Context, &kit)
+ err = c.Update(command.Context, kit)
}
if err != nil {
diff --git a/pkg/cmd/kit_delete.go b/pkg/cmd/kit_delete.go
index 0a0428d..d484195 100644
--- a/pkg/cmd/kit_delete.go
+++ b/pkg/cmd/kit_delete.go
@@ -21,12 +21,13 @@ import (
"errors"
"fmt"
- k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
-
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/spf13/cobra"
k8errors "k8s.io/apimachinery/pkg/api/errors"
+
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
)
func newKitDeleteCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kitDeleteCommandOptions) {
@@ -82,14 +83,14 @@ func (command *kitDeleteCommandOptions) run(args []string) error {
if command.All {
kitList := v1.NewIntegrationKitList()
- if err := c.List(command.Context, &kitList, k8sclient.InNamespace(command.Namespace)); err != nil {
+ if err := c.List(command.Context, &kitList, ctrl.InNamespace(command.Namespace)); err != nil {
return err
}
names = make([]string, 0, len(kitList.Items))
for _, item := range kitList.Items {
// only include non platform Kits
- if item.Labels["camel.apache.org/kit.type"] != v1.IntegrationKitTypePlatform {
+ if item.Labels[v1.IntegrationKitTypeLabel] != v1.IntegrationKitTypePlatform {
names = append(names, item.Name)
}
}
@@ -105,21 +106,17 @@ func (command *kitDeleteCommandOptions) run(args []string) error {
}
func (command *kitDeleteCommandOptions) delete(name string) error {
- ctx := v1.NewIntegrationKit(command.Namespace, name)
- key := k8sclient.ObjectKey{
- Namespace: command.Namespace,
- Name: name,
- }
+ kit := v1.NewIntegrationKit(command.Namespace, name)
c, err := command.GetCmdClient()
if err != nil {
return err
}
- err = c.Get(command.Context, key, &ctx)
+ err = c.Get(command.Context, ctrl.ObjectKeyFromObject(kit), kit)
// pass through if the kit is not found
if err != nil && k8errors.IsNotFound(err) {
- return fmt.Errorf("no integration kit found with name \"%s\"", ctx.Name)
+ return fmt.Errorf("no integration kit found with name \"%s\"", kit.Name)
}
// fail otherwise
@@ -129,25 +126,25 @@ func (command *kitDeleteCommandOptions) delete(name string) error {
// check that it is not a platform one which is supposed to be "read only"
// thus not managed by the end user
- if ctx.Labels["camel.apache.org/kit.type"] == v1.IntegrationKitTypePlatform {
+ if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
// skip platform Kits while deleting all Kits
if command.All {
return nil
}
- return fmt.Errorf("integration kit \"%s\" is not editable", ctx.Name)
+ return fmt.Errorf("integration kit \"%s\" is not editable", kit.Name)
}
- err = c.Delete(command.Context, &ctx)
+ err = c.Delete(command.Context, kit)
if err != nil && !k8errors.IsNotFound(err) {
- return fmt.Errorf("error deleting integration kit \"%s\", %s", ctx.Name, err)
+ return fmt.Errorf("error deleting integration kit \"%s\", %s", kit.Name, err)
}
if err != nil && k8errors.IsNotFound(err) {
- return fmt.Errorf("no integration kit found with name \"%s\"", ctx.Name)
+ return fmt.Errorf("no integration kit found with name \"%s\"", kit.Name)
}
- fmt.Printf("integration kit \"%s\" has been deleted\n", ctx.Name)
+ fmt.Printf("integration kit \"%s\" has been deleted\n", kit.Name)
return err
}
diff --git a/pkg/cmd/kit_get.go b/pkg/cmd/kit_get.go
index 5cba832..b3063cf 100644
--- a/pkg/cmd/kit_get.go
+++ b/pkg/cmd/kit_get.go
@@ -81,7 +81,7 @@ func (command *kitGetCommandOptions) run(cmd *cobra.Command) error {
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 8, 1, '\t', 0)
fmt.Fprintln(w, "NAME\tPHASE\tTYPE\tIMAGE")
for _, ctx := range kitList.Items {
- t := ctx.Labels["camel.apache.org/kit.type"]
+ t := ctx.Labels[v1.IntegrationKitTypeLabel]
u := command.User && t == v1.IntegrationKitTypeUser
e := command.External && t == v1.IntegrationKitTypeExternal
p := command.Platform && t == v1.IntegrationKitTypePlatform
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index 005ed45..cb2919c 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -26,6 +26,7 @@ import (
"github.com/rs/xid"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
+ "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -34,7 +35,6 @@ import (
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/controller"
"github.com/apache/camel-k/pkg/util/kubernetes"
)
@@ -63,7 +63,7 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
}
if kit != nil {
- if kit.Labels["camel.apache.org/kit.type"] == v1.IntegrationKitTypePlatform {
+ if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
// This is a platform kit and as it is auto generated it may get
// out of sync if the integration that has generated it, has been
// amended to add/remove dependencies
@@ -116,13 +116,12 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
return nil, err
}
- platformKitName := fmt.Sprintf("kit-%s", xid.New())
- platformKit := v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(pl), platformKitName)
+ kit = v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(pl), fmt.Sprintf("kit-%s", xid.New()))
// Add some information for post-processing, this may need to be refactored
// to a proper data structure
- platformKit.Labels = map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ kit.Labels = map[string]string{
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
"camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
"camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
@@ -132,19 +131,23 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
}
// Set the kit to have the same characteristics as the integrations
- platformKit.Spec = v1.IntegrationKitSpec{
+ kit.Spec = v1.IntegrationKitSpec{
Dependencies: integration.Status.Dependencies,
Repositories: integration.Spec.Repositories,
Traits: action.filterKitTraits(ctx, integration.Spec.Traits),
}
- if err := action.client.Create(ctx, &platformKit); err != nil {
+ if _, err := trait.Apply(ctx, action.client, integration, kit); err != nil {
+ return nil, err
+ }
+
+ if err := action.client.Create(ctx, kit); err != nil {
return nil, err
}
// Set the kit name so the next handle loop, will fall through the
// same path as integration with a user defined kit
- integration.SetIntegrationKit(&platformKit)
+ integration.SetIntegrationKit(kit)
return integration, nil
}
@@ -181,16 +184,23 @@ func (action *buildKitAction) lookupKitForIntegration(ctx context.Context, c ctr
return nil, err
}
+ kitTypes, err := labels.NewRequirement(v1.IntegrationKitTypeLabel, selection.In, []string{
+ v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeExternal,
+ })
+ if err != nil {
+ return nil, err
+ }
+
options := []ctrl.ListOption{
ctrl.InNamespace(integration.GetIntegrationKitNamespace(pl)),
ctrl.MatchingLabels{
"camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
"camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
},
- controller.NewLabelSelector("camel.apache.org/kit.type", selection.In, []string{
- v1.IntegrationKitTypePlatform,
- v1.IntegrationKitTypeExternal,
- }),
+ ctrl.MatchingLabelsSelector{
+ Selector: labels.NewSelector().Add(*kitTypes),
+ },
}
kits := v1.NewIntegrationKitList()
diff --git a/pkg/controller/integration/build_kit_test.go b/pkg/controller/integration/build_kit_test.go
index 6d1489f..fa3df64 100644
--- a/pkg/controller/integration/build_kit_test.go
+++ b/pkg/controller/integration/build_kit_test.go
@@ -41,7 +41,7 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
Namespace: "ns",
Name: "my-kit-1",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
},
},
Spec: v1.IntegrationKitSpec{
@@ -63,7 +63,7 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
Namespace: "ns",
Name: "my-kit-2",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
},
},
Spec: v1.IntegrationKitSpec{
@@ -120,7 +120,7 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
Namespace: "ns",
Name: "my-kit-1",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
},
},
Spec: v1.IntegrationKitSpec{
@@ -146,7 +146,7 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
Namespace: "ns",
Name: "my-kit-2",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
},
},
Spec: v1.IntegrationKitSpec{
@@ -177,7 +177,7 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
Namespace: "ns",
Name: "my-kit-3",
Labels: map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypePlatform,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
},
},
Spec: v1.IntegrationKitSpec{
diff --git a/pkg/controller/integration/initialize.go b/pkg/controller/integration/initialize.go
index 7a55d80..b55066a 100644
--- a/pkg/controller/integration/initialize.go
+++ b/pkg/controller/integration/initialize.go
@@ -77,7 +77,7 @@ func (action *initializeAction) Handle(ctx context.Context, integration *v1.Inte
}
}
kit := v1.NewIntegrationKit(kitNamespace, kitName)
- integration.SetIntegrationKit(&kit)
+ integration.SetIntegrationKit(kit)
} else {
integration.Status.IntegrationKit = nil
}
diff --git a/pkg/controller/integrationkit/integrationkit_controller.go b/pkg/controller/integrationkit/integrationkit_controller.go
index 3714c52..26b969b 100644
--- a/pkg/controller/integrationkit/integrationkit_controller.go
+++ b/pkg/controller/integrationkit/integrationkit_controller.go
@@ -206,7 +206,7 @@ func (r *reconcileIntegrationKit) Reconcile(ctx context.Context, request reconci
targetLog := rlog.ForIntegrationKit(target)
if target.Status.Phase == v1.IntegrationKitPhaseNone || target.Status.Phase == v1.IntegrationKitPhaseWaitingForPlatform {
- if target.Labels["camel.apache.org/kit.type"] == v1.IntegrationKitTypeExternal {
+ if target.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypeExternal {
target.Status.Phase = v1.IntegrationKitPhaseInitialization
return r.update(ctx, &instance, target)
} else {
diff --git a/pkg/trait/container.go b/pkg/trait/container.go
index b6c5caf..3a08235 100644
--- a/pkg/trait/container.go
+++ b/pkg/trait/container.go
@@ -190,7 +190,7 @@ func (t *containerTrait) configureDependencies(e *Environment) error {
// Add some information for post-processing, this may need to be refactored
// to a proper data structure
kit.Labels = map[string]string{
- "camel.apache.org/kit.type": v1.IntegrationKitTypeExternal,
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeExternal,
kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
kubernetes.CamelCreatorLabelName: e.Integration.Name,
kubernetes.CamelCreatorLabelNamespace: e.Integration.Namespace,
@@ -198,8 +198,8 @@ func (t *containerTrait) configureDependencies(e *Environment) error {
}
t.L.Infof("image %s", kit.Spec.Image)
- e.Resources.Add(&kit)
- e.Integration.SetIntegrationKit(&kit)
+ e.Resources.Add(kit)
+ e.Integration.SetIntegrationKit(kit)
}
if IsTrue(t.ProbesEnabled) {
if capability, ok := e.CamelCatalog.Runtime.Capabilities[v1.CapabilityHealth]; ok {
diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 59210ea..aec1008 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -36,10 +36,9 @@ import (
"k8s.io/client-go/discovery/cached/disk"
"k8s.io/client-go/discovery/cached/memory"
- "sigs.k8s.io/controller-runtime/pkg/client"
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
- util "github.com/apache/camel-k/pkg/util/controller"
)
var (
@@ -99,7 +98,7 @@ func (t *garbageCollectorTrait) Apply(e *Environment) error {
// are ready. This is to be added when the integration scale status is refined with ready replicas
e.PostActions = append(e.PostActions, func(env *Environment) error {
// The collection and deletion are performed asynchronously to avoid blocking
- // the reconcile loop.
+ // the reconciliation loop.
go t.garbageCollectResources(env)
return nil
})
@@ -152,9 +151,9 @@ func (t *garbageCollectorTrait) deleteEachOf(gvks map[schema.GroupVersionKind]st
"kind": gvk.Kind,
},
}
- options := []client.ListOption{
- client.InNamespace(e.Integration.Namespace),
- util.MatchingSelector{Selector: selector},
+ options := []ctrl.ListOption{
+ ctrl.InNamespace(e.Integration.Namespace),
+ ctrl.MatchingLabelsSelector{Selector: selector},
}
if err := t.Client.List(context.TODO(), &resources, options...); err != nil {
if !k8serrors.IsNotFound(err) && !k8serrors.IsForbidden(err) {
@@ -168,7 +167,7 @@ func (t *garbageCollectorTrait) deleteEachOf(gvks map[schema.GroupVersionKind]st
if !t.canBeDeleted(e, r) {
continue
}
- err := t.Client.Delete(context.TODO(), &r, client.PropagationPolicy(metav1.DeletePropagationBackground))
+ err := t.Client.Delete(context.TODO(), &r, ctrl.PropagationPolicy(metav1.DeletePropagationBackground))
if err != nil {
// The resource may have already been deleted
if !k8serrors.IsNotFound(err) {
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 1080de4..81700dc 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -88,10 +88,10 @@ func (t *jvmTrait) Apply(e *Environment) error {
name := e.Integration.Status.IntegrationKit.Name
ns := e.Integration.GetIntegrationKitNamespace(e.Platform)
k := v1.NewIntegrationKit(ns, name)
- if err := t.Client.Get(t.Ctx, ctrl.ObjectKeyFromObject(&k), &k); err != nil {
+ if err := t.Client.Get(t.Ctx, ctrl.ObjectKeyFromObject(k), k); err != nil {
return errors.Wrapf(err, "unable to find integration kit %s/%s, %s", ns, name, err)
}
- kit = &k
+ kit = k
}
if kit == nil {
@@ -114,10 +114,10 @@ func (t *jvmTrait) Apply(e *Environment) error {
classpath.Add(artifact.Target)
}
- if kit.Labels["camel.apache.org/kit.type"] == v1.IntegrationKitTypeExternal {
+ if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypeExternal {
// In case of an external created kit, we do not have any information about
- // the classpath so we assume the all jars in /deployments/dependencies/ have
- // to be taken into account
+ // the classpath, so we assume the all jars in /deployments/dependencies/ have
+ // to be taken into account.
dependencies := path.Join(builder.DeploymentDir, builder.DependenciesDir)
classpath.Add(
dependencies+"/*",
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 343b25d..4c24a18 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -278,7 +278,7 @@ func createNominalJvmTest(kitType string) (*jvmTrait, *Environment) {
Namespace: "kit-namespace",
Name: "kit-name",
Labels: map[string]string{
- "camel.apache.org/kit.type": kitType,
+ v1.IntegrationKitTypeLabel: kitType,
},
},
Status: v1.IntegrationKitStatus{
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index b43e045..97f05fb 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -62,13 +62,22 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
t.PackageType = &packageType
}
- return e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) ||
- e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
- e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
+ return e.IntegrationKitInPhase(v1.IntegrationKitPhaseNone, v1.IntegrationKitPhaseBuildSubmitted) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning),
+ nil
}
func (t *quarkusTrait) Apply(e *Environment) error {
- if e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) {
+ switch e.IntegrationKit.Status.Phase {
+
+ case v1.IntegrationKitPhaseNone:
+ if e.IntegrationKit.Labels == nil {
+ e.IntegrationKit.Labels = make(map[string]string)
+ }
+ e.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel] = string(*t.PackageType)
+
+ case v1.IntegrationKitPhaseBuildSubmitted:
build := getBuilderTask(e.BuildTasks)
if build == nil {
return fmt.Errorf("unable to find builder task: %s", e.Integration.Name)
@@ -99,11 +108,9 @@ func (t *quarkusTrait) Apply(e *Environment) error {
})
build.Steps = builder.StepIDsFor(steps...)
- }
- if e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
- e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning) {
- if t.isNativePackageType() {
+ case v1.IntegrationKitPhaseReady:
+ if e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning) && t.isNativePackageType() {
container := e.getIntegrationContainer()
if container == nil {
return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go
index 7f4d970..9051401 100644
--- a/pkg/trait/quarkus_test.go
+++ b/pkg/trait/quarkus_test.go
@@ -55,12 +55,16 @@ func TestConfigureDisabledQuarkusTraitShouldFail(t *testing.T) {
assert.Nil(t, err)
}
-func TestApplyQuarkusTraitDoesNothing(t *testing.T) {
+func TestApplyQuarkusTraitDefaultKitLayout(t *testing.T) {
quarkusTrait, environment := createNominalQuarkusTest()
- err := quarkusTrait.Apply(environment)
+ configured, err := quarkusTrait.Configure(environment)
+ assert.True(t, configured)
+ assert.Nil(t, err)
+ err = quarkusTrait.Apply(environment)
assert.Nil(t, err)
+ assert.Equal(t, environment.IntegrationKit.Labels[v1.IntegrationKitLayoutLabel], v1.IntegrationKitLayoutFastJar)
}
func createNominalQuarkusTest() (*quarkusTrait, *Environment) {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 630776d..dcc7b38 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -25,7 +25,6 @@ import (
"sort"
"strings"
- "github.com/apache/camel-k/pkg/util/property"
user "github.com/mitchellh/go-homedir"
"github.com/scylladb/go-set/strset"
@@ -36,6 +35,7 @@ import (
"github.com/apache/camel-k/pkg/metadata"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/camel"
+ "github.com/apache/camel-k/pkg/util/property"
)
var exactVersionRegexp = regexp.MustCompile(`^(\d+)\.(\d+)\.([\w-.]+)$`)
@@ -46,8 +46,8 @@ func getIntegrationKit(ctx context.Context, c client.Client, integration *v1.Int
return nil, nil
}
kit := v1.NewIntegrationKit(integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name)
- err := c.Get(ctx, ctrl.ObjectKeyFromObject(&kit), &kit)
- return &kit, err
+ err := c.Get(ctx, ctrl.ObjectKeyFromObject(kit), kit)
+ return kit, err
}
func collectConfigurationValues(configurationType string, configurable ...v1.Configurable) []string {
@@ -221,7 +221,7 @@ func AddSourceDependencies(source v1.SourceSpec, catalog *camel.RuntimeCatalog)
return dependencies
}
-/// Bool pointer operations:
+// Bool pointer operations:
// BoolP returns a pointer to a bool value
func BoolP(b bool) *bool {
diff --git a/pkg/util/controller/util.go b/pkg/util/controller/util.go
deleted file mode 100644
index b80c94e..0000000
--- a/pkg/util/controller/util.go
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-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 controller
-
-import (
- "k8s.io/apimachinery/pkg/labels"
- "k8s.io/apimachinery/pkg/selection"
- "sigs.k8s.io/controller-runtime/pkg/client"
-)
-
-type MatchingSelector struct {
- Selector labels.Selector
-}
-
-func (s MatchingSelector) ApplyToList(opts *client.ListOptions) {
- opts.LabelSelector = s.Selector
-}
-
-func (s MatchingSelector) ApplyToDeleteAllOf(opts *client.DeleteAllOfOptions) {
- opts.LabelSelector = s.Selector
-}
-
-func NewLabelSelector(key string, op selection.Operator, values []string) MatchingSelector {
- provider, _ := labels.NewRequirement(key, op, values)
- selector := labels.NewSelector().Add(*provider)
-
- return MatchingSelector{
- Selector: selector,
- }
-}
diff --git a/pkg/util/kubernetes/client.go b/pkg/util/kubernetes/client.go
index 1f8795b..bb8514e 100644
--- a/pkg/util/kubernetes/client.go
+++ b/pkg/util/kubernetes/client.go
@@ -32,57 +32,34 @@ import (
)
func GetIntegrationPlatform(context context.Context, client ctrl.Reader, name string, namespace string) (*v1.IntegrationPlatform, error) {
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
- }
-
- answer := v1.NewIntegrationPlatform(namespace, name)
-
- if err := client.Get(context, key, &answer); err != nil {
+ platform := v1.NewIntegrationPlatform(namespace, name)
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(&platform), &platform); err != nil {
return nil, err
}
- return &answer, nil
+ return &platform, nil
}
func GetIntegrationKit(context context.Context, client ctrl.Reader, name string, namespace string) (*v1.IntegrationKit, error) {
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
- }
-
- answer := v1.NewIntegrationKit(namespace, name)
-
- if err := client.Get(context, key, &answer); err != nil {
+ kit := v1.NewIntegrationKit(namespace, name)
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(kit), kit); err != nil {
return nil, err
}
- return &answer, nil
+ return kit, nil
}
func GetBuild(context context.Context, client client.Client, name string, namespace string) (*v1.Build, error) {
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
- }
-
- answer := v1.NewBuild(namespace, name)
-
- if err := client.Get(context, key, &answer); err != nil {
+ build := v1.NewBuild(namespace, name)
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(build), build); err != nil {
return nil, err
}
- return &answer, nil
+ return build, nil
}
func GetConfigMap(context context.Context, client ctrl.Reader, name string, namespace string) (*corev1.ConfigMap, error) {
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
- }
-
- answer := corev1.ConfigMap{
+ configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
@@ -93,20 +70,15 @@ func GetConfigMap(context context.Context, client ctrl.Reader, name string, name
},
}
- if err := client.Get(context, key, &answer); err != nil {
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(configMap), configMap); err != nil {
return nil, err
}
- return &answer, nil
+ return configMap, nil
}
func GetSecret(context context.Context, client ctrl.Reader, name string, namespace string) (*corev1.Secret, error) {
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
- }
-
- answer := corev1.Secret{
+ secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "v1",
@@ -117,11 +89,11 @@ func GetSecret(context context.Context, client ctrl.Reader, name string, namespa
},
}
- if err := client.Get(context, key, &answer); err != nil {
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(secret), secret); err != nil {
return nil, err
}
- return &answer, nil
+ return secret, nil
}
// GetSecretRefValue returns the value of a secret in the supplied namespace
@@ -161,7 +133,6 @@ func GetConfigMapRefValue(ctx context.Context, client ctrl.Reader, namespace str
return "", fmt.Errorf("key %s not found in config map %s", selector.Key, selector.Name)
}
-// ResolveValueSource --
func ResolveValueSource(ctx context.Context, client ctrl.Reader, namespace string, valueSource *v1.ValueSource) (string, error) {
if valueSource.ConfigMapKeyRef != nil && valueSource.SecretKeyRef != nil {
return "", fmt.Errorf("value source has bot config map and secret configured")
@@ -176,17 +147,20 @@ func ResolveValueSource(ctx context.Context, client ctrl.Reader, namespace strin
return "", nil
}
-// GetDeployment --
func GetDeployment(context context.Context, client ctrl.Reader, name string, namespace string) (*appsv1.Deployment, error) {
-
- key := ctrl.ObjectKey{
- Name: name,
- Namespace: namespace,
+ deployment := &appsv1.Deployment{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Deployment",
+ APIVersion: appsv1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: name,
+ Namespace: namespace,
+ },
}
- deployment := appsv1.Deployment{}
- if err := client.Get(context, key, &deployment); err != nil {
+ if err := client.Get(context, ctrl.ObjectKeyFromObject(deployment), deployment); err != nil {
return nil, err
}
- return &deployment, nil
+ return deployment, nil
}
[camel-k] 09/37: feat(native): Preserve file permissions when
copying image context
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 622dbdd44d351b37b5e7d118be020421050dbf1d
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Aug 17 11:03:03 2021 +0200
feat(native): Preserve file permissions when copying image context
---
pkg/util/util.go | 74 ++++++++++++++++++++------------------------------------
1 file changed, 26 insertions(+), 48 deletions(-)
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 4a2ffe3..8e61e97 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -30,16 +30,17 @@ import (
"sort"
"strings"
- "github.com/pkg/errors"
+ yaml2 "gopkg.in/yaml.v2"
+ "github.com/pkg/errors"
"github.com/scylladb/go-set/strset"
- yaml2 "gopkg.in/yaml.v2"
)
-/// Directories and file names:
+// Directories and file names:
-// MavenWorkingDirectory -- Directory used by Maven for an invocation of the kamel local command. By default a temporary folder will be used.
-var MavenWorkingDirectory string = ""
+// MavenWorkingDirectory is the directory used by Maven for an invocation of the kamel local command.
+// By default, a temporary folder will be used.
+var MavenWorkingDirectory = ""
// DefaultDependenciesDirectoryName --
const DefaultDependenciesDirectoryName = "dependencies"
@@ -69,16 +70,15 @@ var ContainerResourcesDirectory = "/etc/camel/resources"
var QuarkusDependenciesBaseDirectory = "/quarkus-app"
// ListOfLazyEvaluatedEnvVars -- List of unevaluated environment variables.
-// These are sensitive values or values that may have different values depending
+// These are sensitive values or values that may have different values depending on
// where the integration is run (locally vs. the cloud). These environment variables
// are evaluated at the time of the integration invocation.
-var ListOfLazyEvaluatedEnvVars []string = []string{}
+var ListOfLazyEvaluatedEnvVars = []string{}
// CLIEnvVars -- List of CLI provided environment variables. They take precedence over
// any environment variables with the same name.
-var CLIEnvVars []string = []string{}
+var CLIEnvVars = make([]string, 0)
-// StringSliceJoin --
func StringSliceJoin(slices ...[]string) []string {
size := 0
@@ -95,7 +95,6 @@ func StringSliceJoin(slices ...[]string) []string {
return result
}
-// StringSliceContains --
func StringSliceContains(slice []string, items []string) bool {
for i := 0; i < len(items); i++ {
if !StringSliceExists(slice, items[i]) {
@@ -106,7 +105,6 @@ func StringSliceContains(slice []string, items []string) bool {
return true
}
-// StringSliceExists --
func StringSliceExists(slice []string, item string) bool {
for i := 0; i < len(slice); i++ {
if slice[i] == item {
@@ -117,7 +115,6 @@ func StringSliceExists(slice []string, item string) bool {
return false
}
-// StringSliceContainsAnyOf --
func StringSliceContainsAnyOf(slice []string, items ...string) bool {
for i := 0; i < len(slice); i++ {
for j := 0; j < len(items); j++ {
@@ -130,7 +127,7 @@ func StringSliceContainsAnyOf(slice []string, items ...string) bool {
return false
}
-// StringSliceUniqueAdd append the given item if not already present in the slice
+// StringSliceUniqueAdd appends the given item if not already present in the slice
func StringSliceUniqueAdd(slice *[]string, item string) bool {
if slice == nil {
newSlice := make([]string, 0)
@@ -147,7 +144,7 @@ func StringSliceUniqueAdd(slice *[]string, item string) bool {
return true
}
-// StringSliceUniqueConcat append all the items of the "items" slice if they are not already present in the slice
+// StringSliceUniqueConcat appends all the items of the "items" slice if they are not already present in the slice
func StringSliceUniqueConcat(slice *[]string, items []string) bool {
changed := false
for _, item := range items {
@@ -158,7 +155,6 @@ func StringSliceUniqueConcat(slice *[]string, items []string) bool {
return changed
}
-// SubstringFrom --
func SubstringFrom(s string, substr string) string {
index := strings.Index(s, substr)
if index != -1 {
@@ -167,7 +163,6 @@ func SubstringFrom(s string, substr string) string {
return ""
}
-// EncodeXML --
func EncodeXML(content interface{}) ([]byte, error) {
w := &bytes.Buffer{}
w.WriteString(xml.Header)
@@ -183,14 +178,13 @@ func EncodeXML(content interface{}) ([]byte, error) {
return w.Bytes(), nil
}
-// CopyFile --
func CopyFile(src, dst string) (int64, error) {
- sourceFileStat, err := os.Stat(src)
+ stat, err := os.Stat(src)
if err != nil {
return 0, err
}
- if !sourceFileStat.Mode().IsRegular() {
+ if !stat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", src)
}
@@ -205,16 +199,16 @@ func CopyFile(src, dst string) (int64, error) {
return 0, err
}
- destination, err := os.Create(dst)
+ destination, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, stat.Mode())
if err != nil {
return 0, err
}
+
defer destination.Close()
nBytes, err := io.Copy(destination, source)
return nBytes, err
}
-// WriteFileWithContent --
func WriteFileWithContent(buildDir string, relativePath string, content []byte) error {
filePath := path.Join(buildDir, relativePath)
fileDir := path.Dir(filePath)
@@ -237,7 +231,6 @@ func WriteFileWithContent(buildDir string, relativePath string, content []byte)
return nil
}
-// WriteFileWithBytesMarshallerContent --
func WriteFileWithBytesMarshallerContent(buildDir string, relativePath string, content BytesMarshaller) error {
data, err := content.MarshalBytes()
if err != nil {
@@ -247,7 +240,6 @@ func WriteFileWithBytesMarshallerContent(buildDir string, relativePath string, c
return WriteFileWithContent(buildDir, relativePath, data)
}
-// FindAllDistinctStringSubmatch --
func FindAllDistinctStringSubmatch(data string, regexps ...*regexp.Regexp) []string {
submatchs := strset.New()
@@ -264,7 +256,6 @@ func FindAllDistinctStringSubmatch(data string, regexps ...*regexp.Regexp) []str
return submatchs.List()
}
-// FindNamedMatches ---
func FindNamedMatches(expr string, str string) map[string]string {
regex := regexp.MustCompile(expr)
match := regex.FindStringSubmatch(str)
@@ -276,7 +267,6 @@ func FindNamedMatches(expr string, str string) map[string]string {
return results
}
-// FileExists --
func FileExists(name string) (bool, error) {
info, err := os.Stat(name)
if os.IsNotExist(err) {
@@ -286,7 +276,6 @@ func FileExists(name string) (bool, error) {
return !info.IsDir(), err
}
-// DirectoryExists --
func DirectoryExists(directory string) (bool, error) {
info, err := os.Stat(directory)
if os.IsNotExist(err) {
@@ -300,10 +289,9 @@ func DirectoryExists(directory string) (bool, error) {
return info.IsDir(), nil
}
-// CreateDirectory --
func CreateDirectory(directory string) error {
if directory != "" {
- // If directory does not exist, create it.
+ // If directory does not exist, create it
directoryExists, err := DirectoryExists(directory)
if err != nil {
return err
@@ -320,12 +308,10 @@ func CreateDirectory(directory string) error {
return nil
}
-// BytesMarshaller --
type BytesMarshaller interface {
MarshalBytes() ([]byte, error)
}
-// SortedMapKeys --
func SortedMapKeys(m map[string]interface{}) []string {
res := make([]string, len(m))
i := 0
@@ -337,7 +323,6 @@ func SortedMapKeys(m map[string]interface{}) []string {
return res
}
-// SortedStringMapKeys --
func SortedStringMapKeys(m map[string]string) []string {
res := make([]string, len(m))
i := 0
@@ -361,14 +346,12 @@ func CopyMap(source map[string]string) map[string]string {
return dest
}
-// DependenciesToJSON --
func DependenciesToJSON(list []string) ([]byte, error) {
jsondata := map[string]interface{}{}
jsondata["dependencies"] = list
return json.Marshal(jsondata)
}
-// DependenciesToYAML --
func DependenciesToYAML(list []string) ([]byte, error) {
data, err := DependenciesToJSON(list)
if err != nil {
@@ -378,7 +361,6 @@ func DependenciesToYAML(list []string) ([]byte, error) {
return JSONToYAML(data)
}
-// JSONToYAML --
func JSONToYAML(src []byte) ([]byte, error) {
jsondata := map[string]interface{}{}
err := json.Unmarshal(src, &jsondata)
@@ -393,18 +375,16 @@ func JSONToYAML(src []byte) ([]byte, error) {
return yamldata, nil
}
-// WriteToFile --
func WriteToFile(filePath string, fileContents string) error {
err := ioutil.WriteFile(filePath, []byte(fileContents), 0777)
if err != nil {
return errors.Errorf("error writing file: %v", filePath)
}
- // All went well, return true.
return nil
}
-/// Local directories:
+// Local directories:
// GetLocalPropertiesDir -- <mavenWorkingDirectory>/properties
func GetLocalPropertiesDir() string {
@@ -421,7 +401,6 @@ func GetLocalRoutesDir() string {
return path.Join(MavenWorkingDirectory, DefaultRoutesDirectoryName)
}
-// CreateLocalPropertiesDirectory --
func CreateLocalPropertiesDirectory() error {
// Do not create a directory unless the maven directory contains a valid value.
if MavenWorkingDirectory == "" {
@@ -442,7 +421,6 @@ func CreateLocalPropertiesDirectory() error {
return nil
}
-// CreateLocalDependenciesDirectory --
func CreateLocalDependenciesDirectory() error {
// Do not create a directory unless the maven directory contains a valid value.
if MavenWorkingDirectory == "" {
@@ -463,7 +441,6 @@ func CreateLocalDependenciesDirectory() error {
return nil
}
-// CreateLocalRoutesDirectory --
func CreateLocalRoutesDirectory() error {
// Do not create a directory unless the maven directory contains a valid value.
if MavenWorkingDirectory == "" {
@@ -484,7 +461,6 @@ func CreateLocalRoutesDirectory() error {
return nil
}
-// GetEnvironmentVariable --
func GetEnvironmentVariable(variable string) (string, error) {
value, isPresent := os.LookupEnv(variable)
if !isPresent {
@@ -498,12 +474,12 @@ func GetEnvironmentVariable(variable string) (string, error) {
return value, nil
}
-// EvaluateCLIAndLazyEnvVars -- Function that creates a list of environment
+// EvaluateCLIAndLazyEnvVars creates a list of environment
// variables with entries VAR=value that can be passed when running the integration.
func EvaluateCLIAndLazyEnvVars() ([]string, error) {
evaluatedEnvVars := []string{}
- // Add CLI environment variables.
+ // Add CLI environment variables
setEnvVars := []string{}
for _, cliEnvVar := range CLIEnvVars {
// Mark variable name as set.
@@ -536,19 +512,21 @@ func EvaluateCLIAndLazyEnvVars() ([]string, error) {
return evaluatedEnvVars, nil
}
-// CopyIntegrationFilesToDirectory --
func CopyIntegrationFilesToDirectory(files []string, directory string) ([]string, error) {
- // Create directory if one does not already exist.
+ // Create directory if one does not already exist
err := CreateDirectory(directory)
if err != nil {
return nil, err
}
- // Coopy files to new location. Also create the list with relocated files.
- relocatedFilesList := []string{}
+ // Copy files to new location. Also create the list with relocated files.
+ relocatedFilesList := make([]string, len(files))
for _, filePath := range files {
newFilePath := path.Join(directory, path.Base(filePath))
- CopyFile(filePath, newFilePath)
+ _, err := CopyFile(filePath, newFilePath)
+ if err != nil {
+ return relocatedFilesList, err
+ }
relocatedFilesList = append(relocatedFilesList, newFilePath)
}
[camel-k] 05/37: feat(native): Configure Integration runtime
depending on Quarkus packaging type
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit aec61ef1b29caf9d3fed66c08c5b369b8f2f5463
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 6 12:36:49 2021 +0200
feat(native): Configure Integration runtime depending on Quarkus packaging type
---
pkg/trait/jvm.go | 18 +++++++++++++++---
pkg/trait/quarkus.go | 47 ++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 5cefaae..8d9e3d3 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -37,7 +37,6 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/defaults"
)
// The JVM trait is used to configure the JVM that runs the integration.
@@ -72,6 +71,12 @@ func (t *jvmTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
+ if t := e.Catalog.GetTrait(quarkusTraitId); t != nil && t.(*quarkusTrait).isNativePackageType() {
+ if quarkus := t.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativePackageType() {
+ return false, nil
+ }
+ }
+
return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
}
@@ -185,8 +190,15 @@ func (t *jvmTrait) Apply(e *Environment) error {
args = append(args, "-cp", strings.Join(items, ":"))
args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
- container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
- container.WorkingDir = builder.DeploymentDir
+ if IsNilOrTrue(t.PrintCommand) {
+ args = append([]string{"exec", "java"}, args...)
+ container.Command = []string{"/bin/sh", "-c"}
+ cmd := strings.Join(args, " ")
+ container.Args = []string{"echo " + cmd + " && " + cmd}
+ } else {
+ container.Command = []string{"java"}
+ container.Args = args
+ }
return nil
}
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 5c62f04..cec04cf 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -18,31 +18,64 @@ limitations under the License.
package trait
import (
+ "fmt"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
+ "github.com/apache/camel-k/pkg/util/defaults"
)
-// The Quarkus trait activates the Quarkus runtime.
+type quarkusPackageType string
+
+const (
+ quarkusTraitId = "quarkus"
+
+ fastJarPackageType quarkusPackageType = "fast-jar"
+ nativePackageType quarkusPackageType = "native"
+)
+
+// The Quarkus trait configures the Quarkus runtime.
//
// It's enabled by default.
//
// +camel-k:trait=quarkus
type quarkusTrait struct {
BaseTrait `property:",squash"`
- // The Quarkus runtime type (reserved for future use)
- Native bool `property:"native" json:"native,omitempty"`
+ // The Quarkus package type, either `fast-jar` or `native` (default `fast-jar`)
+ PackageType *quarkusPackageType `property:"package-type" json:"packageType,omitempty"`
}
func newQuarkusTrait() Trait {
return &quarkusTrait{
- BaseTrait: NewBaseTrait("quarkus", 700),
+ BaseTrait: NewBaseTrait(quarkusTraitId, 1700),
}
}
func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
- return IsNilOrTrue(t.Enabled), nil
+ if IsFalse(t.Enabled) {
+ return false, nil
+ }
+
+ if t.PackageType == nil {
+ packageType := fastJarPackageType
+ t.PackageType = &packageType
+ }
+
+ return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
}
func (t *quarkusTrait) Apply(e *Environment) error {
+ if t.isNativePackageType() {
+ container := e.getIntegrationContainer()
+ if container == nil {
+ return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
+ }
+
+ container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
+ container.WorkingDir = builder.DeploymentDir
+ }
+
return nil
}
@@ -59,3 +92,7 @@ func (t *quarkusTrait) InfluencesKit() bool {
func (t *quarkusTrait) addBuildSteps(steps *[]builder.Step) {
*steps = append(*steps, builder.QuarkusSteps...)
}
+
+func (t *quarkusTrait) isNativePackageType() bool {
+ return t.PackageType != nil && *t.PackageType == nativePackageType
+}
[camel-k] 04/37: feat(native): Use Mandrel as operator/builder image
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 446f2d2d785cf968db357ac6f175bd170c4e4d3c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 6 12:11:17 2021 +0200
feat(native): Use Mandrel as operator/builder image
---
build/Dockerfile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/build/Dockerfile b/build/Dockerfile
index 1f3e2ac..52a8297 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM quay.io/quarkus/ubi-quarkus-native-image:21.1.0-java11
-#FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2.0.0-Final-java11
+FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2.0.0-Final-java11
ARG MAVEN_VERSION="3.6.3"
ARG SHA="c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0"
[camel-k] 11/37: chore(native): No need to compute transitive
dependencies for native builds
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit eff1b4f3b456a0990b9c8d490af492e0ff42de0b
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Aug 18 14:34:21 2021 +0200
chore(native): No need to compute transitive dependencies for native builds
---
pkg/builder/image.go | 20 ++++++++++++++++++++
pkg/builder/project.go | 34 +++++++++++++---------------------
pkg/builder/project_test.go | 4 ++--
pkg/builder/quarkus.go | 19 ++++++++++---------
pkg/trait/builder.go | 2 +-
pkg/trait/quarkus.go | 6 +++---
pkg/trait/quarkus_test.go | 2 +-
7 files changed, 50 insertions(+), 37 deletions(-)
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index da702bc..ac33a6f 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -39,6 +39,26 @@ const (
DependenciesDir = "dependencies"
)
+func init() {
+ registerSteps(Image)
+}
+
+type imageSteps struct {
+ IncrementalImageContext Step
+ NativeImageContext Step
+ StandardImageContext Step
+ ExecutableDockerfile Step
+ JvmDockerfile Step
+}
+
+var Image = imageSteps{
+ IncrementalImageContext: NewStep(ApplicationPackagePhase, incrementalImageContext),
+ NativeImageContext: NewStep(ApplicationPackagePhase, nativeImageContext),
+ StandardImageContext: NewStep(ApplicationPackagePhase, standardImageContext),
+ ExecutableDockerfile: NewStep(ApplicationPackagePhase+1, executableDockerfile),
+ JvmDockerfile: NewStep(ApplicationPackagePhase+1, jvmDockerfile),
+}
+
type artifactsSelector func(ctx *builderContext) error
func nativeImageContext(ctx *builderContext) error {
diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index 517e879..4255c61 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -26,41 +26,33 @@ import (
)
func init() {
- registerSteps(Steps)
+ registerSteps(Project)
+
+ Project.CommonSteps = []Step{
+ Project.CleanUpBuildDir,
+ Project.GenerateJavaKeystore,
+ Project.GenerateProjectSettings,
+ Project.InjectDependencies,
+ Project.SanitizeDependencies,
+ }
}
-type steps struct {
+type projectSteps struct {
CleanUpBuildDir Step
GenerateJavaKeystore Step
GenerateProjectSettings Step
InjectDependencies Step
SanitizeDependencies Step
- IncrementalImageContext Step
- NativeImageContext Step
- StandardImageContext Step
- ExecutableDockerfile Step
- JvmDockerfile Step
+
+ CommonSteps []Step
}
-var Steps = steps{
+var Project = projectSteps{
CleanUpBuildDir: NewStep(ProjectGenerationPhase-1, cleanUpBuildDir),
GenerateJavaKeystore: NewStep(ProjectGenerationPhase, generateJavaKeystore),
GenerateProjectSettings: NewStep(ProjectGenerationPhase+1, generateProjectSettings),
InjectDependencies: NewStep(ProjectGenerationPhase+2, injectDependencies),
SanitizeDependencies: NewStep(ProjectGenerationPhase+3, sanitizeDependencies),
- IncrementalImageContext: NewStep(ApplicationPackagePhase, incrementalImageContext),
- NativeImageContext: NewStep(ApplicationPackagePhase, nativeImageContext),
- StandardImageContext: NewStep(ApplicationPackagePhase, standardImageContext),
- ExecutableDockerfile: NewStep(ApplicationPackagePhase+1, executableDockerfile),
- JvmDockerfile: NewStep(ApplicationPackagePhase+1, jvmDockerfile),
-}
-
-var DefaultSteps = []Step{
- Steps.CleanUpBuildDir,
- Steps.GenerateJavaKeystore,
- Steps.GenerateProjectSettings,
- Steps.InjectDependencies,
- Steps.SanitizeDependencies,
}
func cleanUpBuildDir(ctx *builderContext) error {
diff --git a/pkg/builder/project_test.go b/pkg/builder/project_test.go
index 7e03333..9855cac 100644
--- a/pkg/builder/project_test.go
+++ b/pkg/builder/project_test.go
@@ -71,7 +71,7 @@ func TestMavenSettingsFromConfigMap(t *testing.T) {
},
}
- err = Steps.GenerateProjectSettings.execute(&ctx)
+ err = Project.GenerateProjectSettings.execute(&ctx)
assert.Nil(t, err)
assert.Equal(t, []byte("setting-data"), ctx.Maven.SettingsData)
@@ -118,7 +118,7 @@ func TestMavenSettingsFromSecret(t *testing.T) {
},
}
- err = Steps.GenerateProjectSettings.execute(&ctx)
+ err = Project.GenerateProjectSettings.execute(&ctx)
assert.Nil(t, err)
assert.Equal(t, []byte("setting-data"), ctx.Maven.SettingsData)
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index 1e367b2..cdec940 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -35,7 +35,13 @@ import (
)
func init() {
- registerSteps(quarkus)
+ registerSteps(Quarkus)
+
+ Quarkus.CommonSteps = []Step{
+ Quarkus.LoadCamelQuarkusCatalog,
+ Quarkus.GenerateQuarkusProject,
+ Quarkus.BuildQuarkusRunner,
+ }
}
type quarkusSteps struct {
@@ -43,22 +49,17 @@ type quarkusSteps struct {
GenerateQuarkusProject Step
BuildQuarkusRunner Step
ComputeQuarkusDependencies Step
+
+ CommonSteps []Step
}
-var quarkus = quarkusSteps{
+var Quarkus = quarkusSteps{
LoadCamelQuarkusCatalog: NewStep(InitPhase, loadCamelQuarkusCatalog),
GenerateQuarkusProject: NewStep(ProjectGenerationPhase, generateQuarkusProject),
BuildQuarkusRunner: NewStep(ProjectBuildPhase, buildQuarkusRunner),
ComputeQuarkusDependencies: NewStep(ProjectBuildPhase+1, computeQuarkusDependencies),
}
-var QuarkusSteps = []Step{
- quarkus.LoadCamelQuarkusCatalog,
- quarkus.GenerateQuarkusProject,
- quarkus.BuildQuarkusRunner,
- quarkus.ComputeQuarkusDependencies,
-}
-
func loadCamelQuarkusCatalog(ctx *builderContext) error {
catalog, err := camel.LoadCatalog(ctx.C, ctx.Client, ctx.Namespace, ctx.Build.Runtime)
if err != nil {
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index d85414e..7343981 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -166,7 +166,7 @@ func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
}
steps := make([]builder.Step, 0)
- steps = append(steps, builder.DefaultSteps...)
+ steps = append(steps, builder.Project.CommonSteps...)
// sort steps by phase
sort.SliceStable(steps, func(i, j int) bool {
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 97f05fb..d77b614 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -92,14 +92,14 @@ func (t *quarkusTrait) Apply(e *Environment) error {
return err
}
- steps = append(steps, builder.QuarkusSteps...)
+ steps = append(steps, builder.Quarkus.CommonSteps...)
if t.isNativePackageType() {
build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
- steps = append(steps, builder.Steps.NativeImageContext, builder.Steps.ExecutableDockerfile)
+ steps = append(steps, builder.Image.NativeImageContext, builder.Image.ExecutableDockerfile)
} else {
build.Maven.Properties["quarkus.package.type"] = string(fastJarPackageType)
- steps = append(steps, builder.Steps.IncrementalImageContext, builder.Steps.JvmDockerfile)
+ steps = append(steps, builder.Quarkus.ComputeQuarkusDependencies, builder.Image.IncrementalImageContext, builder.Image.JvmDockerfile)
}
// Sort steps by phase
diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go
index 9051401..e09cc2b 100644
--- a/pkg/trait/quarkus_test.go
+++ b/pkg/trait/quarkus_test.go
@@ -42,7 +42,7 @@ func TestConfigureQuarkusTraitBuildSubmitted(t *testing.T) {
build := getBuilderTask(environment.BuildTasks)
assert.NotNil(t, t, build)
- assert.Len(t, build.Steps, len(builder.QuarkusSteps)+2)
+ assert.Len(t, build.Steps, len(builder.Quarkus.CommonSteps)+3)
}
func TestConfigureDisabledQuarkusTraitShouldFail(t *testing.T) {
[camel-k] 23/37: chore(trait): Remove trait context and the
InjectContext interface
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit aecb231de18c7cc519c9d6fd6f57aae588d698e7
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 27 11:15:51 2021 +0200
chore(trait): Remove trait context and the InjectContext interface
---
addons/master/master.go | 4 ++--
addons/tracing/tracing.go | 2 +-
cmd/util/doc-gen/generators/traitdocgen.go | 12 ++---------
pkg/cmd/completion_bash.go | 9 +++-----
pkg/cmd/kit_create.go | 2 +-
pkg/cmd/run.go | 2 +-
pkg/cmd/run_test.go | 2 +-
pkg/cmd/trait_help.go | 4 ++--
pkg/controller/integration/build_kit.go | 2 +-
pkg/trait/builder.go | 2 +-
pkg/trait/builder_test.go | 6 +++---
pkg/trait/camel.go | 6 +++---
pkg/trait/camel_test.go | 2 +-
pkg/trait/container_test.go | 16 +++++++-------
pkg/trait/cron.go | 2 +-
pkg/trait/cron_test.go | 21 +++++++++---------
pkg/trait/dependencies.go | 2 +-
pkg/trait/deployer.go | 8 +++----
pkg/trait/deployer_test.go | 3 +--
pkg/trait/deployment_test.go | 3 +--
pkg/trait/environment_test.go | 9 ++++----
pkg/trait/gc_test.go | 3 +--
pkg/trait/ingress_test.go | 3 +--
pkg/trait/jolokia_test.go | 3 +--
pkg/trait/jvm.go | 2 +-
pkg/trait/jvm_test.go | 4 +---
pkg/trait/kamelets.go | 8 +++----
pkg/trait/kamelets_test.go | 4 +---
pkg/trait/knative.go | 16 +++++++-------
pkg/trait/knative_service.go | 4 ++--
pkg/trait/knative_service_test.go | 7 +++---
pkg/trait/knative_test.go | 15 ++++++-------
pkg/trait/logging_test.go | 6 +++---
pkg/trait/openapi.go | 10 ++++-----
pkg/trait/platform.go | 2 +-
pkg/trait/prometheus_test.go | 3 +--
pkg/trait/pull_secret.go | 4 ++--
pkg/trait/pull_secret_test.go | 4 ++--
pkg/trait/route_test.go | 3 +--
pkg/trait/service.go | 2 +-
pkg/trait/service_binding.go | 2 +-
pkg/trait/service_test.go | 11 +++++-----
pkg/trait/trait.go | 4 ++--
pkg/trait/trait_catalog.go | 6 +-----
pkg/trait/trait_configure_test.go | 17 ++++++++-------
pkg/trait/trait_test.go | 5 ++---
pkg/trait/trait_types.go | 34 +++++++++++++-----------------
pkg/util/maven/maven_command.go | 7 ++----
48 files changed, 135 insertions(+), 173 deletions(-)
diff --git a/addons/master/master.go b/addons/master/master.go
index 5bcdd19..119cf85 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -95,7 +95,7 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, error) {
if t.Auto == nil || *t.Auto {
// Check if the master component has been used
- sources, err := kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -237,7 +237,7 @@ func (t *masterTrait) Apply(e *trait.Environment) error {
}
func (t *masterTrait) canUseLeases(e *trait.Environment) (bool, error) {
- return kubernetes.CheckPermission(t.Ctx, t.Client, "coordination.k8s.io", "leases", e.Integration.Namespace, "", "create")
+ return kubernetes.CheckPermission(e.Ctx, t.Client, "coordination.k8s.io", "leases", e.Integration.Namespace, "", "create")
}
func findAdditionalDependencies(e *trait.Environment, meta metadata.IntegrationMetadata) (dependencies []string) {
diff --git a/addons/tracing/tracing.go b/addons/tracing/tracing.go
index 8c01fba..705d492 100644
--- a/addons/tracing/tracing.go
+++ b/addons/tracing/tracing.go
@@ -83,7 +83,7 @@ func (t *tracingTrait) Configure(e *trait.Environment) (bool, error) {
if trait.IsNilOrTrue(t.Auto) {
if t.Endpoint == "" {
for _, locator := range discovery.TracingLocators {
- endpoint, err := locator.FindEndpoint(e.C, t.Client, t.L, e)
+ endpoint, err := locator.FindEndpoint(e.Ctx, t.Client, t.L, e)
if err != nil {
return false, err
}
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go b/cmd/util/doc-gen/generators/traitdocgen.go
index e99022c..a7623ea 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -18,7 +18,6 @@ limitations under the License.
package generators
import (
- "context"
"fmt"
"io"
"io/ioutil"
@@ -64,7 +63,6 @@ type traitDocGen struct {
generatedTraitFiles []string
}
-// NewTraitDocGen --
func NewTraitDocGen(arguments *args.GeneratorArgs) generator.Generator {
return &traitDocGen{
DefaultGen: generator.DefaultGen{},
@@ -304,19 +302,13 @@ func writeFile(file *os.File, content []string) error {
}
func isPlatformTrait(traitID string) bool {
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- catalog := trait.NewCatalog(ctx, nil)
+ catalog := trait.NewCatalog(nil)
t := catalog.GetTrait(traitID)
return t.IsPlatformTrait()
}
func determineProfiles(traitID string) (profiles []string) {
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- catalog := trait.NewCatalog(ctx, nil)
+ catalog := trait.NewCatalog(nil)
for _, p := range v1.AllTraitProfiles {
traits := catalog.TraitsForProfile(p)
for _, t := range traits {
diff --git a/pkg/cmd/completion_bash.go b/pkg/cmd/completion_bash.go
index 7da2b7b..17c04a4 100644
--- a/pkg/cmd/completion_bash.go
+++ b/pkg/cmd/completion_bash.go
@@ -18,18 +18,15 @@ limitations under the License.
package cmd
import (
- "context"
"fmt"
"strings"
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/spf13/cobra"
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/platform"
-
"github.com/apache/camel-k/pkg/trait"
-
"github.com/apache/camel-k/pkg/util/camel"
- "github.com/spf13/cobra"
)
// ******************************
@@ -74,7 +71,7 @@ __kamel_dependency_type() {
}
__kamel_traits() {
- local type_list="` + strings.Join(trait.NewCatalog(context.TODO(), nil).ComputeTraitsProperties(), " ") + `"
+ local type_list="` + strings.Join(trait.NewCatalog(nil).ComputeTraitsProperties(), " ") + `"
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
compopt -o nospace
}
diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go
index ebf547f..7d0544d 100644
--- a/pkg/cmd/kit_create.go
+++ b/pkg/cmd/kit_create.go
@@ -88,7 +88,7 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
return err
}
- catalog := trait.NewCatalog(command.Context, c)
+ catalog := trait.NewCatalog(c)
tp := catalog.ComputeTraitsProperties()
for _, t := range command.Traits {
kv := strings.SplitN(t, "=", 2)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 8cb1ebf..239259b 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -276,7 +276,7 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
return err
}
- catalog := trait.NewCatalog(o.Context, c)
+ catalog := trait.NewCatalog(c)
tp := catalog.ComputeTraitsProperties()
for _, t := range o.Traits {
kv := strings.SplitN(t, "=", 2)
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 6da2bf0..bfe9ea6 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -366,7 +366,7 @@ func TestConfigureTraits(t *testing.T) {
if err != nil {
t.Error(err)
}
- catalog := trait.NewCatalog(runCmdOptions.Context, client)
+ catalog := trait.NewCatalog(client)
traits, err := configureTraits(runCmdOptions.Traits, catalog)
diff --git a/pkg/cmd/trait_help.go b/pkg/cmd/trait_help.go
index 2af58c3..1834e10 100644
--- a/pkg/cmd/trait_help.go
+++ b/pkg/cmd/trait_help.go
@@ -29,8 +29,8 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
- "github.com/apache/camel-k/pkg/resources"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/pkg/resources"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util/indentedwriter"
)
@@ -99,7 +99,7 @@ func (command *traitHelpCommandOptions) validate(args []string) error {
func (command *traitHelpCommandOptions) run(cmd *cobra.Command, args []string) error {
var traitDescriptions []*traitDescription
- var catalog = trait.NewCatalog(command.Context, nil)
+ var catalog = trait.NewCatalog(nil)
var traitMetaData = &traitMetaData{}
err := yaml.Unmarshal(resources.Resource("/traits.yaml"), traitMetaData)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index 4568f4f..8740cb0 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -246,7 +246,7 @@ func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.Integrati
// hasMatchingTraits compares the traits defined on the v1.Integration with those defined on the v1.IntegrationKit
func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
- catalog := trait.NewCatalog(context.TODO(), action.client)
+ catalog := trait.NewCatalog(action.client)
traitCount := 0
for name, itTrait := range integration.Spec.Traits {
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 7343981..7a78a25 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -71,7 +71,7 @@ func (t *builderTrait) Apply(e *Environment) error {
e.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseError
e.IntegrationKit.Status.SetCondition("IntegrationKitPropertiesFormatValid", corev1.ConditionFalse,
"IntegrationKitPropertiesFormatValid", fmt.Sprintf("One or more properties where not formatted as expected: %s", err.Error()))
- if err := e.Client.Status().Update(e.C, e.IntegrationKit); err != nil {
+ if err := e.Client.Status().Update(e.Ctx, e.IntegrationKit); err != nil {
return err
}
return nil
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index 2c79bd6..5093409 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -108,9 +108,9 @@ func createBuilderTestEnv(cluster v1.IntegrationPlatformCluster, strategy v1.Int
kanikoCache := false
res := &Environment{
- C: context.TODO(),
+ Ctx: context.TODO(),
CamelCatalog: c,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
@@ -148,7 +148,7 @@ func createBuilderTestEnv(cluster v1.IntegrationPlatformCluster, strategy v1.Int
}
func NewBuilderTestCatalog() *Catalog {
- return NewCatalog(context.TODO(), nil)
+ return NewCatalog(nil)
}
func TestMavenPropertyBuilderTrait(t *testing.T) {
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index e02c78b..47a66f2 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -87,7 +87,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
Provider: v1.RuntimeProviderQuarkus,
}
- catalog, err := camel.LoadCatalog(e.C, e.Client, ns, runtime)
+ catalog, err := camel.LoadCatalog(e.Ctx, e.Client, ns, runtime)
if err != nil {
return err
}
@@ -97,7 +97,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
// the required versions (camel and runtime) are not expressed as
// semver constraints
if exactVersionRegexp.MatchString(runtimeVersion) {
- ctx, cancel := context.WithTimeout(e.C, e.Platform.Status.Build.GetTimeout().Duration)
+ ctx, cancel := context.WithTimeout(e.Ctx, e.Platform.Status.Build.GetTimeout().Duration)
defer cancel()
catalog, err = camel.GenerateCatalog(ctx, e.Client, ns, e.Platform.Status.Build.Maven, runtime, []maven.Dependency{})
if err != nil {
@@ -114,7 +114,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
cx.Labels["camel.apache.org/runtime.provider"] = string(runtime.Provider)
cx.Labels["camel.apache.org/catalog.generated"] = True
- err = e.Client.Create(e.C, &cx)
+ err = e.Client.Create(e.Ctx, &cx)
if err != nil {
return errors.Wrapf(err, "unable to create catalog runtime=%s, provider=%s, name=%s",
runtime.Version,
diff --git a/pkg/trait/camel_test.go b/pkg/trait/camel_test.go
index 7b017fa..2932660 100644
--- a/pkg/trait/camel_test.go
+++ b/pkg/trait/camel_test.go
@@ -84,7 +84,7 @@ func createNominalCamelTest() (*camelTrait, *Environment) {
},
},
Catalog: NewEnvironmentTestCatalog(),
- C: context.TODO(),
+ Ctx: context.TODO(),
Client: client,
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
diff --git a/pkg/trait/container_test.go b/pkg/trait/container_test.go
index cf21d68..5a77015 100644
--- a/pkg/trait/container_test.go
+++ b/pkg/trait/container_test.go
@@ -41,7 +41,7 @@ func TestContainerWithDefaults(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -96,7 +96,7 @@ func TestContainerWithCustomName(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -159,10 +159,10 @@ func TestContainerWithCustomImage(t *testing.T) {
assert.Nil(t, err)
client, _ := test.NewFakeClient()
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
- C: context.TODO(),
+ Ctx: context.TODO(),
Client: client,
CamelCatalog: catalog,
Catalog: traitCatalog,
@@ -230,10 +230,10 @@ func TestContainerWithCustomImageAndIntegrationKit(t *testing.T) {
assert.Nil(t, err)
client, _ := test.NewFakeClient()
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
- C: context.TODO(),
+ Ctx: context.TODO(),
Client: client,
CamelCatalog: catalog,
Catalog: traitCatalog,
@@ -284,10 +284,10 @@ func TestContainerWithCustomImageAndDeprecatedIntegrationKit(t *testing.T) {
assert.Nil(t, err)
client, _ := test.NewFakeClient()
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
- C: context.TODO(),
+ Ctx: context.TODO(),
Client: client,
CamelCatalog: catalog,
Catalog: traitCatalog,
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 45a325e..191fcaa 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -382,7 +382,7 @@ func (t *cronTrait) getGlobalCron(e *Environment) (*cronInfo, error) {
func (t *cronTrait) getSourcesFromURIs(e *Environment) ([]string, error) {
var sources []v1.SourceSpec
var err error
- if sources, err = kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, e.Resources); err != nil {
+ if sources, err = kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources); err != nil {
return nil, err
}
meta := metadata.ExtractAll(e.CamelCatalog, sources)
diff --git a/pkg/trait/cron_test.go b/pkg/trait/cron_test.go
index 0c8353a..a52bdfd 100644
--- a/pkg/trait/cron_test.go
+++ b/pkg/trait/cron_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"strings"
"testing"
@@ -31,7 +30,7 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/camel"
- k8sutils "github.com/apache/camel-k/pkg/util/kubernetes"
+ "github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/test"
)
@@ -224,7 +223,7 @@ func TestCronDeps(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -269,14 +268,14 @@ func TestCronDeps(t *testing.T) {
},
EnvVars: make([]corev1.EnvVar, 0),
ExecutedTraits: make([]Trait, 0),
- Resources: k8sutils.NewCollection(),
+ Resources: kubernetes.NewCollection(),
}
environment.Platform.ResyncStatusFullConfig()
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.apply(&environment)
@@ -294,7 +293,7 @@ func TestCronDepsFallback(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -343,14 +342,14 @@ func TestCronDepsFallback(t *testing.T) {
},
EnvVars: make([]corev1.EnvVar, 0),
ExecutedTraits: make([]Trait, 0),
- Resources: k8sutils.NewCollection(),
+ Resources: kubernetes.NewCollection(),
}
environment.Platform.ResyncStatusFullConfig()
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.apply(&environment)
@@ -369,7 +368,7 @@ func TestCronWithQuarkus(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -418,14 +417,14 @@ func TestCronWithQuarkus(t *testing.T) {
},
EnvVars: make([]corev1.EnvVar, 0),
ExecutedTraits: make([]Trait, 0),
- Resources: k8sutils.NewCollection(),
+ Resources: kubernetes.NewCollection(),
}
environment.Platform.ResyncStatusFullConfig()
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.apply(&environment)
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index b5fd7a9..2a5623d 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -64,7 +64,7 @@ func (t *dependenciesTrait) Apply(e *Environment) error {
dependencies.Add(d.GetDependencyID())
}
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return err
}
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index 9e49374..dcc71eb 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -101,7 +101,7 @@ func (t *deployerTrait) serverSideApply(env *Environment, resource ctrl.Object)
if err != nil {
return err
}
- err = env.Client.Patch(env.C, target, ctrl.Apply, ctrl.ForceOwnership, ctrl.FieldOwner("camel-k-operator"))
+ err = env.Client.Patch(env.Ctx, target, ctrl.Apply, ctrl.ForceOwnership, ctrl.FieldOwner("camel-k-operator"))
if err != nil {
return errors.Wrapf(err, "error during apply resource: %v", resource)
}
@@ -109,7 +109,7 @@ func (t *deployerTrait) serverSideApply(env *Environment, resource ctrl.Object)
}
func (t *deployerTrait) clientSideApply(env *Environment, resource ctrl.Object) error {
- err := env.Client.Create(env.C, resource)
+ err := env.Client.Create(env.Ctx, resource)
if err == nil {
return nil
} else if !k8serrors.IsAlreadyExists(err) {
@@ -119,7 +119,7 @@ func (t *deployerTrait) clientSideApply(env *Environment, resource ctrl.Object)
object.SetNamespace(resource.GetNamespace())
object.SetName(resource.GetName())
object.SetGroupVersionKind(resource.GetObjectKind().GroupVersionKind())
- err = env.Client.Get(env.C, ctrl.ObjectKeyFromObject(object), object)
+ err = env.Client.Get(env.Ctx, ctrl.ObjectKeyFromObject(object), object)
if err != nil {
return err
}
@@ -130,7 +130,7 @@ func (t *deployerTrait) clientSideApply(env *Environment, resource ctrl.Object)
// Avoid triggering a patch request for nothing
return nil
}
- err = env.Client.Patch(env.C, resource, ctrl.RawPatch(types.MergePatchType, p))
+ err = env.Client.Patch(env.Ctx, resource, ctrl.RawPatch(types.MergePatchType, p))
if err != nil {
return errors.Wrapf(err, "error during patch resource: %v", resource)
}
diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go
index 939dcb0..6b43c2b 100644
--- a/pkg/trait/deployer_test.go
+++ b/pkg/trait/deployer_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -69,7 +68,7 @@ func createNominalDeployerTest() (*deployerTrait, *Environment) {
trait := newDeployerTrait().(*deployerTrait)
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "integration-name",
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index f4fdd7a..de571ca 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -176,7 +175,7 @@ func createNominalDeploymentTest() (*deploymentTrait, *Environment) {
replicas := int32(3)
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "integration-name",
diff --git a/pkg/trait/environment_test.go b/pkg/trait/environment_test.go
index ad0d3be..61426f1 100644
--- a/pkg/trait/environment_test.go
+++ b/pkg/trait/environment_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -39,7 +38,7 @@ func TestDefaultEnvironment(t *testing.T) {
env := Environment{
CamelCatalog: catalog,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
Status: v1.IntegrationStatus{
Phase: v1.IntegrationPhaseDeploying,
@@ -110,7 +109,7 @@ func TestEnabledContainerMetaDataEnvVars(t *testing.T) {
env := Environment{
CamelCatalog: c,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
Status: v1.IntegrationStatus{
Phase: v1.IntegrationPhaseDeploying,
@@ -176,7 +175,7 @@ func TestDisabledContainerMetaDataEnvVars(t *testing.T) {
env := Environment{
CamelCatalog: c,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
Status: v1.IntegrationStatus{
Phase: v1.IntegrationPhaseDeploying,
@@ -237,5 +236,5 @@ func TestDisabledContainerMetaDataEnvVars(t *testing.T) {
}
func NewEnvironmentTestCatalog() *Catalog {
- return NewCatalog(context.TODO(), nil)
+ return NewCatalog(nil)
}
diff --git a/pkg/trait/gc_test.go b/pkg/trait/gc_test.go
index ac650c5..c261770 100644
--- a/pkg/trait/gc_test.go
+++ b/pkg/trait/gc_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -71,7 +70,7 @@ func createNominalGarbageCollectorTest() (*garbageCollectorTrait, *Environment)
trait.Enabled = BoolP(true)
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "integration-name",
diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go
index a0fb217..84c3a06 100644
--- a/pkg/trait/ingress_test.go
+++ b/pkg/trait/ingress_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -160,7 +159,7 @@ func createNominalIngressTest() (*ingressTrait, *Environment) {
trait.Host = "hostname"
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "integration-name",
diff --git a/pkg/trait/jolokia_test.go b/pkg/trait/jolokia_test.go
index 0551d6f..e7a2802 100644
--- a/pkg/trait/jolokia_test.go
+++ b/pkg/trait/jolokia_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -271,7 +270,7 @@ func createNominalJolokiaTest() (*jolokiaTrait, *Environment) {
trait.Enabled = BoolP(true)
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
Status: v1.IntegrationStatus{
Phase: v1.IntegrationPhaseDeploying,
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 4633494..8d17bcc 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -92,7 +92,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
name := e.Integration.Status.IntegrationKit.Name
ns := e.Integration.GetIntegrationKitNamespace(e.Platform)
k := v1.NewIntegrationKit(ns, name)
- if err := t.Client.Get(t.Ctx, ctrl.ObjectKeyFromObject(k), k); err != nil {
+ if err := t.Client.Get(e.Ctx, ctrl.ObjectKeyFromObject(k), k); err != nil {
return errors.Wrapf(err, "unable to find integration kit %s/%s, %s", ns, name, err)
}
kit = k
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 4c24a18..a6360a7 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"fmt"
"sort"
"strings"
@@ -258,11 +257,10 @@ func createNominalJvmTest(kitType string) (*jvmTrait, *Environment) {
trait := newJvmTrait().(*jvmTrait)
trait.Enabled = BoolP(true)
trait.PrintCommand = BoolP(false)
- trait.Ctx = context.TODO()
trait.Client = client
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
CamelCatalog: catalog,
Integration: &v1.Integration{
Status: v1.IntegrationStatus{
diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go
index 6b0b2a8..cee7ac3 100644
--- a/pkg/trait/kamelets.go
+++ b/pkg/trait/kamelets.go
@@ -99,7 +99,7 @@ func (t *kameletsTrait) Configure(e *Environment) (bool, error) {
if IsNilOrTrue(t.Auto) {
var kamelets []string
if t.List == "" {
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -142,7 +142,7 @@ func (t *kameletsTrait) Apply(e *Environment) error {
}
func (t *kameletsTrait) collectKamelets(e *Environment) (map[string]*v1alpha1.Kamelet, error) {
- repo, err := repository.NewForPlatform(e.C, e.Client, e.Platform, e.Integration.Namespace, platform.GetOperatorNamespace())
+ repo, err := repository.NewForPlatform(e.Ctx, e.Client, e.Platform, e.Integration.Namespace, platform.GetOperatorNamespace())
if err != nil {
return nil, err
}
@@ -152,7 +152,7 @@ func (t *kameletsTrait) collectKamelets(e *Environment) (map[string]*v1alpha1.Ka
availableKamelets := make([]string, 0)
for _, key := range t.getKameletKeys() {
- kamelet, err := repo.Get(e.C, key)
+ kamelet, err := repo.Get(e.Ctx, key)
if err != nil {
return nil, err
}
@@ -320,7 +320,7 @@ func (t *kameletsTrait) addConfigurationSecrets(e *Environment) error {
if k.configurationID != "" {
options.LabelSelector = fmt.Sprintf("%s=%s,%s=%s", kameletLabel, k.kamelet, kameletConfigurationLabel, k.configurationID)
}
- secrets, err := t.Client.CoreV1().Secrets(e.Integration.Namespace).List(e.C, options)
+ secrets, err := t.Client.CoreV1().Secrets(e.Integration.Namespace).List(e.Ctx, options)
if err != nil {
return err
}
diff --git a/pkg/trait/kamelets_test.go b/pkg/trait/kamelets_test.go
index 1e34eae..8c87cd7 100644
--- a/pkg/trait/kamelets_test.go
+++ b/pkg/trait/kamelets_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"encoding/json"
"testing"
@@ -540,11 +539,10 @@ func createKameletsTestEnvironment(flow string, objects ...runtime.Object) (*kam
client, _ := test.NewFakeClient(objects...)
trait := newKameletsTrait().(*kameletsTrait)
- trait.Ctx = context.TODO()
trait.Client = client
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), client),
+ Catalog: NewCatalog(client),
Client: client,
CamelCatalog: catalog,
Integration: &v1.Integration{
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index a76ae57..fa6591e 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -115,7 +115,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
if IsNilOrTrue(t.Auto) {
if len(t.ChannelSources) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -128,7 +128,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
}
if len(t.ChannelSinks) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -141,7 +141,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
}
if len(t.EndpointSources) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -154,7 +154,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
}
if len(t.EndpointSinks) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -167,7 +167,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
}
if len(t.EventSources) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -180,7 +180,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
}
if len(t.EventSinks) == 0 {
items := make([]string, 0)
- sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, e.Resources)
if err != nil {
return false, err
}
@@ -574,7 +574,7 @@ func (t *knativeTrait) withServiceDo(
if len(possibleRefs) == 1 {
actualRef = &possibleRefs[0]
} else {
- actualRef, err = knativeutil.GetAddressableReference(t.Ctx, t.Client, possibleRefs, e.Integration.Namespace, ref.Name)
+ actualRef, err = knativeutil.GetAddressableReference(e.Ctx, t.Client, possibleRefs, e.Integration.Namespace, ref.Name)
if err != nil && k8serrors.IsNotFound(err) {
return errors.Errorf("cannot find %s", serviceType.ResourceDescription(ref.Name))
} else if err != nil {
@@ -583,7 +583,7 @@ func (t *knativeTrait) withServiceDo(
}
urlProvider := func() (*url.URL, error) {
- targetURL, err := knativeutil.GetSinkURL(t.Ctx, t.Client, actualRef, e.Integration.Namespace)
+ targetURL, err := knativeutil.GetSinkURL(e.Ctx, t.Client, actualRef, e.Integration.Namespace)
if err != nil {
return nil, errors.Wrapf(err, "cannot determine address of %s", serviceType.ResourceDescription(ref.Name))
}
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index a86e7bd..5bf9e5c 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -142,7 +142,7 @@ func (t *knativeServiceTrait) Configure(e *Environment) (bool, error) {
if IsNilOrTrue(t.Auto) {
// Check the right value for minScale, as not all services are allowed to scale down to 0
if t.MinScale == nil {
- sources, err := kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources)
if err != nil {
e.Integration.Status.SetErrorCondition(
v1.IntegrationConditionKnativeServiceAvailable,
@@ -247,7 +247,7 @@ func (t *knativeServiceTrait) SelectControllerStrategy(e *Environment) (*Control
var sources []v1.SourceSpec
var err error
- if sources, err = kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, e.Resources); err != nil {
+ if sources, err = kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources); err != nil {
return nil, err
}
diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go
index 482cd89..333449b 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -43,7 +42,7 @@ func TestKnativeService(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
compressedRoute, err := gzip.CompressBase64([]byte(`from("undertow:test").log("hello")`))
assert.NoError(t, err)
@@ -184,7 +183,7 @@ func TestKnativeServiceWithCustomContainerName(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -259,7 +258,7 @@ func TestKnativeServiceWithResr(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go
index 65feefa..5c22c68 100644
--- a/pkg/trait/knative_test.go
+++ b/pkg/trait/knative_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -46,7 +45,7 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -101,7 +100,7 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) {
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.configure(&environment)
assert.Nil(t, err)
@@ -151,7 +150,7 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -220,7 +219,7 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) {
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.configure(&environment)
assert.Nil(t, err)
@@ -288,7 +287,7 @@ func TestKnativePlatformHttpConfig(t *testing.T) {
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.configure(&environment)
assert.Nil(t, err)
@@ -335,7 +334,7 @@ func TestKnativePlatformHttpDependencies(t *testing.T) {
c, err := NewFakeClient("ns")
assert.Nil(t, err)
- tc := NewCatalog(context.TODO(), c)
+ tc := NewCatalog(c)
err = tc.configure(&environment)
assert.Nil(t, err)
@@ -353,7 +352,7 @@ func NewFakeEnvironment(t *testing.T, source v1.SourceSpec) Environment {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go
index f5fc573..058dd42 100644
--- a/pkg/trait/logging_test.go
+++ b/pkg/trait/logging_test.go
@@ -39,9 +39,9 @@ func createLoggingTestEnv(t *testing.T, color bool, json bool, jsonPrettyPrint b
}
res := &Environment{
- C: context.TODO(),
+ Ctx: context.TODO(),
CamelCatalog: c,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
@@ -89,7 +89,7 @@ func createDefaultLoggingTestEnv(t *testing.T) *Environment {
}
func NewLoggingTestCatalog() *Catalog {
- return NewCatalog(context.TODO(), nil)
+ return NewCatalog(nil)
}
func TestEmptyLoggingTrait(t *testing.T) {
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 11d63d2..f5dfc28 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -146,7 +146,7 @@ func (t *openAPITrait) generateOpenAPIConfigMap(e *Environment, resource v1.Reso
Namespace: e.Integration.Namespace,
Name: generatedContentName,
}
- err := t.Client.Get(t.Ctx, key, &cm)
+ err := t.Client.Get(e.Ctx, key, &cm)
if err != nil && k8serrors.IsNotFound(err) {
return t.createNewOpenAPIConfigMap(e, resource, tmpDir, generatedContentName)
} else if err != nil {
@@ -207,7 +207,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
mc.AddArgument("-Dopenapi.spec=" + in)
mc.AddArgument("-Ddsl.out=" + out)
- settings, err := kubernetes.ResolveValueSource(e.C, e.Client, e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings)
+ settings, err := kubernetes.ResolveValueSource(e.Ctx, e.Client, e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings)
if err != nil {
return err
}
@@ -216,13 +216,13 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
}
if e.Platform.Status.Build.Maven.CASecret != nil {
- certData, err := kubernetes.GetSecretRefData(e.C, e.Client, e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
+ certData, err := kubernetes.GetSecretRefData(e.Ctx, e.Client, e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
if err != nil {
return err
}
trustStoreName := "trust.jks"
trustStorePass := jvm.NewKeystorePassword()
- err = jvm.GenerateKeystore(e.C, tmpDir, trustStoreName, trustStorePass, certData)
+ err = jvm.GenerateKeystore(e.Ctx, tmpDir, trustStoreName, trustStorePass, certData)
if err != nil {
return err
}
@@ -232,7 +232,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
)
}
- ctx, cancel := context.WithTimeout(e.C, e.Platform.Status.Build.GetTimeout().Duration)
+ ctx, cancel := context.WithTimeout(e.Ctx, e.Platform.Status.Build.GetTimeout().Duration)
defer cancel()
err = project.Command(mc).Do(ctx)
if err != nil {
diff --git a/pkg/trait/platform.go b/pkg/trait/platform.go
index 525d9cd..e91dea1 100644
--- a/pkg/trait/platform.go
+++ b/pkg/trait/platform.go
@@ -100,7 +100,7 @@ func (t *platformTrait) Apply(e *Environment) error {
}
func (t *platformTrait) getOrCreatePlatform(e *Environment) (*v1.IntegrationPlatform, error) {
- pl, err := platform.GetOrFind(t.Ctx, t.Client, e.Integration.Namespace, e.Integration.Status.Platform, false)
+ pl, err := platform.GetOrFind(e.Ctx, t.Client, e.Integration.Namespace, e.Integration.Status.Platform, false)
if err != nil && k8serrors.IsNotFound(err) {
if IsTrue(t.CreateDefault) {
platformName := e.Integration.Status.Platform
diff --git a/pkg/trait/prometheus_test.go b/pkg/trait/prometheus_test.go
index fbf244b..fe8aa46 100644
--- a/pkg/trait/prometheus_test.go
+++ b/pkg/trait/prometheus_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -124,7 +123,7 @@ func createNominalPrometheusTest() (*prometheusTrait, *Environment) {
}
environment := &Environment{
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
CamelCatalog: camelCatalog,
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
diff --git a/pkg/trait/pull_secret.go b/pkg/trait/pull_secret.go
index 005cdae..20d4722 100644
--- a/pkg/trait/pull_secret.go
+++ b/pkg/trait/pull_secret.go
@@ -74,7 +74,7 @@ func (t *pullSecretTrait) Configure(e *Environment) (bool, error) {
if secret != "" {
key := client.ObjectKey{Namespace: e.Platform.Namespace, Name: secret}
obj := corev1.Secret{}
- if err := t.Client.Get(t.Ctx, key, &obj); err != nil {
+ if err := t.Client.Get(e.Ctx, key, &obj); err != nil {
return false, err
}
if obj.Type == corev1.SecretTypeDockerConfigJson {
@@ -122,7 +122,7 @@ func (t *pullSecretTrait) delegateImagePuller(e *Environment) error {
// Applying the rolebinding directly because it's a resource in the operator namespace
// (different from the integration namespace when delegation is enabled).
rb := t.newImagePullerRoleBinding(e)
- if err := kubernetes.ReplaceResource(e.C, e.Client, rb); err != nil {
+ if err := kubernetes.ReplaceResource(e.Ctx, e.Client, rb); err != nil {
return errors.Wrap(err, "error during the creation of the system:image-puller delegating role binding")
}
return nil
diff --git a/pkg/trait/pull_secret_test.go b/pkg/trait/pull_secret_test.go
index 12cf6b6..afd0049 100644
--- a/pkg/trait/pull_secret_test.go
+++ b/pkg/trait/pull_secret_test.go
@@ -86,7 +86,7 @@ func TestPullSecretImagePullerDelegation(t *testing.T) {
Namespace: "test",
Name: "camel-k-puller-test-default",
}
- err = e.Client.Get(e.C, roleBindingKey, &roleBinding)
+ err = e.Client.Get(e.Ctx, roleBindingKey, &roleBinding)
assert.NoError(t, err)
assert.Len(t, roleBinding.Subjects, 1)
}
@@ -117,7 +117,7 @@ func getEnvironmentAndDeployment(t *testing.T) (*Environment, *appsv1.Deployment
e.Resources = kubernetes.NewCollection(&deployment)
var err error
- e.C = context.TODO()
+ e.Ctx = context.TODO()
e.Client, err = test.NewFakeClient(e.Integration, &deployment)
assert.NoError(t, err)
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index 764fedc..ab7af5c 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"testing"
"github.com/rs/xid"
@@ -41,7 +40,7 @@ func createTestRouteEnvironment(t *testing.T, name string) *Environment {
res := &Environment{
CamelCatalog: catalog,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: name,
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index dc710e7..d12d1c7 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -71,7 +71,7 @@ func (t *serviceTrait) Configure(e *Environment) (bool, error) {
}
if IsNilOrTrue(t.Auto) {
- sources, err := kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, e.Resources)
+ sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, e.Resources)
if err != nil {
e.Integration.Status.SetCondition(
v1.IntegrationConditionServiceAvailable,
diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go
index 5012050..7bb600c 100644
--- a/pkg/trait/service_binding.go
+++ b/pkg/trait/service_binding.go
@@ -172,7 +172,7 @@ func (t *serviceBindingTrait) getServiceBinding(e *Environment, name string) (sb
Namespace: e.Integration.Namespace,
Name: name,
}
- return serviceBinding, t.Client.Get(t.Ctx, key, &serviceBinding)
+ return serviceBinding, t.Client.Get(e.Ctx, key, &serviceBinding)
}
func (t *serviceBindingTrait) parseProvisionedServices(e *Environment) ([]sb.Service, error) {
diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go
index e68f482..9258542 100644
--- a/pkg/trait/service_test.go
+++ b/pkg/trait/service_test.go
@@ -18,18 +18,17 @@ limitations under the License.
package trait
import (
- "context"
"testing"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/camel"
"github.com/apache/camel-k/pkg/util/gzip"
"github.com/apache/camel-k/pkg/util/kubernetes"
+ "github.com/apache/camel-k/pkg/util/test"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "github.com/apache/camel-k/pkg/util/test"
)
const (
@@ -41,7 +40,7 @@ func TestServiceWithDefaults(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
compressedRoute, err := gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
assert.NoError(t, err)
@@ -130,7 +129,7 @@ func TestService(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
compressedRoute, err := gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
assert.NoError(t, err)
@@ -227,7 +226,7 @@ func TestServiceWithCustomContainerName(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
environment := Environment{
CamelCatalog: catalog,
@@ -298,7 +297,7 @@ func TestServiceWithNodePort(t *testing.T) {
catalog, err := camel.DefaultCatalog()
assert.Nil(t, err)
- traitCatalog := NewCatalog(context.TODO(), nil)
+ traitCatalog := NewCatalog(nil)
compressedRoute, err := gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
assert.NoError(t, err)
diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go
index 35ea851..fe837f9 100644
--- a/pkg/trait/trait.go
+++ b/pkg/trait/trait.go
@@ -37,7 +37,7 @@ func Apply(ctx context.Context, c client.Client, integration *v1.Integration, ki
return nil, err
}
- catalog := NewCatalog(ctx, c)
+ catalog := NewCatalog(c)
// set the catalog
environment.Catalog = catalog
@@ -84,7 +84,7 @@ func newEnvironment(ctx context.Context, c client.Client, integration *v1.Integr
}
env := Environment{
- C: ctx,
+ Ctx: ctx,
Platform: pl,
Client: c,
IntegrationKit: kit,
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index 7c51102..f3c31c5 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"reflect"
"sort"
"strings"
@@ -38,7 +37,7 @@ type Catalog struct {
}
// NewCatalog creates a new trait Catalog
-func NewCatalog(ctx context.Context, c client.Client) *Catalog {
+func NewCatalog(c client.Client) *Catalog {
var traitList = make([]Trait, 0, len(FactoryList))
for _, factory := range FactoryList {
traitList = append(traitList, factory())
@@ -56,9 +55,6 @@ func NewCatalog(ctx context.Context, c client.Client) *Catalog {
}
for _, t := range catalog.allTraits() {
- if ctx != nil {
- t.InjectContext(ctx)
- }
if c != nil {
t.InjectClient(c)
}
diff --git a/pkg/trait/trait_configure_test.go b/pkg/trait/trait_configure_test.go
index b454885..34b9e3f 100644
--- a/pkg/trait/trait_configure_test.go
+++ b/pkg/trait/trait_configure_test.go
@@ -18,13 +18,14 @@ limitations under the License.
package trait
import (
- "context"
"testing"
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
- "github.com/apache/camel-k/pkg/util/test"
"github.com/stretchr/testify/assert"
+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/pkg/util/test"
)
func TestTraitConfigurationFromAnnotations(t *testing.T) {
@@ -47,7 +48,7 @@ func TestTraitConfigurationFromAnnotations(t *testing.T) {
},
},
}
- c := NewCatalog(context.Background(), nil)
+ c := NewCatalog(nil)
assert.NoError(t, c.configure(&env))
assert.True(t, *c.GetTrait("cron").(*cronTrait).Fallback)
assert.Equal(t, "annotated-policy", c.GetTrait("cron").(*cronTrait).ConcurrencyPolicy)
@@ -67,7 +68,7 @@ func TestFailOnWrongTraitAnnotations(t *testing.T) {
},
},
}
- c := NewCatalog(context.Background(), nil)
+ c := NewCatalog(nil)
assert.Error(t, c.configure(&env))
}
@@ -121,7 +122,7 @@ func TestTraitConfigurationOverrideRulesFromAnnotations(t *testing.T) {
},
},
}
- c := NewCatalog(context.Background(), nil)
+ c := NewCatalog(nil)
assert.NoError(t, c.configure(&env))
assert.Equal(t, "schedule2", c.GetTrait("cron").(*cronTrait).Schedule)
assert.Equal(t, "cmp4", c.GetTrait("cron").(*cronTrait).Components)
@@ -142,7 +143,7 @@ func TestTraitListConfigurationFromAnnotations(t *testing.T) {
},
},
}
- c := NewCatalog(context.Background(), nil)
+ c := NewCatalog(nil)
assert.NoError(t, c.configure(&env))
assert.Equal(t, []string{"opt1", "opt2"}, c.GetTrait("jolokia").(*jolokiaTrait).Options)
assert.Equal(t, []string{"Binding:xxx"}, c.GetTrait("service-binding").(*serviceBindingTrait).ServiceBindings)
@@ -161,7 +162,7 @@ func TestTraitSplitConfiguration(t *testing.T) {
},
},
}
- c := NewCatalog(context.Background(), nil)
+ c := NewCatalog(nil)
assert.NoError(t, c.configure(&env))
assert.Equal(t, []string{"opt1", "opt2"}, c.GetTrait("owner").(*ownerTrait).TargetLabels)
}
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 100056d..6eb0261 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -18,7 +18,6 @@ limitations under the License.
package trait
import (
- "context"
"path"
"testing"
@@ -568,7 +567,7 @@ func createTestEnv(t *testing.T, cluster v1.IntegrationPlatformCluster, script s
res := &Environment{
CamelCatalog: catalog,
- Catalog: NewCatalog(context.TODO(), nil),
+ Catalog: NewCatalog(nil),
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: TestDeploymentName,
@@ -608,5 +607,5 @@ func createTestEnv(t *testing.T, cluster v1.IntegrationPlatformCluster, script s
}
func NewTraitTestCatalog() *Catalog {
- return NewCatalog(context.TODO(), nil)
+ return NewCatalog(nil)
}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 2ab9296..50fcb1a 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -25,12 +25,13 @@ import (
"strconv"
"strings"
- "github.com/apache/camel-k/pkg/util/property"
"github.com/pkg/errors"
+
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
serving "knative.dev/serving/pkg/apis/serving/v1"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -42,11 +43,13 @@ import (
"github.com/apache/camel-k/pkg/util/camel"
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/log"
+ "github.com/apache/camel-k/pkg/util/property"
)
-// True --
-const True = "true"
-const False = "false"
+const (
+ True = "true"
+ False = "false"
+)
var (
basePath = "/etc/camel"
@@ -72,9 +75,6 @@ type Trait interface {
Identifiable
client.Injectable
- // InjectContext to inject a context
- InjectContext(context.Context)
-
// Configure the trait
Configure(environment *Environment) (bool, error)
@@ -131,11 +131,10 @@ func NewBaseTrait(id string, order int) BaseTrait {
type BaseTrait struct {
TraitID ID `json:"-"`
// Can be used to enable or disable a trait. All traits share this common property.
- Enabled *bool `property:"enabled" json:"enabled,omitempty"`
- Client client.Client `json:"-"`
- Ctx context.Context `json:"-"`
- ExecutionOrder int `json:"-"`
- L log.Logger `json:"-"`
+ Enabled *bool `property:"enabled" json:"enabled,omitempty"`
+ Client client.Client `json:"-"`
+ ExecutionOrder int `json:"-"`
+ L log.Logger `json:"-"`
}
// ID returns the identifier of the trait
@@ -148,11 +147,6 @@ func (trait *BaseTrait) InjectClient(c client.Client) {
trait.Client = c
}
-// InjectContext allows to inject a context into the trait
-func (trait *BaseTrait) InjectContext(ctx context.Context) {
- trait.Ctx = ctx
-}
-
// InfluencesKit determines if the trait has any influence on Integration Kits
func (trait *BaseTrait) InfluencesKit() bool {
return false
@@ -192,8 +186,10 @@ type Environment struct {
CamelCatalog *camel.RuntimeCatalog
RuntimeVersion string
Catalog *Catalog
- C context.Context
- Client client.Client
+ // The Go standard context for the traits execution
+ Ctx context.Context
+ // The client to the API server
+ Client client.Client
// The active Platform
Platform *v1.IntegrationPlatform
// The current Integration
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index bca1a97..2e49333 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -159,15 +159,12 @@ func NewContext(buildDir string) Context {
}
type Context struct {
- Path string
- // Project Project
+ Path string
ExtraMavenOpts []string
SettingsContent []byte
AdditionalArguments []string
AdditionalEntries map[string]interface{}
- // Timeout time.Duration
- LocalRepository string
- // Stdout io.Writer
+ LocalRepository string
}
func (c *Context) AddEntry(id string, entry interface{}) {
[camel-k] 17/37: chore(native): Simplify integration transition out
of kit building phase
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b35a9b305f094e06768bca8333114b05a587ff28
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 19 17:11:23 2021 +0200
chore(native): Simplify integration transition out of kit building phase
---
pkg/controller/integration/build_kit.go | 5 +--
pkg/trait/deployer.go | 68 +++++++++++++--------------------
pkg/trait/deployer_test.go | 10 -----
3 files changed, 27 insertions(+), 56 deletions(-)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index fbb665a..348d3a5 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -92,12 +92,9 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
if kit.Status.Phase == v1.IntegrationKitPhaseReady {
integration.Status.Image = kit.Status.Image
+ integration.Status.Phase = v1.IntegrationPhaseDeploying
integration.SetIntegrationKit(kit)
- if _, err := trait.Apply(ctx, action.client, integration, kit); err != nil {
- return nil, err
- }
-
return integration, nil
}
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index 609519c..9e49374 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -33,8 +33,8 @@ import (
"github.com/apache/camel-k/pkg/util/patch"
)
-// The deployer trait can be used to explicitly select the kind of high level resource that
-// will deploy the integration.
+// The deployer trait is responsible for deploying the resources owned by the integration, and can be used
+// to explicitly select the underlying controller that will manage the integration pods.
//
// +camel-k:trait=deployer
type deployerTrait struct {
@@ -59,55 +59,39 @@ func (t *deployerTrait) Configure(e *Environment) (bool, error) {
v1.IntegrationPhaseWaitingForBindings,
v1.IntegrationPhaseWaitingForPlatform,
v1.IntegrationPhaseInitialization,
- v1.IntegrationPhaseBuildingKit,
v1.IntegrationPhaseDeploying,
v1.IntegrationPhaseRunning,
), nil
}
func (t *deployerTrait) Apply(e *Environment) error {
- switch e.Integration.Status.Phase {
-
- case v1.IntegrationPhaseBuildingKit:
- if e.IntegrationKitInPhase(v1.IntegrationKitPhaseReady) {
- e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
- // trigger integration deploy
- e.Integration.Status.Phase = v1.IntegrationPhaseDeploying
- return nil
- })
- }
-
- case v1.IntegrationPhaseNone, v1.IntegrationPhaseInitialization,
- v1.IntegrationPhaseWaitingForPlatform, v1.IntegrationPhaseWaitingForBindings,
- v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning:
- // Register a post action that patches the resources generated by the traits
- e.PostActions = append(e.PostActions, func(env *Environment) error {
- for _, resource := range env.Resources.Items() {
- // We assume that server-side apply is enabled by default.
- // It is currently convoluted to check pro-actively whether server-side apply
- // is enabled. This is possible to fetch the OpenAPI endpoint, which returns
- // the entire server API document, then lookup the resource PATCH endpoint, and
- // check its list of accepted MIME types.
- // As a simpler solution, we fall back to client-side apply at the first
- // 415 error, and assume server-side apply is not available globally.
- if hasServerSideApply {
- if err := t.serverSideApply(env, resource); err == nil {
- continue
- } else if isIncompatibleServerError(err) {
- t.L.Info("Fallback to client-side apply to patch resources")
- hasServerSideApply = false
- } else {
- // Keep server-side apply unless server is incompatible with it
- return err
- }
- }
- if err := t.clientSideApply(env, resource); err != nil {
+ // Register a post action that patches the resources generated by the traits
+ e.PostActions = append(e.PostActions, func(env *Environment) error {
+ for _, resource := range env.Resources.Items() {
+ // We assume that server-side apply is enabled by default.
+ // It is currently convoluted to check pro-actively whether server-side apply
+ // is enabled. This is possible to fetch the OpenAPI endpoint, which returns
+ // the entire server API document, then lookup the resource PATCH endpoint, and
+ // check its list of accepted MIME types.
+ // As a simpler solution, we fall back to client-side apply at the first
+ // 415 error, and assume server-side apply is not available globally.
+ if hasServerSideApply {
+ if err := t.serverSideApply(env, resource); err == nil {
+ continue
+ } else if isIncompatibleServerError(err) {
+ t.L.Info("Fallback to client-side apply to patch resources")
+ hasServerSideApply = false
+ } else {
+ // Keep server-side apply unless server is incompatible with it
return err
}
}
- return nil
- })
- }
+ if err := t.clientSideApply(env, resource); err != nil {
+ return err
+ }
+ }
+ return nil
+ })
return nil
}
diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go
index c595f2c..939dcb0 100644
--- a/pkg/trait/deployer_test.go
+++ b/pkg/trait/deployer_test.go
@@ -65,16 +65,6 @@ func TestApplyDeployerTraitInInitializationPhaseDoesSucceed(t *testing.T) {
assert.Len(t, environment.PostActions, 1)
}
-func TestApplyDeployerTraitInResolvingKitPhaseSkipPostActions(t *testing.T) {
- deployerTrait, environment := createNominalDeployerTest()
- environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
-
- err := deployerTrait.Apply(environment)
-
- assert.Nil(t, err)
- assert.Len(t, environment.PostActions, 0)
-}
-
func createNominalDeployerTest() (*deployerTrait, *Environment) {
trait := newDeployerTrait().(*deployerTrait)
[camel-k] 16/37: chore(native): Remove unused
IntegrationPhaseResolvingKit phase
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 546759fed1bbd82240c274253dd5dbd0b2a697bf
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 19 16:30:11 2021 +0200
chore(native): Remove unused IntegrationPhaseResolvingKit phase
---
pkg/apis/camel/v1/integration_types.go | 5 ++---
pkg/controller/integration/build_kit.go | 3 +--
pkg/trait/deployer.go | 5 ++---
pkg/trait/deployer_test.go | 2 +-
pkg/trait/deployment_test.go | 2 +-
pkg/trait/prometheus_test.go | 2 +-
6 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/pkg/apis/camel/v1/integration_types.go b/pkg/apis/camel/v1/integration_types.go
index 79005f6..32125c8 100644
--- a/pkg/apis/camel/v1/integration_types.go
+++ b/pkg/apis/camel/v1/integration_types.go
@@ -116,9 +116,8 @@ const (
IntegrationPhaseWaitingForPlatform IntegrationPhase = "Waiting For Platform"
// IntegrationPhaseBuildingKit --
IntegrationPhaseBuildingKit IntegrationPhase = "Building Kit"
- // IntegrationPhaseResolvingKit --
- IntegrationPhaseResolvingKit IntegrationPhase = "Resolving Kit"
- // IntegrationPhaseWaitingForBindings e.g Service Bindings --
+ // IntegrationPhaseWaitingForBindings means the Integration is currently waiting to be bound
+ // to other resources, e.g., Service Bindings.
IntegrationPhaseWaitingForBindings IntegrationPhase = "Waiting for Bindings"
// IntegrationPhaseDeploying --
IntegrationPhaseDeploying IntegrationPhase = "Deploying"
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index cb2919c..fbb665a 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -51,8 +51,7 @@ func (action *buildKitAction) Name() string {
}
func (action *buildKitAction) CanHandle(integration *v1.Integration) bool {
- return integration.Status.Phase == v1.IntegrationPhaseBuildingKit ||
- integration.Status.Phase == v1.IntegrationPhaseResolvingKit
+ return integration.Status.Phase == v1.IntegrationPhaseBuildingKit
}
func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integration) (*v1.Integration, error) {
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index 301d7d0..609519c 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -60,7 +60,6 @@ func (t *deployerTrait) Configure(e *Environment) (bool, error) {
v1.IntegrationPhaseWaitingForPlatform,
v1.IntegrationPhaseInitialization,
v1.IntegrationPhaseBuildingKit,
- v1.IntegrationPhaseResolvingKit,
v1.IntegrationPhaseDeploying,
v1.IntegrationPhaseRunning,
), nil
@@ -69,7 +68,7 @@ func (t *deployerTrait) Configure(e *Environment) (bool, error) {
func (t *deployerTrait) Apply(e *Environment) error {
switch e.Integration.Status.Phase {
- case v1.IntegrationPhaseBuildingKit, v1.IntegrationPhaseResolvingKit:
+ case v1.IntegrationPhaseBuildingKit:
if e.IntegrationKitInPhase(v1.IntegrationKitPhaseReady) {
e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error {
// trigger integration deploy
@@ -89,7 +88,7 @@ func (t *deployerTrait) Apply(e *Environment) error {
// is enabled. This is possible to fetch the OpenAPI endpoint, which returns
// the entire server API document, then lookup the resource PATCH endpoint, and
// check its list of accepted MIME types.
- // As a simpler solution, we fallback to client-side apply at the first
+ // As a simpler solution, we fall back to client-side apply at the first
// 415 error, and assume server-side apply is not available globally.
if hasServerSideApply {
if err := t.serverSideApply(env, resource); err == nil {
diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go
index d5ffb97..c595f2c 100644
--- a/pkg/trait/deployer_test.go
+++ b/pkg/trait/deployer_test.go
@@ -67,7 +67,7 @@ func TestApplyDeployerTraitInInitializationPhaseDoesSucceed(t *testing.T) {
func TestApplyDeployerTraitInResolvingKitPhaseSkipPostActions(t *testing.T) {
deployerTrait, environment := createNominalDeployerTest()
- environment.Integration.Status.Phase = v1.IntegrationPhaseResolvingKit
+ environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
err := deployerTrait.Apply(environment)
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index a84ca82..f4fdd7a 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -93,7 +93,7 @@ func TestConfigureDeploymentTraitWhileWaitingPlatformDoesNotSucceed(t *testing.T
func TestApplyDeploymentTraitWhileResolvingKitDoesNotSucceed(t *testing.T) {
deploymentTrait, environment := createNominalDeploymentTest()
- environment.Integration.Status.Phase = v1.IntegrationPhaseResolvingKit
+ environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
configured, err := deploymentTrait.Configure(environment)
diff --git a/pkg/trait/prometheus_test.go b/pkg/trait/prometheus_test.go
index 670a911..fbf244b 100644
--- a/pkg/trait/prometheus_test.go
+++ b/pkg/trait/prometheus_test.go
@@ -45,7 +45,7 @@ func TestConfigurePrometheusTraitInRightPhaseDoesSucceed(t *testing.T) {
func TestConfigurePrometheusTraitInWrongPhaseDoesNotSucceed(t *testing.T) {
trait, environment := createNominalPrometheusTest()
- environment.Integration.Status.Phase = v1.IntegrationPhaseResolvingKit
+ environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
configured, err := trait.Configure(environment)
[camel-k] 30/37: feat(native): Add builder native e2e test
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a9242cfe223c202253820428dee49a5344394845
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Sep 3 10:15:32 2021 +0200
feat(native): Add builder native e2e test
---
e2e/builder/build_test.go | 42 +++++++++++++++++++++++++++++--------
e2e/support/test_support.go | 50 +++++++++++++++++++++++++++++++--------------
2 files changed, 69 insertions(+), 23 deletions(-)
diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go
index 737647e..8419950 100644
--- a/e2e/builder/build_test.go
+++ b/e2e/builder/build_test.go
@@ -30,25 +30,51 @@ import (
"github.com/apache/camel-k/pkg/apis/camel/v1"
)
+type kitOptions struct {
+ dependencies []string
+ traits []string
+}
+
func TestKitTimerToLogFullBuild(t *testing.T) {
- doKitFullBuild(t, "timer-to-log", "camel:timer", "camel:log")
+ doKitFullBuild(t, "timer-to-log", kitOptions{
+ dependencies: []string{
+ "camel:timer", "camel:log",
+ },
+ })
}
func TestKitKnativeFullBuild(t *testing.T) {
- doKitFullBuild(t, "knative", "camel:knative")
+ doKitFullBuild(t, "knative", kitOptions{
+ dependencies: []string{
+ "camel:knative",
+ },
+ })
}
-func doKitFullBuild(t *testing.T, name string, dependencies ...string) {
+func TestKitTimerToLogFullNativeBuild(t *testing.T) {
+ doKitFullBuild(t, "timer-to-log", kitOptions{
+ dependencies: []string{
+ "camel:timer", "camel:log",
+ },
+ traits: []string{
+ "quarkus.package-type=native",
+ },
+ })
+}
+
+func doKitFullBuild(t *testing.T, name string, options kitOptions) {
WithNewTestNamespace(t, func(ns string) {
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
buildKitArgs := []string{"kit", "create", name, "-n", ns}
- for _, dep := range dependencies {
- buildKitArgs = append(buildKitArgs, "-d", dep)
+ for _, dependency := range options.dependencies {
+ buildKitArgs = append(buildKitArgs, "-d", dependency)
+ }
+ for _, trait := range options.traits {
+ buildKitArgs = append(buildKitArgs, "-t", trait)
}
Expect(Kamel(buildKitArgs...).Execute()).To(Succeed())
Eventually(Build(ns, name)).ShouldNot(BeNil())
- Eventually(func() v1.BuildPhase {
- return Build(ns, name)().Status.Phase
- }, TestTimeoutMedium).Should(Equal(v1.BuildPhaseSucceeded))
+ Eventually(BuildPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.BuildPhaseSucceeded))
+ Eventually(KitPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationKitPhaseReady))
})
}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index a85b0d4..6f29b22 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -26,7 +26,6 @@ import (
"bytes"
"context"
"encoding/json"
- "errors"
"fmt"
"io"
"io/ioutil"
@@ -36,11 +35,9 @@ import (
"testing"
"time"
- "github.com/apache/camel-k/pkg/util/patch"
"github.com/google/uuid"
"github.com/onsi/gomega"
"github.com/spf13/cobra"
- "k8s.io/apimachinery/pkg/types"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/batch/v1beta1"
@@ -49,6 +46,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -70,6 +68,7 @@ import (
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/log"
"github.com/apache/camel-k/pkg/util/openshift"
+ "github.com/apache/camel-k/pkg/util/patch"
// let's enable addons in all tests
_ "github.com/apache/camel-k/addons"
@@ -569,6 +568,28 @@ func IntegrationKit(ns string, name string) func() string {
}
}
+func Kit(ns, name string) func() *v1.IntegrationKit {
+ return func() *v1.IntegrationKit {
+ kit := v1.NewIntegrationKit(ns, name)
+ if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(kit), kit); err != nil && !k8serrors.IsNotFound(err) {
+ panic(err)
+ } else if err != nil && k8serrors.IsNotFound(err) {
+ return nil
+ }
+ return kit
+ }
+}
+
+func KitPhase(ns, name string) func() v1.IntegrationKitPhase {
+ return func() v1.IntegrationKitPhase {
+ kit := Kit(ns, name)()
+ if kit == nil {
+ return v1.IntegrationKitPhaseNone
+ }
+ return kit.Status.Phase
+ }
+}
+
func UpdateIntegration(ns string, name string, upd func(it *v1.Integration)) error {
it := Integration(ns, name)()
if it == nil {
@@ -851,7 +872,7 @@ func DeploymentCondition(ns string, name string, conditionType appsv1.Deployment
}
}
-func Build(ns string, name string) func() *v1.Build {
+func Build(ns, name string) func() *v1.Build {
return func() *v1.Build {
build := v1.NewBuild(ns, name)
if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(build), build); err != nil && k8serrors.IsNotFound(err) {
@@ -864,6 +885,16 @@ func Build(ns string, name string) func() *v1.Build {
}
}
+func BuildPhase(ns, name string) func() v1.BuildPhase {
+ return func() v1.BuildPhase {
+ build := Build(ns, name)()
+ if build != nil {
+ return build.Status.Phase
+ }
+ return v1.BuildPhaseNone
+ }
+}
+
func Platform(ns string) func() *v1.IntegrationPlatform {
return func() *v1.IntegrationPlatform {
lst := v1.NewIntegrationPlatformList()
@@ -894,17 +925,6 @@ func DeletePlatform(ns string) func() bool {
}
}
-func SetPlatformVersion(ns string, version string) func() error {
- return func() error {
- p := Platform(ns)()
- if p == nil {
- return errors.New("no platform found")
- }
- p.Status.Version = version
- return TestClient().Status().Update(TestContext, p)
- }
-}
-
func PlatformVersion(ns string) func() string {
return func() string {
p := Platform(ns)()
[camel-k] 29/37: chore(e2e): Remove redundant Quarkus trait e2e test
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3a8d5c59a7c269c75d5fcc16d73bc4aa03b2902e
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Sep 1 14:54:22 2021 +0200
chore(e2e): Remove redundant Quarkus trait e2e test
---
e2e/common/languages/yaml_test.go | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/e2e/common/languages/yaml_test.go b/e2e/common/languages/yaml_test.go
index f97562e..3cfd598 100644
--- a/e2e/common/languages/yaml_test.go
+++ b/e2e/common/languages/yaml_test.go
@@ -44,15 +44,6 @@ func TestRunSimpleYamlExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
- t.Run("run yaml Quarkus", func(t *testing.T) {
- Expect(Kamel("run", "-n", ns, "--name", "yaml-quarkus", "files/yaml.yaml", "-t", "quarkus.enabled=true").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "yaml-quarkus"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "yaml-quarkus", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "yaml-quarkus"), TestTimeoutShort).Should(ContainSubstring("powered by Quarkus"))
- Eventually(IntegrationLogs(ns, "yaml-quarkus"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
- Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
- })
-
t.Run("init run yaml", func(t *testing.T) {
RunInitGeneratedExample(camelv1.LanguageYaml, ns, t)
})
[camel-k] 26/37: feat(native): Automatic rollout to highest
priority kit
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 48525daa7028d7fc298463a3649539faae1cfc26
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Aug 30 17:21:13 2021 +0200
feat(native): Automatic rollout to highest priority kit
---
pkg/controller/integration/build_kit.go | 216 +--------------------
pkg/controller/integration/build_kit_test.go | 8 +-
.../integration/integration_controller.go | 66 ++++---
.../integration/{build_kit.go => kits.go} | 167 ++--------------
pkg/controller/integration/monitor.go | 55 +++++-
5 files changed, 112 insertions(+), 400 deletions(-)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index ff396dd..a0fee46 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -19,19 +19,10 @@ package integration
import (
"context"
- "encoding/json"
- "reflect"
"github.com/pkg/errors"
- k8serrors "k8s.io/apimachinery/pkg/api/errors"
- "k8s.io/apimachinery/pkg/labels"
- "k8s.io/apimachinery/pkg/selection"
-
- ctrl "sigs.k8s.io/controller-runtime/pkg/client"
-
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
- "github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/defaults"
@@ -64,7 +55,7 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
}
if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
- match, err := action.integrationMatches(integration, kit)
+ match, err := integrationMatches(integration, kit)
if err != nil {
return nil, err
} else if !match {
@@ -91,7 +82,7 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
return nil, nil
}
- existingKits, err := action.lookupKitsForIntegration(ctx, action.client, integration)
+ existingKits, err := lookupKitsForIntegration(ctx, action.client, integration)
if err != nil {
return nil, err
}
@@ -138,79 +129,6 @@ kits:
return integration, nil
}
-func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration) ([]v1.IntegrationKit, error) {
- pl, err := platform.GetCurrent(ctx, c, integration.Namespace)
- if err != nil && !k8serrors.IsNotFound(err) {
- return nil, err
- }
-
- kitTypes, err := labels.NewRequirement(v1.IntegrationKitTypeLabel, selection.In, []string{
- v1.IntegrationKitTypePlatform,
- v1.IntegrationKitTypeExternal,
- })
- if err != nil {
- return nil, err
- }
-
- options := []ctrl.ListOption{
- ctrl.InNamespace(integration.GetIntegrationKitNamespace(pl)),
- ctrl.MatchingLabels{
- "camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
- "camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
- },
- ctrl.MatchingLabelsSelector{
- Selector: labels.NewSelector().Add(*kitTypes),
- },
- }
-
- list := v1.NewIntegrationKitList()
- if err := c.List(ctx, &list, options...); err != nil {
- return nil, err
- }
-
- kits := make([]v1.IntegrationKit, 0)
- for _, kit := range list.Items {
- match, err := action.integrationMatches(integration, &kit)
- if err != nil {
- return nil, err
- } else if !match {
- continue
- }
- kits = append(kits, kit)
- }
-
- return kits, nil
-}
-
-// integrationMatches returns whether the v1.IntegrationKit meets the requirements of the v1.Integration
-func (action *buildKitAction) integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
- if kit.Status.Phase == v1.IntegrationKitPhaseError {
- return false, nil
- }
- if kit.Status.Version != integration.Status.Version {
- return false, nil
- }
- if len(integration.Status.Dependencies) != len(kit.Spec.Dependencies) {
- return false, nil
- }
- // When a platform kit is created it inherits the traits from the integrations and as
- // some traits may influence the build thus the artifacts present on the container image,
- // we need to take traits into account when looking up for compatible kits.
- //
- // It could also happen that an integration is updated and a trait is modified, if we do
- // not include traits in the lookup, we may use a kit that does not have all the
- // characteristics required by the integration.
- //
- // A kit can be used only if it contains a subset of the traits and related configurations
- // declared on integration.
- if match, err := action.hasMatchingTraits(integration, kit); !match || err != nil {
- return false, err
- }
- if !util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies) {
- return false, nil
- }
- return true, nil
-}
// kitMatches returns whether the v1.IntegrationKit match
func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.IntegrationKit) (bool, error) {
@@ -233,7 +151,7 @@ func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.Integrati
if !ok {
return false, nil
}
- match, err := action.hasMatchingTrait(&kt1, &kt2)
+ match, err := hasMatchingTrait(&kt1, &kt2)
if !match || err != nil {
return false, err
}
@@ -243,131 +161,3 @@ func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.Integrati
}
return true, nil
}
-
-// hasMatchingTraits compares the traits defined on the v1.Integration with those defined on the v1.IntegrationKit
-func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
- catalog := trait.NewCatalog(action.client)
-
- traitCount := 0
- for name, itTrait := range integration.Spec.Traits {
- t := catalog.GetTrait(name)
- if t != nil && !t.InfluencesKit() {
- // We don't store the trait configuration if the trait cannot influence the kit behavior
- continue
- }
- traitCount++
- kitTrait, ok := kit.Spec.Traits[name]
- if !ok {
- // skip it because trait configured on integration is not defined on kit
- return false, nil
- }
- if ct, ok := t.(trait.ComparableTrait); ok {
- comparable, err := action.hasComparableTrait(ct, &itTrait, &kitTrait)
- if !comparable || err != nil {
- return false, err
- }
- } else {
- match, err := action.hasMatchingTrait(&itTrait, &kitTrait)
- if !match || err != nil {
- return false, err
- }
- }
- }
-
- // Check the number of influencing traits matches
- if len(kit.Spec.Traits) != traitCount {
- return false, nil
- }
-
- return true, nil
-}
-
-func (action *buildKitAction) hasComparableTrait(c trait.ComparableTrait, itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
- it := reflect.New(reflect.TypeOf(c).Elem()).Interface()
- data, err := json.Marshal(itTrait.Configuration)
- if err != nil {
- return false, err
- }
- err = json.Unmarshal(data, &it)
- if err != nil {
- return false, err
- }
-
- kt := reflect.New(reflect.TypeOf(c).Elem()).Interface()
- data, err = json.Marshal(kitTrait.Configuration)
- if err != nil {
- return false, err
- }
- err = json.Unmarshal(data, &kt)
- if err != nil {
- return false, err
- }
-
- return kt.(trait.ComparableTrait).Matches(it.(trait.Trait)), nil
-}
-
-func (action *buildKitAction) hasMatchingTrait(itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
- data, err := json.Marshal(itTrait.Configuration)
- if err != nil {
- return false, err
- }
- itConf := make(map[string]interface{})
- err = json.Unmarshal(data, &itConf)
- if err != nil {
- return false, err
- }
- data, err = json.Marshal(kitTrait.Configuration)
- if err != nil {
- return false, err
- }
- kitConf := make(map[string]interface{})
- err = json.Unmarshal(data, &kitConf)
- if err != nil {
- return false, err
- }
- for ck, cv := range kitConf {
- iv, ok := itConf[ck]
- if !ok {
- // skip it because trait configured on kit has a value that is not defined
- // in integration trait
- return false, nil
- }
- if !equal(iv, cv) {
- // skip it because trait configured on kit has a value that differs from
- // the one configured on integration
- return false, nil
- }
- }
- return true, nil
-}
-
-// We need to try to perform a slice equality in order to prevent a runtime panic
-func equal(a, b interface{}) bool {
- aSlice, aOk := a.([]interface{})
- bSlice, bOk := b.([]interface{})
-
- if aOk && bOk {
- // Both are slices
- return sliceEqual(aSlice, bSlice)
- }
-
- if aOk || bOk {
- // One of the 2 is a slice
- return false
- }
-
- // None is a slice
- return a == b
-}
-
-func sliceEqual(a, b []interface{}) bool {
- if len(a) != len(b) {
- return false
- }
- for i, v := range a {
- if v != b[i] {
- return false
- }
- }
- return true
-}
diff --git a/pkg/controller/integration/build_kit_test.go b/pkg/controller/integration/build_kit_test.go
index a1538e3..430dc38 100644
--- a/pkg/controller/integration/build_kit_test.go
+++ b/pkg/controller/integration/build_kit_test.go
@@ -84,7 +84,7 @@ func TestLookupKitForIntegration_DiscardKitsInError(t *testing.T) {
a.InjectLogger(log.Log)
a.InjectClient(c)
- kits, err := a.lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
+ kits, err := lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKind,
@@ -207,7 +207,7 @@ func TestLookupKitForIntegration_DiscardKitsWithIncompatibleTraits(t *testing.T)
a.InjectLogger(log.Log)
a.InjectClient(c)
- kits, err := a.lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
+ kits, err := lookupKitsForIntegration(context.TODO(), c, &v1.Integration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.IntegrationKind,
@@ -276,7 +276,7 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := a.hasMatchingTraits(integration, integrationKitSpec)
+ ok, err := hasMatchingTraits(integration, integrationKitSpec)
assert.Nil(t, err)
assert.False(t, ok)
}
@@ -327,7 +327,7 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) {
a := buildKitAction{}
a.InjectLogger(log.Log)
- ok, err := a.hasMatchingTraits(integration, integrationKitSpec)
+ ok, err := hasMatchingTraits(integration, integrationKitSpec)
assert.Nil(t, err)
assert.True(t, ok)
}
diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go
index 0a4df39..55bf2ec 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -49,8 +49,6 @@ import (
"github.com/apache/camel-k/pkg/util/monitoring"
)
-// Add creates a new Integration Controller and adds it to the Manager. The Manager will set fields on the Controller
-// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
c, err := client.FromManager(mgr)
if err != nil {
@@ -59,7 +57,6 @@ func Add(mgr manager.Manager) error {
return add(mgr, newReconciler(mgr, c), c)
}
-// newReconciler returns a new reconcile.Reconciler
func newReconciler(mgr manager.Manager, c client.Client) reconcile.Reconciler {
return monitoring.NewInstrumentedReconciler(
&reconcileIntegration{
@@ -75,7 +72,6 @@ func newReconciler(mgr manager.Manager, c client.Client) reconcile.Reconciler {
)
}
-// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler, cl client.Client) error {
// Create a new controller
c, err := controller.New("integration-controller", mgr, controller.Options{Reconciler: r})
@@ -92,7 +88,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, cl client.Client) error {
newIntegration := e.ObjectNew.(*v1.Integration)
// Ignore updates to the integration status in which case metadata.Generation does not change,
// or except when the integration phase changes as it's used to transition from one phase
- // to another
+ // to another.
return oldIntegration.Generation != newIntegration.Generation ||
oldIntegration.Status.Phase != newIntegration.Status.Phase
},
@@ -106,40 +102,46 @@ func add(mgr manager.Manager, r reconcile.Reconciler, cl client.Client) error {
return err
}
- // Watch for IntegrationKit phase transitioning to ready or error and
- // enqueue requests for any integrations that are in phase waiting for
- // kit
+ // Watch for IntegrationKit phase transitioning to ready or error, and
+ // enqueue requests for any integration that matches the kit, in building
+ // or running phase.
err = c.Watch(&source.Kind{Type: &v1.IntegrationKit{}},
handler.EnqueueRequestsFromMapFunc(func(a ctrl.Object) []reconcile.Request {
kit := a.(*v1.IntegrationKit)
var requests []reconcile.Request
- if kit.Status.Phase == v1.IntegrationKitPhaseReady || kit.Status.Phase == v1.IntegrationKitPhaseError {
- list := &v1.IntegrationList{}
+ if kit.Status.Phase != v1.IntegrationKitPhaseReady && kit.Status.Phase != v1.IntegrationKitPhaseError {
+ return requests
+ }
- // Do global search in case of global operator (it may be using a global platform)
- var opts []ctrl.ListOption
- if !platform.IsCurrentOperatorGlobal() {
- opts = append(opts, ctrl.InNamespace(kit.Namespace))
- }
+ list := &v1.IntegrationList{}
+ // Do global search in case of global operator (it may be using a global platform)
+ var opts []ctrl.ListOption
+ if !platform.IsCurrentOperatorGlobal() {
+ opts = append(opts, ctrl.InNamespace(kit.Namespace))
+ }
+ if err := mgr.GetClient().List(context.Background(), list, opts...); err != nil {
+ log.Error(err, "Failed to retrieve integration list")
+ return requests
+ }
- if err := mgr.GetClient().List(context.TODO(), list, opts...); err != nil {
- log.Error(err, "Failed to retrieve integration list")
- return requests
+ for _, integration := range list.Items {
+ if match, err := integrationMatches(&integration, kit); err != nil {
+ log.Errorf(err, "Error matching integration %q with kit %q", integration.Name, kit.Name)
+ continue
+ } else if !match {
+ continue
}
-
- for _, integration := range list.Items {
- if integration.Status.Phase == v1.IntegrationPhaseBuildingKit {
- log.Infof("Kit %s ready, wake-up integration: %s", kit.Name, integration.Name)
- requests = append(requests, reconcile.Request{
- NamespacedName: types.NamespacedName{
- Namespace: integration.Namespace,
- Name: integration.Name,
- },
- })
- }
+ if integration.Status.Phase == v1.IntegrationPhaseBuildingKit ||
+ integration.Status.Phase == v1.IntegrationPhaseRunning {
+ log.Infof("Kit %s ready, notify integration: %s", kit.Name, integration.Name)
+ requests = append(requests, reconcile.Request{
+ NamespacedName: types.NamespacedName{
+ Namespace: integration.Namespace,
+ Name: integration.Name,
+ },
+ })
}
-
}
return requests
@@ -228,7 +230,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, cl client.Client) error {
return err
}
- // Watch cronjob to update the ready condition
+ // Watch for CronJob to update the ready condition
err = c.Watch(&source.Kind{Type: &v1beta1.CronJob{}}, &handler.EnqueueRequestForOwner{
OwnerType: &v1.Integration{},
IsController: false,
@@ -261,7 +263,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, cl client.Client) error {
var _ reconcile.Reconciler = &reconcileIntegration{}
-// reconcileIntegration reconciles a Integration object
+// reconcileIntegration reconciles an Integration object
type reconcileIntegration struct {
// This client, initialized using mgr.Client() above, is a split client
// that reads objects from the cache and writes to the API server
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/kits.go
similarity index 53%
copy from pkg/controller/integration/build_kit.go
copy to pkg/controller/integration/kits.go
index ff396dd..2a7eab0 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/kits.go
@@ -22,8 +22,6 @@ import (
"encoding/json"
"reflect"
- "github.com/pkg/errors"
-
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
@@ -34,111 +32,9 @@ import (
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/defaults"
- "github.com/apache/camel-k/pkg/util/kubernetes"
)
-func newBuildKitAction() Action {
- return &buildKitAction{}
-}
-
-type buildKitAction struct {
- baseAction
-}
-
-func (action *buildKitAction) Name() string {
- return "build-kit"
-}
-
-func (action *buildKitAction) CanHandle(integration *v1.Integration) bool {
- return integration.Status.Phase == v1.IntegrationPhaseBuildingKit
-}
-
-func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integration) (*v1.Integration, error) {
- // TODO: we may need to add a timeout strategy, i.e give up after some time in case of an unrecoverable error.
-
- if integration.Status.IntegrationKit != nil {
- kit, err := kubernetes.GetIntegrationKit(ctx, action.client, integration.Status.IntegrationKit.Name, integration.Status.IntegrationKit.Namespace)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to find integration kit %s/%s, %s", integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err)
- }
-
- if kit.Labels[v1.IntegrationKitTypeLabel] == v1.IntegrationKitTypePlatform {
- match, err := action.integrationMatches(integration, kit)
- if err != nil {
- return nil, err
- } else if !match {
- // We need to re-generate a kit, or search for a new one that
- // matches the integration, so let's remove the association
- // with the kit.
- integration.SetIntegrationKit(&v1.IntegrationKit{})
- return integration, nil
- }
- }
-
- if kit.Status.Phase == v1.IntegrationKitPhaseError {
- integration.Status.Phase = v1.IntegrationPhaseError
- integration.SetIntegrationKit(kit)
- return integration, nil
- }
-
- if kit.Status.Phase == v1.IntegrationKitPhaseReady {
- integration.Status.Phase = v1.IntegrationPhaseDeploying
- integration.SetIntegrationKit(kit)
- return integration, nil
- }
-
- return nil, nil
- }
-
- existingKits, err := action.lookupKitsForIntegration(ctx, action.client, integration)
- if err != nil {
- return nil, err
- }
-
- env, err := trait.Apply(ctx, action.client, integration, nil)
- if err != nil {
- return nil, err
- }
-
- var integrationKit *v1.IntegrationKit
-kits:
- for _, kit := range env.IntegrationKits {
- kit := kit
- for i, k := range existingKits {
- match, err := action.kitMatches(&kit, &k)
- if err != nil {
- return nil, err
- }
- if match {
- if integrationKit == nil ||
- integrationKit.Status.Phase != v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady ||
- integrationKit.Status.Phase == v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady && k.HasHigherPriorityThan(integrationKit) {
- integrationKit = &existingKits[i]
- }
- continue kits
- }
- }
- if err := action.client.Create(ctx, &kit); err != nil {
- return nil, err
- }
- if integrationKit == nil {
- integrationKit = &kit
- }
- }
-
- // Set the kit name so the next handle loop, will fall through the
- // same path as integration with a user defined kit
- integration.SetIntegrationKit(integrationKit)
-
- if integrationKit.Status.Phase == v1.IntegrationKitPhaseReady {
- integration.Status.Phase = v1.IntegrationPhaseDeploying
- }
-
- return integration, nil
-}
-
-func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration) ([]v1.IntegrationKit, error) {
+func lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v1.Integration, options ...ctrl.ListOption) ([]v1.IntegrationKit, error) {
pl, err := platform.GetCurrent(ctx, c, integration.Namespace)
if err != nil && !k8serrors.IsNotFound(err) {
return nil, err
@@ -152,7 +48,7 @@ func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ct
return nil, err
}
- options := []ctrl.ListOption{
+ listOptions := []ctrl.ListOption{
ctrl.InNamespace(integration.GetIntegrationKitNamespace(pl)),
ctrl.MatchingLabels{
"camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
@@ -162,15 +58,16 @@ func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ct
Selector: labels.NewSelector().Add(*kitTypes),
},
}
+ listOptions = append(listOptions, options...)
list := v1.NewIntegrationKitList()
- if err := c.List(ctx, &list, options...); err != nil {
+ if err := c.List(ctx, &list, listOptions...); err != nil {
return nil, err
}
kits := make([]v1.IntegrationKit, 0)
for _, kit := range list.Items {
- match, err := action.integrationMatches(integration, &kit)
+ match, err := integrationMatches(integration, &kit)
if err != nil {
return nil, err
} else if !match {
@@ -183,13 +80,19 @@ func (action *buildKitAction) lookupKitsForIntegration(ctx context.Context, c ct
}
// integrationMatches returns whether the v1.IntegrationKit meets the requirements of the v1.Integration
-func (action *buildKitAction) integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
+func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
if kit.Status.Phase == v1.IntegrationKitPhaseError {
return false, nil
}
if kit.Status.Version != integration.Status.Version {
return false, nil
}
+ if kit.Status.RuntimeProvider != integration.Status.RuntimeProvider {
+ return false, nil
+ }
+ if kit.Status.RuntimeVersion != integration.Status.RuntimeVersion {
+ return false, nil
+ }
if len(integration.Status.Dependencies) != len(kit.Spec.Dependencies) {
return false, nil
}
@@ -203,7 +106,7 @@ func (action *buildKitAction) integrationMatches(integration *v1.Integration, ki
//
// A kit can be used only if it contains a subset of the traits and related configurations
// declared on integration.
- if match, err := action.hasMatchingTraits(integration, kit); !match || err != nil {
+ if match, err := hasMatchingTraits(integration, kit); !match || err != nil {
return false, err
}
if !util.StringSliceContains(kit.Spec.Dependencies, integration.Status.Dependencies) {
@@ -212,41 +115,9 @@ func (action *buildKitAction) integrationMatches(integration *v1.Integration, ki
return true, nil
}
-// kitMatches returns whether the v1.IntegrationKit match
-func (action *buildKitAction) kitMatches(k1 *v1.IntegrationKit, k2 *v1.IntegrationKit) (bool, error) {
- version := k1.Status.Version
- if version == "" {
- // Defaults with the version that is going to be set during the kit initialization
- version = defaults.Version
- }
- if version != k2.Status.Version {
- return false, nil
- }
- if len(k1.Spec.Dependencies) != len(k2.Spec.Dependencies) {
- return false, nil
- }
- if len(k1.Spec.Traits) != len(k2.Spec.Traits) {
- return false, nil
- }
- for name, kt1 := range k1.Spec.Traits {
- kt2, ok := k2.Spec.Traits[name]
- if !ok {
- return false, nil
- }
- match, err := action.hasMatchingTrait(&kt1, &kt2)
- if !match || err != nil {
- return false, err
- }
- }
- if !util.StringSliceContains(k1.Spec.Dependencies, k2.Spec.Dependencies) {
- return false, nil
- }
- return true, nil
-}
-
// hasMatchingTraits compares the traits defined on the v1.Integration with those defined on the v1.IntegrationKit
-func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
- catalog := trait.NewCatalog(action.client)
+func hasMatchingTraits(integration *v1.Integration, kit *v1.IntegrationKit) (bool, error) {
+ catalog := trait.NewCatalog(nil)
traitCount := 0
for name, itTrait := range integration.Spec.Traits {
@@ -262,12 +133,12 @@ func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit
return false, nil
}
if ct, ok := t.(trait.ComparableTrait); ok {
- comparable, err := action.hasComparableTrait(ct, &itTrait, &kitTrait)
+ comparable, err := hasComparableTrait(ct, &itTrait, &kitTrait)
if !comparable || err != nil {
return false, err
}
} else {
- match, err := action.hasMatchingTrait(&itTrait, &kitTrait)
+ match, err := hasMatchingTrait(&itTrait, &kitTrait)
if !match || err != nil {
return false, err
}
@@ -282,7 +153,7 @@ func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, kit
return true, nil
}
-func (action *buildKitAction) hasComparableTrait(c trait.ComparableTrait, itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
+func hasComparableTrait(c trait.ComparableTrait, itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
it := reflect.New(reflect.TypeOf(c).Elem()).Interface()
data, err := json.Marshal(itTrait.Configuration)
if err != nil {
@@ -306,7 +177,7 @@ func (action *buildKitAction) hasComparableTrait(c trait.ComparableTrait, itTrai
return kt.(trait.ComparableTrait).Matches(it.(trait.Trait)), nil
}
-func (action *buildKitAction) hasMatchingTrait(itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
+func hasMatchingTrait(itTrait *v1.TraitSpec, kitTrait *v1.TraitSpec) (bool, error) {
data, err := json.Marshal(itTrait.Configuration)
if err != nil {
return false, err
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index 858b22b..532ad8f 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -19,13 +19,16 @@ package integration
import (
"context"
+ "strconv"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/labels"
+ "k8s.io/apimachinery/pkg/selection"
- k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/trait"
@@ -51,6 +54,7 @@ func (action *monitorAction) CanHandle(integration *v1.Integration) bool {
}
func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integration) (*v1.Integration, error) {
+ // Check if the Integration has changed
hash, err := digest.ComputeForIntegration(integration)
if err != nil {
return nil, err
@@ -70,6 +74,29 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
return nil, errors.Wrapf(err, "unable to find integration kit %s/%s, %s", integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err)
}
+ // Check if an IntegrationKit with higher priority is ready
+ priority, ok := kit.Labels[v1.IntegrationKitPriorityLabel]
+ if !ok {
+ priority = "0"
+ }
+ withHigherPriority, err := labels.NewRequirement(v1.IntegrationKitPriorityLabel, selection.GreaterThan, []string{priority})
+ if err != nil {
+ return nil, err
+ }
+ kits, err := lookupKitsForIntegration(ctx, action.client, integration, ctrl.MatchingLabelsSelector{
+ Selector: labels.NewSelector().Add(*withHigherPriority),
+ })
+ if err != nil {
+ return nil, err
+ }
+ priorityReadyKit, err := findHighestPriorityReadyKit(kits)
+ if err != nil {
+ return nil, err
+ }
+ if priorityReadyKit != nil {
+ integration.SetIntegrationKit(priorityReadyKit)
+ }
+
// Run traits that are enabled for the running phase
_, err = trait.Apply(ctx, action.client, integration, kit)
if err != nil {
@@ -84,8 +111,8 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
// Check replicas
replicaSets := &appsv1.ReplicaSetList{}
err = action.client.List(ctx, replicaSets,
- k8sclient.InNamespace(integration.Namespace),
- k8sclient.MatchingLabels{
+ ctrl.InNamespace(integration.Namespace),
+ ctrl.MatchingLabels{
v1.IntegrationLabel: integration.Name,
})
if err != nil {
@@ -160,3 +187,25 @@ func findLatestReplicaSet(list *appsv1.ReplicaSetList) *appsv1.ReplicaSet {
}
return &latest
}
+
+func findHighestPriorityReadyKit(kits []v1.IntegrationKit) (*v1.IntegrationKit, error) {
+ if len(kits) == 0 {
+ return nil, nil
+ }
+ var kit *v1.IntegrationKit
+ priority := 0
+ for i, k := range kits {
+ if k.Status.Phase != v1.IntegrationKitPhaseReady {
+ continue
+ }
+ p, err := strconv.Atoi(k.Labels[v1.IntegrationKitPriorityLabel])
+ if err != nil {
+ return nil, err
+ }
+ if p > priority {
+ kit = &kits[i]
+ priority = p
+ }
+ }
+ return kit, nil
+}
[camel-k] 14/37: feat(native): Enable builds to run concurrently
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a53c5bfb65e46bde848a48cee2448a5b3497a605
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Aug 18 16:28:23 2021 +0200
feat(native): Enable builds to run concurrently
---
pkg/controller/build/schedule.go | 35 +++++++++++++++++++++++++++++-----
pkg/controller/integrationkit/build.go | 4 +++-
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/pkg/controller/build/schedule.go b/pkg/controller/build/schedule.go
index da060c1..c49b904 100644
--- a/pkg/controller/build/schedule.go
+++ b/pkg/controller/build/schedule.go
@@ -23,6 +23,8 @@ import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/labels"
+ "k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -58,10 +60,29 @@ func (action *scheduleAction) Handle(ctx context.Context, build *v1.Build) (*v1.
action.lock.Lock()
defer action.lock.Unlock()
+ layout := build.Labels[v1.IntegrationKitLayoutLabel]
+
+ // Native builds can be run in parallel, as incremental images is not applicable.
+ if layout == v1.IntegrationKitLayoutNative {
+ // Reset the Build status, and transition it to pending phase.
+ // This must be done in the critical section, rather than delegated to the controller.
+ return nil, action.toPendingPhase(ctx, build)
+ }
+
+ // We assume incremental images is only applicable across images whose layout is identical
+ withCompatibleLayout, err := labels.NewRequirement(v1.IntegrationKitLayoutLabel, selection.Equals, []string{layout})
+ if err != nil {
+ return nil, err
+ }
+
builds := &v1.BuildList{}
// We use the non-caching client as informers cache is not invalidated nor updated
// atomically by write operations
- err := action.reader.List(ctx, builds, ctrl.InNamespace(build.Namespace))
+ err = action.reader.List(ctx, builds,
+ ctrl.InNamespace(build.Namespace),
+ ctrl.MatchingLabelsSelector{
+ Selector: labels.NewSelector().Add(*withCompatibleLayout),
+ })
if err != nil {
return nil, err
}
@@ -69,7 +90,7 @@ func (action *scheduleAction) Handle(ctx context.Context, build *v1.Build) (*v1.
// Emulate a serialized working queue to only allow one build to run at a given time.
// This is currently necessary for the incremental build to work as expected.
// We may want to explicitly manage build priority as opposed to relying on
- // the reconcile loop to handle the queuing
+ // the reconciliation loop to handle the queuing.
for _, b := range builds.Items {
if b.Status.Phase == v1.BuildPhasePending || b.Status.Phase == v1.BuildPhaseRunning {
// Let's requeue the build in case one is already running
@@ -79,7 +100,11 @@ func (action *scheduleAction) Handle(ctx context.Context, build *v1.Build) (*v1.
// Reset the Build status, and transition it to pending phase.
// This must be done in the critical section, rather than delegated to the controller.
- err = action.patchBuildStatus(ctx, build, func(b *v1.Build) {
+ return nil, action.toPendingPhase(ctx, build)
+}
+
+func (action *scheduleAction) toPendingPhase(ctx context.Context, build *v1.Build) error {
+ err := action.patchBuildStatus(ctx, build, func(b *v1.Build) {
now := metav1.Now()
b.Status = v1.BuildStatus{
Phase: v1.BuildPhasePending,
@@ -90,13 +115,13 @@ func (action *scheduleAction) Handle(ctx context.Context, build *v1.Build) (*v1.
}
})
if err != nil {
- return nil, err
+ return err
}
// Report the duration the Build has been waiting in the build queue
queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
- return nil, nil
+ return nil
}
func (action *scheduleAction) patchBuildStatus(ctx context.Context, build *v1.Build, mutate func(b *v1.Build)) error {
diff --git a/pkg/controller/integrationkit/build.go b/pkg/controller/integrationkit/build.go
index 599022f..62b6820 100644
--- a/pkg/controller/integrationkit/build.go
+++ b/pkg/controller/integrationkit/build.go
@@ -82,6 +82,8 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
return nil, errors.New("undefined camel catalog")
}
+ labels := kubernetes.FilterCamelCreatorLabels(kit.Labels)
+ labels[v1.IntegrationKitLayoutLabel] = kit.Labels[v1.IntegrationKitLayoutLabel]
build = &v1.Build{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
@@ -90,7 +92,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
ObjectMeta: metav1.ObjectMeta{
Namespace: kit.Namespace,
Name: kit.Name,
- Labels: kubernetes.FilterCamelCreatorLabels(kit.Labels),
+ Labels: labels,
},
Spec: v1.BuildSpec{
Tasks: env.BuildTasks,
[camel-k] 13/37: chore(native): Upgrade Maven to version 3.8.2
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3dd8cc3ce5fce64a4b271afbd90b0c9792479926
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Aug 18 16:27:15 2021 +0200
chore(native): Upgrade Maven to version 3.8.2
---
build/Dockerfile | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/build/Dockerfile b/build/Dockerfile
index 52a8297..96b6e99 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -15,19 +15,20 @@
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2.0.0-Final-java11
-ARG MAVEN_VERSION="3.6.3"
-ARG SHA="c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0"
+ARG MAVEN_VERSION="3.8.2"
+ARG MAVEN_HOME="/usr/share/maven"
+ARG SHA="b0bf39460348b2d8eae1c861ced6c3e8a077b6e761fb3d4669be5de09490521a74db294cf031b0775b2dfcd57bd82246e42ce10904063ef8e3806222e686f222"
ARG BASE_URL="https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries"
USER 0
-RUN mkdir -p /usr/share/maven \
+RUN mkdir -p ${MAVEN_HOME} \
&& curl -Lso /tmp/maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/maven.tar.gz" | sha512sum -c - \
- && tar -xzC /usr/share/maven --strip-components=1 -f /tmp/maven.tar.gz \
+ && tar -xzC ${MAVEN_HOME} --strip-components=1 -f /tmp/maven.tar.gz \
&& rm -v /tmp/maven.tar.gz \
- && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn \
- && rm /usr/share/maven/lib/maven-slf4j-provider*
+ && ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn \
+ && rm ${MAVEN_HOME}/lib/maven-slf4j-provider*
ADD build/_maven_output /tmp/artifacts/m2
ADD build/_kamelets /kamelets
[camel-k] 34/37: chore(native): Rebuild resources
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit eef9d5f471670b3a1ebaa6c9d9a27cd90c472dce
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Sep 7 12:57:30 2021 +0200
chore(native): Rebuild resources
---
deploy/traits.yaml | 19 +++++++++++++------
docs/modules/traits/pages/deployer.adoc | 4 ++--
docs/modules/traits/pages/quarkus.adoc | 13 +++++++++----
pkg/resources/resources.go | 4 ++--
4 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/deploy/traits.yaml b/deploy/traits.yaml
index 62f63c0..073fff9 100755
--- a/deploy/traits.yaml
+++ b/deploy/traits.yaml
@@ -249,8 +249,9 @@ traits:
- Kubernetes
- Knative
- OpenShift
- description: The deployer trait can be used to explicitly select the kind of high
- level resource that will deploy the integration.
+ description: The deployer trait is responsible for deploying the resources owned
+ by the integration, and can be used to explicitly select the underlying controller
+ that will manage the integration pods.
properties:
- name: enabled
type: bool
@@ -807,15 +808,21 @@ traits:
- Kubernetes
- Knative
- OpenShift
- description: The Quarkus trait activates the Quarkus runtime. It's enabled by default.
+ description: The Quarkus trait configures the Quarkus runtime. It's enabled by default.
properties:
- name: enabled
type: bool
description: Can be used to enable or disable a trait. All traits share this common
property.
- - name: native
- type: bool
- description: The Quarkus runtime type (reserved for future use)
+ - name: package-type
+ type: '[]./pkg/trait.quarkusPackageType'
+ description: The Quarkus package types, either `fast-jar` or `native` (default
+ `fast-jar`).In case both `fast-jar` and `native` are specified, two IntegrationKits
+ are created,with the `native` kit having precedence over the `fast-jar' one
+ once ready.The order influences the resolution of the current IntegrationKit
+ for the Integration.The IntegrationKit corresponding to the first package type
+ will be assigned to theIntegration in case no existing IntegrationKit that matches
+ the Integration exists.
- name: route
platform: false
profiles:
diff --git a/docs/modules/traits/pages/deployer.adoc b/docs/modules/traits/pages/deployer.adoc
index efdaec5..61181e5 100755
--- a/docs/modules/traits/pages/deployer.adoc
+++ b/docs/modules/traits/pages/deployer.adoc
@@ -1,8 +1,8 @@
= Deployer Trait
// Start of autogenerated code - DO NOT EDIT! (description)
-The deployer trait can be used to explicitly select the kind of high level resource that
-will deploy the integration.
+The deployer trait is responsible for deploying the resources owned by the integration, and can be used
+to explicitly select the underlying controller that will manage the integration pods.
This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.
diff --git a/docs/modules/traits/pages/quarkus.adoc b/docs/modules/traits/pages/quarkus.adoc
index dac0a3f..5127c0d 100755
--- a/docs/modules/traits/pages/quarkus.adoc
+++ b/docs/modules/traits/pages/quarkus.adoc
@@ -1,7 +1,7 @@
= Quarkus Trait
// Start of autogenerated code - DO NOT EDIT! (description)
-The Quarkus trait activates the Quarkus runtime.
+The Quarkus trait configures the Quarkus runtime.
It's enabled by default.
@@ -29,9 +29,14 @@ The following configuration options are available:
| bool
| Can be used to enable or disable a trait. All traits share this common property.
-| quarkus.native
-| bool
-| The Quarkus runtime type (reserved for future use)
+| quarkus.package-type
+| []./pkg/trait.quarkusPackageType
+| The Quarkus package types, either `fast-jar` or `native` (default `fast-jar`).
+In case both `fast-jar` and `native` are specified, two IntegrationKits are created,
+with the `native` kit having precedence over the `fast-jar' one once ready.
+The order influences the resolution of the current IntegrationKit for the Integration.
+The IntegrationKit corresponding to the first package type will be assigned to the
+Integration in case no existing IntegrationKit that matches the Integration exists.
|===
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index a545399..815ff3b 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -467,9 +467,9 @@ var assets = func() http.FileSystem {
"/traits.yaml": &vfsgen۰CompressedFileInfo{
name: "traits.yaml",
modTime: time.Time{},
- uncompressedSize: 39128,
+ uncompressedSize: 39715,
- compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\x7b\x73\x24\xb7\xf1\xd8\xff\xf7\x29\x50\xfc\xa5\xea\x48\xd6\xee\xf0\x24\xc7\xb6\xc2\x44\x71\x51\x77\x27\x8b\xd2\x3d\x98\x23\x2d\x57\x4a\x51\x79\xb1\x33\xbd\xbb\x38\x62\x80\x31\x80\x21\x6f\x1d\xe7\xbb\xa7\xd0\x8d\xd7\xec\x0e\x97\xcb\x93\xa8\x12\x53\xb1\xff\xd0\x91\x9c\x69\x34\x1a\x8d\x7e\x77\x8f\x33\x5c\x38\x7b\xfa\x6c\xca\x14\x6f\xe1\x94\xf1\xc5\x42\x28\xe1\xd6\xcf\x18\xeb\x24\x77\x0b\x6d\xda\x53\xb6\xe0\xd2\x [...]
+ compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfb\x73\x24\xb7\xd1\xd8\xef\xf7\x57\xa0\xf8\xa5\x8a\x8f\xda\x1d\x52\x76\xec\x4f\x61\xa2\xb8\xe8\xbb\x93\x45\xe9\x1e\xcc\x91\x92\x2b\x75\x51\x79\xb1\x33\xbd\xbb\x38\x62\x80\x31\x80\x21\x6f\x9d\x2f\xff\x7b\x0a\xdd\x78\xcd\xec\x92\x5c\x9e\x44\x95\x98\x8a\xfd\x83\x8e\xe4\xa0\xd1\x68\x34\xfa\x8d\x86\x33\x5c\x38\x7b\xfa\x62\xca\x14\x6f\xe1\x94\xf1\xc5\x42\x28\xe1\xd6\x2f\x18\xeb\x24\x77\x0b\x6d\xda\x53\xb6\xe0\xd2\x [...]
},
}
fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
[camel-k] 35/37: feat(native): Increase native build timeout to
sensible default
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2e4eaacab1849f76628e41ad751e917473af559f
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Sep 8 12:04:54 2021 +0200
feat(native): Increase native build timeout to sensible default
---
pkg/controller/integrationkit/build.go | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/pkg/controller/integrationkit/build.go b/pkg/controller/integrationkit/build.go
index 9a8c390..4e8a688 100644
--- a/pkg/controller/integrationkit/build.go
+++ b/pkg/controller/integrationkit/build.go
@@ -21,6 +21,7 @@ import (
"context"
"fmt"
"strings"
+ "time"
"github.com/pkg/errors"
@@ -84,6 +85,13 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
labels := kubernetes.FilterCamelCreatorLabels(kit.Labels)
labels[v1.IntegrationKitLayoutLabel] = kit.Labels[v1.IntegrationKitLayoutLabel]
+ timeout := env.Platform.Status.Build.GetTimeout()
+ if layout := labels[v1.IntegrationKitLayoutLabel]; env.Platform.Spec.Build.Timeout == nil && layout == v1.IntegrationKitLayoutNative {
+ // Increase the timeout to a sensible default
+ timeout = metav1.Duration{
+ Duration: 10 * time.Minute,
+ }
+ }
build = &v1.Build{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
@@ -96,7 +104,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int
},
Spec: v1.BuildSpec{
Tasks: env.BuildTasks,
- Timeout: env.Platform.Status.Build.GetTimeout(),
+ Timeout: timeout,
},
}
[camel-k] 21/37: chore(native): Polish build kit logic
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2bbbba1d98ed2d4a56da3cef15d575d679a4326c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 26 17:19:09 2021 +0200
chore(native): Polish build kit logic
---
pkg/controller/integration/build_kit.go | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index 3187512..4568f4f 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -74,18 +74,15 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
integration.SetIntegrationKit(&v1.IntegrationKit{})
return integration, nil
}
-
}
if kit.Status.Phase == v1.IntegrationKitPhaseError {
- integration.Status.Image = kit.Status.Image
integration.Status.Phase = v1.IntegrationPhaseError
integration.SetIntegrationKit(kit)
return integration, nil
}
if kit.Status.Phase == v1.IntegrationKitPhaseReady {
- integration.Status.Image = kit.Status.Image
integration.Status.Phase = v1.IntegrationPhaseDeploying
integration.SetIntegrationKit(kit)
return integration, nil
@@ -106,8 +103,9 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
var integrationKit *v1.IntegrationKit
kits:
- for i, kit := range env.IntegrationKits {
- for j, k := range existingKits {
+ for _, kit := range env.IntegrationKits {
+ kit := kit
+ for i, k := range existingKits {
match, err := action.kitMatches(&kit, &k)
if err != nil {
return nil, err
@@ -116,7 +114,7 @@ kits:
if integrationKit == nil ||
integrationKit.Status.Phase != v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady ||
integrationKit.Status.Phase == v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady && k.HasHigherPriorityThan(integrationKit) {
- integrationKit = &existingKits[j]
+ integrationKit = &existingKits[i]
}
continue kits
}
@@ -125,17 +123,17 @@ kits:
return nil, err
}
if integrationKit == nil {
- integrationKit = &env.IntegrationKits[i]
+ integrationKit = &kit
}
}
// Set the kit name so the next handle loop, will fall through the
// same path as integration with a user defined kit
+ integration.SetIntegrationKit(integrationKit)
+
if integrationKit.Status.Phase == v1.IntegrationKitPhaseReady {
- integration.Status.Image = integrationKit.Status.Image
integration.Status.Phase = v1.IntegrationPhaseDeploying
}
- integration.SetIntegrationKit(integrationKit)
return integration, nil
}
[camel-k] 31/37: fix(e2e): Increase build timeout for native tests
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d6500f737c575acd723925a94f27d2bd21ec38cb
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Sep 3 11:28:26 2021 +0200
fix(e2e): Increase build timeout for native tests
---
e2e/builder/build_test.go | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go
index 8419950..53ba598 100644
--- a/e2e/builder/build_test.go
+++ b/e2e/builder/build_test.go
@@ -23,6 +23,7 @@ package builder
import (
"testing"
+ "time"
. "github.com/onsi/gomega"
@@ -36,7 +37,7 @@ type kitOptions struct {
}
func TestKitTimerToLogFullBuild(t *testing.T) {
- doKitFullBuild(t, "timer-to-log", kitOptions{
+ doKitFullBuild(t, "timer-to-log", "5m0s", TestTimeoutLong, kitOptions{
dependencies: []string{
"camel:timer", "camel:log",
},
@@ -44,7 +45,7 @@ func TestKitTimerToLogFullBuild(t *testing.T) {
}
func TestKitKnativeFullBuild(t *testing.T) {
- doKitFullBuild(t, "knative", kitOptions{
+ doKitFullBuild(t, "knative", "5m0s", TestTimeoutLong, kitOptions{
dependencies: []string{
"camel:knative",
},
@@ -52,7 +53,7 @@ func TestKitKnativeFullBuild(t *testing.T) {
}
func TestKitTimerToLogFullNativeBuild(t *testing.T) {
- doKitFullBuild(t, "timer-to-log", kitOptions{
+ doKitFullBuild(t, "timer-to-log", "15m0s", 2*TestTimeoutLong, kitOptions{
dependencies: []string{
"camel:timer", "camel:log",
},
@@ -62,9 +63,9 @@ func TestKitTimerToLogFullNativeBuild(t *testing.T) {
})
}
-func doKitFullBuild(t *testing.T, name string, options kitOptions) {
+func doKitFullBuild(t *testing.T, name string, buildTimeout string, testTimeout time.Duration, options kitOptions) {
WithNewTestNamespace(t, func(ns string) {
- Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+ Expect(Kamel("install", "-n", ns, "--build-timeout", buildTimeout).Execute()).To(Succeed())
buildKitArgs := []string{"kit", "create", name, "-n", ns}
for _, dependency := range options.dependencies {
buildKitArgs = append(buildKitArgs, "-d", dependency)
@@ -74,7 +75,7 @@ func doKitFullBuild(t *testing.T, name string, options kitOptions) {
}
Expect(Kamel(buildKitArgs...).Execute()).To(Succeed())
Eventually(Build(ns, name)).ShouldNot(BeNil())
- Eventually(BuildPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.BuildPhaseSucceeded))
- Eventually(KitPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationKitPhaseReady))
+ Eventually(BuildPhase(ns, name), testTimeout).Should(Equal(v1.BuildPhaseSucceeded))
+ Eventually(KitPhase(ns, name), testTimeout).Should(Equal(v1.IntegrationKitPhaseReady))
})
}
[camel-k] 18/37: fix(native): Only evaluate Quarkus packaging for
JVM trait active phases
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 7840bf6f56a281b43850eea4d0cb67484fde44fa
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 26 16:04:46 2021 +0200
fix(native): Only evaluate Quarkus packaging for JVM trait active phases
---
pkg/trait/jvm.go | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 81700dc..4633494 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -71,14 +71,18 @@ func (t *jvmTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
+ if !e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) &&
+ !e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning) {
+ return false, nil
+ }
+
if trait := e.Catalog.GetTrait(quarkusTraitId); trait != nil {
- if quarkus := trait.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.isNativePackageType() {
+ if quarkus := trait.(*quarkusTrait); IsNilOrTrue(quarkus.Enabled) && quarkus.hasNativePackageType(e) {
return false, nil
}
}
- return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
- e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
+ return true, nil
}
func (t *jvmTrait) Apply(e *Environment) error {
[camel-k] 22/37: fix(native): Do not add default Quarkus trait
configuration to kit
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d2cb79c9c9d3fbc93ff843eec214164674ea6aec
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Aug 27 10:40:55 2021 +0200
fix(native): Do not add default Quarkus trait configuration to kit
---
pkg/trait/quarkus.go | 104 ++++++++++++++++++++++++++++-----------------------
1 file changed, 58 insertions(+), 46 deletions(-)
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 2e47f5b..138d3a1 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -106,10 +106,6 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
- if len(t.PackageTypes) == 0 {
- t.PackageTypes = []quarkusPackageType{fastJarPackageType}
- }
-
return e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) ||
e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
@@ -119,50 +115,39 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
func (t *quarkusTrait) Apply(e *Environment) error {
if e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) {
- integration := e.Integration
-
- for _, packageType := range t.PackageTypes {
- kit := v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(e.Platform), fmt.Sprintf("kit-%s", xid.New()))
-
- kit.Labels = map[string]string{
- v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
- "camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
- "camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
- v1.IntegrationKitLayoutLabel: string(packageType),
- v1.IntegrationKitPriorityLabel: kitPriority[packageType],
- kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
- kubernetes.CamelCreatorLabelName: integration.Name,
- kubernetes.CamelCreatorLabelNamespace: integration.Namespace,
- kubernetes.CamelCreatorLabelVersion: integration.ResourceVersion,
- }
-
- traits := t.getKitTraits(e)
- data, err := json.Marshal(traits[quarkusTraitId].Configuration)
- if err != nil {
- return err
- }
- trait := quarkusTrait{}
- err = json.Unmarshal(data, &trait)
- if err != nil {
- return err
- }
- trait.PackageTypes = []quarkusPackageType{packageType}
- data, err = json.Marshal(trait)
- if err != nil {
- return err
- }
- traits[quarkusTraitId] = v1.TraitSpec{
- Configuration: v1.TraitConfiguration{
- RawMessage: data,
- },
- }
- kit.Spec = v1.IntegrationKitSpec{
- Dependencies: e.Integration.Status.Dependencies,
- Repositories: e.Integration.Spec.Repositories,
- Traits: traits,
- }
+ switch len(t.PackageTypes) {
+ case 0:
+ kit := t.newIntegrationKit(e, fastJarPackageType)
+ e.IntegrationKits = append(e.IntegrationKits, *kit)
+ case 1:
+ kit := t.newIntegrationKit(e, t.PackageTypes[0])
e.IntegrationKits = append(e.IntegrationKits, *kit)
+
+ default:
+ for _, packageType := range t.PackageTypes {
+ kit := t.newIntegrationKit(e, packageType)
+ data, err := json.Marshal(kit.Spec.Traits[quarkusTraitId].Configuration)
+ if err != nil {
+ return err
+ }
+ trait := quarkusTrait{}
+ err = json.Unmarshal(data, &trait)
+ if err != nil {
+ return err
+ }
+ trait.PackageTypes = []quarkusPackageType{packageType}
+ data, err = json.Marshal(trait)
+ if err != nil {
+ return err
+ }
+ kit.Spec.Traits[quarkusTraitId] = v1.TraitSpec{
+ Configuration: v1.TraitConfiguration{
+ RawMessage: data,
+ },
+ }
+ e.IntegrationKits = append(e.IntegrationKits, *kit)
+ }
}
return nil
@@ -225,6 +210,33 @@ func (t *quarkusTrait) Apply(e *Environment) error {
return nil
}
+func (t *quarkusTrait) newIntegrationKit(e *Environment, packageType quarkusPackageType) *v1.IntegrationKit {
+ integration := e.Integration
+ kit := v1.NewIntegrationKit(integration.GetIntegrationKitNamespace(e.Platform), fmt.Sprintf("kit-%s", xid.New()))
+
+ kit.Labels = map[string]string{
+ v1.IntegrationKitTypeLabel: v1.IntegrationKitTypePlatform,
+ "camel.apache.org/runtime.version": integration.Status.RuntimeVersion,
+ "camel.apache.org/runtime.provider": string(integration.Status.RuntimeProvider),
+ v1.IntegrationKitLayoutLabel: string(packageType),
+ v1.IntegrationKitPriorityLabel: kitPriority[packageType],
+ kubernetes.CamelCreatorLabelKind: v1.IntegrationKind,
+ kubernetes.CamelCreatorLabelName: integration.Name,
+ kubernetes.CamelCreatorLabelNamespace: integration.Namespace,
+ kubernetes.CamelCreatorLabelVersion: integration.ResourceVersion,
+ }
+
+ traits := t.getKitTraits(e)
+
+ kit.Spec = v1.IntegrationKitSpec{
+ Dependencies: e.Integration.Status.Dependencies,
+ Repositories: e.Integration.Spec.Repositories,
+ Traits: traits,
+ }
+
+ return kit
+}
+
func (t *quarkusTrait) getKitTraits(e *Environment) map[string]v1.TraitSpec {
traits := make(map[string]v1.TraitSpec)
for name, spec := range e.Integration.Spec.Traits {
[camel-k] 03/37: chore(native): Move to quarkus-distroless-image
base image for native builds
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 62513d515fb1186c697ff95e6b38a7f1b65e7280
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jul 29 12:25:26 2021 +0200
chore(native): Move to quarkus-distroless-image base image for native builds
---
pkg/builder/image.go | 20 ++++++++++----------
pkg/trait/jvm.go | 10 +---------
2 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index b4f02c2..3d13d13 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -34,7 +34,7 @@ import (
const (
ContextDir = "context"
- DeploymentDir = "/deployments"
+ DeploymentDir = "/home/nonroot"
DependenciesDir = "dependencies"
)
@@ -118,17 +118,17 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
return err
}
+ err = os.Chmod(path.Join(contextDir, runner), 0755)
+ if err != nil {
+ return err
+ }
+
// #nosec G202
dockerfile := []byte(`
- FROM ` + ctx.BaseImage + `
- ADD . ` + DeploymentDir + `
-
- RUN chmod 775 ` + DeploymentDir + ` ` + DeploymentDir + `/` + runner + ` \
- && chown -R 1000 ` + DeploymentDir + ` \
- && chmod -R "g+rwX" ` + DeploymentDir + ` \
- && chown -R 1000:root ` + DeploymentDir + `
-
- USER 1000
+ FROM quay.io/quarkus/quarkus-distroless-image:1.0
+ WORKDIR ` + DeploymentDir + `
+ COPY --chown=nonroot:root ` + runner + ` ` + runner + `
+ USER nonroot
`)
err = ioutil.WriteFile(path.Join(contextDir, "Dockerfile"), dockerfile, 0777)
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index c6a4b2b..5cefaae 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -185,15 +185,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
args = append(args, "-cp", strings.Join(items, ":"))
args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
- if IsNilOrTrue(t.PrintCommand) {
- args = []string{"exec", "./camel-k-integration-" + defaults.Version + "-runner"}
- container.Command = []string{"/bin/sh", "-c"}
- cmd := strings.Join(args, " ")
- container.Args = []string{"echo " + cmd + " && " + cmd}
- } else {
- container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
- }
-
+ container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
container.WorkingDir = builder.DeploymentDir
return nil
[camel-k] 06/37: feat(native): Configure Build depending on Quarkus
packaging type
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 41581b0720da80a282da10f5f94837eacd384257
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Aug 16 13:00:50 2021 +0200
feat(native): Configure Build depending on Quarkus packaging type
---
pkg/builder/builder.go | 13 ++++------
pkg/builder/image.go | 43 +++++++++++++++++--------------
pkg/builder/project.go | 7 ++---
pkg/builder/quarkus.go | 15 +++++------
pkg/builder/steps.go | 12 +++++++++
pkg/trait/builder.go | 7 ++---
pkg/trait/quarkus.go | 65 +++++++++++++++++++++++++++++++++++++++--------
pkg/trait/quarkus_test.go | 28 +++++++++++---------
8 files changed, 124 insertions(+), 66 deletions(-)
diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go
index 12d3718..5668119 100644
--- a/pkg/builder/builder.go
+++ b/pkg/builder/builder.go
@@ -86,14 +86,11 @@ func (t *builderTask) Do(ctx context.Context) v1.BuildStatus {
})
}
- steps := make([]Step, 0)
- for _, step := range t.task.Steps {
- s, ok := stepsByID[step]
- if !ok {
- log.Info("Skipping unknown build step", "step", step)
- continue
- }
- steps = append(steps, s)
+ steps, err := StepsFrom(t.task.Steps...)
+ if err != nil {
+ t.log.Errorf(err,"invalid builder steps: %s", t.task.Steps)
+ result.Failed(err)
+ return result
}
// Sort steps by phase
sort.SliceStable(steps, func(i, j int) bool {
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 3d13d13..4a35be5 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -23,7 +23,8 @@ import (
"path"
"k8s.io/apimachinery/pkg/selection"
- k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/platform"
@@ -34,12 +35,28 @@ import (
const (
ContextDir = "context"
- DeploymentDir = "/home/nonroot"
+ DeploymentDir = "/deployments"
DependenciesDir = "dependencies"
)
type artifactsSelector func(ctx *builderContext) error
+func nativeImageContext(ctx *builderContext) error {
+ return imageContext(ctx, func(ctx *builderContext) error {
+ runner := "camel-k-integration-" + defaults.Version + "-runner"
+
+ ctx.BaseImage = "quay.io/quarkus/quarkus-distroless-image:1.0"
+ ctx.SelectedArtifacts = []v1.Artifact{
+ {
+ Location: path.Join(ctx.Path, "maven", "target", runner),
+ Target: runner,
+ },
+ }
+
+ return nil
+ })
+}
+
func standardImageContext(ctx *builderContext) error {
return imageContext(ctx, func(ctx *builderContext) error {
ctx.SelectedArtifacts = ctx.Artifacts
@@ -112,22 +129,10 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
}
}
- runner := "camel-k-integration-" + defaults.Version + "-runner"
- _, err = util.CopyFile(path.Join(ctx.Path, "maven", "target", runner), path.Join(contextDir, runner))
- if err != nil {
- return err
- }
-
- err = os.Chmod(path.Join(contextDir, runner), 0755)
- if err != nil {
- return err
- }
-
// #nosec G202
dockerfile := []byte(`
- FROM quay.io/quarkus/quarkus-distroless-image:1.0
- WORKDIR ` + DeploymentDir + `
- COPY --chown=nonroot:root ` + runner + ` ` + runner + `
+ FROM ` + ctx.BaseImage + `
+ COPY --chown=nonroot:root . ` + DeploymentDir + `
USER nonroot
`)
@@ -140,9 +145,9 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
}
func listPublishedImages(context *builderContext) ([]v1.IntegrationKitStatus, error) {
- options := []k8sclient.ListOption{
- k8sclient.InNamespace(context.Namespace),
- k8sclient.MatchingLabels{
+ options := []ctrl.ListOption{
+ ctrl.InNamespace(context.Namespace),
+ ctrl.MatchingLabels{
"camel.apache.org/runtime.version": context.Catalog.Runtime.Version,
"camel.apache.org/runtime.provider": string(context.Catalog.Runtime.Provider),
},
diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index 39182e0..6cb8a0b 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -35,8 +35,9 @@ type steps struct {
GenerateProjectSettings Step
InjectDependencies Step
SanitizeDependencies Step
- StandardImageContext Step
IncrementalImageContext Step
+ NativeImageContext Step
+ StandardImageContext Step
}
var Steps = steps{
@@ -45,8 +46,9 @@ var Steps = steps{
GenerateProjectSettings: NewStep(ProjectGenerationPhase+1, generateProjectSettings),
InjectDependencies: NewStep(ProjectGenerationPhase+2, injectDependencies),
SanitizeDependencies: NewStep(ProjectGenerationPhase+3, sanitizeDependencies),
- StandardImageContext: NewStep(ApplicationPackagePhase, standardImageContext),
IncrementalImageContext: NewStep(ApplicationPackagePhase, incrementalImageContext),
+ NativeImageContext: NewStep(ApplicationPackagePhase, nativeImageContext),
+ StandardImageContext: NewStep(ApplicationPackagePhase, standardImageContext),
}
var DefaultSteps = []Step{
@@ -55,7 +57,6 @@ var DefaultSteps = []Step{
Steps.GenerateProjectSettings,
Steps.InjectDependencies,
Steps.SanitizeDependencies,
- Steps.IncrementalImageContext,
}
func cleanUpBuildDir(ctx *builderContext) error {
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index 3757af3..1e367b2 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -99,18 +99,17 @@ func GenerateQuarkusProjectCommon(camelQuarkusVersion string, runtimeVersion str
p.Dependencies = make([]maven.Dependency, 0)
p.Build = &maven.Build{Plugins: make([]maven.Plugin, 0)}
- // camel-quarkus does routes discovery at startup but we don't want
+ // camel-quarkus does route discovery at startup, but we don't want
// this to happen as routes are loaded at runtime and looking for
// routes at build time may try to load camel-k-runtime routes builder
- // proxies which in some case may fail
+ // proxies which in some case may fail.
p.Properties["quarkus.camel.routes-discovery.enabled"] = "false"
- // disable quarkus banner ...
+ // disable quarkus banner
p.Properties["quarkus.banner.enabled"] = "false"
- // set fast-jar packaging since it gives some startup time improvements
- p.Properties["quarkus.package.type"] = "native"
- // p.Properties["quarkus.native.additional-build-args"] = "--language:js"
+ // set fast-jar packaging by default, since it gives some startup time improvements
+ p.Properties["quarkus.package.type"] = "fast-jar"
// DependencyManagement
p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies,
@@ -199,7 +198,7 @@ func computeQuarkusDependencies(ctx *builderContext) error {
mc.SettingsContent = ctx.Maven.SettingsData
mc.LocalRepository = ctx.Build.Maven.LocalRepository
- // Process artifacts list and add it to existing artifacts.
+ // Process artifacts list and add it to existing artifacts
artifacts, err := ProcessQuarkusTransitiveDependencies(mc)
if err != nil {
return err
@@ -212,7 +211,7 @@ func computeQuarkusDependencies(ctx *builderContext) error {
func ProcessQuarkusTransitiveDependencies(mc maven.Context) ([]v1.Artifact, error) {
var artifacts []v1.Artifact
- // Quarkus fast-jar format is split into various sub directories in quarkus-app
+ // Quarkus fast-jar format is split into various sub-directories in quarkus-app
quarkusAppDir := path.Join(mc.Path, "target", "quarkus-app")
// Discover application dependencies from the Quarkus fast-jar directory tree
diff --git a/pkg/builder/steps.go b/pkg/builder/steps.go
index d78e433..245a389 100644
--- a/pkg/builder/steps.go
+++ b/pkg/builder/steps.go
@@ -57,6 +57,18 @@ func NewStep(phase int32, task StepTask) Step {
return &s
}
+func StepsFrom(ids ...string) ([]Step, error) {
+ steps := make([]Step, 0)
+ for _, id := range ids {
+ s, ok := stepsByID[id]
+ if !ok {
+ return steps, fmt.Errorf("unknown build step: %s", id)
+ }
+ steps = append(steps, s)
+ }
+ return steps, nil
+}
+
func StepIDsFor(steps ...Step) []string {
IDs := make([]string, 0)
for _, step := range steps {
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index c4da97b..d85414e 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -21,12 +21,12 @@ import (
"fmt"
"sort"
- "github.com/apache/camel-k/pkg/util/property"
corev1 "k8s.io/api/core/v1"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
mvn "github.com/apache/camel-k/pkg/util/maven"
+ "github.com/apache/camel-k/pkg/util/property"
)
// The builder trait is internally used to determine the best strategy to
@@ -137,7 +137,7 @@ func (t *builderTrait) Apply(e *Environment) error {
func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
maven := e.Platform.Status.Build.Maven
- // Add Maven repositories defined in the IntergrationKit
+ // Add Maven repositories defined in the IntegrationKit
for _, repo := range e.IntegrationKit.Spec.Repositories {
maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
}
@@ -168,9 +168,6 @@ func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
steps := make([]builder.Step, 0)
steps = append(steps, builder.DefaultSteps...)
- quarkus := e.Catalog.GetTrait("quarkus").(*quarkusTrait)
- quarkus.addBuildSteps(&steps)
-
// sort steps by phase
sort.SliceStable(steps, func(i, j int) bool {
return steps[i].Phase() < steps[j].Phase()
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index cec04cf..47f1f95 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -19,6 +19,7 @@ package trait
import (
"fmt"
+ "sort"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
@@ -61,19 +62,56 @@ func (t *quarkusTrait) Configure(e *Environment) (bool, error) {
t.PackageType = &packageType
}
- return e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
+ return e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning), nil
}
func (t *quarkusTrait) Apply(e *Environment) error {
- if t.isNativePackageType() {
- container := e.getIntegrationContainer()
- if container == nil {
- return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
+ if e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) {
+ build := getBuilderTask(e.BuildTasks)
+ if build == nil {
+ return fmt.Errorf("unable to find builder task: %s", e.Integration.Name)
}
- container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
- container.WorkingDir = builder.DeploymentDir
+ if build.Maven.Properties == nil {
+ build.Maven.Properties = make(map[string]string)
+ }
+
+ steps, err := builder.StepsFrom(build.Steps...)
+ if err != nil {
+ return err
+ }
+
+ steps = append(steps, builder.QuarkusSteps...)
+
+ if t.isNativePackageType() {
+ build.Maven.Properties["quarkus.package.type"] = string(nativePackageType)
+ steps = append(steps, builder.Steps.NativeImageContext)
+ } else {
+ build.Maven.Properties["quarkus.package.type"] = string(fastJarPackageType)
+ steps = append(steps, builder.Steps.IncrementalImageContext)
+ }
+
+ // Sort steps by phase
+ sort.SliceStable(steps, func(i, j int) bool {
+ return steps[i].Phase() < steps[j].Phase()
+ })
+
+ build.Steps = builder.StepIDsFor(steps...)
+ }
+
+ if e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseDeploying) ||
+ e.InPhase(v1.IntegrationKitPhaseReady, v1.IntegrationPhaseRunning) {
+ if t.isNativePackageType() {
+ container := e.getIntegrationContainer()
+ if container == nil {
+ return fmt.Errorf("unable to find integration container: %s", e.Integration.Name)
+ }
+
+ container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
+ container.WorkingDir = builder.DeploymentDir
+ }
}
return nil
@@ -89,10 +127,15 @@ func (t *quarkusTrait) InfluencesKit() bool {
return true
}
-func (t *quarkusTrait) addBuildSteps(steps *[]builder.Step) {
- *steps = append(*steps, builder.QuarkusSteps...)
-}
-
func (t *quarkusTrait) isNativePackageType() bool {
return t.PackageType != nil && *t.PackageType == nativePackageType
}
+
+func getBuilderTask(tasks []v1.Task) *v1.BuilderTask {
+ for i, task := range tasks {
+ if task.Builder != nil {
+ return tasks[i].Builder
+ }
+ }
+ return nil
+}
diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go
index 318bbb3..688194a 100644
--- a/pkg/trait/quarkus_test.go
+++ b/pkg/trait/quarkus_test.go
@@ -27,13 +27,22 @@ import (
"github.com/apache/camel-k/pkg/util/camel"
)
-func TestConfigureQuarkusTraitShouldSucceed(t *testing.T) {
+func TestConfigureQuarkusTraitBuildSubmitted(t *testing.T) {
quarkusTrait, environment := createNominalQuarkusTest()
+ environment.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseBuildSubmitted
configured, err := quarkusTrait.Configure(environment)
assert.True(t, configured)
assert.Nil(t, err)
+
+ err = quarkusTrait.Apply(environment)
+ assert.Nil(t, err)
+
+ build := getBuilderTask(environment.BuildTasks)
+ assert.NotNil(t, t, build)
+
+ assert.Len(t, build.Steps, len(builder.QuarkusSteps)+1)
}
func TestConfigureDisabledQuarkusTraitShouldFail(t *testing.T) {
@@ -54,17 +63,6 @@ func TestApplyQuarkusTraitDoesNothing(t *testing.T) {
assert.Nil(t, err)
}
-func TestQuarkusTraitAddBuildStepsShouldSucceed(t *testing.T) {
- quarkusTrait, _ := createNominalQuarkusTest()
-
- steps := make([]builder.Step, 0)
- steps = append(steps, builder.DefaultSteps...)
-
- quarkusTrait.addBuildSteps(&steps)
-
- assert.Len(t, steps, len(builder.DefaultSteps)+len(builder.QuarkusSteps))
-}
-
func createNominalQuarkusTest() (*quarkusTrait, *Environment) {
trait := newQuarkusTrait().(*quarkusTrait)
trait.Enabled = BoolP(true)
@@ -80,6 +78,12 @@ func createNominalQuarkusTest() (*quarkusTrait, *Environment) {
},
},
},
+ IntegrationKit: &v1.IntegrationKit{},
+ BuildTasks: []v1.Task{
+ {
+ Builder: &v1.BuilderTask{},
+ },
+ },
Platform: &v1.IntegrationPlatform{},
}
[camel-k] 20/37: chore(native): Pass current kit to evaluate traits
for running Integrations
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 6d20fb0b31f7f4024d4acbb9665251a1c8dd99ac
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Aug 26 16:29:18 2021 +0200
chore(native): Pass current kit to evaluate traits for running Integrations
---
pkg/controller/integration/monitor.go | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index 515d2d4..858b22b 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -20,6 +20,8 @@ package integration
import (
"context"
+ "github.com/pkg/errors"
+
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@@ -63,8 +65,13 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
return integration, nil
}
+ kit, err := kubernetes.GetIntegrationKit(ctx, action.client, integration.Status.IntegrationKit.Name, integration.Status.IntegrationKit.Namespace)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to find integration kit %s/%s, %s", integration.Status.IntegrationKit.Namespace, integration.Status.IntegrationKit.Name, err)
+ }
+
// Run traits that are enabled for the running phase
- _, err = trait.Apply(ctx, action.client, integration, nil)
+ _, err = trait.Apply(ctx, action.client, integration, kit)
if err != nil {
return nil, err
}
@@ -99,9 +106,8 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
previous := integration.Status.GetCondition(v1.IntegrationConditionReady)
kubernetes.MirrorReadyCondition(ctx, action.client, integration)
- if next := integration.Status.GetCondition(v1.IntegrationConditionReady);
- (previous == nil || previous.FirstTruthyTime == nil || previous.FirstTruthyTime.IsZero()) &&
- next != nil && next.Status == corev1.ConditionTrue && !(next.FirstTruthyTime == nil || next.FirstTruthyTime.IsZero()) {
+ if next := integration.Status.GetCondition(v1.IntegrationConditionReady); (previous == nil || previous.FirstTruthyTime == nil || previous.FirstTruthyTime.IsZero()) &&
+ next != nil && next.Status == corev1.ConditionTrue && !(next.FirstTruthyTime == nil || next.FirstTruthyTime.IsZero()) {
// Observe the time to first readiness metric
duration := next.FirstTruthyTime.Time.Sub(integration.Status.InitializationTimestamp.Time)
action.L.Infof("First readiness after %s", duration)
@@ -131,9 +137,9 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
}
if deployUnavailable && progressingFailing {
notAvailableCondition := v1.IntegrationCondition{
- Type: v1.IntegrationConditionReady,
- Status: corev1.ConditionFalse,
- Reason: v1.IntegrationConditionErrorReason,
+ Type: v1.IntegrationConditionReady,
+ Status: corev1.ConditionFalse,
+ Reason: v1.IntegrationConditionErrorReason,
Message: "The corresponding pod(s) may be in error state, look at the pod status or log for errors",
}
integration.Status.SetConditions(notAvailableCondition)
[camel-k] 01/37: feat: Switch on Quarkus native build
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 41b7ccf902c4bebcce33fa667aa0dce7f9385940
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jul 29 11:34:06 2021 +0200
feat: Switch on Quarkus native build
---
build/Dockerfile | 7 ++++---
pkg/builder/image.go | 13 +++++++++++++
pkg/builder/quarkus.go | 3 ++-
pkg/trait/jvm.go | 6 +++---
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/build/Dockerfile b/build/Dockerfile
index 3bfc57c..1f3e2ac 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -13,12 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM adoptopenjdk/openjdk11:slim
+FROM quay.io/quarkus/ubi-quarkus-native-image:21.1.0-java11
+#FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2.0.0-Final-java11
ARG MAVEN_VERSION="3.6.3"
ARG SHA="c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0"
ARG BASE_URL="https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries"
+USER 0
+
RUN mkdir -p /usr/share/maven \
&& curl -Lso /tmp/maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/maven.tar.gz" | sha512sum -c - \
@@ -34,8 +37,6 @@ ADD build/logback.xml /usr/share/maven/conf/
ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=/usr/share/maven/conf/logback.xml"
-USER 0
-
RUN chgrp -R 0 /tmp/artifacts/m2 \
&& chmod -R g=u /tmp/artifacts/m2 \
&& chgrp -R 0 /kamelets \
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index ce01bff..b4f02c2 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -29,6 +29,7 @@ import (
"github.com/apache/camel-k/pkg/platform"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/controller"
+ "github.com/apache/camel-k/pkg/util/defaults"
)
const (
@@ -111,10 +112,22 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
}
}
+ runner := "camel-k-integration-" + defaults.Version + "-runner"
+ _, err = util.CopyFile(path.Join(ctx.Path, "maven", "target", runner), path.Join(contextDir, runner))
+ if err != nil {
+ return err
+ }
+
// #nosec G202
dockerfile := []byte(`
FROM ` + ctx.BaseImage + `
ADD . ` + DeploymentDir + `
+
+ RUN chmod 775 ` + DeploymentDir + ` ` + DeploymentDir + `/` + runner + ` \
+ && chown -R 1000 ` + DeploymentDir + ` \
+ && chmod -R "g+rwX" ` + DeploymentDir + ` \
+ && chown -R 1000:root ` + DeploymentDir + `
+
USER 1000
`)
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index 6bdfecb..3757af3 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -109,7 +109,8 @@ func GenerateQuarkusProjectCommon(camelQuarkusVersion string, runtimeVersion str
p.Properties["quarkus.banner.enabled"] = "false"
// set fast-jar packaging since it gives some startup time improvements
- p.Properties["quarkus.package.type"] = "fast-jar"
+ p.Properties["quarkus.package.type"] = "native"
+ // p.Properties["quarkus.native.additional-build-args"] = "--language:js"
// DependencyManagement
p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies,
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index b31bca6..c6a4b2b 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -37,6 +37,7 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/util"
+ "github.com/apache/camel-k/pkg/util/defaults"
)
// The JVM trait is used to configure the JVM that runs the integration.
@@ -185,13 +186,12 @@ func (t *jvmTrait) Apply(e *Environment) error {
args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
if IsNilOrTrue(t.PrintCommand) {
- args = append([]string{"exec", "java"}, args...)
+ args = []string{"exec", "./camel-k-integration-" + defaults.Version + "-runner"}
container.Command = []string{"/bin/sh", "-c"}
cmd := strings.Join(args, " ")
container.Args = []string{"echo " + cmd + " && " + cmd}
} else {
- container.Command = []string{"java"}
- container.Args = args
+ container.Command = []string{"./camel-k-integration-" + defaults.Version + "-runner"}
}
container.WorkingDir = builder.DeploymentDir
[camel-k] 32/37: fix(cli): Do not skip dependencies in kit create
command
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 55f852511b3c0010a064d0fed14b47a42e24b37c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Sep 6 11:20:01 2021 +0200
fix(cli): Do not skip dependencies in kit create command
---
e2e/builder/build_test.go | 2 +-
pkg/cmd/kit_create.go | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go
index 53ba598..1e4bfe6 100644
--- a/e2e/builder/build_test.go
+++ b/e2e/builder/build_test.go
@@ -47,7 +47,7 @@ func TestKitTimerToLogFullBuild(t *testing.T) {
func TestKitKnativeFullBuild(t *testing.T) {
doKitFullBuild(t, "knative", "5m0s", TestTimeoutLong, kitOptions{
dependencies: []string{
- "camel:knative",
+ "camel-k-knative",
},
})
}
diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go
index 7d0544d..b3a7e83 100644
--- a/pkg/cmd/kit_create.go
+++ b/pkg/cmd/kit_create.go
@@ -135,14 +135,14 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
}
for _, item := range command.Dependencies {
switch {
- case strings.HasPrefix(item, "mvn:"):
- kit.Spec.Dependencies = append(kit.Spec.Dependencies, item)
- case strings.HasPrefix(item, "file:"):
- kit.Spec.Dependencies = append(kit.Spec.Dependencies, item)
case strings.HasPrefix(item, "camel-quarkus-"):
kit.Spec.Dependencies = append(kit.Spec.Dependencies, "camel:"+strings.TrimPrefix(item, "camel-quarkus-"))
+ case strings.HasPrefix(item, "camel-k-"):
+ kit.Spec.Dependencies = append(kit.Spec.Dependencies, "camel-k:"+strings.TrimPrefix(item, "camel-k-"))
case strings.HasPrefix(item, "camel-"):
kit.Spec.Dependencies = append(kit.Spec.Dependencies, "camel:"+strings.TrimPrefix(item, "camel-"))
+ default:
+ kit.Spec.Dependencies = append(kit.Spec.Dependencies, item)
}
}