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/04/12 11:59:01 UTC

[camel-k] branch master updated (dad0c47 -> 2d2bc00)

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 dad0c47  chore: pass configuration variable with empty value
     new 1997acd  chore(operator): core_factory unit test
     new 4af9bd3  core(operator): NodeSelector factory
     new 654e039  feat(operator): provide operator NodeSelector
     new dd2ca05  feat(operator): provide OLM NodeSelector
     new 2d2bc00  refactor(util): factory naming convention

The 5 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                  |   7 +-
 pkg/install/operator.go             |  13 ++++
 pkg/util/kubernetes/factory.go      |  17 ++++-
 pkg/util/kubernetes/factory_test.go | 136 ++++++++++++++++++++++++++++++++++++
 pkg/util/olm/operator.go            |  17 ++++-
 5 files changed, 186 insertions(+), 4 deletions(-)
 create mode 100644 pkg/util/kubernetes/factory_test.go

[camel-k] 03/05: feat(operator): provide operator NodeSelector

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 654e039c77e5fbeb3f1bcb1ae8bf8e9e367a7110
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 26 12:51:14 2021 +0100

    feat(operator): provide operator NodeSelector
    
    Adding a flag to allow defining any NodeSelector during regular installation procedure
---
 pkg/cmd/install.go      |  5 ++++-
 pkg/install/operator.go | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 0adbac4..e3ec076 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -128,6 +128,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO
 
 	// Pod settings
 	cmd.Flags().StringArrayP("toleration", "", nil, "Add a Toleration to the operator Pod")
+	cmd.Flags().StringArrayP("node-selector", "", nil, "Add a NodeSelector to the operator Pod")
 
 	// save
 	cmd.Flags().Bool("save", false, "Save the install parameters into the default kamel configuration file (kamel-config.yaml)")
@@ -175,6 +176,7 @@ type installCmdOptions struct {
 	Properties              []string `mapstructure:"properties"`
 	TraitProfile            string   `mapstructure:"trait-profile"`
 	Tolerations             []string `mapstructure:"tolerations"`
+	NodeSelectors           []string `mapstructure:"node-selectors"`
 	HTTPProxySecret         string   `mapstructure:"http-proxy-secret"`
 
 	registry         v1.IntegrationPlatformRegistrySpec
@@ -272,7 +274,8 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 					Enabled: o.Monitoring,
 					Port:    o.MonitoringPort,
 				},
-				Tolerations: o.Tolerations,
+				Tolerations:   o.Tolerations,
+				NodeSelectors: o.NodeSelectors,
 			}
 			err = install.OperatorOrCollect(o.Context, c, cfg, collection, o.Force)
 			if err != nil {
diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 1fc6cf7..3442c82 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -55,6 +55,7 @@ type OperatorConfiguration struct {
 	Health                OperatorHealthConfiguration
 	Monitoring            OperatorMonitoringConfiguration
 	Tolerations           []string
+	NodeSelectors         []string
 }
 
 // OperatorHealthConfiguration --
@@ -99,6 +100,18 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
 			}
 		}
 
