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/03/26 13:13:22 UTC

[camel-k] branch master updated (6d3cafa -> cb19602)

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

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


    from 6d3cafa  Updated CHANGELOG.md
     new 21e7ceb  feat(operator): toleration install flag
     new 978311a  refactor(util): k8s helper methods
     new cb19602  feat(operator): revert OperatorOrCollect Reverted from c407bbd885c82d23d4baab48f8c59e946a7201fd change

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pkg/cmd/install.go                              |   8 +-
 pkg/cmd/install_test.go                         |  10 ++
 pkg/install/operator.go                         |  13 ++
 pkg/trait/toleration.go                         |  40 +----
 pkg/util/kubernetes/{util.go => core_client.go} |  90 +++++------
 pkg/util/kubernetes/core_factory.go             |  62 ++++++++
 pkg/util/kubernetes/util.go                     | 190 ------------------------
 pkg/util/olm/operator.go                        |  19 ++-
 8 files changed, 147 insertions(+), 285 deletions(-)
 copy pkg/util/kubernetes/{util.go => core_client.go} (93%)
 create mode 100644 pkg/util/kubernetes/core_factory.go

[camel-k] 02/03: refactor(util): k8s helper methods

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 978311a57a0408cfa42048249f3d7b0bae1ff6c3
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 12 14:40:56 2021 +0100

    refactor(util): k8s helper methods
---
 pkg/util/kubernetes/{util.go => core_client.go} | 128 ++++---------
 pkg/util/kubernetes/core_factory.go             |  62 +++++++
 pkg/util/kubernetes/util.go                     | 228 ------------------------
 3 files changed, 98 insertions(+), 320 deletions(-)

diff --git a/pkg/util/kubernetes/util.go b/pkg/util/kubernetes/core_client.go
similarity index 79%
copy from pkg/util/kubernetes/util.go
copy to pkg/util/kubernetes/core_client.go
index 26bba6a..822b209 100644
--- a/pkg/util/kubernetes/util.go
+++ b/pkg/util/kubernetes/core_client.go
@@ -20,54 +20,23 @@ package kubernetes
 import (
 	"context"
 	"fmt"
-	"regexp"
-	"strconv"
 
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/apimachinery/pkg/runtime"
-	"k8s.io/apimachinery/pkg/util/json"
 	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
-	"github.com/apache/camel-k/pkg/util"
 )
 
