Skip to content

Commit

Permalink
feat: add flags to be able to override helm values over command line
Browse files Browse the repository at this point in the history
Signed-off-by: Utku Ozdemir <uoz@protonmail.com>
  • Loading branch information
utkuozdemir committed Nov 14, 2021
1 parent 03977f5 commit e67e346
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
26 changes: 26 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const (
FlagSshdServiceAccount = "sshd-service-account"
FlagSSHKeyAlgorithm = "ssh-key-algorithm"

FlagHelmValues = "helm-values"
FlagHelmSet = "helm-set"
FlagHelmSetString = "helm-set-string"
FlagHelmSetFile = "helm-set-file"

loggerContextKey cliAppContextKey = "logger"
)

Expand Down Expand Up @@ -83,6 +88,10 @@ func New(rootLogger *log.Logger, version string, commit string) *cli.App {
NoChown: c.Bool(FlagNoChown),
NoProgressBar: c.Bool(FlagNoProgressBar),
KeyAlgorithm: c.String(FlagSSHKeyAlgorithm),
HelmValuesFiles: c.StringSlice(FlagHelmValues),
HelmValues: c.StringSlice(FlagHelmSet),
HelmStringValues: c.StringSlice(FlagHelmSetString),
HelmFileValues: c.StringSlice(FlagHelmSetFile),
}

strategies := strings.Split(c.String(FlagStrategies), ",")
Expand Down Expand Up @@ -227,6 +236,23 @@ func New(rootLogger *log.Logger, version string, commit string) *cli.App {
Usage: fmt.Sprintf("SSH key algorithm to be used. Valid values are %s", sshKeyAlgs),
Value: ssh.Ed25519KeyAlgorithm,
},
&cli.StringSliceFlag{
Name: FlagHelmValues,
Aliases: []string{"f"},
Usage: "Set additional Helm values by a YAML file or a URL (can specify multiple)",
},
&cli.StringSliceFlag{
Name: FlagHelmSet,
Usage: "Set additional Helm values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)",
},
&cli.StringSliceFlag{
Name: FlagHelmSetString,
Usage: "Set additional Helm STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)",
},
&cli.StringSliceFlag{
Name: FlagHelmSetFile,
Usage: "Set additional Helm values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)",
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/strategy/lbsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func installOnSource(e *task.Execution, publicKey string) error {
"source.path=" + t.Migration.Source.Path,
}

vals, err := getMergedHelmValues(helmValues)
vals, err := getMergedHelmValues(helmValues, opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func installOnDest(e *task.Execution, privateKey string, privateKeyMountPath str
"dest.path=" + t.Migration.Dest.Path,
}

vals, err := getMergedHelmValues(helmValues)
vals, err := getMergedHelmValues(helmValues, opts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/strategy/mnt2.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *Mnt2) Run(e *task.Execution) (bool, error) {
"dest.path=" + t.Migration.Dest.Path,
}

vals, err := getMergedHelmValues(helmValues)
vals, err := getMergedHelmValues(helmValues, opts)
if err != nil {
return true, err
}
Expand Down
9 changes: 7 additions & 2 deletions internal/strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/utkuozdemir/pv-migrate/internal/pvc"
"github.com/utkuozdemir/pv-migrate/internal/task"
"github.com/utkuozdemir/pv-migrate/migration"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/cli/values"
Expand Down Expand Up @@ -134,9 +135,13 @@ func initHelmActionConfig(logger *log.Entry, pvcInfo *pvc.Info) (*action.Configu
return actionConfig, nil
}

func getMergedHelmValues(helmValues []string) (map[string]interface{}, error) {
func getMergedHelmValues(helmValues []string, opts *migration.Options) (map[string]interface{}, error) {
allValues := append(helmValues, opts.HelmValues...)
valsOptions := values.Options{
Values: helmValues,
Values: allValues,
ValueFiles: opts.HelmValuesFiles,
StringValues: opts.HelmStringValues,
FileValues: opts.HelmFileValues,
}

return valsOptions.MergeValues(helmProviders)
Expand Down
2 changes: 1 addition & 1 deletion internal/strategy/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *Svc) Run(e *task.Execution) (bool, error) {
"dest.path=" + t.Migration.Dest.Path,
}

vals, err := getMergedHelmValues(helmValues)
vals, err := getMergedHelmValues(helmValues, opts)
if err != nil {
return true, err
}
Expand Down
4 changes: 4 additions & 0 deletions migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ type Options struct {
NoProgressBar bool
SourceMountReadOnly bool
KeyAlgorithm string
HelmValuesFiles []string
HelmValues []string
HelmFileValues []string
HelmStringValues []string
}

0 comments on commit e67e346

Please sign in to comment.