diff --git a/cmd/commands.go b/cmd/commands.go index 9ff2362..850405a 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -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), + }, }, }, { diff --git a/cmd/k3d.go b/cmd/k3d.go index 83df182..02833c7 100644 --- a/cmd/k3d.go +++ b/cmd/k3d.go @@ -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 @@ -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 } @@ -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 }