Skip to content

Commit

Permalink
refactor(util): factory naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez authored and astefanutti committed Apr 12, 2021
1 parent dd2ca05 commit 2d2bc00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/kubernetes/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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))

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2d2bc00

Please sign in to comment.