-var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
-
-// ToJSON --
-func ToJSON(value runtime.Object) ([]byte, error) {
-	return json.Marshal(value)
-}
-
-// ToYAML --
-func ToYAML(value runtime.Object) ([]byte, error) {
-	data, err := ToJSON(value)
-	if err != nil {
-		return nil, err
-	}
-
-	return util.JSONToYAML(data)
-}
-
-// GetConfigMap --
-func GetConfigMap(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.ConfigMap, error) {
+// GetIntegrationPlatform --
+func GetIntegrationPlatform(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationPlatform, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := corev1.ConfigMap{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "ConfigMap",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name,
-			Namespace: namespace,
-		},
-	}
+	answer := v1.NewIntegrationPlatform(namespace, name)
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -76,23 +45,14 @@ func GetConfigMap(context context.Context, client k8sclient.Reader, name string,
 	return &answer, nil
 }
 
-// GetSecret --
-func GetSecret(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.Secret, error) {
+// GetIntegrationKit --
+func GetIntegrationKit(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationKit, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := corev1.Secret{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "Secret",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name,
-			Namespace: namespace,
-		},
-	}
+	answer := v1.NewIntegrationKit(namespace, name)
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -101,14 +61,14 @@ func GetSecret(context context.Context, client k8sclient.Reader, name string, na
 	return &answer, nil
 }
 
-// GetIntegrationPlatform --
-func GetIntegrationPlatform(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationPlatform, error) {
+// GetIntegration --
+func GetIntegration(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.Integration, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := v1.NewIntegrationPlatform(namespace, name)
+	answer := v1.NewIntegration(namespace, name)
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -117,14 +77,14 @@ func GetIntegrationPlatform(context context.Context, client k8sclient.Reader, na
 	return &answer, nil
 }
 
-// GetIntegrationKit --
-func GetIntegrationKit(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationKit, error) {
+// GetBuild --
+func GetBuild(context context.Context, client client.Client, name string, namespace string) (*v1.Build, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := v1.NewIntegrationKit(namespace, name)
+	answer := v1.NewBuild(namespace, name)
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -133,14 +93,23 @@ func GetIntegrationKit(context context.Context, client k8sclient.Reader, name st
 	return &answer, nil
 }
 
-// GetIntegration --
-func GetIntegration(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.Integration, error) {
+// GetConfigMap --
+func GetConfigMap(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.ConfigMap, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := v1.NewIntegration(namespace, name)
+	answer := corev1.ConfigMap{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "ConfigMap",
+			APIVersion: "v1",
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      name,
+			Namespace: namespace,
+		},
+	}
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -149,14 +118,23 @@ func GetIntegration(context context.Context, client k8sclient.Reader, name strin
 	return &answer, nil
 }
 
-// GetBuild --
-func GetBuild(context context.Context, client client.Client, name string, namespace string) (*v1.Build, error) {
+// GetSecret --
+func GetSecret(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.Secret, error) {
 	key := k8sclient.ObjectKey{
 		Name:      name,
 		Namespace: namespace,
 	}
 
-	answer := v1.NewBuild(namespace, name)
+	answer := corev1.Secret{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "Secret",
+			APIVersion: "v1",
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      name,
+			Namespace: namespace,
+		},
+	}
 
 	if err := client.Get(context, key, &answer); err != nil {
 		return nil, err
@@ -232,37 +210,3 @@ func ResolveValueSource(ctx context.Context, client k8sclient.Reader, namespace
 
 	return "", nil
 }
-
-// GetTolerations build an array of Tolerations from an array of string
-func GetTolerations(taints []string) ([]corev1.Toleration, error) {
-	tolerations := make([]corev1.Toleration, 0)
-	for _, t := range taints {
-		if !validTaintRegexp.MatchString(t) {
-			return nil, fmt.Errorf("could not match taint %v", t)
-		}
-		toleration := corev1.Toleration{}
-		// Parse the regexp groups
-		groups := validTaintRegexp.FindStringSubmatch(t)
-		toleration.Key = groups[1]
-		if groups[2] != "" {
-			toleration.Operator = corev1.TolerationOpEqual
-		} else {
-			toleration.Operator = corev1.TolerationOpExists
-		}
-		if groups[3] != "" {
-			toleration.Value = groups[3]
-		}
-		toleration.Effect = corev1.TaintEffect(groups[4])
-
-		if groups[5] != "" {
-			tolerationSeconds, err := strconv.ParseInt(groups[5], 10, 64)
-			if err != nil {
-				return nil, err
-			}
-			toleration.TolerationSeconds = &tolerationSeconds
-		}
-		tolerations = append(tolerations, toleration)
-	}
-
-	return tolerations, nil
-}
diff --git a/pkg/util/kubernetes/core_factory.go b/pkg/util/kubernetes/core_factory.go
new file mode 100644
index 0000000..5ae1891
--- /dev/null
+++ b/pkg/util/kubernetes/core_factory.go
@@ -0,0 +1,62 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package kubernetes
+
+import (
+	"fmt"
+	"regexp"
+	"strconv"
+
+	corev1 "k8s.io/api/core/v1"
+)
+
+var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
+
+// GetTolerations build an array of Tolerations from an array of string
+func GetTolerations(taints []string) ([]corev1.Toleration, error) {
+	tolerations := make([]corev1.Toleration, 0)
+	for _, t := range taints {
+		if !validTaintRegexp.MatchString(t) {
+			return nil, fmt.Errorf("could not match taint %v", t)
+		}
+		toleration := corev1.Toleration{}
+		// Parse the regexp groups
+		groups := validTaintRegexp.FindStringSubmatch(t)
+		toleration.Key = groups[1]
+		if groups[2] != "" {
+			toleration.Operator = corev1.TolerationOpEqual
+		} else {
+			toleration.Operator = corev1.TolerationOpExists
+		}
+		if groups[3] != "" {
+			toleration.Value = groups[3]
+		}
+		toleration.Effect = corev1.TaintEffect(groups[4])
+
+		if groups[5] != "" {
+			tolerationSeconds, err := strconv.ParseInt(groups[5], 10, 64)
+			if err != nil {
+				return nil, err
+			}
+			toleration.TolerationSeconds = &tolerationSeconds
+		}
+		tolerations = append(tolerations, toleration)
+	}
+
+	return tolerations, nil
+}
diff --git a/pkg/util/kubernetes/util.go b/pkg/util/kubernetes/util.go
index 26bba6a..23d3401 100644
--- a/pkg/util/kubernetes/util.go
+++ b/pkg/util/kubernetes/util.go
@@ -18,24 +18,12 @@ limitations under the License.
 package kubernetes
 
 import (
-	"context"
-	"fmt"
-	"regexp"
-	"strconv"
-
-	corev1 "k8s.io/api/core/v1"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/util/json"
-	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
-	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/util"
 )
 
-var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
-
 // ToJSON --
 func ToJSON(value runtime.Object) ([]byte, error) {
 	return json.Marshal(value)
@@ -50,219 +38,3 @@ func ToYAML(value runtime.Object) ([]byte, error) {
 
 	return util.JSONToYAML(data)
 }
-
-// GetConfigMap --
-func GetConfigMap(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.ConfigMap, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := corev1.ConfigMap{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "ConfigMap",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name,
-			Namespace: namespace,
-		},
-	}
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetSecret --
-func GetSecret(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.Secret, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := corev1.Secret{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "Secret",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name,
-			Namespace: namespace,
-		},
-	}
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetIntegrationPlatform --
-func GetIntegrationPlatform(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationPlatform, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := v1.NewIntegrationPlatform(namespace, name)
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetIntegrationKit --
-func GetIntegrationKit(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.IntegrationKit, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := v1.NewIntegrationKit(namespace, name)
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetIntegration --
-func GetIntegration(context context.Context, client k8sclient.Reader, name string, namespace string) (*v1.Integration, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := v1.NewIntegration(namespace, name)
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetBuild --
-func GetBuild(context context.Context, client client.Client, name string, namespace string) (*v1.Build, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := v1.NewBuild(namespace, name)
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetService --
-func GetService(context context.Context, client k8sclient.Reader, name string, namespace string) (*corev1.Service, error) {
-	key := k8sclient.ObjectKey{
-		Name:      name,
-		Namespace: namespace,
-	}
-
-	answer := corev1.Service{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "Service",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name,
-			Namespace: namespace,
-		},
-	}
-
-	if err := client.Get(context, key, &answer); err != nil {
-		return nil, err
-	}
-
-	return &answer, nil
-}
-
-// GetSecretRefValue returns the value of a secret in the supplied namespace --
-func GetSecretRefValue(ctx context.Context, client k8sclient.Reader, namespace string, selector *corev1.SecretKeySelector) (string, error) {
-	secret, err := GetSecret(ctx, client, selector.Name, namespace)
-	if err != nil {
-		return "", err
-	}
-
-	if data, ok := secret.Data[selector.Key]; ok {
-		return string(data), nil
-	}
-
-	return "", fmt.Errorf("key %s not found in secret %s", selector.Key, selector.Name)
-}
-
-// GetConfigMapRefValue returns the value of a configmap in the supplied namespace
-func GetConfigMapRefValue(ctx context.Context, client k8sclient.Reader, namespace string, selector *corev1.ConfigMapKeySelector) (string, error) {
-	cm, err := GetConfigMap(ctx, client, selector.Name, namespace)
-	if err != nil {
-		return "", err
-	}
-
-	if data, ok := cm.Data[selector.Key]; ok {
-		return data, nil
-	}
-
-	return "", fmt.Errorf("key %s not found in config map %s", selector.Key, selector.Name)
-}
-
-// ResolveValueSource --
-func ResolveValueSource(ctx context.Context, client k8sclient.Reader, namespace string, valueSource *v1.ValueSource) (string, error) {
-	if valueSource.ConfigMapKeyRef != nil && valueSource.SecretKeyRef != nil {
-		return "", fmt.Errorf("value source has bot config map and secret configured")
-	}
-	if valueSource.ConfigMapKeyRef != nil {
-		return GetConfigMapRefValue(ctx, client, namespace, valueSource.ConfigMapKeyRef)
-	}
-	if valueSource.SecretKeyRef != nil {
-		return GetSecretRefValue(ctx, client, namespace, valueSource.SecretKeyRef)
-	}
-
-	return "", nil
-}
-
-// GetTolerations build an array of Tolerations from an array of string
-func GetTolerations(taints []string) ([]corev1.Toleration, error) {
-	tolerations := make([]corev1.Toleration, 0)
-	for _, t := range taints {
-		if !validTaintRegexp.MatchString(t) {
-			return nil, fmt.Errorf("could not match taint %v", t)
-		}
-		toleration := corev1.Toleration{}
-		// Parse the regexp groups
-		groups := validTaintRegexp.FindStringSubmatch(t)
-		toleration.Key = groups[1]
-		if groups[2] != "" {
-			toleration.Operator = corev1.TolerationOpEqual
-		} else {
-			toleration.Operator = corev1.TolerationOpExists
-		}
-		if groups[3] != "" {
-			toleration.Value = groups[3]
-		}
-		toleration.Effect = corev1.TaintEffect(groups[4])
-
-		if groups[5] != "" {
-			tolerationSeconds, err := strconv.ParseInt(groups[5], 10, 64)
-			if err != nil {
-				return nil, err
-			}
-			toleration.TolerationSeconds = &tolerationSeconds
-		}
-		tolerations = append(tolerations, toleration)
-	}
-
-	return tolerations, nil
-}

[camel-k] 01/03: feat(operator): toleration install flag

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 21e7ceb37da0262fb5ad4cf401cb52629ee839f3
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 11 14:34:33 2021 +0100

    feat(operator): toleration install flag
    
    * Refactored toleration trait to create Tolerations in a util method
    * Refactored OperatorOrCollect method to ease readability
    * Added toleration configuration in OLM and non OLM installations
---
 pkg/cmd/install.go          |   8 +-
 pkg/cmd/install_test.go     |  10 +++
 pkg/install/operator.go     | 180 ++++++++++++++++++++++++++------------------
 pkg/trait/toleration.go     |  40 +---------
 pkg/util/kubernetes/util.go |  38 ++++++++++
 pkg/util/olm/operator.go    |  19 ++++-
 6 files changed, 180 insertions(+), 115 deletions(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index a116c50..a6b7468 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -125,6 +125,9 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO
 	cmd.Flags().Bool("monitoring", false, "To enable or disable the operator monitoring")
 	cmd.Flags().Int("monitoring-port", 8080, "The port of the metrics endpoint")
 
+	// Pod settings
+	cmd.Flags().StringArrayP("toleration", "", nil, "Add a Toleration to the operator Pod")
+
 	// save
 	cmd.Flags().Bool("save", false, "Save the install parameters into the default kamel configuration file (kamel-config.yaml)")
 
@@ -169,6 +172,7 @@ type installCmdOptions struct {
 	MonitoringPort          int32    `mapstructure:"monitoring-port"`
 	Properties              []string `mapstructure:"properties"`
 	TraitProfile            string   `mapstructure:"trait-profile"`
+	Tolerations             []string `mapstructure:"tolerations"`
 	HTTPProxySecret         string   `mapstructure:"http-proxy-secret"`
 
 	registry         v1.IntegrationPlatformRegistrySpec
@@ -199,7 +203,6 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 		if olmAvailable, err = olm.IsAPIAvailable(o.Context, olmClient, o.Namespace); err != nil {
 			return errors.Wrap(err, "error while checking OLM availability. Run with '--olm=false' to skip this check")
 		}
-
 		if olmAvailable {
 			if installViaOLM, err = olm.HasPermissionToInstall(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions); err != nil {
 				return errors.Wrap(err, "error while checking permissions to install operator via OLM. Run with '--olm=false' to skip this check")
@@ -216,7 +219,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 		if installViaOLM {
 			fmt.Fprintln(cobraCmd.OutOrStdout(), "OLM is available in the cluster")
 			var installed bool
-			if installed, err = olm.Install(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions, collection); err != nil {
+			if installed, err = olm.Install(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions, collection, o.Tolerations); err != nil {
 				return err
 			}
 			if !installed {
@@ -267,6 +270,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 					Enabled: o.Monitoring,
 					Port:    o.MonitoringPort,
 				},
+				Tolerations: o.Tolerations,
 			}
 			err = install.OperatorOrCollect(o.Context, c, cfg, collection, o.Force)
 			if err != nil {
diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go
index 157430c..b26c3eb 100644
--- a/pkg/cmd/install_test.go
+++ b/pkg/cmd/install_test.go
@@ -371,3 +371,13 @@ func TestDecodeMavenSettings(t *testing.T) {
 	_, err = decodeMavenSettings("secret")
 	assert.NotNil(t, err)
 }
+
+func TestInstallTolerationFlag(t *testing.T) {
+	installCmdOptions, rootCmd, _ := initializeInstallCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdInstall,
+		"--toleration", "key1=value1:NoSchedule",
+		"--toleration", "key2=value2:NoExecute")
+	assert.Nil(t, err)
+	assert.Equal(t, "key1=value1:NoSchedule", installCmdOptions.Tolerations[0])
+	assert.Equal(t, "key2=value2:NoExecute", installCmdOptions.Tolerations[1])
+}
diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 2a650f8..397047b 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -31,6 +31,7 @@ import (
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/api/meta"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/util/intstr"
 
 	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -54,6 +55,7 @@ type OperatorConfiguration struct {
 	ClusterType           string
 	Health                OperatorHealthConfiguration
 	Monitoring            OperatorMonitoringConfiguration
+	Tolerations           []string
 }
 
 // OperatorHealthConfiguration --
@@ -70,81 +72,15 @@ type OperatorMonitoringConfiguration struct {
 // OperatorOrCollect installs the operator resources or adds them to the collector if present
 func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfiguration, collection *kubernetes.Collection, force bool) error {
 	customizer := func(o ctrl.Object) ctrl.Object {
-		if cfg.CustomImage != "" {
-			if d, ok := o.(*appsv1.Deployment); ok {
-				if d.Labels["camel.apache.org/component"] == "operator" {
-					d.Spec.Template.Spec.Containers[0].Image = cfg.CustomImage
-				}
-			}
-		}
-
-		if cfg.CustomImagePullPolicy != "" {
-			if d, ok := o.(*appsv1.Deployment); ok {
-				if d.Labels["camel.apache.org/component"] == "operator" {
-					d.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(cfg.CustomImagePullPolicy)
-				}
-			}
-		}
-
-		if d, ok := o.(*appsv1.Deployment); ok {
-			if d.Labels["camel.apache.org/component"] == "operator" {
-				// Metrics endpoint port
-				d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
-					fmt.Sprintf("--monitoring-port=%d", cfg.Monitoring.Port))
-				d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = cfg.Monitoring.Port
-				// Health endpoint port
-				d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
-					fmt.Sprintf("--health-port=%d", cfg.Health.Port))
-				d.Spec.Template.Spec.Containers[0].LivenessProbe.HTTPGet.Port = intstr.FromInt(int(cfg.Health.Port))
-			}
-		}
-
-		if cfg.Global {
-			if d, ok := o.(*appsv1.Deployment); ok {
-				if d.Labels["camel.apache.org/component"] == "operator" {
-					// Make the operator watch all namespaces
-					envvar.SetVal(&d.Spec.Template.Spec.Containers[0].Env, "WATCH_NAMESPACE", "")
-				}
-			}
-
-			// Turn Role & RoleBinding into their equivalent cluster types
-			if r, ok := o.(*rbacv1.Role); ok {
-				if strings.HasPrefix(r.Name, "camel-k-operator") {
-					o = &rbacv1.ClusterRole{
-						ObjectMeta: metav1.ObjectMeta{
-							Namespace: cfg.Namespace,
-							Name:      r.Name,
-							Labels: map[string]string{
-								"app": "camel-k",
-							},
-						},
-						Rules: r.Rules,
-					}
-				}
-			}
-
-			if rb, ok := o.(*rbacv1.RoleBinding); ok {
-				if strings.HasPrefix(rb.Name, "camel-k-operator") {
-					rb.Subjects[0].Namespace = cfg.Namespace
-
-					o = &rbacv1.ClusterRoleBinding{
-						ObjectMeta: metav1.ObjectMeta{
-							Namespace: cfg.Namespace,
-							Name:      rb.Name,
-							Labels: map[string]string{
-								"app": "camel-k",
-							},
-						},
-						Subjects: rb.Subjects,
-						RoleRef: rbacv1.RoleRef{
-							APIGroup: rb.RoleRef.APIGroup,
-							Kind:     "ClusterRole",
-							Name:     rb.RoleRef.Name,
-						},
-					}
-				}
-			}
+		operatorDeployment := operatorDeployment(o)
+		if operatorDeployment == nil {
+			return o
 		}
+		maybeSetCustomImage(cfg, operatorDeployment)
+		maybeSetCustomImagePullPolicy(cfg, operatorDeployment)
+		setPorts(cfg, operatorDeployment)
+		maybeSetGlobal(cfg, o)
+		maybeSetTolerations(cfg, operatorDeployment)
 		return o
 	}
 
@@ -237,6 +173,102 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
 	return nil
 }
 
+func operatorDeployment(o runtime.Object) *appsv1.Deployment {
+	if d, ok := o.(*appsv1.Deployment); ok {
+		if d.Labels["camel.apache.org/component"] == "operator" {
+			return d
+		}
+	}
+	return nil
+}
+
+func maybeSetCustomImage(cfg OperatorConfiguration, d *appsv1.Deployment) error {
+	if cfg.CustomImage != "" {
+		d.Spec.Template.Spec.Containers[0].Image = cfg.CustomImage
+	}
+	return nil
+}
+
+func maybeSetCustomImagePullPolicy(cfg OperatorConfiguration, d *appsv1.Deployment) error {
+	if cfg.CustomImagePullPolicy != "" {
+		d.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(cfg.CustomImagePullPolicy)
+	}
+	return nil
+}
+
+func maybeSetTolerations(cfg OperatorConfiguration, d *appsv1.Deployment) error {
+	if cfg.Tolerations != nil {
+		tolerations, err := kubernetes.GetTolerations(cfg.Tolerations)
+		if err != nil {
+			return err
+		}
+		d.Spec.Template.Spec.Tolerations = tolerations
+	}
+	return nil
+}
+
+func maybeSetGlobal(cfg OperatorConfiguration, o runtime.Object) error {
+	if cfg.Global {
+		if d, ok := o.(*appsv1.Deployment); ok {
+			if d.Labels["camel.apache.org/component"] == "operator" {
+				// Make the operator watch all namespaces
+				envvar.SetVal(&d.Spec.Template.Spec.Containers[0].Env, "WATCH_NAMESPACE", "")
+			}
+		}
+
+		// Turn Role & RoleBinding into their equivalent cluster types
+		if r, ok := o.(*rbacv1.Role); ok {
+			if strings.HasPrefix(r.Name, "camel-k-operator") {
+				o = &rbacv1.ClusterRole{
+					ObjectMeta: metav1.ObjectMeta{
+						Namespace: cfg.Namespace,
+						Name:      r.Name,
+						Labels: map[string]string{
+							"app": "camel-k",
+						},
+					},
+					Rules: r.Rules,
+				}
+			}
+		}
+
+		if rb, ok := o.(*rbacv1.RoleBinding); ok {
+			if strings.HasPrefix(rb.Name, "camel-k-operator") {
+				rb.Subjects[0].Namespace = cfg.Namespace
+
+				o = &rbacv1.ClusterRoleBinding{
+					ObjectMeta: metav1.ObjectMeta{
+						Namespace: cfg.Namespace,
+						Name:      rb.Name,
+						Labels: map[string]string{
+							"app": "camel-k",
+						},
+					},
+					Subjects: rb.Subjects,
+					RoleRef: rbacv1.RoleRef{
+						APIGroup: rb.RoleRef.APIGroup,
+						Kind:     "ClusterRole",
+						Name:     rb.RoleRef.Name,
+					},
+				}
+			}
+		}
+	}
+	return nil
+}
+
+func setPorts(cfg OperatorConfiguration, d *appsv1.Deployment) error {
+	// Metrics endpoint port
+	d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
+		fmt.Sprintf("--monitoring-port=%d", cfg.Monitoring.Port))
+	d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = cfg.Monitoring.Port
+	// Health endpoint port
+	d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
+		fmt.Sprintf("--health-port=%d", cfg.Health.Port))
+	d.Spec.Template.Spec.Containers[0].LivenessProbe.HTTPGet.Port = intstr.FromInt(int(cfg.Health.Port))
+	return nil
+}
+
 func installOpenShiftClusterRoleBinding(ctx context.Context, c client.Client, collection *kubernetes.Collection, namespace string) error {
 	var target *rbacv1.ClusterRoleBinding
 	existing, err := c.RbacV1().ClusterRoleBindings().Get(ctx, "camel-k-operator-openshift", metav1.GetOptions{})
diff --git a/pkg/trait/toleration.go b/pkg/trait/toleration.go
index c62bb7a..9b97c6e 100644
--- a/pkg/trait/toleration.go
+++ b/pkg/trait/toleration.go
@@ -19,13 +19,12 @@ package trait
 
 import (
 	"fmt"
-	"regexp"
-	"strconv"
 
 	corev1 "k8s.io/api/core/v1"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/util"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 )
 
 // This trait sets Tolerations over Integration pods. Tolerations allow (but do not require) the pods to schedule onto nodes with matching taints.
@@ -48,8 +47,6 @@ type tolerationTrait struct {
 	Taints []string `property:"taints" json:"taints,omitempty"`
 }
 
-var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
-
 func newTolerationTrait() Trait {
 	return &tolerationTrait{
 		BaseTrait: NewBaseTrait("toleration", 1200),
@@ -69,7 +66,7 @@ func (t *tolerationTrait) Configure(e *Environment) (bool, error) {
 }
 
 func (t *tolerationTrait) Apply(e *Environment) (err error) {
-	tolerations, err := t.getTolerations()
+	tolerations, err := kubernetes.GetTolerations(t.Taints)
 	if err != nil {
 		return err
 	}
@@ -84,36 +81,3 @@ func (t *tolerationTrait) Apply(e *Environment) (err error) {
 	podSpec.Tolerations = append(podSpec.Tolerations, tolerations...)
 	return nil
 }
-
-func (t *tolerationTrait) getTolerations() ([]corev1.Toleration, error) {
-	tolerations := make([]corev1.Toleration, 0)
-	for _, t := range t.Taints {
-		if !validTaintRegexp.MatchString(t) {
-			return nil, fmt.Errorf("could not match taint %v", t)
-		}
-		toleration := corev1.Toleration{}
-		// Parse the regexp groups
-		groups := validTaintRegexp.FindStringSubmatch(t)
-		toleration.Key = groups[1]
-		if groups[2] != "" {
-			toleration.Operator = corev1.TolerationOpEqual
-		} else {
-			toleration.Operator = corev1.TolerationOpExists
-		}
-		if groups[3] != "" {
-			toleration.Value = groups[3]
-		}
-		toleration.Effect = corev1.TaintEffect(groups[4])
-
-		if groups[5] != "" {
-			tolerationSeconds, err := strconv.ParseInt(groups[5], 10, 64)
-			if err != nil {
-				return nil, err
-			}
-			toleration.TolerationSeconds = &tolerationSeconds
-		}
-		tolerations = append(tolerations, toleration)
-	}
-
-	return tolerations, nil
-}
diff --git a/pkg/util/kubernetes/util.go b/pkg/util/kubernetes/util.go
index 0ce1517..26bba6a 100644
--- a/pkg/util/kubernetes/util.go
+++ b/pkg/util/kubernetes/util.go
@@ -20,6 +20,8 @@ package kubernetes
 import (
 	"context"
 	"fmt"
+	"regexp"
+	"strconv"
 
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -32,6 +34,8 @@ import (
 	"github.com/apache/camel-k/pkg/util"
 )
 
+var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
+
 // ToJSON --
 func ToJSON(value runtime.Object) ([]byte, error) {
 	return json.Marshal(value)
@@ -228,3 +232,37 @@ func ResolveValueSource(ctx context.Context, client k8sclient.Reader, namespace
 
 	return "", nil
 }
+
+// GetTolerations build an array of Tolerations from an array of string
+func GetTolerations(taints []string) ([]corev1.Toleration, error) {
+	tolerations := make([]corev1.Toleration, 0)
+	for _, t := range taints {
+		if !validTaintRegexp.MatchString(t) {
+			return nil, fmt.Errorf("could not match taint %v", t)
+		}
+		toleration := corev1.Toleration{}
+		// Parse the regexp groups
+		groups := validTaintRegexp.FindStringSubmatch(t)
+		toleration.Key = groups[1]
+		if groups[2] != "" {
+			toleration.Operator = corev1.TolerationOpEqual
+		} else {
+			toleration.Operator = corev1.TolerationOpExists
+		}
+		if groups[3] != "" {
+			toleration.Value = groups[3]
+		}
+		toleration.Effect = corev1.TaintEffect(groups[4])
+
+		if groups[5] != "" {
+			tolerationSeconds, err := strconv.ParseInt(groups[5], 10, 64)
+			if err != nil {
+				return nil, err
+			}
+			toleration.TolerationSeconds = &tolerationSeconds
+		}
+		tolerations = append(tolerations, toleration)
+	}
+
+	return tolerations, nil
+}
diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go
index a01a2f0..360cc15 100644
--- a/pkg/util/olm/operator.go
+++ b/pkg/util/olm/operator.go
@@ -138,7 +138,7 @@ func HasPermissionToInstall(ctx context.Context, client client.Client, namespace
 }
 
 // Install creates a subscription for the OLM package
-func Install(ctx context.Context, client client.Client, namespace string, global bool, options Options, collection *kubernetes.Collection) (bool, error) {
+func Install(ctx context.Context, client client.Client, namespace string, global bool, options Options, collection *kubernetes.Collection, tolerations []string) (bool, error) {
 	options = fillDefaults(options)
 	if installed, err := IsOperatorInstalled(ctx, client, namespace, global, options); err != nil {
 		return false, err
@@ -166,6 +166,12 @@ func Install(ctx context.Context, client client.Client, namespace string, global
 			InstallPlanApproval:    operatorsv1alpha1.ApprovalAutomatic,
 		},
 	}
+	// Additional configuration
+	err := maybeSetTolerations(&sub, tolerations)
+	if err != nil {
+		return false, errors.Wrap(err, fmt.Sprintf("could not set tolerations"))
+	}
+
 	if collection != nil {
 		collection.Add(&sub)
 	} else if err := client.Create(ctx, &sub); err != nil {
@@ -199,6 +205,17 @@ func Install(ctx context.Context, client client.Client, namespace string, global
 	return true, nil
 }
 
+func maybeSetTolerations(sub *operatorsv1alpha1.Subscription, tolArray []string) error {
+	if tolArray != nil {
+		tolerations, err := kubernetes.GetTolerations(tolArray)
+		if err != nil {
+			return err
+		}
+		sub.Spec.Config.Tolerations = tolerations
+	}
+	return nil
+}
+
 // Uninstall removes CSV and subscription from the namespace
 func Uninstall(ctx context.Context, client client.Client, namespace string, global bool, options Options) error {
 	sub, err := findSubscription(ctx, client, namespace, global, options)

[camel-k] 03/03: feat(operator): revert OperatorOrCollect Reverted from c407bbd885c82d23d4baab48f8c59e946a7201fd change

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cb19602c6367a0d7d0f559623ffc7456163bad79
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Mar 22 14:48:55 2021 +0100

    feat(operator): revert OperatorOrCollect
    Reverted from c407bbd885c82d23d4baab48f8c59e946a7201fd change
---
 pkg/install/operator.go | 191 ++++++++++++++++++++++--------------------------
 1 file changed, 86 insertions(+), 105 deletions(-)

diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 397047b..9798d1a 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -31,7 +31,6 @@ import (
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/api/meta"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/util/intstr"
 
 	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -72,15 +71,93 @@ type OperatorMonitoringConfiguration struct {
 // OperatorOrCollect installs the operator resources or adds them to the collector if present
 func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfiguration, collection *kubernetes.Collection, force bool) error {
 	customizer := func(o ctrl.Object) ctrl.Object {
-		operatorDeployment := operatorDeployment(o)
-		if operatorDeployment == nil {
-			return o
+		if cfg.CustomImage != "" {
+			if d, ok := o.(*appsv1.Deployment); ok {
+				if d.Labels["camel.apache.org/component"] == "operator" {
+					d.Spec.Template.Spec.Containers[0].Image = cfg.CustomImage
+				}
+			}
+		}
+
+		if cfg.CustomImagePullPolicy != "" {
+			if d, ok := o.(*appsv1.Deployment); ok {
+				if d.Labels["camel.apache.org/component"] == "operator" {
+					d.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(cfg.CustomImagePullPolicy)
+				}
+			}
+		}
+
+		if cfg.Tolerations != nil {
+			if d, ok := o.(*appsv1.Deployment); ok {
+				if d.Labels["camel.apache.org/component"] == "operator" {
+					tolerations, err := kubernetes.GetTolerations(cfg.Tolerations)
+					if err != nil {
+						fmt.Println("Warning: could not parse the configured tolerations!")
+					}
+					d.Spec.Template.Spec.Tolerations = tolerations
+				}
+			}
+		}
+
+		if d, ok := o.(*appsv1.Deployment); ok {
+			if d.Labels["camel.apache.org/component"] == "operator" {
+				// Metrics endpoint port
+				d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
+					fmt.Sprintf("--monitoring-port=%d", cfg.Monitoring.Port))
+				d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = cfg.Monitoring.Port
+				// Health endpoint port
+				d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
+					fmt.Sprintf("--health-port=%d", cfg.Health.Port))
+				d.Spec.Template.Spec.Containers[0].LivenessProbe.HTTPGet.Port = intstr.FromInt(int(cfg.Health.Port))
+			}
+		}
+
+		if cfg.Global {
+			if d, ok := o.(*appsv1.Deployment); ok {
+				if d.Labels["camel.apache.org/component"] == "operator" {
+					// Make the operator watch all namespaces
+					envvar.SetVal(&d.Spec.Template.Spec.Containers[0].Env, "WATCH_NAMESPACE", "")
+				}
+			}
+
+			// Turn Role & RoleBinding into their equivalent cluster types
+			if r, ok := o.(*rbacv1.Role); ok {
+				if strings.HasPrefix(r.Name, "camel-k-operator") {
+					o = &rbacv1.ClusterRole{
+						ObjectMeta: metav1.ObjectMeta{
+							Namespace: cfg.Namespace,
+							Name:      r.Name,
+							Labels: map[string]string{
+								"app": "camel-k",
+							},
+						},
+						Rules: r.Rules,
+					}
+				}
+			}
+
+			if rb, ok := o.(*rbacv1.RoleBinding); ok {
+				if strings.HasPrefix(rb.Name, "camel-k-operator") {
+					rb.Subjects[0].Namespace = cfg.Namespace
+
+					o = &rbacv1.ClusterRoleBinding{
+						ObjectMeta: metav1.ObjectMeta{
+							Namespace: cfg.Namespace,
+							Name:      rb.Name,
+							Labels: map[string]string{
+								"app": "camel-k",
+							},
+						},
+						Subjects: rb.Subjects,
+						RoleRef: rbacv1.RoleRef{
+							APIGroup: rb.RoleRef.APIGroup,
+							Kind:     "ClusterRole",
+							Name:     rb.RoleRef.Name,
+						},
+					}
+				}
+			}
 		}
-		maybeSetCustomImage(cfg, operatorDeployment)
-		maybeSetCustomImagePullPolicy(cfg, operatorDeployment)
-		setPorts(cfg, operatorDeployment)
-		maybeSetGlobal(cfg, o)
-		maybeSetTolerations(cfg, operatorDeployment)
 		return o
 	}
 
@@ -173,102 +250,6 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
 	return nil
 }
 
-func operatorDeployment(o runtime.Object) *appsv1.Deployment {
-	if d, ok := o.(*appsv1.Deployment); ok {
-		if d.Labels["camel.apache.org/component"] == "operator" {
-			return d
-		}
-	}
-	return nil
-}
-
-func maybeSetCustomImage(cfg OperatorConfiguration, d *appsv1.Deployment) error {
-	if cfg.CustomImage != "" {
-		d.Spec.Template.Spec.Containers[0].Image = cfg.CustomImage
-	}
-	return nil
-}
-
-func maybeSetCustomImagePullPolicy(cfg OperatorConfiguration, d *appsv1.Deployment) error {
-	if cfg.CustomImagePullPolicy != "" {
-		d.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(cfg.CustomImagePullPolicy)
-	}
-	return nil
-}
-
-func maybeSetTolerations(cfg OperatorConfiguration, d *appsv1.Deployment) error {
-	if cfg.Tolerations != nil {
-		tolerations, err := kubernetes.GetTolerations(cfg.Tolerations)
-		if err != nil {
-			return err
-		}
-		d.Spec.Template.Spec.Tolerations = tolerations
-	}
-	return nil
-}
-
-func maybeSetGlobal(cfg OperatorConfiguration, o runtime.Object) error {
-	if cfg.Global {
-		if d, ok := o.(*appsv1.Deployment); ok {
-			if d.Labels["camel.apache.org/component"] == "operator" {
-				// Make the operator watch all namespaces
-				envvar.SetVal(&d.Spec.Template.Spec.Containers[0].Env, "WATCH_NAMESPACE", "")
-			}
-		}
-
-		// Turn Role & RoleBinding into their equivalent cluster types
-		if r, ok := o.(*rbacv1.Role); ok {
-			if strings.HasPrefix(r.Name, "camel-k-operator") {
-				o = &rbacv1.ClusterRole{
-					ObjectMeta: metav1.ObjectMeta{
-						Namespace: cfg.Namespace,
-						Name:      r.Name,
-						Labels: map[string]string{
-							"app": "camel-k",
-						},
-					},
-					Rules: r.Rules,
-				}
-			}
-		}
-
-		if rb, ok := o.(*rbacv1.RoleBinding); ok {
-			if strings.HasPrefix(rb.Name, "camel-k-operator") {
-				rb.Subjects[0].Namespace = cfg.Namespace
-
-				o = &rbacv1.ClusterRoleBinding{
-					ObjectMeta: metav1.ObjectMeta{
-						Namespace: cfg.Namespace,
-						Name:      rb.Name,
-						Labels: map[string]string{
-							"app": "camel-k",
-						},
-					},
-					Subjects: rb.Subjects,
-					RoleRef: rbacv1.RoleRef{
-						APIGroup: rb.RoleRef.APIGroup,
-						Kind:     "ClusterRole",
-						Name:     rb.RoleRef.Name,
-					},
-				}
-			}
-		}
-	}
-	return nil
-}
-
-func setPorts(cfg OperatorConfiguration, d *appsv1.Deployment) error {
-	// Metrics endpoint port
-	d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
-		fmt.Sprintf("--monitoring-port=%d", cfg.Monitoring.Port))
-	d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = cfg.Monitoring.Port
-	// Health endpoint port
-	d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
-		fmt.Sprintf("--health-port=%d", cfg.Health.Port))
-	d.Spec.Template.Spec.Containers[0].LivenessProbe.HTTPGet.Port = intstr.FromInt(int(cfg.Health.Port))
-	return nil
-}
-
 func installOpenShiftClusterRoleBinding(ctx context.Context, c client.Client, collection *kubernetes.Collection, namespace string) error {
 	var target *rbacv1.ClusterRoleBinding
 	existing, err := c.RbacV1().ClusterRoleBindings().Get(ctx, "camel-k-operator-openshift", metav1.GetOptions{})