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 d85129a0775a382f7b633f8775b5d83af2a9538c Author: John Poth <[email protected]> AuthorDate: Thu Jan 28 10:30:38 2021 +0100 Do not watch ServiceBindings if Service Binding Operator is not installed (#1445) --- .../integration/integration_controller.go | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go index 012a20c..6294d67 100644 --- a/pkg/controller/integration/integration_controller.go +++ b/pkg/controller/integration/integration_controller.go @@ -23,6 +23,7 @@ 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" @@ -218,15 +219,18 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { return err } - // Watch ServiceBindings created - err = c.Watch(&source.Kind{Type: &sb.ServiceBinding{}}, &handler.EnqueueRequestForOwner{ - OwnerType: &v1.Integration{}, - IsController: true, - }) - if err != nil { - return err + if IsServiceBindingOperatorInstalled(mgr) { + // Watch ServiceBindings created + err = c.Watch(&source.Kind{Type: &sb.ServiceBinding{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &v1.Integration{}, + IsController: true, + }) + if err != nil { + return err + } + } else { + log.Infof("ServiceBinding monitoring is disabled, install Service Binding Operator before camel-k if needed") } - return nil } @@ -337,3 +341,16 @@ 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 +}