+		if cfg.NodeSelectors != nil {
+			if d, ok := o.(*appsv1.Deployment); ok {
+				if d.Labels["camel.apache.org/component"] == "operator" {
+					nodeSelector, err := kubernetes.GetNodeSelectors(cfg.NodeSelectors)
+					if err != nil {
+						fmt.Println("Warning: could not parse the configured node selectors!")
+					}
+					d.Spec.Template.Spec.NodeSelector = nodeSelector
+				}
+			}
+		}
+
 		if d, ok := o.(*appsv1.Deployment); ok {
 			if d.Labels["camel.apache.org/component"] == "operator" {
 				// Metrics endpoint port

[camel-k] 02/05: core(operator): NodeSelector factory

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 4af9bd3e5769e57cd4e86bde43dfea6352db406c
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 26 12:49:32 2021 +0100

    core(operator): NodeSelector factory
    
    Adding a factory to simplify creation of NodeSelectors and related unit tests
---
 pkg/util/kubernetes/core_factory_test.go | 39 ++++++++++++++++++++++++++++++++
 pkg/util/kubernetes/factory.go           | 15 ++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/pkg/util/kubernetes/core_factory_test.go b/pkg/util/kubernetes/core_factory_test.go
index 9903246..2a751e2 100644
--- a/pkg/util/kubernetes/core_factory_test.go
+++ b/pkg/util/kubernetes/core_factory_test.go
@@ -95,3 +95,42 @@ func TestValueTolerations(t *testing.T) {
 	assert.Equal(t, v1.TaintEffectNoSchedule, toleration[3].Effect)
 	assert.Equal(t, int64(120), *toleration[3].TolerationSeconds)
 }
+
+func TestValidNodeSelectors(t *testing.T) {
+	validNodeSelectors := [][]string{
+		{"key1=value"},
+		{"kubernetes.io/hostname=worker0"},
+		{"disktype=ssd"},
+		{"key=path-to-value"},
+		{"keyNum=123"},
+	}
+	for _, vds := range validNodeSelectors {
+		_, err := GetNodeSelectors(vds)
+		assert.Nil(t, err)
+	}
+}
+
+func TestInvalidNodeSelectors(t *testing.T) {
+	validNodeSelectors := [][]string{
+		{"key1"},
+		{"kubernetes.io@hostname=worker0"},
+		{"key=path/to/value"},
+	}
+	for _, vds := range validNodeSelectors {
+		_, err := GetNodeSelectors(vds)
+		assert.NotNil(t, err)
+	}
+}
+
+func TestValueNodeSelectors(t *testing.T) {
+	nodeSelectorsArray := []string{
+		"key=value",
+		"kubernetes.io/hostname=worker0",
+	}
+	nodeSelectors, err := GetNodeSelectors(nodeSelectorsArray)
+	assert.Nil(t, err)
+	assert.Equal(t, 2, len(nodeSelectors))
+
+	assert.Equal(t, "value", nodeSelectors["key"])
+	assert.Equal(t, "worker0", nodeSelectors["kubernetes.io/hostname"])
+}
diff --git a/pkg/util/kubernetes/factory.go b/pkg/util/kubernetes/factory.go
index a85c472..af9266d 100644
--- a/pkg/util/kubernetes/factory.go
+++ b/pkg/util/kubernetes/factory.go
@@ -26,6 +26,7 @@ import (
 )
 
 var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
+var validNodeSelectorRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)=([\w_\-\.]+)$`)
 
 // GetTolerations build an array of Tolerations from an array of string
 func NewTolerations(taints []string) ([]corev1.Toleration, error) {
@@ -60,3 +61,17 @@ func NewTolerations(taints []string) ([]corev1.Toleration, error) {
 
 	return tolerations, nil
 }
+
+// GetNodeSelectors build a map of NodeSelectors from an array of string
+func GetNodeSelectors(nsArray []string) (map[string]string, error) {
+	nodeSelectors := make(map[string]string)
+	for _, ns := range nsArray {
+		if !validNodeSelectorRegexp.MatchString(ns) {
+			return nil, fmt.Errorf("could not match node selector %v", ns)
+		}
+		// Parse the regexp groups
+		groups := validNodeSelectorRegexp.FindStringSubmatch(ns)
+		nodeSelectors[groups[1]] = groups[2]
+	}
+	return nodeSelectors, nil
+}

[camel-k] 01/05: chore(operator): core_factory unit test

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 1997acdcd526bf039f4eefbecb0b27f2929211b4
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 26 12:16:27 2021 +0100

    chore(operator): core_factory unit test
---
 pkg/util/kubernetes/core_factory_test.go | 97 ++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/pkg/util/kubernetes/core_factory_test.go b/pkg/util/kubernetes/core_factory_test.go
new file mode 100644
index 0000000..9903246
--- /dev/null
+++ b/pkg/util/kubernetes/core_factory_test.go
@@ -0,0 +1,97 @@
+/*
+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 (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	v1 "k8s.io/api/core/v1"
+)
+
+func TestValidTolerations(t *testing.T) {
+	validTolerations := [][]string{
+		{"key=value:NoSchedule"},
+		{"key=value:NoExecute"},
+		{"key=value:PreferNoSchedule"},
+		{"key=value:NoSchedule:120"},
+		{"key=value:NoExecute:120"},
+		{"key=value:PreferNoSchedule:120"},
+		{"existKey:NoSchedule"},
+		{"existKey:NoExecute"},
+		{"existKey:PreferNoSchedule"},
+		{"existKey:NoSchedule:120"},
+		{"existKey:NoExecute:120"},
+		{"existKey:PreferNoSchedule:120"},
+	}
+	for _, vd := range validTolerations {
+		_, err := GetTolerations(vd)
+		assert.Nil(t, err)
+	}
+}
+
+func TestInvalidTolerations(t *testing.T) {
+	validTolerations := [][]string{
+		{"key-NoSchedule"},
+		{"key=value:Something"},
+		{"key@wrong=value:PreferNoSchedule"},
+		{"key=value%wrong:NoSchedule:120"},
+		{"existKey"},
+		{"existKey:"},
+		{"existKey:Something"},
+		{"existKey:PreferNoSchedule:something"},
+	}
+	for _, vd := range validTolerations {
+		_, err := GetTolerations(vd)
+		assert.NotNil(t, err)
+	}
+}
+
+func TestValueTolerations(t *testing.T) {
+	tolerations := []string{
+		"key=value:NoSchedule",
+		"key=value:NoExecute:120",
+		"existKey:PreferNoSchedule",
+		"existKey:NoSchedule:120",
+	}
+	toleration, err := GetTolerations(tolerations)
+	assert.Nil(t, err)
+	assert.Equal(t, 4, len(toleration))
+
+	assert.Equal(t, "key", toleration[0].Key)
+	assert.Equal(t, v1.TolerationOpEqual, toleration[0].Operator)
+	assert.Equal(t, "value", toleration[0].Value)
+	assert.Equal(t, v1.TaintEffectNoSchedule, toleration[0].Effect)
+
+	assert.Equal(t, "key", toleration[1].Key)
+	assert.Equal(t, v1.TolerationOpEqual, toleration[1].Operator)
+	assert.Equal(t, "value", toleration[1].Value)
+	assert.Equal(t, v1.TaintEffectNoExecute, toleration[1].Effect)
+	assert.Equal(t, int64(120), *toleration[1].TolerationSeconds)
+
+	assert.Equal(t, "existKey", toleration[2].Key)
+	assert.Equal(t, v1.TolerationOpExists, toleration[2].Operator)
+	assert.Equal(t, "", toleration[2].Value)
+	assert.Equal(t, v1.TaintEffectPreferNoSchedule, toleration[2].Effect)
+
+	assert.Equal(t, "existKey", toleration[3].Key)
+	assert.Equal(t, v1.TolerationOpExists, toleration[3].Operator)
+	assert.Equal(t, "", toleration[3].Value)
+	assert.Equal(t, v1.TaintEffectNoSchedule, toleration[3].Effect)
+	assert.Equal(t, int64(120), *toleration[3].TolerationSeconds)
+}

[camel-k] 05/05: refactor(util): factory naming convention

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 2d2bc006e9946523f4f421c3e6c512a330ca15d4
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Apr 12 10:46:58 2021 +0200

    refactor(util): factory naming convention
---
 pkg/install/operator.go                                      |  2 +-
 pkg/util/kubernetes/factory.go                               |  6 +++---
 .../kubernetes/{core_factory_test.go => factory_test.go}     | 12 ++++++------
 pkg/util/olm/operator.go                                     |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 3442c82..50d4e5b 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -103,7 +103,7 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
 		if cfg.NodeSelectors != nil {
 			if d, ok := o.(*appsv1.Deployment); ok {
 				if d.Labels["camel.apache.org/component"] == "operator" {
-					nodeSelector, err := kubernetes.GetNodeSelectors(cfg.NodeSelectors)
+					nodeSelector, err := kubernetes.NewNodeSelectors(cfg.NodeSelectors)
 					if err != nil {
 						fmt.Println("Warning: could not parse the configured node selectors!")
 					}
diff --git a/pkg/util/kubernetes/factory.go b/pkg/util/kubernetes/factory.go
index af9266d..956627c 100644
--- a/pkg/util/kubernetes/factory.go
+++ b/pkg/util/kubernetes/factory.go
@@ -28,7 +28,7 @@ import (
 var validTaintRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)(=)?([\w_\-\.]+)?:(NoSchedule|NoExecute|PreferNoSchedule):?(\d*)?$`)
 var validNodeSelectorRegexp = regexp.MustCompile(`^([\w\/_\-\.]+)=([\w_\-\.]+)$`)
 
