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

refactor cluster create command (frontend only) #10334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 22 additions & 16 deletions cmd/talosctl/cmd/mgmt/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,51 @@
package cluster

import (
"errors"
"path/filepath"

"github.com/spf13/cobra"

clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
"github.com/siderolabs/talos/pkg/provision/providers"
)

const (
// ProvisionerFlag is the flag with which the provisioner is configured.
ProvisionerFlag = "provisioner"
)

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

return nil
},
// CmdOps are the options for the cluster command.
type CmdOps struct {
ProvisionerName string
StateDir string
ClusterName string
}

var (
provisionerName string
stateDir string
clusterName string

defaultStateDir string
defaultCNIDir string

// DefaultCNIDir is the default location of the cni binaries.
DefaultCNIDir string
)

// Flags are the flags of the cluster command.
var Flags CmdOps

func init() {
talosDir, err := clientconfig.GetTalosDirectory()
if err == nil {
defaultStateDir = filepath.Join(talosDir, "clusters")
defaultCNIDir = filepath.Join(talosDir, "cni")
DefaultCNIDir = filepath.Join(talosDir, "cni")
}

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