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:25 UTC
[camel-k] 03/03: feat(operator): revert OperatorOrCollect Reverted
from c407bbd885c82d23d4baab48f8c59e946a7201fd change
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{})