-
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
77cb9db
commit 74c529f
Showing
3 changed files
with
142 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,110 @@ | ||
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") | ||
rk.Flags().Bool("with-extra-mounts", false, "add extra mounts") | ||
rk.Flags().Bool("with-vfio", false, "use vfio") | ||
rk.Flags().Uint("pf-count-per-node", 1, "count of physical functions to pass to sriov node") | ||
rk.Flags().Uint("vf-count-per-node", 6, "count of virtual functions to create on sriov node") | ||
|
||
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 | ||
} | ||
mounts, err := cmd.Flags().GetBool("with-extra-mounts") | ||
if err != nil { | ||
return err | ||
} | ||
vfio, err := cmd.Flags().GetBool("with-vfio") | ||
if err != nil { | ||
return err | ||
} | ||
pfs, err := cmd.Flags().GetUint("pf-count-per-node") | ||
if err != nil { | ||
return err | ||
} | ||
vfs, err := cmd.Flags().GetUint("vf-count-per-node") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
kindVersion := args[0] | ||
conf := &kind.KindConfig{ | ||
Nodes: int(nodes), | ||
Version: kindVersion, | ||
RegistryPort: port, | ||
RegistryProxy: rp, | ||
WithCPUManager: cpum, | ||
IpFamily: ipf, | ||
WithExtraMounts: mounts, | ||
WithVfio: vfio, | ||
} | ||
|
||
switch kindVersion { | ||
case "k8s-1.28": | ||
kindProvider, err = kind.NewKindBaseProvider(conf) | ||
if err != nil { | ||
return err | ||
} | ||
case "sriov": | ||
kindProvider, err = sriov.NewKindSriovProvider(conf, int(pfs), int(vfs)) | ||
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 | ||
} |