Skip to content

Commit

Permalink
#29 - refactoring k3d list command
Browse files Browse the repository at this point in the history
  • Loading branch information
apanasiuk-el committed Sep 30, 2024
1 parent 5318f79 commit 12b1761
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ func Commands() []*cli.Command {
BashComplete: util.ShellCompleteCustomOutput,
Action: K3DAction(conf, K3DRunner.createDeleteK3DCluster),
},
{
Name: "list",
Usage: "List CAPI clusters",
Aliases: []string{"l"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "capi",
BashComplete: util.ShellCompleteCustomOutput,
Action: K3DAction(conf, K3DRunner.listK3DClusters),
},
},
},
{
Expand Down
20 changes: 17 additions & 3 deletions cmd/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ func (k *K3DCommands) prepareK3D(args ...string) error {
return nil
}

func (k *K3DCommands) createDeleteK3DCluster() error {
func (k *K3DCommands) selectCluster() {
switch k.Ctx.Command.Category {
case util.CAPI:
k.APICluster = true
case util.K3DPrefix:
k.K3DCluster = true
}
}

func (k *K3DCommands) createDeleteK3DCluster() error {
k.selectCluster()

if _, _, err := k.getKubeContext(); err != nil {
return err
Expand Down Expand Up @@ -102,11 +106,20 @@ func (k *K3DCommands) importImageToK3DCluster() error {
}

func (k *K3DCommands) listK3DClusters() error {
k.K3DCluster = true
k.selectCluster()

if _, _, err := k.getKubeContext(); err != nil {
return err
}

if k.APICluster {
if err := k.prepareK3D("cluster", k.Ctx.Command.Name, util.CAPI); err != nil {
return err
}

return runner(k).runCMD()
}

if err := k.prepareK3D("cluster", k.Ctx.Command.Name); err != nil {
return err
}
Expand All @@ -115,7 +128,8 @@ func (k *K3DCommands) listK3DClusters() error {
}

func (k *K3DCommands) startStopK3DCluster() error {
k.K3DCluster = true
k.selectCluster()

if _, _, err := k.getKubeContext(); err != nil {
return err
}
Expand Down

0 comments on commit 12b1761

Please sign in to comment.