This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 4bec325b596175d75444aadfa78fc20a4cb1a4c0 Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Mon Jan 31 10:53:36 2022 +0100 chore(cli): Install Knative addressable-resolver ClusterRole and ClusterRoleBinding --- pkg/install/cluster.go | 18 ++++++++++++++++++ pkg/install/operator.go | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/pkg/install/cluster.go b/pkg/install/cluster.go index 7902986..966f5ea 100644 --- a/pkg/install/cluster.go +++ b/pkg/install/cluster.go @@ -35,6 +35,7 @@ import ( "github.com/apache/camel-k/pkg/client" "github.com/apache/camel-k/pkg/resources" + "github.com/apache/camel-k/pkg/util/knative" "github.com/apache/camel-k/pkg/util/kubernetes" ) @@ -193,6 +194,23 @@ func SetupClusterWideResourcesOrCollect(ctx context.Context, clientProvider clie } } + isKnative, err := knative.IsInstalled(ctx, c) + if err != nil { + return err + } + if isKnative { + ok, err := isClusterRoleInstalled(ctx, c, "camel-k-operator-bind-addressable-resolver") + if err != nil { + return err + } + if !ok || collection != nil { + err := installResource(ctx, c, collection, "/rbac/operator-cluster-role-addressable-resolver.yaml") + if err != nil { + return err + } + } + } + return nil } diff --git a/pkg/install/operator.go b/pkg/install/operator.go index 47c5a0c..18fa8f0 100644 --- a/pkg/install/operator.go +++ b/pkg/install/operator.go @@ -247,44 +247,51 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu if err := installKnative(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { return err } + if err := installClusterRoleBinding(ctx, c, collection, cfg.Namespace, "camel-k-operator-bind-addressable-resolver", "/rbac/operator-cluster-role-binding-addressable-resolver.yaml"); err != nil { + if k8serrors.IsForbidden(err) { + fmt.Println("Warning: the operator will not be able to bind Knative addressable-resolver ClusterRole. Try installing the operator as cluster-admin.") + } else { + return err + } + } } - if errevt := installEvents(ctx, c, cfg.Namespace, customizer, collection, force); errevt != nil { - if k8serrors.IsAlreadyExists(errevt) { - return errevt + if err = installEvents(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { + if k8serrors.IsAlreadyExists(err) { + return err } fmt.Println("Warning: the operator will not be able to publish Kubernetes events. Try installing as cluster-admin to allow it to generate events.") } - if errmtr := installKedaBindings(ctx, c, cfg.Namespace, customizer, collection, force); errmtr != nil { - if k8serrors.IsAlreadyExists(errmtr) { - return errmtr + if err = installKedaBindings(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { + if k8serrors.IsAlreadyExists(err) { + return err } fmt.Println("Warning: the operator will not be able to create KEDA resources. Try installing as cluster-admin.") } - if errmtr := installPodMonitors(ctx, c, cfg.Namespace, customizer, collection, force); errmtr != nil { - if k8serrors.IsAlreadyExists(errmtr) { - return errmtr + if err = installPodMonitors(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { + if k8serrors.IsAlreadyExists(err) { + return err } fmt.Println("Warning: the operator will not be able to create PodMonitor resources. Try installing as cluster-admin.") } - if errmtr := installStrimziBindings(ctx, c, cfg.Namespace, customizer, collection, force); errmtr != nil { - if k8serrors.IsAlreadyExists(errmtr) { - return errmtr + if err := installStrimziBindings(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { + if k8serrors.IsAlreadyExists(err) { + return err } fmt.Println("Warning: the operator will not be able to lookup strimzi kafka resources. Try installing as cluster-admin to allow the lookup of strimzi kafka resources.") } - if errmtr := installLeaseBindings(ctx, c, cfg.Namespace, customizer, collection, force); errmtr != nil { - if k8serrors.IsAlreadyExists(errmtr) { - return errmtr + if err = installLeaseBindings(ctx, c, cfg.Namespace, customizer, collection, force); err != nil { + if k8serrors.IsAlreadyExists(err) { + return err } fmt.Println("Warning: the operator will not be able to create Leases. Try installing as cluster-admin to allow management of Lease resources.") } - if errmtr := installClusterRoleBinding(ctx, c, collection, cfg.Namespace, "camel-k-operator-custom-resource-definitions", "/rbac/operator-cluster-role-binding-custom-resource-definitions.yaml"); errmtr != nil { + if err = installClusterRoleBinding(ctx, c, collection, cfg.Namespace, "camel-k-operator-custom-resource-definitions", "/rbac/operator-cluster-role-binding-custom-resource-definitions.yaml"); err != nil { fmt.Println("Warning: the operator will not be able to get CustomResourceDefinitions resources and the service-binding trait will fail if used. Try installing the operator as cluster-admin.") } @@ -309,7 +316,6 @@ func installClusterRoleBinding(ctx context.Context, c client.Client, collection existing, err := c.RbacV1().ClusterRoleBindings().Get(ctx, name, metav1.GetOptions{}) switch { case k8serrors.IsNotFound(err): - content, err := resources.ResourceAsString(path) if err != nil { return err @@ -324,8 +330,10 @@ func installClusterRoleBinding(ctx context.Context, c client.Client, collection if err != nil { return err } - // nolint: forcetypeassert - target = obj.(*rbacv1.ClusterRoleBinding) + var ok bool + if target, ok = obj.(*rbacv1.ClusterRoleBinding); !ok { + return fmt.Errorf("file %v does not contain a ClusterRoleBinding resource", path) + } case err != nil: return err default: