Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adejanovski committed Feb 15, 2024
1 parent 151680a commit 76f770c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pkg/tasks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func CreateClusterTask(ctx context.Context, kubeClient client.Client, command co
},
}

if len(datacenters) > 0 {
if len(datacenters) > 0 && datacenters[0] != "" {
task.Spec.Datacenters = datacenters
}

Expand Down
26 changes: 9 additions & 17 deletions pkg/tasks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func restartArguments(rackName string) *controlapi.JobArguments {

func CreateClusterRestartTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := restartArguments(rackName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandRestart, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandRestart, namespace, cluster, []string{dcName}, args)
}

// Replace
Expand All @@ -56,7 +56,7 @@ func CreateClusterReplaceTask(ctx context.Context, kubeClient client.Client, nam
return nil, err
}

return CreateClusterTask(ctx, kubeClient, controlapi.CommandReplaceNode, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandReplaceNode, namespace, cluster, []string{dcName}, args)
}

// Flush
Expand All @@ -68,7 +68,7 @@ func CreateFlushTask(ctx context.Context, kubeClient client.Client, dc *cassdcap

func CreateClusterFlushTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName, podName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := commonArguments(rackName, podName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandFlush, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandFlush, namespace, cluster, []string{dcName}, args)
}

// Cleanup
Expand All @@ -80,7 +80,7 @@ func CreateCleanupTask(ctx context.Context, kubeClient client.Client, dc *cassdc

func CreateClusterCleanupTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName, podName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := commonArguments(rackName, podName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandCleanup, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandCleanup, namespace, cluster, []string{dcName}, args)
}

// UpgradeSSTables
Expand All @@ -92,7 +92,7 @@ func CreateUpgradeSSTablesTask(ctx context.Context, kubeClient client.Client, dc

func CreateClusterUpgradeSSTablesTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName, podName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := commonArguments(rackName, podName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandUpgradeSSTables, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandUpgradeSSTables, namespace, cluster, []string{dcName}, args)
}

// Scrub
Expand All @@ -104,7 +104,7 @@ func CreateScrubTask(ctx context.Context, kubeClient client.Client, dc *cassdcap

func CreateClusterScrubTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName, podName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := commonArguments(rackName, podName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandScrub, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandScrub, namespace, cluster, []string{dcName}, args)
}

// Compaction
Expand Down Expand Up @@ -137,7 +137,7 @@ func CreateClusterCompactionTask(ctx context.Context, kubeClient client.Client,
if err != nil {
return nil, err
}
return CreateClusterTask(ctx, kubeClient, controlapi.CommandCompaction, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandCompaction, namespace, cluster, []string{dcName}, args)
}

// Move
Expand All @@ -151,7 +151,7 @@ func CreateGCTask(ctx context.Context, kubeClient client.Client, dc *cassdcapi.C

func CreateClusterGCTask(ctx context.Context, kubeClient client.Client, namespace, cluster, dcName, rackName, podName string) (*k8ssandrataskapi.K8ssandraTask, error) {
args := commonArguments(rackName, podName)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandGarbageCollect, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandGarbageCollect, namespace, cluster, []string{dcName}, args)
}

// Rebuild
Expand Down Expand Up @@ -179,7 +179,7 @@ func CreateClusterRebuildTask(ctx context.Context, kubeClient client.Client, nam
if err != nil {
return nil, err
}
return CreateClusterTask(ctx, kubeClient, controlapi.CommandRebuild, namespace, cluster, DcNames(dcName), args)
return CreateClusterTask(ctx, kubeClient, controlapi.CommandRebuild, namespace, cluster, []string{dcName}, args)
}

// Assistance methods
Expand Down Expand Up @@ -222,11 +222,3 @@ func CreateTask(ctx context.Context, kubeClient client.Client, command controlap

return task, nil
}

func DcNames(dcName string) []string {
var dcNames []string
if dcName != "" {
dcNames = []string{dcName}
}
return dcNames
}
14 changes: 0 additions & 14 deletions pkg/tasks/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,3 @@ func TestCreateClusterWideTask(t *testing.T) {
assert.Equal(t, controlapi.CommandRestart, task.Spec.Template.Jobs[0].Command)
assert.Equal(t, 0, len(task.Spec.Datacenters))
}

func TestDcNames(t *testing.T) {
t.Run("empty string", func(t *testing.T) {
result := tasks.DcNames("")
assert.Equal(t, 0, len(result))
})

t.Run("non-empty string", func(t *testing.T) {
dcName := "test-dc"
result := tasks.DcNames(dcName)
assert.Equal(t, 1, len(result))
assert.Equal(t, dcName, result[0])
})
}

0 comments on commit 76f770c

Please sign in to comment.