From 49dcb0ac376b7395c0f2b422f06cfccbed3c9ca2 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 3 May 2024 08:44:37 +0200 Subject: [PATCH] fix loading defaults --- main.go | 13 +++++++++++++ pkg/commands/apply.go | 5 +++-- pkg/commands/root.go | 16 ---------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index a17fa16..a13f432 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strings" + "time" "gopkg.in/yaml.v3" @@ -98,5 +99,17 @@ func loadConfig(filename string) error { if commands.GlobalArgs.Talosconfig == "" { commands.GlobalArgs.Talosconfig = commands.Config.GlobalOptions.Talosconfig } + if commands.Config.TemplateOptions.KubernetesVersion == "" { + commands.Config.TemplateOptions.KubernetesVersion = constants.DefaultKubernetesVersion + } + if commands.Config.ApplyOptions.Timeout == "" { + commands.Config.ApplyOptions.Timeout = constants.ConfigTryTimeout.String() + } else { + var err error + commands.Config.ApplyOptions.TimeoutDuration, err = time.ParseDuration(commands.Config.ApplyOptions.Timeout) + if err != nil { + panic(err) + } + } return nil } diff --git a/pkg/commands/apply.go b/pkg/commands/apply.go index dcded73..267f650 100644 --- a/pkg/commands/apply.go +++ b/pkg/commands/apply.go @@ -17,6 +17,7 @@ import ( "github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers" machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine" "github.com/siderolabs/talos/pkg/machinery/client" + "github.com/siderolabs/talos/pkg/machinery/constants" ) var applyCmdFlags struct { @@ -151,10 +152,10 @@ func init() { applyCmd.Flags().StringVar(&applyCmdFlags.talosVersion, "talos-version", "", "the desired Talos version to generate config for (backwards compatibility, e.g. v0.8)") applyCmd.Flags().StringVar(&applyCmdFlags.withSecrets, "with-secrets", "", "use a secrets file generated using 'gen secrets'") - applyCmd.Flags().StringVar(&applyCmdFlags.kubernetesVersion, "kubernetes-version", "", "desired kubernetes version to run") + applyCmd.Flags().StringVar(&applyCmdFlags.kubernetesVersion, "kubernetes-version", constants.DefaultKubernetesVersion, "desired kubernetes version to run") applyCmd.Flags().BoolVar(&applyCmdFlags.dryRun, "dry-run", false, "check how the config change will be applied in dry-run mode") - applyCmd.Flags().DurationVar(&applyCmdFlags.configTryTimeout, "timeout", 0, "the config will be rolled back after specified timeout (if try mode is selected)") + applyCmd.Flags().DurationVar(&applyCmdFlags.configTryTimeout, "timeout", constants.ConfigTryTimeout, "the config will be rolled back after specified timeout (if try mode is selected)") applyCmd.Flags().StringSliceVar(&applyCmdFlags.certFingerprints, "cert-fingerprint", nil, "list of server certificate fingeprints to accept (defaults to no check)") applyCmd.Flags().BoolVar(&applyCmdFlags.force, "force", false, "will overwrite existing files") helpers.AddModeFlags(&applyCmdFlags.Mode, applyCmd) diff --git a/pkg/commands/root.go b/pkg/commands/root.go index cc3a651..a30194d 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -14,7 +14,6 @@ import ( "github.com/siderolabs/talos/cmd/talosctl/pkg/talos/global" _ "github.com/siderolabs/talos/pkg/grpc/codec" // register codec "github.com/siderolabs/talos/pkg/machinery/client" - "github.com/siderolabs/talos/pkg/machinery/constants" ) var kubernetesFlag bool @@ -78,18 +77,3 @@ var Commands []*cobra.Command func addCommand(cmd *cobra.Command) { Commands = append(Commands, cmd) } - -func init() { - if Config.TemplateOptions.KubernetesVersion == "" { - Config.TemplateOptions.KubernetesVersion = constants.DefaultKubernetesVersion - } - if Config.ApplyOptions.Timeout == "" { - Config.ApplyOptions.Timeout = constants.ConfigTryTimeout.String() - } else { - var err error - Config.ApplyOptions.TimeoutDuration, err = time.ParseDuration(Config.ApplyOptions.Timeout) - if err != nil { - panic(err) - } - } -}