From 1df779693518c3c4842ad0cc6ea88f12890425e6 Mon Sep 17 00:00:00 2001 From: Francesco Torta <62566275+fra98@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:58:01 +0200 Subject: [PATCH] Added --dump-values-path check --- cmd/liqoctl/cmd/install.go | 5 +++-- pkg/liqoctl/install/const.go | 3 +++ pkg/liqoctl/install/validation.go | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cmd/liqoctl/cmd/install.go b/cmd/liqoctl/cmd/install.go index d73fe04aa4..cda28aa4f7 100644 --- a/cmd/liqoctl/cmd/install.go +++ b/cmd/liqoctl/cmd/install.go @@ -138,8 +138,9 @@ func newInstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command { cmd.PersistentFlags().BoolVar(&options.OnlyOutputValues, "only-output-values", false, "Generate the pre-configured values file for further customization, instead of installing Liqo (default false)") - cmd.PersistentFlags().StringVar(&options.ValuesPath, "dump-values-path", "./values.yaml", - "The path where the generated values file is saved (only in case --only-output-values is set)") + // the default value is set during the validation to check if the flag has been set or not + cmd.PersistentFlags().StringVar(&options.ValuesPath, "dump-values-path", "", + "The path where the generated values file is saved (only in case --only-output-values is set). Default: './values.yaml'") cmd.PersistentFlags().BoolVar(&options.DryRun, "dry-run", false, "Simulate the installation process (default false)") cmd.PersistentFlags().DurationVar(&options.Timeout, "timeout", 10*time.Minute, diff --git a/pkg/liqoctl/install/const.go b/pkg/liqoctl/install/const.go index 6b8e8ff7e6..3591104383 100644 --- a/pkg/liqoctl/install/const.go +++ b/pkg/liqoctl/install/const.go @@ -21,4 +21,7 @@ const ( // LiqoReleaseName indicates the default release name when installing the Liqo chart. LiqoReleaseName = "liqo" + + // DefaultDumpValuesPath is the default path where the helm values file is written. + DefaultDumpValuesPath = "./values.yaml" ) diff --git a/pkg/liqoctl/install/validation.go b/pkg/liqoctl/install/validation.go index 55c3dc5d09..b47e5af5f1 100644 --- a/pkg/liqoctl/install/validation.go +++ b/pkg/liqoctl/install/validation.go @@ -57,6 +57,10 @@ func (o *Options) validate(ctx context.Context) error { } o.Printer.Verbosef("Service CIDR: %s\n", o.ServiceCIDR) + if err := o.validateOutputValues(); err != nil { + return fmt.Errorf("failed validating output values: %w", err) + } + return nil } @@ -194,6 +198,17 @@ func (o *Options) validateServiceCIDR(ctx context.Context) error { return nil } +// validateOutputValues validates the flags related to values. +func (o *Options) validateOutputValues() (err error) { + if o.ValuesPath != "" && !o.OnlyOutputValues { + return fmt.Errorf("--dump-values-path can only be used in conjunction with --only-output-values") + } + if o.ValuesPath == "" { + o.ValuesPath = DefaultDumpValuesPath + } + return nil +} + func getHostnamePort(urlString string) (hostname, port string, err error) { if !strings.HasPrefix(urlString, "https://") { urlString = fmt.Sprintf("https://%v", urlString)