13
"github.com/aenix-io/talm/pkg/modeline"
14
"github.com/spf13/cobra"
15
"google.golang.org/grpc"
17
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/global"
18
_ "github.com/siderolabs/talos/pkg/grpc/codec"
19
"github.com/siderolabs/talos/pkg/machinery/client"
22
var kubernetesFlag bool
25
var GlobalArgs global.Args
29
GlobalOptions struct {
30
Talosconfig string `yaml:"talosconfig"`
31
} `yaml:"globalOptions"`
32
TemplateOptions struct {
33
Offline bool `yaml:"offline"`
34
ValueFiles []string `yaml:"valueFiles"`
35
Values []string `yaml:"values"`
36
StringValues []string `yaml:"stringValues"`
37
FileValues []string `yaml:"fileValues"`
38
JsonValues []string `yaml:"jsonValues"`
39
LiteralValues []string `yaml:"literalValues"`
40
TalosVersion string `yaml:"talosVersion"`
41
WithSecrets string `yaml:"withSecrets"`
42
KubernetesVersion string `yaml:"kubernetesVersion"`
43
Full bool `yaml:"full"`
44
} `yaml:"templateOptions"`
46
DryRun bool `yaml:"preserve"`
47
Timeout string `yaml:"timeout"`
48
TimeoutDuration time.Duration
49
CertFingerprints []string `yaml:"certFingerprints"`
50
} `yaml:"applyOptions"`
51
UpgradeOptions struct {
52
Preserve bool `yaml:"preserve"`
53
Stage bool `yaml:"stage"`
54
Force bool `yaml:"force"`
55
} `yaml:"upgradeOptions"`
61
const pathAutoCompleteLimit = 500
66
func WithClientNoNodes(action func(context.Context, *client.Client) error, dialOptions ...grpc.DialOption) error {
67
return GlobalArgs.WithClientNoNodes(action, dialOptions...)
71
func WithClient(action func(context.Context, *client.Client) error, dialOptions ...grpc.DialOption) error {
72
return WithClientNoNodes(
73
func(ctx context.Context, cli *client.Client) error {
74
if len(GlobalArgs.Nodes) < 1 {
75
configContext := cli.GetConfigContext()
76
if configContext == nil {
77
return errors.New("failed to resolve config context")
80
GlobalArgs.Nodes = configContext.Nodes
83
ctx = client.WithNodes(ctx, GlobalArgs.Nodes...)
85
return action(ctx, cli)
93
func WithClientMaintenance(enforceFingerprints []string, action func(context.Context, *client.Client) error) error {
94
return GlobalArgs.WithClientMaintenance(enforceFingerprints, action)
98
var Commands []*cobra.Command
100
func addCommand(cmd *cobra.Command) {
101
Commands = append(Commands, cmd)
104
func processModelineAndUpdateGlobals(configFile string, nodesFromArgs bool, endpointsFromArgs bool, owerwrite bool) error {
105
modelineConfig, err := modeline.ReadAndParseModeline(configFile)
107
fmt.Printf("Warning: modeline parsing failed: %v\n", err)
112
if modelineConfig != nil {
113
if !nodesFromArgs && len(modelineConfig.Nodes) > 0 {
115
GlobalArgs.Nodes = modelineConfig.Nodes
117
GlobalArgs.Nodes = append(GlobalArgs.Nodes, modelineConfig.Nodes...)
120
if !endpointsFromArgs && len(modelineConfig.Endpoints) > 0 {
122
GlobalArgs.Endpoints = modelineConfig.Endpoints
124
GlobalArgs.Endpoints = append(GlobalArgs.Endpoints, modelineConfig.Endpoints...)
129
if len(GlobalArgs.Nodes) < 1 {
130
return errors.New("nodes are not set for the command: please use `--nodes` flag or configuration file to set the nodes to run the command against")