You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/08/04 16:32:41 UTC

[camel-k] 01/03: Fix #2530: fix type and do not add cross-namespace owner references

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch release-1.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 1c74469b4ff95d4635376a6a503786e1e09838f4
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Wed Jul 28 17:58:10 2021 +0200

    Fix #2530: fix type and do not add cross-namespace owner references
---
 pkg/trait/owner.go       | 23 +++++++++++++----------
 pkg/trait/pull_secret.go |  4 ++++
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/pkg/trait/owner.go b/pkg/trait/owner.go
index c821e02..e6abc6d 100644
--- a/pkg/trait/owner.go
+++ b/pkg/trait/owner.go
@@ -78,17 +78,20 @@ func (t *ownerTrait) Apply(e *Environment) error {
 	}
 
 	e.Resources.VisitMetaObject(func(res metav1.Object) {
-		references := []metav1.OwnerReference{
-			{
-				APIVersion:         e.Integration.APIVersion,
-				Kind:               e.Integration.Kind,
-				Name:               e.Integration.Name,
-				UID:                e.Integration.UID,
-				Controller:         &controller,
-				BlockOwnerDeletion: &blockOwnerDeletion,
-			},
+		// Avoid setting owner references across namespaces (resources are asynchronously refused by the api server)
+		if res.GetNamespace() == "" || res.GetNamespace() == e.Integration.Namespace {
+			references := []metav1.OwnerReference{
+				{
+					APIVersion:         e.Integration.APIVersion,
+					Kind:               e.Integration.Kind,
+					Name:               e.Integration.Name,
+					UID:                e.Integration.UID,
+					Controller:         &controller,
+					BlockOwnerDeletion: &blockOwnerDeletion,
+				},
+			}
+			res.SetOwnerReferences(references)
 		}
-		res.SetOwnerReferences(references)
 
 		// Transfer annotations
 		t.propagateLabelAndAnnotations(res, targetLabels, targetAnnotations)
diff --git a/pkg/trait/pull_secret.go b/pkg/trait/pull_secret.go
index 115d601..b1612ce 100644
--- a/pkg/trait/pull_secret.go
+++ b/pkg/trait/pull_secret.go
@@ -122,6 +122,10 @@ func (t *pullSecretTrait) newImagePullerRoleBinding(e *Environment) *rbacv1.Role
 		serviceAccount = "default"
 	}
 	return &rbacv1.RoleBinding{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "RoleBinding",
+			APIVersion: rbacv1.SchemeGroupVersion.String(),
+		},
 		ObjectMeta: metav1.ObjectMeta{
 			Namespace: e.Integration.GetIntegrationKitNamespace(e.Platform),
 			Name:      fmt.Sprintf("camel-k-puller-%s", e.Integration.Namespace),