Skip to content

Commit

Permalink
fix loading defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps committed May 3, 2024
1 parent 0617928 commit 49dcb0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions pkg/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 49dcb0a

Please sign in to comment.