From 9cb3165c12439bc47a8a4a97ca6c526c9084e09e Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Thu, 12 Dec 2024 08:17:43 +0100 Subject: [PATCH] feat(runtime): enable plain Quarkus runtime Added the support for plain Quarkus runtime. Trait `camel.runtime-provider` is in charge to control the possibility to use `plain-quarkus`. --- .github/workflows/native.yml | 5 - .github/workflows/nightly-latest-runtime.yml | 2 +- .../nightly-quarkus-plain-runtime.yml | 140 ++++++++++++++++++ .../ROOT/partials/apis/camel-k-crds.adoc | 11 +- docs/modules/traits/pages/camel.adoc | 8 +- helm/camel-k/crds/camel-k-crds.yaml | 88 +++++++++-- .../camel/v1/camelcatalog_types_support.go | 5 + pkg/apis/camel/v1/common_types.go | 11 +- pkg/apis/camel/v1/trait/camel.go | 7 +- pkg/builder/quarkus.go | 41 +++-- pkg/builder/quarkus_test.go | 2 +- pkg/controller/integrationplatform/monitor.go | 80 ++++++++++ .../camel.apache.org_integrationkits.yaml | 11 +- ...camel.apache.org_integrationplatforms.yaml | 22 ++- .../camel.apache.org_integrationprofiles.yaml | 22 ++- .../bases/camel.apache.org_integrations.yaml | 22 ++- .../crd/bases/camel.apache.org_pipes.yaml | 11 +- pkg/trait/camel.go | 19 ++- pkg/trait/environment.go | 5 + pkg/trait/mount.go | 66 +++++---- pkg/trait/telemetry.go | 9 +- pkg/util/camel/camel_dependencies.go | 2 +- pkg/util/camel/camel_runtime_catalog.go | 4 +- pkg/util/camel/camel_util.go | 2 +- 24 files changed, 497 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/nightly-quarkus-plain-runtime.yml diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index 6bbac51b45..622b3ba823 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -73,11 +73,6 @@ jobs: - name: Infra setting uses: ./.github/actions/infra-setting - - name: Install Knative - shell: bash - run: | - ./e2e/knative/files/setup.sh - - name: Install operator shell: bash run: | diff --git a/.github/workflows/nightly-latest-runtime.yml b/.github/workflows/nightly-latest-runtime.yml index dd31c340eb..d4faf78362 100644 --- a/.github/workflows/nightly-latest-runtime.yml +++ b/.github/workflows/nightly-latest-runtime.yml @@ -32,7 +32,7 @@ on: workflow_dispatch: jobs: - release: + smoke-tests: strategy: fail-fast: false matrix: diff --git a/.github/workflows/nightly-quarkus-plain-runtime.yml b/.github/workflows/nightly-quarkus-plain-runtime.yml new file mode 100644 index 0000000000..624a8d86f0 --- /dev/null +++ b/.github/workflows/nightly-quarkus-plain-runtime.yml @@ -0,0 +1,140 @@ +--- # --------------------------------------------------------------------------- + +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +name: Nightly check against plain Quarkus runtime + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CAMEL_K_TEST_TIMEOUT_SHORT: 2m + CAMEL_K_TEST_TIMEOUT_MEDIUM: 5m + CAMEL_K_TEST_TIMEOUT_LONG: 10m + CAMEL_K_TEST_TIMEOUT_VERY_LONG: 30m + +on: + schedule: + - cron: "30 3 * * *" + workflow_dispatch: + +jobs: + common: + strategy: + matrix: + # We want to check this on latest development branch only + ref-branch: [main] + + if: github.repository == 'apache/camel-k' + runs-on: ubuntu-latest + steps: + + - name: "Checkout code" + uses: actions/checkout@v4 + with: + ref: ${{ matrix.ref-branch }} + persist-credentials: false + submodules: recursive + + - name: Infra setting + uses: ./.github/actions/infra-setting + + - name: Install operator + shell: bash + run: | + kubectl create ns camel-k + make install-k8s-global + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + kubectl patch itp camel-k -n camel-k -p '{"spec":{"traits":{"camel":{"runtimeProvider":"plain-quarkus"}}}}' --type=merge + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + + - name: Run test + shell: bash + run: | + DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-common + + quarkus-native: + strategy: + matrix: + # We want to check this on latest development branch only + ref-branch: [main] + + if: github.repository == 'apache/camel-k' + runs-on: ubuntu-latest + steps: + + - name: "Checkout code" + uses: actions/checkout@v4 + with: + ref: ${{ matrix.ref-branch }} + persist-credentials: false + submodules: recursive + + - name: Infra setting + uses: ./.github/actions/infra-setting + + - name: Install operator + shell: bash + run: | + kubectl create ns camel-k + make install-k8s-global + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + kubectl patch itp camel-k -n camel-k -p '{"spec":{"traits":{"camel":{"runtimeProvider":"plain-quarkus"}}}}' --type=merge + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + + - name: Run test + shell: bash + run: | + DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-quarkus-native + + knative: + strategy: + matrix: + # We want to check this on latest development branch only + ref-branch: [main] + + if: github.repository == 'apache/camel-k' + runs-on: ubuntu-latest + steps: + + - name: "Checkout code" + uses: actions/checkout@v4 + with: + ref: ${{ matrix.ref-branch }} + persist-credentials: false + submodules: recursive + + - name: Infra setting + uses: ./.github/actions/infra-setting + + - name: Install Knative + shell: bash + run: | + ./e2e/knative/files/setup.sh + + - name: Install operator + shell: bash + run: | + kubectl create ns camel-k + make install-k8s-global + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + kubectl patch itp camel-k -n camel-k -p '{"spec":{"traits":{"camel":{"runtimeProvider":"plain-quarkus"}}}}' --type=merge + kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s + + - name: Run test + shell: bash + run: | + DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-knative diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index c92a62aec0..8cb076f6d0 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -6497,14 +6497,21 @@ The Camel trait can be used to configure versions of Apache Camel K runtime and +|`runtimeProvider` + +string +| + + +The runtime provider to use for the integration. (Default, Camel K Runtime). + |`runtimeVersion` + string | -The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. +The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve -to the best matching Catalog existing on the cluster. +to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). |`properties` + []string diff --git a/docs/modules/traits/pages/camel.adoc b/docs/modules/traits/pages/camel.adoc index 82f3810439..415b0b1e8d 100755 --- a/docs/modules/traits/pages/camel.adoc +++ b/docs/modules/traits/pages/camel.adoc @@ -29,11 +29,15 @@ The following configuration options are available: | bool | Deprecated: no longer in use. +| camel.runtime-provider +| string +| The runtime provider to use for the integration. (Default, Camel K Runtime). + | camel.runtime-version | string -| The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. +| The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve -to the best matching Catalog existing on the cluster. +to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). | camel.properties | []string diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml index f2dde79ccb..42a7f1da5b 100644 --- a/helm/camel-k/crds/camel-k-crds.yaml +++ b/helm/camel-k/crds/camel-k-crds.yaml @@ -3023,11 +3023,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object quarkus: @@ -3965,11 +3972,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -6154,11 +6168,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -8246,11 +8267,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -10314,11 +10342,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -18763,11 +18798,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -20758,11 +20800,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -30582,11 +30631,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: diff --git a/pkg/apis/camel/v1/camelcatalog_types_support.go b/pkg/apis/camel/v1/camelcatalog_types_support.go index 98a0161701..97c8808d5a 100644 --- a/pkg/apis/camel/v1/camelcatalog_types_support.go +++ b/pkg/apis/camel/v1/camelcatalog_types_support.go @@ -182,6 +182,11 @@ func (c *CamelCatalogSpec) GetRuntimeVersion() string { return c.Runtime.Version } +// GetRuntimeVersion returns the Camel K runtime version of the catalog. +func (c *CamelCatalogSpec) GetRuntimeProvider() RuntimeProvider { + return c.Runtime.Provider +} + // GetCamelVersion returns the Camel version the runtime is based on. func (c *CamelCatalogSpec) GetCamelVersion() string { return c.Runtime.Metadata["camel.version"] diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go index b5d7cb8a2b..d181b1e922 100644 --- a/pkg/apis/camel/v1/common_types.go +++ b/pkg/apis/camel/v1/common_types.go @@ -18,10 +18,9 @@ limitations under the License. package v1 import ( + "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" ) const ( @@ -433,10 +432,16 @@ type Flow struct { type RuntimeProvider string const ( - // RuntimeProviderQuarkus Camel Quarkus runtime. + // RuntimeProviderQuarkus Camel K runtime (Quarkus based). RuntimeProviderQuarkus RuntimeProvider = "quarkus" + // RuntimeProviderPlainQuarkus Camel Quarkus plain runtime. + RuntimeProviderPlainQuarkus RuntimeProvider = "plain-quarkus" ) +func (rt RuntimeProvider) IsQuarkusBased() bool { + return rt == RuntimeProviderQuarkus || rt == RuntimeProviderPlainQuarkus +} + // SourceSpec defines the configuration for one or more routes to be executed in a certain Camel DSL language. type SourceSpec struct { // contains configuration related to the source code diff --git a/pkg/apis/camel/v1/trait/camel.go b/pkg/apis/camel/v1/trait/camel.go index 97603d359d..a08e1943ff 100644 --- a/pkg/apis/camel/v1/trait/camel.go +++ b/pkg/apis/camel/v1/trait/camel.go @@ -22,9 +22,12 @@ package trait // +camel-k:trait=camel. type CamelTrait struct { PlatformBaseTrait `property:",squash" json:",inline"` - // The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + // The runtime provider to use for the integration. (Default, Camel K Runtime). + // +kubebuilder:validation:Enum=quarkus;plain-quarkus + RuntimeProvider string `property:"runtime-provider" json:"runtimeProvider,omitempty"` + // The runtime version to use for the integration. It overrides the default version set in the Integration Platform. // You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - // to the best matching Catalog existing on the cluster. + // to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). RuntimeVersion string `property:"runtime-version" json:"runtimeVersion,omitempty"` // A list of properties to be provided to the Integration runtime Properties []string `property:"properties" json:"properties,omitempty"` diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go index 2a0b7b77a8..65a09ac704 100644 --- a/pkg/builder/quarkus.go +++ b/pkg/builder/quarkus.go @@ -119,6 +119,7 @@ func loadCamelQuarkusCatalog(ctx *builderContext) error { func generateQuarkusProject(ctx *builderContext) error { p := generateQuarkusProjectCommon( + ctx.Build.Runtime.Provider, ctx.Build.Runtime.Version, ctx.Build.Runtime.Metadata["quarkus.version"], ) @@ -132,7 +133,7 @@ func generateQuarkusProject(ctx *builderContext) error { return nil } -func generateQuarkusProjectCommon(runtimeVersion string, quarkusPlatformVersion string) maven.Project { +func generateQuarkusProjectCommon(runtimeProvider v1.RuntimeProvider, runtimeVersion string, quarkusPlatformVersion string) maven.Project { p := maven.NewProjectWithGAV("org.apache.camel.k.integration", "camel-k-integration", defaults.Version) p.DependencyManagement = &maven.DependencyManagement{Dependencies: make([]maven.Dependency, 0)} p.Dependencies = make([]maven.Dependency, 0) @@ -143,15 +144,35 @@ func generateQuarkusProjectCommon(runtimeVersion string, quarkusPlatformVersion // Reproducible builds: https://maven.apache.org/guides/mini/guide-reproducible-builds.html p.Properties.Add("project.build.outputTimestamp", time.Now().Format(time.RFC3339)) // DependencyManagement - p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies, - maven.Dependency{ - GroupID: "org.apache.camel.k", - ArtifactID: "camel-k-runtime-bom", - Version: runtimeVersion, - Type: "pom", - Scope: "import", - }, - ) + if runtimeProvider == v1.RuntimeProviderPlainQuarkus { + p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies, + maven.Dependency{ + GroupID: "io.quarkus.platform", + ArtifactID: "quarkus-camel-bom", + Version: runtimeVersion, + Type: "pom", + Scope: "import", + }, + maven.Dependency{ + GroupID: "io.quarkus.platform", + ArtifactID: "quarkus-bom", + Version: runtimeVersion, + Type: "pom", + Scope: "import", + }, + ) + } else { + // Camel K Runtime (Quarkus based) default + p.DependencyManagement.Dependencies = append(p.DependencyManagement.Dependencies, + maven.Dependency{ + GroupID: "org.apache.camel.k", + ArtifactID: "camel-k-runtime-bom", + Version: runtimeVersion, + Type: "pom", + Scope: "import", + }, + ) + } // Plugins p.Build.Plugins = append(p.Build.Plugins, diff --git a/pkg/builder/quarkus_test.go b/pkg/builder/quarkus_test.go index 42db8bdfc9..44ddad33e4 100644 --- a/pkg/builder/quarkus_test.go +++ b/pkg/builder/quarkus_test.go @@ -37,7 +37,7 @@ import ( ) func TestGenerateQuarkusProjectCommon(t *testing.T) { - p := generateQuarkusProjectCommon("1.2.3", "4.5.6") + p := generateQuarkusProjectCommon(v1.RuntimeProviderQuarkus, "1.2.3", "4.5.6") assert.Equal(t, "org.apache.camel.k.integration", p.GroupID) assert.Equal(t, "camel-k-integration", p.ArtifactID) assert.Equal(t, defaults.Version, p.Version) diff --git a/pkg/controller/integrationplatform/monitor.go b/pkg/controller/integrationplatform/monitor.go index 34ceff647b..32df553879 100644 --- a/pkg/controller/integrationplatform/monitor.go +++ b/pkg/controller/integrationplatform/monitor.go @@ -27,6 +27,7 @@ import ( "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/openshift" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // NewMonitorAction returns an action that monitors the integration platform after it's fully initialized. @@ -112,6 +113,13 @@ func (action *monitorAction) Handle(ctx context.Context, platform *v1.Integratio } } action.checkTraitAnnotationsDeprecatedNotice(platform) + if err = action.addPlainQuarkusCatalog(ctx, catalog); err != nil { + // Only warn the user, we don't want to fail + action.L.Infof( + "WARN: the operator wasn't able to clone %s catalog. You won't be able to run a plain Quarkus runtime provider.", + catalog.Name, + ) + } return platform, nil } @@ -143,3 +151,75 @@ func specOrDefault(runtimeVersionSpec string) string { } return runtimeVersionSpec } + +// addPlainQuarkusCatalog is a workaround while a CamelCatalog custom resource is required. The goal is to clone any existing +// Camel K Runtime catalog and adjust to make it work with plain Quarkus runtime provider. +func (action *monitorAction) addPlainQuarkusCatalog(ctx context.Context, catalog *v1.CamelCatalog) error { + runtimeSpec := v1.RuntimeSpec{ + Version: catalog.Spec.GetRuntimeVersion(), + Provider: v1.RuntimeProviderPlainQuarkus, + } + cat, err := loadCatalog(ctx, action.client, catalog.Namespace, runtimeSpec) + if err != nil { + return err + } + if cat == nil { + // Clone the catalog to enable Quarkus Plain runtime + clonedCatalog := catalog.DeepCopy() + clonedCatalog.Status = v1.CamelCatalogStatus{} + clonedCatalog.ObjectMeta = metav1.ObjectMeta{ + Namespace: catalog.Namespace, + Name: strings.ReplaceAll(catalog.Name, "camel-catalog", "camel-catalog-quarkus"), + Labels: catalog.Labels, + Annotations: catalog.Annotations, + } + clonedCatalog.Spec.Runtime.Provider = v1.RuntimeProviderPlainQuarkus + clonedCatalog.Spec.Runtime.Dependencies = []v1.MavenArtifact{ + { + GroupID: "org.apache.camel.quarkus", + ArtifactID: "camel-quarkus-core", + }, + } + if clonedCatalog.Spec.Runtime.Capabilities != nil { + clonedCatalog.Spec.Runtime.Capabilities["cron"] = v1.Capability{ + Dependencies: []v1.MavenArtifact{}, + } + clonedCatalog.Spec.Runtime.Capabilities["knative"] = v1.Capability{ + Dependencies: []v1.MavenArtifact{ + { + GroupID: "org.apache.camel.quarkus", + ArtifactID: "camel-quarkus-knative", + }, + }, + } + clonedCatalog.Spec.Runtime.Capabilities["master"] = v1.Capability{ + Dependencies: []v1.MavenArtifact{}, + } + clonedCatalog.Spec.Runtime.Capabilities["resume-kafka"] = v1.Capability{ + Dependencies: []v1.MavenArtifact{}, + } + clonedCatalog.Spec.Runtime.Capabilities["jolokia"] = v1.Capability{ + Dependencies: []v1.MavenArtifact{ + { + GroupID: "org.apache.camel.quarkus", + ArtifactID: "camel-quarkus-jaxb", + }, + { + GroupID: "org.apache.camel.quarkus", + ArtifactID: "camel-quarkus-jaxb", + }, + { + GroupID: "org.jolokia", + ArtifactID: "jolokia-agent-jvm", + Classifier: "javaagent", + Version: "2.1.1", + }, + }, + } + } + + return action.client.Create(ctx, clonedCatalog) + } + + return nil +} diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml index ca19be9882..e6190a4f3d 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationkits.yaml @@ -360,11 +360,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object quarkus: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml index fb199688e6..a5c62d97a4 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -735,11 +735,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -2924,11 +2931,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml index 79425e7751..84efe52308 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml @@ -604,11 +604,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -2672,11 +2679,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index 2169dc54f7..5baf4779a2 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -6964,11 +6964,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: @@ -8959,11 +8966,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 16d1270da6..e71202e95d 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -7027,11 +7027,18 @@ spec: items: type: string type: array + runtimeProvider: + description: The runtime provider to use for the integration. + (Default, Camel K Runtime). + enum: + - quarkus + - plain-quarkus + type: string runtimeVersion: description: |- - The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform. + The runtime version to use for the integration. It overrides the default version set in the Integration Platform. You can use a fixed version (for example "3.2.3") or a semantic version (for example "3.x") which will try to resolve - to the best matching Catalog existing on the cluster. + to the best matching Catalog existing on the cluster (Default, the one provided by the operator version). type: string type: object container: diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go index 6e2db3cdbc..530d5a8bc0 100644 --- a/pkg/trait/camel.go +++ b/pkg/trait/camel.go @@ -43,7 +43,8 @@ type camelTrait struct { BasePlatformTrait traitv1.CamelTrait `property:",squash"` // private configuration used only internally - runtimeVersion string + runtimeVersion string + runtimeProvider string } func newCamelTrait() Trait { @@ -81,6 +82,12 @@ func (t *camelTrait) Configure(e *Environment) (bool, *TraitCondition, error) { t.runtimeVersion = t.RuntimeVersion } + if t.RuntimeProvider == "" { + t.runtimeProvider = "quarkus" + } else { + t.runtimeProvider = t.RuntimeProvider + } + var cond *TraitCondition //nolint: staticcheck if (e.Integration != nil && !e.Integration.IsManagedBuild()) || (e.IntegrationKit != nil && e.IntegrationKit.IsSynthetic()) { @@ -106,7 +113,7 @@ func (t *camelTrait) Apply(e *Environment) error { // expects a CamelCatalog to be loaded regardless it's a managed or // non managed build Integration if e.CamelCatalog == nil { - if err := t.loadOrCreateCatalog(e, t.runtimeVersion); err != nil { + if err := t.loadOrCreateCatalog(e); err != nil { return err } } @@ -140,15 +147,15 @@ func (t *camelTrait) Apply(e *Environment) error { return nil } -func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string) error { +func (t *camelTrait) loadOrCreateCatalog(e *Environment) error { catalogNamespace := e.DetermineCatalogNamespace() if catalogNamespace == "" { return errors.New("unable to determine namespace") } runtime := v1.RuntimeSpec{ - Version: runtimeVersion, - Provider: v1.RuntimeProviderQuarkus, + Version: t.runtimeVersion, + Provider: v1.RuntimeProvider(t.runtimeProvider), } catalog, err := camel.LoadCatalog(e.Ctx, e.Client, catalogNamespace, runtime) @@ -160,7 +167,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string) // if the catalog is not found in the cluster, try to create it if // the required versions (camel and runtime) are not expressed as // semver constraints - if exactVersionRegexp.MatchString(runtimeVersion) { + if exactVersionRegexp.MatchString(t.runtimeVersion) { catalog, err = camel.CreateCatalog(e.Ctx, e.Client, catalogNamespace, e.Platform, runtime) if err != nil { return err diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go index d50b22fd96..6ce36ac3f4 100644 --- a/pkg/trait/environment.go +++ b/pkg/trait/environment.go @@ -18,6 +18,7 @@ limitations under the License. package trait import ( + "fmt" "os" "k8s.io/utils/ptr" @@ -79,6 +80,10 @@ func (t *environmentTrait) Apply(e *Environment) error { envvar.SetVal(&e.EnvVars, envVarCamelKRuntimeVersion, e.Integration.Status.RuntimeVersion) envvar.SetVal(&e.EnvVars, envVarMountPathConfigMaps, camel.ConfigConfigmapsMountPath) envvar.SetVal(&e.EnvVars, envVarMountPathSecrets, camel.ConfigSecretsMountPath) + if e.CamelCatalog.GetRuntimeProvider() == v1.RuntimeProviderPlainQuarkus { + envvar.SetVal(&e.EnvVars, "QUARKUS_CONFIG_LOCATIONS", + fmt.Sprintf("%s/application.properties,%s/user.properties", camel.BasePath, camel.ConfDPath)) + } if ptr.Deref(t.ContainerMeta, true) { envvar.SetValFrom(&e.EnvVars, envVarNamespace, "metadata.namespace") diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go index fe87b5db2e..dfa350530b 100644 --- a/pkg/trait/mount.go +++ b/pkg/trait/mount.go @@ -433,43 +433,51 @@ func (t *mountTrait) computeApplicationProperties(e *Environment) (*corev1.Confi } // addSourcesProperties is in charge to add the sources in the application.properties required by Camel K Runtime. +// +//nolint:nestif func (t *mountTrait) addSourcesProperties(e *Environment) { if e.ApplicationProperties == nil { e.ApplicationProperties = make(map[string]string) } - idx := 0 - for _, s := range e.Integration.AllSources() { - // We don't process routes embedded (native) or Kamelets - if e.isEmbedded(s) || s.IsGeneratedFromKamelet() { - continue - } - srcName := strings.TrimPrefix(filepath.ToSlash(s.Name), "/") - src := "file:" + path.Join(filepath.ToSlash(camel.SourcesMountPath), srcName) - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].location", idx)] = src + if e.CamelCatalog.GetRuntimeProvider() == v1.RuntimeProviderPlainQuarkus { + e.ApplicationProperties["camel.main.source-location-enabled"] = boolean.TrueString + e.ApplicationProperties["camel.main.routes-include-pattern"] = fmt.Sprintf("file:%s/**", camel.SourcesMountPath) + } else { + idx := 0 + for _, s := range e.Integration.AllSources() { + // We don't process routes embedded (native) or Kamelets + if e.isEmbedded(s) || s.IsGeneratedFromKamelet() { + continue + } + srcName := strings.TrimPrefix(filepath.ToSlash(s.Name), "/") + src := "file:" + path.Join(filepath.ToSlash(camel.SourcesMountPath), srcName) + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].location", idx)] = src - simpleName := srcName - if strings.Contains(srcName, ".") { - simpleName = srcName[0:strings.Index(srcName, ".")] - } - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].name", idx)] = simpleName + simpleName := srcName + if strings.Contains(srcName, ".") { + simpleName = srcName[0:strings.Index(srcName, ".")] + } + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].name", idx)] = simpleName - for pid, p := range s.PropertyNames { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].property-names[%d]", idx, pid)] = p - } + for pid, p := range s.PropertyNames { + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].property-names[%d]", idx, pid)] = p + } - if s.Type != "" { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].type", idx)] = string(s.Type) - } - if s.InferLanguage() != "" { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].language", idx)] = string(s.InferLanguage()) - } - if s.Loader != "" { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].loader", idx)] = s.Loader - } - if s.Compression { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].compressed", idx)] = boolean.TrueString + if s.Type != "" { + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].type", idx)] = string(s.Type) + } + if s.InferLanguage() != "" { + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].language", idx)] = string(s.InferLanguage()) + } + if s.Loader != "" { + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].loader", idx)] = s.Loader + } + if s.Compression { + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].compressed", idx)] = boolean.TrueString + } + + idx++ } - idx++ } } diff --git a/pkg/trait/telemetry.go b/pkg/trait/telemetry.go index 3eb820e898..e4ab41ec8c 100644 --- a/pkg/trait/telemetry.go +++ b/pkg/trait/telemetry.go @@ -52,6 +52,13 @@ var ( propSamplerRatio: "quarkus.opentelemetry.tracer.sampler.ratio", propSamplerParentBased: "quarkus.opentelemetry.tracer.sampler.parent-based", }, + v1.RuntimeProviderPlainQuarkus: { + propEndpoint: "quarkus.opentelemetry.tracer.exporter.otlp.endpoint", + propServiceName: "quarkus.opentelemetry.tracer.resource-attributes", + propSampler: "quarkus.opentelemetry.tracer.sampler", + propSamplerRatio: "quarkus.opentelemetry.tracer.sampler.ratio", + propSamplerParentBased: "quarkus.opentelemetry.tracer.sampler.parent-based", + }, } ) @@ -124,7 +131,7 @@ func (t *telemetryTrait) Apply(e *Environment) error { util.StringSliceUniqueAdd(&e.Integration.Status.Capabilities, v1.CapabilityTelemetry) // Hack for camel-k-runtime 3.15.0 - if e.CamelCatalog.CamelCatalogSpec.Runtime.Provider == v1.RuntimeProviderQuarkus && + if e.CamelCatalog.CamelCatalogSpec.Runtime.Provider.IsQuarkusBased() && e.CamelCatalog.CamelCatalogSpec.Runtime.Version == "3.15.0" { t.setRuntimeProviderQuarkus315Properties(e) return nil diff --git a/pkg/util/camel/camel_dependencies.go b/pkg/util/camel/camel_dependencies.go index 74d23d6d22..f1022db185 100644 --- a/pkg/util/camel/camel_dependencies.go +++ b/pkg/util/camel/camel_dependencies.go @@ -169,7 +169,7 @@ func addBOM(project *maven.Project, dependency string) error { func addCamelComponent(project *maven.Project, catalog *RuntimeCatalog, dependency string) { artifactID := strings.TrimPrefix(dependency, "camel:") - if catalog != nil && catalog.Runtime.Provider == v1.RuntimeProviderQuarkus { + if catalog != nil && catalog.Runtime.Provider.IsQuarkusBased() { if !strings.HasPrefix(artifactID, "camel-") { artifactID = "camel-quarkus-" + artifactID } diff --git a/pkg/util/camel/camel_runtime_catalog.go b/pkg/util/camel/camel_runtime_catalog.go index b98103fcc9..c16972ee12 100644 --- a/pkg/util/camel/camel_runtime_catalog.go +++ b/pkg/util/camel/camel_runtime_catalog.go @@ -89,7 +89,7 @@ type RuntimeCatalog struct { func (c *RuntimeCatalog) HasArtifact(artifact string) bool { a := artifact if !strings.HasPrefix(a, "camel-") { - if c.Runtime.Provider == v1.RuntimeProviderQuarkus { + if c.Runtime.Provider.IsQuarkusBased() { a = "camel-quarkus-" + a } else { a = "camel-" + a @@ -105,7 +105,7 @@ func (c *RuntimeCatalog) HasArtifact(artifact string) bool { func (c *RuntimeCatalog) HasLoaderByArtifact(artifact string) bool { a := artifact if !strings.HasPrefix(a, "camel-") { - if c.Runtime.Provider == v1.RuntimeProviderQuarkus { + if c.Runtime.Provider.IsQuarkusBased() { a = "camel-quarkus-" + a } else { a = "camel-" + a diff --git a/pkg/util/camel/camel_util.go b/pkg/util/camel/camel_util.go index 321ab9ad1b..dcf8e2020e 100644 --- a/pkg/util/camel/camel_util.go +++ b/pkg/util/camel/camel_util.go @@ -105,7 +105,7 @@ func newCatalogVersionCollection(catalogs []v1.CamelCatalog) CatalogVersionColle } func getDependency(artifact v1.CamelArtifact, runtimeProvider v1.RuntimeProvider) string { - if runtimeProvider == v1.RuntimeProviderQuarkus { + if runtimeProvider.IsQuarkusBased() { return strings.Replace(artifact.ArtifactID, "camel-quarkus-", "camel:", 1) } return strings.Replace(artifact.ArtifactID, "camel-", "camel:", 1)