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/05/23 08:59:38 UTC

[camel-k] 05/07: Fix #669: filter unneeded annotations by default

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

commit 204c0a01a4b01db431cdbe36a4eed7a3867fb4c3
Author: nferraro <ni...@gmail.com>
AuthorDate: Tue May 21 23:56:37 2019 +0200

    Fix #669: filter unneeded annotations by default
---
 pkg/trait/deployment.go      |  7 +++----
 pkg/trait/knative_service.go |  2 +-
 pkg/trait/util.go            | 13 +++++++++++++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 75d2898..91bf938 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -130,7 +130,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 	// create a copy to avoid sharing the underlying annotation map
 	annotations := make(map[string]string)
 	if e.Integration.Annotations != nil {
-		for k, v := range e.Integration.Annotations {
+		for k, v := range FilterTransferableAnnotations(e.Integration.Annotations) {
 			annotations[k] = v
 		}
 	}
@@ -146,9 +146,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 		ObjectMeta: metav1.ObjectMeta{
 			Name:      e.Integration.Name,
 			Namespace: e.Integration.Namespace,
-			Labels: map[string]string{
-				"camel.apache.org/integration": e.Integration.Name,
-			},
+			Labels: labels,
 			Annotations: annotations,
 		},
 		Spec: appsv1.DeploymentSpec{
@@ -159,6 +157,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 			Template: corev1.PodTemplateSpec{
 				ObjectMeta: metav1.ObjectMeta{
 					Labels: labels,
+					Annotations: annotations,
 				},
 				Spec: corev1.PodSpec{
 					ServiceAccountName: e.Integration.Spec.ServiceAccountName,
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 692ea81..cb04bc6 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -128,7 +128,7 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
 
 	// Copy annotations from the integration resource
 	if e.Integration.Annotations != nil {
-		for k, v := range e.Integration.Annotations {
+		for k, v := range FilterTransferableAnnotations(e.Integration.Annotations) {
 			annotations[k] = v
 		}
 	}
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 30ab45a..4355c8d 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -133,6 +133,19 @@ func parseCsvMap(csvMap *string) (map[string]string, error) {
 	return m, nil
 }
 
+// FilterTransferableAnnotations returns a map containing annotations that are meaningful for being transferred to child resources.
+func FilterTransferableAnnotations(annotations map[string]string) map[string]string {
+	res := make(map[string]string)
+	for k, v := range annotations {
+		if strings.HasPrefix(k, "kubectl.kubernetes.io") {
+			// filter out kubectl annotations
+			continue
+		}
+		res[k]=v
+	}
+	return res
+}
+
 func decodeTraitSpec(in *v1alpha1.TraitSpec, target interface{}) error {
 	md := mapstructure.Metadata{}