-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce commands for running and removing kind clusters
The new command will parse flags into a KindConfig and run the cluster with it. Signed-off-by: aerosouund <[email protected]>
- Loading branch information
1 parent
604abd3
commit 4bbafff
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
kind "kubevirt.io/kubevirtci/cluster-provision/gocli/providers/kind/kindbase" | ||
) | ||
|
||
func NewRemoveKindCommand() *cobra.Command { | ||
rm := &cobra.Command{ | ||
Use: "rm-kind", | ||
Short: "rm deletes all traces of a kind cluster", | ||
RunE: rmKind, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
return rm | ||
} | ||
|
||
func rmKind(cmd *cobra.Command, args []string) error { | ||
prefix := args[0] | ||
|
||
kindProvider, err := kind.NewKindBaseProvider(&kind.KindConfig{Version: prefix}) | ||
if err != nil { | ||
return err | ||
} | ||
if err = kindProvider.Delete(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
kind "kubevirt.io/kubevirtci/cluster-provision/gocli/providers/kind/kindbase" | ||
"kubevirt.io/kubevirtci/cluster-provision/gocli/providers/kind/sriov" | ||
"kubevirt.io/kubevirtci/cluster-provision/gocli/providers/kind/vgpu" | ||
) | ||
|
||
var kindProvider kind.KindProvider | ||
|
||
func NewRunKindCommand() *cobra.Command { | ||
rk := &cobra.Command{ | ||
Use: "run-kind", | ||
Short: "runs a kind provider", | ||
RunE: runKind, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
rk.Flags().UintP("nodes", "n", 1, "number of cluster nodes to start") | ||
rk.Flags().String("registry-port", "5000", "forwarded host port for registry container") | ||
rk.Flags().String("registry-proxy", "", "registry proxy to use") | ||
rk.Flags().String("ip-family", "", "ip family") | ||
rk.Flags().Bool("enable-cpu-manager", false, "enable cpu manager") | ||
return rk | ||
} | ||
|
||
func runKind(cmd *cobra.Command, args []string) error { | ||
nodes, err := cmd.Flags().GetUint("nodes") | ||
if err != nil { | ||
return err | ||
} | ||
port, err := cmd.Flags().GetString("registry-port") | ||
if err != nil { | ||
return err | ||
} | ||
rp, err := cmd.Flags().GetString("registry-proxy") | ||
if err != nil { | ||
return err | ||
} | ||
ipf, err := cmd.Flags().GetString("ip-family") | ||
if err != nil { | ||
return err | ||
} | ||
cpum, err := cmd.Flags().GetBool("enable-cpu-manager") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
kindVersion := args[0] | ||
conf := &kind.KindConfig{ | ||
Nodes: int(nodes), | ||
Version: kindVersion, | ||
RegistryPort: port, | ||
RegistryProxy: rp, | ||
WithCPUManager: cpum, | ||
IpFamily: ipf, | ||
} | ||
|
||
switch kindVersion { | ||
case "k8s-1.28": | ||
kindProvider, err = kind.NewKindBaseProvider(conf) | ||
if err != nil { | ||
return err | ||
} | ||
case "sriov": | ||
kindProvider, err = sriov.NewKindSriovProvider(conf) | ||
if err != nil { | ||
return err | ||
} | ||
case "vgpu": | ||
kindProvider, err = vgpu.NewKindVGPU(conf) | ||
default: | ||
return fmt.Errorf("Invalid k8s version passed, please use one of k8s-1.28, sriov or vgpu") | ||
} | ||
|
||
b := context.Background() | ||
ctx, cancel := context.WithCancel(b) | ||
|
||
err = kindProvider.Start(ctx, cancel) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |