You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2024/03/22 09:02:39 UTC
(camel-k) branch main updated: feat(catalog): support placeholders
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 2f595d154 feat(catalog): support placeholders
2f595d154 is described below
commit 2f595d15473acf90d984189d4d7598795239e3b1
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 22 08:51:39 2024 +0100
feat(catalog): support placeholders
Ref https://github.com/apache/camel-k-runtime/pull/1192
---
docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 35 +++++++++++-
helm/camel-k/crds/crd-build.yaml | 64 ++++++++++++++++++----
helm/camel-k/crds/crd-camel-catalog.yaml | 30 ++++++++--
pkg/apis/camel/v1/common_types.go | 12 +++-
pkg/apis/camel/v1/integrationkit_types_support.go | 11 ++++
pkg/apis/camel/v1/zz_generated.deepcopy.go | 27 ++++++---
.../applyconfiguration/camel/v1/camelproperty.go | 49 +++++++++++++++++
.../applyconfiguration/camel/v1/capability.go | 38 ++++++-------
pkg/client/camel/applyconfiguration/utils.go | 2 +
.../config/crd/bases/camel.apache.org_builds.yaml | 64 ++++++++++++++++++----
.../crd/bases/camel.apache.org_camelcatalogs.yaml | 30 ++++++++--
pkg/trait/trait_types.go | 17 ++++++
pkg/trait/trait_types_test.go | 10 ++++
13 files changed, 320 insertions(+), 69 deletions(-)
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index f1cc0545e..edb8c1408 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -1322,6 +1322,37 @@ map[string]string
the metadata of the loader
+|===
+
+[#_camel_apache_org_v1_CamelProperty]
+=== CamelProperty
+
+*Appears on:*
+
+* <<#_camel_apache_org_v1_Capability, Capability>>
+
+CamelProperty represents a Camel property that may end up in an application.properties file.
+
+[cols="2,2a",options="header"]
+|===
+|Field
+|Description
+
+|`key` +
+string
+|
+
+
+
+
+|`value` +
+string
+|
+
+
+
+
+
|===
[#_camel_apache_org_v1_CamelScheme]
@@ -1423,14 +1454,14 @@ which are specified in the runtime catalog.
List of required Maven dependencies
|`runtimeProperties` +
-map[string]string
+*xref:#_camel_apache_org_v1_CamelProperty[[\]CamelProperty]*
|
Set of required Camel runtime properties
|`buildTimeProperties` +
-map[string]string
+*xref:#_camel_apache_org_v1_CamelProperty[[\]CamelProperty]*
|
diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml
index 9ccd0da7a..31635f79d 100644
--- a/helm/camel-k/crds/crd-build.yaml
+++ b/helm/camel-k/crds/crd-build.yaml
@@ -660,11 +660,21 @@ spec:
properties which are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time
properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -697,10 +707,20 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
@@ -1514,11 +1534,21 @@ spec:
properties which are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time
properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -1551,10 +1581,20 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
diff --git a/helm/camel-k/crds/crd-camel-catalog.yaml b/helm/camel-k/crds/crd-camel-catalog.yaml
index 99458fd96..e76c6bb59 100644
--- a/helm/camel-k/crds/crd-camel-catalog.yaml
+++ b/helm/camel-k/crds/crd-camel-catalog.yaml
@@ -376,10 +376,19 @@ spec:
are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time properties
- type: object
+ items:
+ description: CamelProperty represents a Camel property
+ that may end up in an application.properties file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -412,10 +421,19 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel property
+ that may end up in an application.properties file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go
index f441ec918..d5af69100 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -350,11 +350,17 @@ type Capability struct {
// List of required Maven dependencies
Dependencies []MavenArtifact `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
// Set of required Camel runtime properties
- RuntimeProperties map[string]string `json:"runtimeProperties,omitempty" yaml:"runtimeProperties,omitempty"`
+ RuntimeProperties []CamelProperty `json:"runtimeProperties,omitempty" yaml:"runtimeProperties,omitempty"`
// Set of required Camel build time properties
- BuildTimeProperties map[string]string `json:"buildTimeProperties,omitempty" yaml:"buildTimeProperties,omitempty"`
+ BuildTimeProperties []CamelProperty `json:"buildTimeProperties,omitempty" yaml:"buildTimeProperties,omitempty"`
// Set of generic metadata
- Metadata map[string]string `json:"metadata,omitempty" yaml:"Metadata,omitempty"`
+ Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
+}
+
+// CamelProperty represents a Camel property that may end up in an application.properties file.
+type CamelProperty struct {
+ Key string `json:"key" yaml:"key"`
+ Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
const (
diff --git a/pkg/apis/camel/v1/integrationkit_types_support.go b/pkg/apis/camel/v1/integrationkit_types_support.go
index 6bcde2c03..c1c8d2a5f 100644
--- a/pkg/apis/camel/v1/integrationkit_types_support.go
+++ b/pkg/apis/camel/v1/integrationkit_types_support.go
@@ -106,6 +106,17 @@ func (in *IntegrationKit) IsExternal() bool {
return in.Labels[IntegrationKitTypeLabel] == IntegrationKitTypeExternal
}
+// HasCapability returns true if the Kit is enabled with such a capability.
+func (in *IntegrationKit) HasCapability(capability string) bool {
+ for _, cap := range in.Spec.Capabilities {
+ if cap == capability {
+ return true
+ }
+ }
+
+ return false
+}
+
// GetCondition returns the condition with the provided type.
func (in *IntegrationKitStatus) GetCondition(condType IntegrationKitConditionType) *IntegrationKitCondition {
for i := range in.Conditions {
diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go
index 9113c57df..8d1e9dc13 100644
--- a/pkg/apis/camel/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go
@@ -568,6 +568,21 @@ func (in *CamelLoader) DeepCopy() *CamelLoader {
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CamelProperty) DeepCopyInto(out *CamelProperty) {
+ *out = *in
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CamelProperty.
+func (in *CamelProperty) DeepCopy() *CamelProperty {
+ if in == nil {
+ return nil
+ }
+ out := new(CamelProperty)
+ in.DeepCopyInto(out)
+ return out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CamelScheme) DeepCopyInto(out *CamelScheme) {
*out = *in
@@ -617,17 +632,13 @@ func (in *Capability) DeepCopyInto(out *Capability) {
}
if in.RuntimeProperties != nil {
in, out := &in.RuntimeProperties, &out.RuntimeProperties
- *out = make(map[string]string, len(*in))
- for key, val := range *in {
- (*out)[key] = val
- }
+ *out = make([]CamelProperty, len(*in))
+ copy(*out, *in)
}
if in.BuildTimeProperties != nil {
in, out := &in.BuildTimeProperties, &out.BuildTimeProperties
- *out = make(map[string]string, len(*in))
- for key, val := range *in {
- (*out)[key] = val
- }
+ *out = make([]CamelProperty, len(*in))
+ copy(*out, *in)
}
if in.Metadata != nil {
in, out := &in.Metadata, &out.Metadata
diff --git a/pkg/client/camel/applyconfiguration/camel/v1/camelproperty.go b/pkg/client/camel/applyconfiguration/camel/v1/camelproperty.go
new file mode 100644
index 000000000..a93d9ab6c
--- /dev/null
+++ b/pkg/client/camel/applyconfiguration/camel/v1/camelproperty.go
@@ -0,0 +1,49 @@
+/*
+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.
+*/
+
+// Code generated by applyconfiguration-gen. DO NOT EDIT.
+
+package v1
+
+// CamelPropertyApplyConfiguration represents an declarative configuration of the CamelProperty type for use
+// with apply.
+type CamelPropertyApplyConfiguration struct {
+ Key *string `json:"key,omitempty"`
+ Value *string `json:"value,omitempty"`
+}
+
+// CamelPropertyApplyConfiguration constructs an declarative configuration of the CamelProperty type for use with
+// apply.
+func CamelProperty() *CamelPropertyApplyConfiguration {
+ return &CamelPropertyApplyConfiguration{}
+}
+
+// WithKey sets the Key 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 Key field is set to the value of the last call.
+func (b *CamelPropertyApplyConfiguration) WithKey(value string) *CamelPropertyApplyConfiguration {
+ b.Key = &value
+ return b
+}
+
+// WithValue sets the Value 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 Value field is set to the value of the last call.
+func (b *CamelPropertyApplyConfiguration) WithValue(value string) *CamelPropertyApplyConfiguration {
+ b.Value = &value
+ return b
+}
diff --git a/pkg/client/camel/applyconfiguration/camel/v1/capability.go b/pkg/client/camel/applyconfiguration/camel/v1/capability.go
index d6d3073b2..28b155f38 100644
--- a/pkg/client/camel/applyconfiguration/camel/v1/capability.go
+++ b/pkg/client/camel/applyconfiguration/camel/v1/capability.go
@@ -23,8 +23,8 @@ package v1
// with apply.
type CapabilityApplyConfiguration struct {
Dependencies []MavenArtifactApplyConfiguration `json:"dependencies,omitempty"`
- RuntimeProperties map[string]string `json:"runtimeProperties,omitempty"`
- BuildTimeProperties map[string]string `json:"buildTimeProperties,omitempty"`
+ RuntimeProperties []CamelPropertyApplyConfiguration `json:"runtimeProperties,omitempty"`
+ BuildTimeProperties []CamelPropertyApplyConfiguration `json:"buildTimeProperties,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
@@ -47,30 +47,28 @@ func (b *CapabilityApplyConfiguration) WithDependencies(values ...*MavenArtifact
return b
}
-// WithRuntimeProperties puts the entries into the RuntimeProperties field in the declarative configuration
+// WithRuntimeProperties adds the given value to the RuntimeProperties field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
-// If called multiple times, the entries provided by each call will be put on the RuntimeProperties field,
-// overwriting an existing map entries in RuntimeProperties field with the same key.
-func (b *CapabilityApplyConfiguration) WithRuntimeProperties(entries map[string]string) *CapabilityApplyConfiguration {
- if b.RuntimeProperties == nil && len(entries) > 0 {
- b.RuntimeProperties = make(map[string]string, len(entries))
- }
- for k, v := range entries {
- b.RuntimeProperties[k] = v
+// If called multiple times, values provided by each call will be appended to the RuntimeProperties field.
+func (b *CapabilityApplyConfiguration) WithRuntimeProperties(values ...*CamelPropertyApplyConfiguration) *CapabilityApplyConfiguration {
+ for i := range values {
+ if values[i] == nil {
+ panic("nil value passed to WithRuntimeProperties")
+ }
+ b.RuntimeProperties = append(b.RuntimeProperties, *values[i])
}
return b
}
-// WithBuildTimeProperties puts the entries into the BuildTimeProperties field in the declarative configuration
+// WithBuildTimeProperties adds the given value to the BuildTimeProperties field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
-// If called multiple times, the entries provided by each call will be put on the BuildTimeProperties field,
-// overwriting an existing map entries in BuildTimeProperties field with the same key.
-func (b *CapabilityApplyConfiguration) WithBuildTimeProperties(entries map[string]string) *CapabilityApplyConfiguration {
- if b.BuildTimeProperties == nil && len(entries) > 0 {
- b.BuildTimeProperties = make(map[string]string, len(entries))
- }
- for k, v := range entries {
- b.BuildTimeProperties[k] = v
+// If called multiple times, values provided by each call will be appended to the BuildTimeProperties field.
+func (b *CapabilityApplyConfiguration) WithBuildTimeProperties(values ...*CamelPropertyApplyConfiguration) *CapabilityApplyConfiguration {
+ for i := range values {
+ if values[i] == nil {
+ panic("nil value passed to WithBuildTimeProperties")
+ }
+ b.BuildTimeProperties = append(b.BuildTimeProperties, *values[i])
}
return b
}
diff --git a/pkg/client/camel/applyconfiguration/utils.go b/pkg/client/camel/applyconfiguration/utils.go
index 737a3d5eb..6632cd823 100644
--- a/pkg/client/camel/applyconfiguration/utils.go
+++ b/pkg/client/camel/applyconfiguration/utils.go
@@ -68,6 +68,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} {
return &camelv1.CamelCatalogStatusApplyConfiguration{}
case v1.SchemeGroupVersion.WithKind("CamelLoader"):
return &camelv1.CamelLoaderApplyConfiguration{}
+ case v1.SchemeGroupVersion.WithKind("CamelProperty"):
+ return &camelv1.CamelPropertyApplyConfiguration{}
case v1.SchemeGroupVersion.WithKind("CamelScheme"):
return &camelv1.CamelSchemeApplyConfiguration{}
case v1.SchemeGroupVersion.WithKind("CamelSchemeScope"):
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_builds.yaml b/pkg/resources/config/crd/bases/camel.apache.org_builds.yaml
index 9ccd0da7a..31635f79d 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_builds.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_builds.yaml
@@ -660,11 +660,21 @@ spec:
properties which are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time
properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -697,10 +707,20 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
@@ -1514,11 +1534,21 @@ spec:
properties which are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time
properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -1551,10 +1581,20 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel
+ property that may end up in an application.properties
+ file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_camelcatalogs.yaml b/pkg/resources/config/crd/bases/camel.apache.org_camelcatalogs.yaml
index 99458fd96..e76c6bb59 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_camelcatalogs.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_camelcatalogs.yaml
@@ -376,10 +376,19 @@ spec:
are specified in the runtime catalog.
properties:
buildTimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel build time properties
- type: object
+ items:
+ description: CamelProperty represents a Camel property
+ that may end up in an application.properties file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
dependencies:
description: List of required Maven dependencies
items:
@@ -412,10 +421,19 @@ spec:
description: Set of generic metadata
type: object
runtimeProperties:
- additionalProperties:
- type: string
description: Set of required Camel runtime properties
- type: object
+ items:
+ description: CamelProperty represents a Camel property
+ that may end up in an application.properties file.
+ properties:
+ key:
+ type: string
+ value:
+ type: string
+ required:
+ - key
+ type: object
+ type: array
type: object
description: features offered by this runtime
type: object
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 85d152e47..46690b28b 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -22,6 +22,7 @@ import (
"fmt"
"path"
"path/filepath"
+ "regexp"
"sort"
"strings"
@@ -51,6 +52,8 @@ const (
sourceCompressionAnnotation = "camel.apache.org/source.compression"
)
+var capabilityDynamicProperty = regexp.MustCompile(`(\$\{([^}]*)\})`)
+
// Identifiable represent an identifiable type.
type Identifiable interface {
ID() ID
@@ -727,3 +730,17 @@ func (e *Environment) getIntegrationContainerPort() *corev1.ContainerPort {
return nil
}
+
+// CapabilityPropertyKey returns the key or expand any variable provided in it. vars variable contain the
+// possible dynamic values to use.
+func CapabilityPropertyKey(camelPropertyKey string, vars map[string]string) string {
+ if capabilityDynamicProperty.MatchString(camelPropertyKey) && vars != nil {
+ match := capabilityDynamicProperty.FindStringSubmatch(camelPropertyKey)
+ if len(match) < 2 {
+ // Should not happen, but fallback to the key not expanded instead of panic if it comes to happen
+ return camelPropertyKey
+ }
+ return strings.ReplaceAll(camelPropertyKey, match[1], vars[match[2]])
+ }
+ return camelPropertyKey
+}
diff --git a/pkg/trait/trait_types_test.go b/pkg/trait/trait_types_test.go
index 75f5384f9..978487b74 100644
--- a/pkg/trait/trait_types_test.go
+++ b/pkg/trait/trait_types_test.go
@@ -154,3 +154,13 @@ func TestVolumeWithKeyOnly(t *testing.T) {
assert.Equal(t, "SomeKey", items[0].Key)
assert.Equal(t, "SomeKey", items[0].Path)
}
+
+func TestCapabilityPropertyKey(t *testing.T) {
+ camelPropertyKeyStatic := CapabilityPropertyKey("quarkus.camel.cluster.kubernetes.resource-name", nil)
+ assert.Equal(t, "quarkus.camel.cluster.kubernetes.resource-name", camelPropertyKeyStatic)
+ vars := map[string]string{
+ "camel.k.master.labelKey": "org.apache.camel/integration",
+ }
+ camelPropertyKeyDynamic := CapabilityPropertyKey(`quarkus.camel.cluster.kubernetes.labels."${camel.k.master.labelKey}"`, vars)
+ assert.Equal(t, `quarkus.camel.cluster.kubernetes.labels."org.apache.camel/integration"`, camelPropertyKeyDynamic)
+}