This is an automated email from the ASF dual-hosted git repository.
squakez 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 d9eb979a3 feat(trait): Support owner trait wildcard (#6734)
d9eb979a3 is described below
commit d9eb979a3a4289fb8f608bd1b5e531f184f0668b
Author: Subhramit Basu <[email protected]>
AuthorDate: Mon Aug 3 17:52:21 2026 +0530
feat(trait): Support owner trait wildcard (#6734)
* Fix #6497: support owner trait wildcard
Signed-off-by: subhramit <[email protected]>
* Update docs for owner traits wildcard support
Signed-off-by: subhramit <[email protected]>
* Use make generate and make update-docs
Signed-off-by: Subhramit Basu <[email protected]>
* Address make lint errors
Signed-off-by: subhramit <[email protected]>
* Fix make fmt issues
Signed-off-by: Subhramit Basu <[email protected]>
* Revert "Fix make fmt issues"
This reverts commit eade33027e112f49ce16630604a7e7428dd60163.
Signed-off-by: Subhramit Basu <[email protected]>
---------
Signed-off-by: subhramit <[email protected]>
Signed-off-by: Subhramit Basu <[email protected]>
---
docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 4 +-
docs/modules/traits/pages/owner.adoc | 4 +-
helm/camel-k/crds/camel-k-crds.yaml | 48 ++++++++++++++--------
pkg/apis/camel/v1/trait/owner.go | 4 +-
.../camel.apache.org_integrationplatforms.yaml | 12 ++++--
.../camel.apache.org_integrationprofiles.yaml | 12 ++++--
.../crd/bases/camel.apache.org_integrations.yaml | 12 ++++--
.../config/crd/bases/camel.apache.org_pipes.yaml | 12 ++++--
pkg/trait/owner.go | 27 +++++++++---
pkg/trait/owner_test.go | 27 ++++++++++++
10 files changed, 118 insertions(+), 44 deletions(-)
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 1b0a6383f..3b2c022e9 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -8929,14 +8929,14 @@ and transfers annotations and labels on the integration
onto these owned resourc
|
-The set of annotations to be transferred
+The set of annotations to be transferred. Use "*" to transfer all annotations.
|`targetLabels` +
[]string
|
-The set of labels to be transferred
+The set of labels to be transferred. Use "*" to transfer all labels.
|===
diff --git a/docs/modules/traits/pages/owner.adoc
b/docs/modules/traits/pages/owner.adoc
index 01cc735f3..a249e77a6 100755
--- a/docs/modules/traits/pages/owner.adoc
+++ b/docs/modules/traits/pages/owner.adoc
@@ -32,11 +32,11 @@ The following configuration options are available:
| owner.targetAnnotations
| []string
-| The set of annotations to be transferred
+| The set of annotations to be transferred. Use "*" to transfer all
annotations.
| owner.targetLabels
| []string
-| The set of labels to be transferred
+| The set of labels to be transferred. Use "*" to transfer all labels.
|===
diff --git a/helm/camel-k/crds/camel-k-crds.yaml
b/helm/camel-k/crds/camel-k-crds.yaml
index 6042d351b..9328938d3 100644
--- a/helm/camel-k/crds/camel-k-crds.yaml
+++ b/helm/camel-k/crds/camel-k-crds.yaml
@@ -5393,12 +5393,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -7935,12 +7937,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -10371,12 +10375,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -12793,12 +12799,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -22077,12 +22085,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -24460,12 +24470,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -35111,12 +35123,14 @@ spec:
All traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be
transferred
+ description: The set of annotations to be
transferred.
+ Use "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred.
Use
+ "*" to transfer all labels.
items:
type: string
type: array
@@ -37412,12 +37426,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
diff --git a/pkg/apis/camel/v1/trait/owner.go b/pkg/apis/camel/v1/trait/owner.go
index d3bedeea9..d393cf4ef 100644
--- a/pkg/apis/camel/v1/trait/owner.go
+++ b/pkg/apis/camel/v1/trait/owner.go
@@ -26,8 +26,8 @@ package trait
type OwnerTrait struct {
Trait `json:",inline" property:",squash"`
- // The set of annotations to be transferred
+ // The set of annotations to be transferred. Use "*" to transfer all
annotations.
TargetAnnotations []string `json:"targetAnnotations,omitempty"
property:"target-annotations"`
- // The set of labels to be transferred
+ // The set of labels to be transferred. Use "*" to transfer all labels.
TargetLabels []string `json:"targetLabels,omitempty"
property:"target-labels"`
}
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 df5200c9d..f1b0c2b26 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -2087,12 +2087,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -4629,12 +4631,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
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 351a07e69..80852a2e7 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
@@ -1945,12 +1945,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -4367,12 +4369,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
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 a4408a412..710abc0dc 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
@@ -8796,12 +8796,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
@@ -11179,12 +11181,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
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 b1a629e6d..56e9c3e4e 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
@@ -8855,12 +8855,14 @@ spec:
All traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be
transferred
+ description: The set of annotations to be
transferred.
+ Use "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred.
Use
+ "*" to transfer all labels.
items:
type: string
type: array
@@ -11156,12 +11158,14 @@ spec:
traits share this common property.
type: boolean
targetAnnotations:
- description: The set of annotations to be transferred
+ description: The set of annotations to be transferred.
Use
+ "*" to transfer all annotations.
items:
type: string
type: array
targetLabels:
- description: The set of labels to be transferred
+ description: The set of labels to be transferred. Use
"*"
+ to transfer all labels.
items:
type: string
type: array
diff --git a/pkg/trait/owner.go b/pkg/trait/owner.go
index 121a0e2e8..0ec69ed4b 100644
--- a/pkg/trait/owner.go
+++ b/pkg/trait/owner.go
@@ -18,6 +18,9 @@ limitations under the License.
package trait
import (
+ "maps"
+ "slices"
+
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
@@ -61,18 +64,26 @@ func (t *ownerTrait) Apply(e *Environment) error {
targetLabels := make(map[string]string)
if e.Integration.Labels != nil {
- for _, k := range t.TargetLabels {
- if v, ok := e.Integration.Labels[k]; ok {
- targetLabels[k] = v
+ if containsWildcard(t.TargetLabels) {
+ maps.Copy(targetLabels, e.Integration.Labels)
+ } else {
+ for _, k := range t.TargetLabels {
+ if v, ok := e.Integration.Labels[k]; ok {
+ targetLabels[k] = v
+ }
}
}
}
targetAnnotations := make(map[string]string)
if e.Integration.Annotations != nil {
- for _, k := range t.TargetAnnotations {
- if v, ok := e.Integration.Annotations[k]; ok {
- targetAnnotations[k] = v
+ if containsWildcard(t.TargetAnnotations) {
+ maps.Copy(targetAnnotations, e.Integration.Annotations)
+ } else {
+ for _, k := range t.TargetAnnotations {
+ if v, ok := e.Integration.Annotations[k]; ok {
+ targetAnnotations[k] = v
+ }
}
}
}
@@ -142,3 +153,7 @@ func (t *ownerTrait) propagateLabelAndAnnotations(res
metav1.Object, targetLabel
}
res.SetLabels(labels)
}
+
+func containsWildcard(values []string) bool {
+ return slices.Contains(values, "*")
+}
diff --git a/pkg/trait/owner_test.go b/pkg/trait/owner_test.go
index e6d499933..709378c2e 100644
--- a/pkg/trait/owner_test.go
+++ b/pkg/trait/owner_test.go
@@ -89,6 +89,33 @@ func ValidateOwnerResources(t *testing.T, env *Environment,
withOwnerRef bool) {
ValidateLabelsAndAnnotations(t, &deployments[0].Spec.Template)
}
+func TestOwnerWildcard(t *testing.T) {
+ env := createTestEnv(t, "camel:core")
+ env.Integration.Spec.Traits = v1.Traits{
+ Owner: &traitv1.OwnerTrait{
+ TargetLabels: []string{"*"},
+ TargetAnnotations: []string{"*"},
+ },
+ }
+ env.Integration.SetLabels(map[string]string{
+ "com.mycompany/mylabel1": "myvalue1",
+ "com.mycompany/mylabel2": "myvalue2",
+ })
+ env.Integration.SetAnnotations(map[string]string{
+ "com.mycompany/myannotation1": "myannotation1",
+ "com.mycompany/myannotation2": "myannotation2",
+ })
+
+ processTestEnv(t, env)
+
+ env.Resources.VisitMetaObject(func(res metav1.Object) {
+ assert.Contains(t, res.GetLabels(), "com.mycompany/mylabel1")
+ assert.Contains(t, res.GetLabels(), "com.mycompany/mylabel2")
+ assert.Contains(t, res.GetAnnotations(),
"com.mycompany/myannotation1")
+ assert.Contains(t, res.GetAnnotations(),
"com.mycompany/myannotation2")
+ })
+}
+
func ValidateLabelsAndAnnotations(t *testing.T, res metav1.Object) {
t.Helper()