Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added k3d #1865

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions completers/k3d_completer/cmd/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var clusterCmd = &cobra.Command{
Use: "cluster",
Short: "Manage cluster(s)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(clusterCmd).Standalone()

rootCmd.AddCommand(clusterCmd)
}
101 changes: 101 additions & 0 deletions completers/k3d_completer/cmd/cluster_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/k3d"
"github.com/spf13/cobra"
)

var cluster_createCmd = &cobra.Command{
Use: "create NAME",
Short: "Create a new cluster",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_createCmd).Standalone()

cluster_createCmd.Flags().StringP("agents", "a", "", "Specify how many agents you want to create")
cluster_createCmd.Flags().String("agents-memory", "", "Memory limit imposed on the agents nodes [From docker]")
cluster_createCmd.Flags().String("api-port", "", "Specify the Kubernetes API server port exposed on the LoadBalancer (Format: `[HOST:]HOSTPORT`)")
cluster_createCmd.Flags().StringP("config", "c", "", "Path of a config file to use")
cluster_createCmd.Flags().StringSliceP("env", "e", []string{}, "Add environment variables to nodes (Format: `KEY[=VALUE][@NODEFILTER[;NODEFILTER...]]`")
cluster_createCmd.Flags().String("gpus", "", "GPU devices to add to the cluster node containers ('all' to pass all GPUs) [From docker]")
cluster_createCmd.Flags().StringSlice("host-alias", []string{}, "Add `ip:host[,host,...]` mappings")
cluster_createCmd.Flags().Bool("host-pid-mode", false, "Enable host pid mode of server(s) and agent(s)")
cluster_createCmd.Flags().StringP("image", "i", "", "Specify k3s image that you want to use for the nodes")
cluster_createCmd.Flags().StringSlice("k3s-arg", []string{}, "Additional args passed to k3s command (Format: `ARG@NODEFILTER[;@NODEFILTER]`)")
cluster_createCmd.Flags().StringSlice("k3s-node-label", []string{}, "Add label to k3s node (Format: `KEY[=VALUE][@NODEFILTER[;NODEFILTER...]]`")
cluster_createCmd.Flags().Bool("kubeconfig-switch-context", false, "Directly switch the default kubeconfig's current-context to the new cluster's context (requires --kubeconfig-update-default)")
cluster_createCmd.Flags().Bool("kubeconfig-update-default", false, "Directly update the default kubeconfig with the new cluster's context")
cluster_createCmd.Flags().StringSlice("lb-config-override", []string{}, "Use dotted YAML path syntax to override nginx loadbalancer settings")
cluster_createCmd.Flags().String("network", "", "Join an existing network")
cluster_createCmd.Flags().Bool("no-image-volume", false, "Disable the creation of a volume for importing images")
cluster_createCmd.Flags().Bool("no-lb", false, "Disable the creation of a LoadBalancer in front of the server nodes")
cluster_createCmd.Flags().Bool("no-rollback", false, "Disable the automatic rollback actions, if anything goes wrong")
cluster_createCmd.Flags().StringSliceP("port", "p", []string{}, "Map ports from the node containers (via the serverlb) to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)")
cluster_createCmd.Flags().String("registry-config", "", "Specify path to an extra registries.yaml file")
cluster_createCmd.Flags().String("registry-create", "", "Create a k3d-managed registry and connect it to the cluster (Format: `NAME[:HOST][:HOSTPORT]`")
cluster_createCmd.Flags().StringSlice("registry-use", []string{}, "Connect to one or more k3d-managed registries running locally")
cluster_createCmd.Flags().StringSlice("runtime-label", []string{}, "Add label to container runtime (Format: `KEY[=VALUE][@NODEFILTER[;NODEFILTER...]]`")
cluster_createCmd.Flags().StringSlice("runtime-ulimit", []string{}, "Add ulimit to container runtime (Format: `NAME[=SOFT]:[HARD]`")
cluster_createCmd.Flags().StringP("servers", "s", "", "Specify how many servers you want to create")
cluster_createCmd.Flags().String("servers-memory", "", "Memory limit imposed on the server nodes [From docker]")
cluster_createCmd.Flags().String("subnet", "", "[Experimental: IPAM] Define a subnet for the newly created container network (Example: `172.28.0.0/16`)")
cluster_createCmd.Flags().String("timeout", "", "Rollback changes if cluster couldn't be created in specified duration.")
cluster_createCmd.Flags().String("token", "", "Specify a cluster token. By default, we generate one.")
cluster_createCmd.Flags().StringSliceP("volume", "v", []string{}, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`")
cluster_createCmd.Flags().Bool("wait", false, "Wait for the server(s) to be ready before returning. Use '--timeout DURATION' to not wait forever.")
clusterCmd.AddCommand(cluster_createCmd)

carapace.Gen(cluster_createCmd).FlagCompletion(carapace.ActionMap{
"api-port": carapace.ActionValues(), // TODO
"config": carapace.ActionFiles(),
"env": carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return carapace.ActionValues() // KEY=VALUE
default:
return k3d.ActionNodeFilter().List(";")
}
}),
"gpus": carapace.ActionValues(), // TODO
"host-alias": carapace.ActionValues(),
"image": carapace.ActionValues(),
"k3s-arg": carapace.ActionValues(),
"k3s-node-label": carapace.ActionValues(),
"lb-config-override": carapace.ActionValues(),
"network": carapace.ActionValues(),
"port": carapace.ActionValues(),
"registry-config": carapace.ActionValues(),
"registry-create": carapace.ActionValues(),
"registry-use": carapace.ActionValues(),
"runtime-label": carapace.ActionValues(),
"runtime-ulimit": carapace.ActionValues(),
"servers": carapace.ActionValues(),
"servers-memory": carapace.ActionValues(),
"subnet": carapace.ActionValues(),
"timeout": carapace.ActionValues(),
"token": carapace.ActionValues(),
"volume": carapace.ActionValues(),
})
}

func x() {

Check failure on line 84 in completers/k3d_completer/cmd/cluster_create.go

View workflow job for this annotation

GitHub Actions / build

func x is unused (U1000)

Check failure on line 84 in completers/k3d_completer/cmd/cluster_create.go

View workflow job for this annotation

GitHub Actions / build

func x is unused (U1000)
// KEY[=VALUE][@NODEFILTER[;NODEFILTER...]]
carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return carapace.ActionMultiPartsN("=", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return carapace.ActionValues("TODO:key")
default:
return carapace.ActionValues("TODO:value")
}
})
default:
return carapace.ActionValues("TODO:nodefilter").List(";")
}
}).List(",")
}
26 changes: 26 additions & 0 deletions completers/k3d_completer/cmd/cluster_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/k3d"
"github.com/spf13/cobra"
)

var cluster_deleteCmd = &cobra.Command{
Use: "delete [NAME [NAME ...] | --all]",
Short: "Delete cluster(s).",
Aliases: []string{"del", "rm"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_deleteCmd).Standalone()

cluster_deleteCmd.Flags().BoolP("all", "a", false, "Delete all existing clusters")
cluster_deleteCmd.Flags().StringP("config", "c", "", "Path of a config file to use")
clusterCmd.AddCommand(cluster_deleteCmd)

carapace.Gen(cluster_deleteCmd).PositionalAnyCompletion(
k3d.ActionClusters().FilterArgs(),
)
}
41 changes: 41 additions & 0 deletions completers/k3d_completer/cmd/cluster_edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/k3d"
"github.com/spf13/cobra"
)

var cluster_editCmd = &cobra.Command{
Use: "edit CLUSTER",
Short: "[EXPERIMENTAL] Edit cluster(s).",
Aliases: []string{"update"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_editCmd).Standalone()

cluster_editCmd.Flags().StringSlice("port-add", []string{}, "[EXPERIMENTAL] Map ports from the node containers (via the serverlb) to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)")
clusterCmd.AddCommand(cluster_editCmd)

carapace.Gen(cluster_editCmd).FlagCompletion(carapace.ActionMap{
"port-add": carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action {
cluster := ""
if len(c.Args) > 0 {
cluster = c.Args[0]
}

switch len(c.Parts) {
case 0:
return carapace.ActionValues()
default:
return k3d.ActionNodes(k3d.NodeOpts{Cluster: cluster, Running: true, Stopped: true}).UniqueList(",") // TODO nodefilter?
}
}),
})

carapace.Gen(cluster_editCmd).PositionalCompletion(
k3d.ActionClusters(),
)
}
22 changes: 22 additions & 0 deletions completers/k3d_completer/cmd/cluster_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var cluster_listCmd = &cobra.Command{
Use: "list [NAME [NAME...]]",
Short: "List cluster(s)",
Aliases: []string{"ls", "get"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_listCmd).Standalone()

cluster_listCmd.Flags().Bool("no-headers", false, "Disable headers")
cluster_listCmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
cluster_listCmd.Flags().Bool("token", false, "Print k3s cluster token")
clusterCmd.AddCommand(cluster_listCmd)
}
21 changes: 21 additions & 0 deletions completers/k3d_completer/cmd/cluster_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var cluster_startCmd = &cobra.Command{
Use: "start [NAME [NAME...] | --all]",
Short: "Start existing k3d cluster(s)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_startCmd).Standalone()

cluster_startCmd.Flags().BoolP("all", "a", false, "Start all existing clusters")
cluster_startCmd.Flags().String("timeout", "", "Maximum waiting time for '--wait' before canceling/returning.")
cluster_startCmd.Flags().Bool("wait", false, "Wait for the server(s) (and loadbalancer) to be ready before returning.")
clusterCmd.AddCommand(cluster_startCmd)
}
19 changes: 19 additions & 0 deletions completers/k3d_completer/cmd/cluster_stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var cluster_stopCmd = &cobra.Command{
Use: "stop [NAME [NAME...] | --all]",
Short: "Stop existing k3d cluster(s)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cluster_stopCmd).Standalone()

cluster_stopCmd.Flags().BoolP("all", "a", false, "Stop all existing clusters")
clusterCmd.AddCommand(cluster_stopCmd)
}
18 changes: 18 additions & 0 deletions completers/k3d_completer/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var completionCmd = &cobra.Command{
Use: "completion SHELL",
Short: "Generate completion scripts for [bash, zsh, fish, powershell | psh]",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(completionCmd).Standalone()

rootCmd.AddCommand(completionCmd)
}
18 changes: 18 additions & 0 deletions completers/k3d_completer/cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var configCmd = &cobra.Command{
Use: "config",
Short: "Work with config file(s)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(configCmd).Standalone()

rootCmd.AddCommand(configCmd)
}
21 changes: 21 additions & 0 deletions completers/k3d_completer/cmd/config_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var config_initCmd = &cobra.Command{
Use: "init",
Short: "",
Aliases: []string{"create"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(config_initCmd).Standalone()

config_initCmd.Flags().BoolP("force", "f", false, "Force overwrite of target file")
config_initCmd.Flags().StringP("output", "o", "", "Write a default k3d config")
configCmd.AddCommand(config_initCmd)
}
19 changes: 19 additions & 0 deletions completers/k3d_completer/cmd/config_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var config_migrateCmd = &cobra.Command{
Use: "migrate INPUT [OUTPUT]",
Short: "",
Aliases: []string{"update"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(config_migrateCmd).Standalone()

configCmd.AddCommand(config_migrateCmd)
}
19 changes: 19 additions & 0 deletions completers/k3d_completer/cmd/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var debugCmd = &cobra.Command{
Use: "debug",
Short: "Debug k3d cluster(s)",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(debugCmd).Standalone()

rootCmd.AddCommand(debugCmd)
}
19 changes: 19 additions & 0 deletions completers/k3d_completer/cmd/debug_loadbalancer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var debug_loadbalancerCmd = &cobra.Command{
Use: "loadbalancer",
Short: "Debug the loadbalancer",
Aliases: []string{"lb"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(debug_loadbalancerCmd).Standalone()

debugCmd.AddCommand(debug_loadbalancerCmd)
}
18 changes: 18 additions & 0 deletions completers/k3d_completer/cmd/debug_loadbalancer_getConfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var debug_loadbalancer_getConfigCmd = &cobra.Command{
Use: "get-config CLUSTERNAME",
Short: "",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(debug_loadbalancer_getConfigCmd).Standalone()

debug_loadbalancerCmd.AddCommand(debug_loadbalancer_getConfigCmd)
}
Loading
Loading