Repository: scylladb/scylla-operator (go)

Issue:
Should not allow to create repair/backup tasks with same name
**Describe the bug**
Currently we allow to have multiple tasks with same name, which should not be the case:

```
    repairs:
    - interval: "0"
      name: test-name
      numRetries: 3
      smallTableThreshold: 1GiB
      startDate: now
    - interval: "0"
      name: test-name
      numRetries: 3
      smallTableThreshold: 1GiB
      startDate: now
```


Pull request:
manager: validate uniqueness of task names (#293)
Fixes #293

**Checklist:**
- [x] Documentation has been updated, if necessary.
- [x] Image has been built (`make docker-build`) on the last commit.

Patch:
diff --git a/pkg/api/v1alpha1/cluster_validation.go b/pkg/api/v1alpha1/cluster_validation.go
index 495be2068..0ae279c2d 100644
--- a/pkg/api/v1alpha1/cluster_validation.go
+++ b/pkg/api/v1alpha1/cluster_validation.go
@@ -6,6 +6,7 @@ import (
 
 	"github.com/blang/semver"
 	"github.com/pkg/errors"
+	"github.com/scylladb/go-set/strset"
 	"k8s.io/apimachinery/pkg/util/sets"
 )
 
@@ -85,7 +86,13 @@ func checkValues(c *ScyllaCluster) error {
 		}
 	}
 
+	managerTaskNames := strset.New()
 	for _, r := range c.Spec.Repairs {
+		if managerTaskNames.Has(r.Name) {
+			return errors.Errorf("manager task names must be unique, got collision on %q", r.Name)
+		}
+		managerTaskNames.Add(r.Name)
+
 		if r.Intensity != nil {
 			_, err := strconv.ParseFloat(*r.Intensity, 64)
 			if err != nil {
@@ -94,6 +101,13 @@ func checkValues(c *ScyllaCluster) error {
 		}
 	}
 
+	for _, b := range c.Spec.Backups {
+		if managerTaskNames.Has(b.Name) {
+			return errors.Errorf("manager task names must be unique, got collision on %q", b.Name)
+		}
+		managerTaskNames.Add(b.Name)
+	}
+
 	return nil
 }
 


Test patch:
diff --git a/pkg/api/v1alpha1/cluster_validation_test.go b/pkg/api/v1alpha1/cluster_validation_test.go
index 4e031c229..d4d70af6d 100644
--- a/pkg/api/v1alpha1/cluster_validation_test.go
+++ b/pkg/api/v1alpha1/cluster_validation_test.go
@@ -28,6 +28,18 @@ func TestCheckValues(t *testing.T) {
 		Intensity: pointer.StringPtr("100Mib"),
 	})
 
+	nonUniqueManagerTaskNames := validCluster.DeepCopy()
+	nonUniqueManagerTaskNames.Spec.Backups = append(nonUniqueManagerTaskNames.Spec.Backups, v1alpha1.BackupTaskSpec{
+		SchedulerTaskSpec: v1alpha1.SchedulerTaskSpec{
+			Name: "task-name",
+		},
+	})
+	nonUniqueManagerTaskNames.Spec.Repairs = append(nonUniqueManagerTaskNames.Spec.Repairs, v1alpha1.RepairTaskSpec{
+		SchedulerTaskSpec: v1alpha1.SchedulerTaskSpec{
+			Name: "task-name",
+		},
+	})
+
 	tests := []struct {
 		name    string
 		obj     *v1alpha1.ScyllaCluster
@@ -48,6 +60,11 @@ func TestCheckValues(t *testing.T) {
 			obj:     invalidIntensity,
 			allowed: false,
 		},
+		{
+			name:    "non-unique names in manager tasks spec",
+			obj:     nonUniqueManagerTaskNames,
+			allowed: false,
+		},
 	}
 
 	for _, test := range tests {