You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/02/09 12:32:05 UTC

[camel-k] 04/06: fix: use checkPermission to check if ServiceBinding is installed, allow ServiceBinding trait on all profiles (#1445)

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

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit e4e5127bd849b6e26fbe410263ee129d7900d7cf
Author: John Poth <po...@gmail.com>
AuthorDate: Fri Jan 29 15:29:52 2021 +0100

    fix: use checkPermission to check if ServiceBinding is installed, allow ServiceBinding trait on all profiles (#1445)
---
 .../integration/integration_controller.go          | 27 ++++++++--------------
 pkg/trait/service_binding.go                       |  6 -----
 2 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go
index 6294d67..bb94174 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -23,7 +23,6 @@ import (
 	appsv1 "k8s.io/api/apps/v1"
 	"k8s.io/api/batch/v1beta1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
-	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/types"
@@ -43,9 +42,10 @@ import (
 	camelevent "github.com/apache/camel-k/pkg/event"
 	"github.com/apache/camel-k/pkg/platform"
 	"github.com/apache/camel-k/pkg/util/digest"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/apache/camel-k/pkg/util/log"
 	"github.com/apache/camel-k/pkg/util/monitoring"
-    sb "github.com/redhat-developer/service-binding-operator/pkg/apis/operators/v1alpha1"
+	sb "github.com/redhat-developer/service-binding-operator/pkg/apis/operators/v1alpha1"
 )
 
 // Add creates a new Integration Controller and adds it to the Manager. The Manager will set fields on the Controller
@@ -219,7 +219,13 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
 		return err
 	}
 
-	if IsServiceBindingOperatorInstalled(mgr) {
+	if client, err := client.FromManager(mgr); err != nil {
+		log.Error(err, "cannot check permissions for watching ServiceBindings")
+	} else if ok, err := kubernetes.CheckPermission(context.TODO(), client, "operators.coreos.com", "ServiceBinding", "", "", "create"); err != nil {
+		log.Error(err, "cannot check permissions for watching ServiceBindings")
+	} else if !ok {
+		log.Info("ServiceBinding monitoring is disabled, install Service Binding Operator before camel-k if needed")
+	} else {
 		// Watch ServiceBindings created
 		err = c.Watch(&source.Kind{Type: &sb.ServiceBinding{}}, &handler.EnqueueRequestForOwner{
 			OwnerType:    &v1.Integration{},
@@ -228,8 +234,6 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
 		if err != nil {
 			return err
 		}
-	} else {
-		log.Infof("ServiceBinding monitoring is disabled, install Service Binding Operator before camel-k if needed")
 	}
 	return nil
 }
@@ -341,16 +345,3 @@ func (r *reconcileIntegration) update(ctx context.Context, base *v1.Integration,
 
 	return reconcile.Result{}, err
 }
-
-func IsServiceBindingOperatorInstalled(mgr manager.Manager) bool {
-	u := &unstructured.Unstructured{}
-	u.SetGroupVersionKind(schema.GroupVersionKind{
-		Group:   "apiextensions.k8s.io",
-		Kind:    "CustomResourceDefinition",
-		Version: "v1beta1",
-	})
-	err := mgr.GetClient().Get(context.Background(), k8sclient.ObjectKey{
-		Name: "servicebindings.operators.coreos.com",
-	}, u)
-	return err == nil
-}
diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go
index 131d2c5..1b313a5 100644
--- a/pkg/trait/service_binding.go
+++ b/pkg/trait/service_binding.go
@@ -45,12 +45,6 @@ func newServiceBindingTrait() Trait {
 	}
 }
 
-// IsAllowedInProfile overrides default
-func (t *serviceBindingTrait) IsAllowedInProfile(profile v1.TraitProfile) bool {
-	return profile == v1.TraitProfileKubernetes ||
-		profile == v1.TraitProfileOpenShift
-}
-
 func (t *serviceBindingTrait) Configure(e *Environment) (bool, error) {
 	if t.Enabled != nil && !*t.Enabled {
 		return false, nil