From 2d2bc006e9946523f4f421c3e6c512a330ca15d4 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Mon, 12 Apr 2021 10:46:58 +0200 Subject: [PATCH] refactor(util): factory naming convention --- pkg/install/operator.go | 2 +- pkg/util/kubernetes/factory.go | 6 +++--- .../{core_factory_test.go => factory_test.go} | 12 ++++++------ pkg/util/olm/operator.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) rename pkg/util/kubernetes/{core_factory_test.go => factory_test.go} (94%) diff --git a/pkg/install/operator.go b/pkg/install/operator.go index 3442c829df..50d4e5b351 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 af9266d68b..956627c1e0 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 2a751e23ed..1bda9f3431 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 74970d03f5..bb9ce2af8a 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 }