Skip to content

Commit cc4b521

Browse files
committed
refactor: cluster create command
User facing changes: * Add two sub-commands: "cluster create qemu" and "cluster create docker" The commands only have flags relevant to the applicable providers * Error if invalid provider's flags are passed * Add (QEMU only) or (docker only) at the start of the flag description * Group flags by providers and then sort alphabetically. Internal: * Split common cluster creation logic into a ClusterMaker abstraction * Split creation logic of cluster and qemu clusters * Add basic unit tests for all the options unrelated * Use default kubeconfig instead of kubeconfig.SinglePath() * If KVM is not available, log a warning and proceed without it Signed-off-by: Orzelius <33936483+Orzelius@users.noreply.github.com>
1 parent 68a19a3 commit cc4b521

File tree

22 files changed

+3711
-1768
lines changed

22 files changed

+3711
-1768
lines changed

cmd/talosctl/cmd/mgmt/cluster/cluster.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,51 @@
66
package cluster
77

88
import (
9-
"errors"
109
"path/filepath"
1110

1211
"github.com/spf13/cobra"
1312

1413
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
14+
"github.com/siderolabs/talos/pkg/provision/providers"
15+
)
16+
17+
const (
18+
// ProvisionerFlag is the flag with which the provisioner is configured.
19+
ProvisionerFlag = "provisioner"
1520
)
1621

1722
// Cmd represents the cluster command.
1823
var Cmd = &cobra.Command{
1924
Use: "cluster",
2025
Short: "A collection of commands for managing local docker-based or QEMU-based clusters",
2126
Long: ``,
22-
PersistentPreRunE: func(*cobra.Command, []string) error {
23-
if provisionerName == docker && !bootloaderEnabled {
24-
return errors.New("docker provisioner requires bootloader to be enabled")
25-
}
27+
}
2628

27-
return nil
28-
},
29+
// CmdOps are the options for the cluster command.
30+
type CmdOps struct {
31+
ProvisionerName string
32+
StateDir string
33+
ClusterName string
2934
}
3035

3136
var (
32-
provisionerName string
33-
stateDir string
34-
clusterName string
35-
3637
defaultStateDir string
37-
defaultCNIDir string
38+
39+
// DefaultCNIDir is the default location of the cni binaries.
40+
DefaultCNIDir string
3841
)
3942

43+
// Flags are the flags of the cluster command.
44+
var Flags CmdOps
45+
4046
func init() {
4147
talosDir, err := clientconfig.GetTalosDirectory()
4248
if err == nil {
4349
defaultStateDir = filepath.Join(talosDir, "clusters")
44-
defaultCNIDir = filepath.Join(talosDir, "cni")
50+
DefaultCNIDir = filepath.Join(talosDir, "cni")
4551
}
4652

47-
Cmd.PersistentFlags().StringVar(&provisionerName, "provisioner", docker, "Talos cluster provisioner to use")
48-
Cmd.PersistentFlags().StringVar(&stateDir, "state", defaultStateDir, "directory path to store cluster state")
49-
Cmd.PersistentFlags().StringVar(&clusterName, "name", "talos-default", "the name of the cluster")
53+
Cmd.PersistentFlags().StringVar(&Flags.ProvisionerName, ProvisionerFlag, providers.DockerProviderName, "Talos cluster provisioner to use")
54+
Cmd.PersistentFlags().StringVar(&Flags.StateDir, "state", defaultStateDir, "directory path to store cluster state")
55+
Cmd.PersistentFlags().StringVar(&Flags.ClusterName, "name", "talos-default", "the name of the cluster")
5056
}

0 commit comments

Comments
 (0)