From b6a2d70fc6dfed9cd5120d237ad958c139bd73c2 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Thu, 5 Sep 2024 12:08:24 +0200 Subject: [PATCH] feat(api): expose Camel core version It is useful to know what core version of Camel the runtime is running --- docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 7 +++++++ helm/camel-k/crds/camel-k-crds.yaml | 10 ++++++++++ pkg/apis/camel/v1/integrationplatform_types.go | 3 +++ .../camel/v1/integrationplatformbuildspec.go | 9 +++++++++ pkg/controller/integrationplatform/catalog.go | 6 ++++-- pkg/controller/integrationplatform/catalog_test.go | 6 ++++++ pkg/controller/integrationplatform/monitor.go | 1 + .../bases/camel.apache.org_integrationplatforms.yaml | 10 ++++++++++ 8 files changed, 50 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 4761b27477..2e66f7153e 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -2830,6 +2830,13 @@ the Camel K Runtime dependency version the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version 1.5) +|`runtimeCoreVersion` + +string +| + + +the Camel core version used by this IntegrationPlatform + |`baseImage` + string | diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml index 632193ad51..21a332ad3c 100644 --- a/helm/camel-k/crds/camel-k-crds.yaml +++ b/helm/camel-k/crds/camel-k-crds.yaml @@ -3212,6 +3212,10 @@ spec: jsonPath: .status.build.runtimeVersion name: Default runtime type: string + - description: The default Camel core version + jsonPath: .status.build.runtimeCoreVersion + name: Camel version + type: string name: v1 schema: openAPIV3Schema: @@ -3571,6 +3575,9 @@ spec: description: the secret where credentials are stored type: string type: object + runtimeCoreVersion: + description: the Camel core version used by this IntegrationPlatform + type: string runtimeProvider: description: the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version @@ -5624,6 +5631,9 @@ spec: description: the secret where credentials are stored type: string type: object + runtimeCoreVersion: + description: the Camel core version used by this IntegrationPlatform + type: string runtimeProvider: description: the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version diff --git a/pkg/apis/camel/v1/integrationplatform_types.go b/pkg/apis/camel/v1/integrationplatform_types.go index 81ae587cd7..3cc8e3a654 100644 --- a/pkg/apis/camel/v1/integrationplatform_types.go +++ b/pkg/apis/camel/v1/integrationplatform_types.go @@ -72,6 +72,7 @@ type IntegrationPlatformStatus struct { // +kubebuilder:printcolumn:name="Publish strategy",type=string,JSONPath=`.status.build.publishStrategy`,description="The default publish strategy" // +kubebuilder:printcolumn:name="Registry address",type=string,JSONPath=`.status.build.registry.address`,description="The container registry address" // +kubebuilder:printcolumn:name="Default runtime",type=string,JSONPath=`.status.build.runtimeVersion`,description="The default runtime version" +// +kubebuilder:printcolumn:name="Camel version",type=string,JSONPath=`.status.build.runtimeCoreVersion`,description="The default Camel core version" // IntegrationPlatform is the resource used to drive the Camel K operator behavior. // It defines the behavior of all Custom Resources (`IntegrationKit`, `Integration`, `Kamelet`) in the given namespace. @@ -119,6 +120,8 @@ type IntegrationPlatformBuildSpec struct { RuntimeVersion string `json:"runtimeVersion,omitempty"` // the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version 1.5) RuntimeProvider RuntimeProvider `json:"runtimeProvider,omitempty"` + // the Camel core version used by this IntegrationPlatform + RuntimeCoreVersion string `json:"runtimeCoreVersion,omitempty"` // a base image that can be used as base layer for all images. // It can be useful if you want to provide some custom base image with further utility software BaseImage string `json:"baseImage,omitempty"` diff --git a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go index 924aaea512..6c3432908c 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/integrationplatformbuildspec.go @@ -31,6 +31,7 @@ type IntegrationPlatformBuildSpecApplyConfiguration struct { PublishStrategy *camelv1.IntegrationPlatformBuildPublishStrategy `json:"publishStrategy,omitempty"` RuntimeVersion *string `json:"runtimeVersion,omitempty"` RuntimeProvider *camelv1.RuntimeProvider `json:"runtimeProvider,omitempty"` + RuntimeCoreVersion *string `json:"runtimeCoreVersion,omitempty"` BaseImage *string `json:"baseImage,omitempty"` Registry *RegistrySpecApplyConfiguration `json:"registry,omitempty"` BuildCatalogToolTimeout *metav1.Duration `json:"buildCatalogToolTimeout,omitempty"` @@ -78,6 +79,14 @@ func (b *IntegrationPlatformBuildSpecApplyConfiguration) WithRuntimeProvider(val return b } +// WithRuntimeCoreVersion sets the RuntimeCoreVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the RuntimeCoreVersion field is set to the value of the last call. +func (b *IntegrationPlatformBuildSpecApplyConfiguration) WithRuntimeCoreVersion(value string) *IntegrationPlatformBuildSpecApplyConfiguration { + b.RuntimeCoreVersion = &value + return b +} + // WithBaseImage sets the BaseImage field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the BaseImage field is set to the value of the last call. diff --git a/pkg/controller/integrationplatform/catalog.go b/pkg/controller/integrationplatform/catalog.go index 7be5aabb5e..ea1406f1fb 100644 --- a/pkg/controller/integrationplatform/catalog.go +++ b/pkg/controller/integrationplatform/catalog.go @@ -51,12 +51,13 @@ func (action *catalogAction) Handle(ctx context.Context, platform *v1.Integratio Provider: v1.RuntimeProviderQuarkus, } - if catalog, err := camel.LoadCatalog(ctx, action.client, platform.Namespace, runtimeSpec); err != nil { + catalog, err := camel.LoadCatalog(ctx, action.client, platform.Namespace, runtimeSpec) + if err != nil { action.L.Error(err, "IntegrationPlatform unable to load Camel catalog", "runtime-version", runtimeSpec.Version, "runtime-provider", runtimeSpec.Provider) return platform, nil } else if catalog == nil { - if _, err = camel.CreateCatalog(ctx, action.client, platform.Namespace, platform, runtimeSpec); err != nil { + if catalog, err = camel.CreateCatalog(ctx, action.client, platform.Namespace, platform, runtimeSpec); err != nil { action.L.Error(err, "IntegrationPlatform unable to create Camel catalog", "runtime-version", runtimeSpec.Version, "runtime-provider", runtimeSpec.Provider) @@ -77,6 +78,7 @@ func (action *catalogAction) Handle(ctx context.Context, platform *v1.Integratio corev1.ConditionTrue, v1.IntegrationPlatformConditionCamelCatalogAvailableReason, fmt.Sprintf("camel catalog %s available", runtimeSpec.Version)) + platform.Status.Build.RuntimeCoreVersion = catalog.Runtime.Metadata["camel.version"] return platform, nil } diff --git a/pkg/controller/integrationplatform/catalog_test.go b/pkg/controller/integrationplatform/catalog_test.go index 9e4d863f21..f2c5265089 100644 --- a/pkg/controller/integrationplatform/catalog_test.go +++ b/pkg/controller/integrationplatform/catalog_test.go @@ -121,6 +121,8 @@ func TestCreateCatalog(t *testing.T) { assert.Equal(t, v1.IntegrationPlatformPhaseReady, answer.Status.Phase, "Error", answer.Status.Conditions[0].Message) assert.Equal(t, corev1.ConditionTrue, answer.Status.GetCondition(v1.IntegrationPlatformConditionCamelCatalogAvailable).Status) + // We don't know exactly which is the core version, it is enough to check is not empty in the test + assert.NotEqual(t, "", answer.Status.Build.RuntimeCoreVersion) list := v1.NewCamelCatalogList() err = c.List(context.TODO(), &list, k8sclient.InNamespace(ip.Namespace)) @@ -160,6 +162,9 @@ func TestCatalogAlreadyPresent(t *testing.T) { catalog := v1.NewCamelCatalog("ns", fmt.Sprintf("camel-catalog-%s", defaults.DefaultRuntimeVersion)) catalog.Spec.Runtime.Version = defaults.DefaultRuntimeVersion catalog.Spec.Runtime.Provider = v1.RuntimeProviderQuarkus + catalog.Spec.Runtime.Metadata = map[string]string{ + "camel.version": "4.4.0", + } c, err := test.NewFakeClient(&ip, &catalog) require.NoError(t, err) @@ -176,6 +181,7 @@ func TestCatalogAlreadyPresent(t *testing.T) { assert.NotNil(t, answer) assert.Equal(t, v1.IntegrationPlatformPhaseReady, answer.Status.Phase) + assert.Equal(t, "4.4.0", answer.Status.Build.RuntimeCoreVersion) assert.Equal(t, corev1.ConditionTrue, answer.Status.GetCondition(v1.IntegrationPlatformConditionCamelCatalogAvailable).Status) } diff --git a/pkg/controller/integrationplatform/monitor.go b/pkg/controller/integrationplatform/monitor.go index 3a3b3c25e6..474fe2934f 100644 --- a/pkg/controller/integrationplatform/monitor.go +++ b/pkg/controller/integrationplatform/monitor.go @@ -121,6 +121,7 @@ func (action *monitorAction) Handle(ctx context.Context, platform *v1.Integratio corev1.ConditionTrue, v1.IntegrationPlatformConditionCamelCatalogAvailableReason, fmt.Sprintf("camel catalog %s available", runtimeSpec.Version)) + platform.Status.Build.RuntimeCoreVersion = catalog.Runtime.Metadata["camel.version"] } } 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 0a1614617f..214358b96b 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -57,6 +57,10 @@ spec: jsonPath: .status.build.runtimeVersion name: Default runtime type: string + - description: The default Camel core version + jsonPath: .status.build.runtimeCoreVersion + name: Camel version + type: string name: v1 schema: openAPIV3Schema: @@ -416,6 +420,9 @@ spec: description: the secret where credentials are stored type: string type: object + runtimeCoreVersion: + description: the Camel core version used by this IntegrationPlatform + type: string runtimeProvider: description: the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version @@ -2469,6 +2476,9 @@ spec: description: the secret where credentials are stored type: string type: object + runtimeCoreVersion: + description: the Camel core version used by this IntegrationPlatform + type: string runtimeProvider: description: the runtime used. Likely Camel Quarkus (we used to have main runtime which has been discontinued since version