You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/02/13 06:56:37 UTC
[camel-k] branch master updated: Support transfering annotations
and labels from an integration onto owned resources
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new da5bc1f Support transfering annotations and labels from an integration onto owned resources
da5bc1f is described below
commit da5bc1ff74c24d6afbed7f95019b37e08692558a
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Feb 12 18:28:53 2019 +0100
Support transfering annotations and labels from an integration onto owned resources
Fixes #263
---
docs/traits.adoc | 23 ++++++++++++++++++++---
pkg/trait/owner.go | 42 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/docs/traits.adoc b/docs/traits.adoc
index 3a6a0f3..8520c80 100644
--- a/docs/traits.adoc
+++ b/docs/traits.adoc
@@ -51,7 +51,7 @@ for the `route` trait to work.
The following is a list of common traits that can be configured by the end users:
-[options="header",cols="1m,2,3a"]
+[options="header",cols="1m,,3a"]
|=======================
| Trait | Profiles | Description
@@ -226,8 +226,25 @@ It's disabled by default.
There are also platform traits that **normally should not be configured** by the end user. So change them **only if you know what you're doing**.
-[options="header",cols="m,,"]
+[options="header",cols="1m,2,3a"]
|=======================
| Trait | Profiles | Description
-| owner | Kubernetes, OpenShift | Makes sure that every resource created by the traits belongs to the integration custom resource (so they are deleted when the integration is deleted).
+| owner
+| All
+| Ensures that all created resources belong to the integration being created (so they are deleted when the integration is deleted) and transfers annotations and labels on the integration onto these owned resources.
+ +
+ +
+ It's enabled by default.
+
+[cols="m,"]
+!===
+
+! owner.target-annotations
+! The annotations to be transfered (A comma-separared list of label keys)
+
+! owner.target-labels
+! The labels to be transfered (A comma-separared list of label keys)
+
+!===
+
|=======================
diff --git a/pkg/trait/owner.go b/pkg/trait/owner.go
index 770c00d..f4d3737 100644
--- a/pkg/trait/owner.go
+++ b/pkg/trait/owner.go
@@ -18,13 +18,19 @@ limitations under the License.
package trait
import (
+ "strings"
+
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ownerTrait ensures that all created resources belong to the integration being created
+// and transfers annotations and labels on the integration onto these owned resources being created
type ownerTrait struct {
BaseTrait `property:",squash"`
+
+ TargetAnnotations string `property:"target-annotations"`
+ TargetLabels string `property:"target-labels"`
}
func newOwnerTrait() *ownerTrait {
@@ -41,10 +47,26 @@ func (t *ownerTrait) Configure(e *Environment) (bool, error) {
return e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying), nil
}
-func (*ownerTrait) Apply(e *Environment) error {
+func (t *ownerTrait) Apply(e *Environment) error {
controller := true
blockOwnerDeletion := true
+
+ targetLabels := map[string]string{}
+ for _, k := range strings.Split(t.TargetLabels, ",") {
+ if v, ok := e.Integration.Labels[k]; ok {
+ targetLabels[k] = v
+ }
+ }
+
+ targetAnnotations := map[string]string{}
+ for _, k := range strings.Split(t.TargetAnnotations, ",") {
+ if v, ok := e.Integration.Annotations[k]; ok {
+ targetAnnotations[k] = v
+ }
+ }
+
e.Resources.VisitMetaObject(func(res metav1.Object) {
+ // Add owner reference
references := []metav1.OwnerReference{
{
APIVersion: e.Integration.APIVersion,
@@ -56,6 +78,24 @@ func (*ownerTrait) Apply(e *Environment) error {
},
}
res.SetOwnerReferences(references)
+
+ // Transfer annotations
+ annotations := res.GetAnnotations()
+ for k, v := range targetAnnotations {
+ if _, ok := annotations[k]; !ok {
+ annotations[k] = v
+ }
+ }
+ res.SetAnnotations(annotations)
+
+ // Transfer labels
+ labels := res.GetLabels()
+ for k, v := range targetLabels {
+ if _, ok := labels[k]; !ok {
+ labels[k] = v
+ }
+ }
+ res.SetLabels(labels)
})
return nil
}