-// GetTolerations build an array of Tolerations from an array of string
+// NewTolerations build an array of Tolerations from an array of string
 func NewTolerations(taints []string) ([]corev1.Toleration, error) {
 	tolerations := make([]corev1.Toleration, 0)
 	for _, t := range taints {
@@ -62,8 +62,8 @@ func NewTolerations(taints []string) ([]corev1.Toleration, error) {
 	return tolerations, nil
 }
 
-// GetNodeSelectors build a map of NodeSelectors from an array of string
-func GetNodeSelectors(nsArray []string) (map[string]string, error) {
+// NewNodeSelectors build a map of NodeSelectors from an array of string
+func NewNodeSelectors(nsArray []string) (map[string]string, error) {
 	nodeSelectors := make(map[string]string)
 	for _, ns := range nsArray {
 		if !validNodeSelectorRegexp.MatchString(ns) {
diff --git a/pkg/util/kubernetes/core_factory_test.go b/pkg/util/kubernetes/factory_test.go
similarity index 94%
rename from pkg/util/kubernetes/core_factory_test.go
rename to pkg/util/kubernetes/factory_test.go
index 2a751e2..1bda9f3 100644
--- a/pkg/util/kubernetes/core_factory_test.go
+++ b/pkg/util/kubernetes/factory_test.go
@@ -40,7 +40,7 @@ func TestValidTolerations(t *testing.T) {
 		{"existKey:PreferNoSchedule:120"},
 	}
 	for _, vd := range validTolerations {
-		_, err := GetTolerations(vd)
+		_, err := NewTolerations(vd)
 		assert.Nil(t, err)
 	}
 }
@@ -57,7 +57,7 @@ func TestInvalidTolerations(t *testing.T) {
 		{"existKey:PreferNoSchedule:something"},
 	}
 	for _, vd := range validTolerations {
-		_, err := GetTolerations(vd)
+		_, err := NewTolerations(vd)
 		assert.NotNil(t, err)
 	}
 }
@@ -69,7 +69,7 @@ func TestValueTolerations(t *testing.T) {
 		"existKey:PreferNoSchedule",
 		"existKey:NoSchedule:120",
 	}
-	toleration, err := GetTolerations(tolerations)
+	toleration, err := NewTolerations(tolerations)
 	assert.Nil(t, err)
 	assert.Equal(t, 4, len(toleration))
 
@@ -105,7 +105,7 @@ func TestValidNodeSelectors(t *testing.T) {
 		{"keyNum=123"},
 	}
 	for _, vds := range validNodeSelectors {
-		_, err := GetNodeSelectors(vds)
+		_, err := NewNodeSelectors(vds)
 		assert.Nil(t, err)
 	}
 }
@@ -117,7 +117,7 @@ func TestInvalidNodeSelectors(t *testing.T) {
 		{"key=path/to/value"},
 	}
 	for _, vds := range validNodeSelectors {
-		_, err := GetNodeSelectors(vds)
+		_, err := NewNodeSelectors(vds)
 		assert.NotNil(t, err)
 	}
 }
@@ -127,7 +127,7 @@ func TestValueNodeSelectors(t *testing.T) {
 		"key=value",
 		"kubernetes.io/hostname=worker0",
 	}
-	nodeSelectors, err := GetNodeSelectors(nodeSelectorsArray)
+	nodeSelectors, err := NewNodeSelectors(nodeSelectorsArray)
 	assert.Nil(t, err)
 	assert.Equal(t, 2, len(nodeSelectors))
 
diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go
index 74970d0..bb9ce2a 100644
--- a/pkg/util/olm/operator.go
+++ b/pkg/util/olm/operator.go
@@ -222,7 +222,7 @@ func maybeSetTolerations(sub *operatorsv1alpha1.Subscription, tolArray []string)
 
 func maybeSetNodeSelectors(sub *operatorsv1alpha1.Subscription, nsArray []string) error {
 	if nsArray != nil {
-		nodeSelectors, err := kubernetes.GetNodeSelectors(nsArray)
+		nodeSelectors, err := kubernetes.NewNodeSelectors(nsArray)
 		if err != nil {
 			return err
 		}

[camel-k] 04/05: feat(operator): provide OLM NodeSelector

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 dd2ca05e181612ebbf5ecad67a1a3f15d5120733
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 26 12:51:50 2021 +0100

    feat(operator): provide OLM NodeSelector
    
    Adding a flag to allow defining any NodeSelector during OLM installation procedure
---
 pkg/cmd/install.go       |  2 +-
 pkg/util/olm/operator.go | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index e3ec076..1692c15 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -223,7 +223,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, o.Tolerations); err != nil {
+			if installed, err = olm.Install(o.Context, olmClient, o.Namespace, o.Global, o.olmOptions, collection, o.Tolerations, o.NodeSelectors); err != nil {
 				return err
 			}
 			if !installed {
diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go
index 896b241..74970d0 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, tolerations []string) (bool, error) {
+func Install(ctx context.Context, client client.Client, namespace string, global bool, options Options, collection *kubernetes.Collection, tolerations []string, nodeSelectors []string) (bool, error) {
 	options = fillDefaults(options)
 	if installed, err := IsOperatorInstalled(ctx, client, namespace, global, options); err != nil {
 		return false, err
@@ -171,6 +171,10 @@ func Install(ctx context.Context, client client.Client, namespace string, global
 	if err != nil {
 		return false, errors.Wrap(err, fmt.Sprintf("could not set tolerations"))
 	}
+	err = maybeSetNodeSelectors(&sub, nodeSelectors)
+	if err != nil {
+		return false, errors.Wrap(err, fmt.Sprintf("could not set node selectors"))
+	}
 
 	if collection != nil {
 		collection.Add(&sub)
@@ -216,6 +220,17 @@ func maybeSetTolerations(sub *operatorsv1alpha1.Subscription, tolArray []string)
 	return nil
 }
 
+func maybeSetNodeSelectors(sub *operatorsv1alpha1.Subscription, nsArray []string) error {
+	if nsArray != nil {
+		nodeSelectors, err := kubernetes.GetNodeSelectors(nsArray)
+		if err != nil {
+			return err
+		}
+		sub.Spec.Config.NodeSelector = nodeSelectors
+	}
+	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)