From e5e8309ea603bb865984bb62114abde10934ba55 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Fri, 10 Jun 2022 09:24:30 +0800 Subject: [PATCH] Move diff charts template subcommand to a dedicated source file (#139) Signed-off-by: yxxhero --- cmd/charts.go | 37 +++++++++++ cmd/diff.go | 88 +++++++++++++++++++++++++ cmd/root.go | 3 + cmd/template.go | 73 +++++++++++++++++++++ main.go | 168 ------------------------------------------------ 5 files changed, 201 insertions(+), 168 deletions(-) create mode 100644 cmd/charts.go create mode 100644 cmd/diff.go create mode 100644 cmd/template.go diff --git a/cmd/charts.go b/cmd/charts.go new file mode 100644 index 00000000..a6a01649 --- /dev/null +++ b/cmd/charts.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "github.com/helmfile/helmfile/pkg/app" + "github.com/helmfile/helmfile/pkg/config" + "github.com/urfave/cli" +) + +func addChartsSubcommand(cliApp *cli.App) { + cliApp.Commands = append(cliApp.Commands, cli.Command{ + Name: "charts", + Usage: "DEPRECATED: sync releases from state file (helm upgrade --install)", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "args", + Value: "", + Usage: "pass args to helm exec", + }, + cli.StringSliceFlag{ + Name: "set", + Usage: "additional values to be merged into the command", + }, + cli.StringSliceFlag{ + Name: "values", + Usage: "additional value files to be merged into the command", + }, + cli.IntFlag{ + Name: "concurrency", + Value: 0, + Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", + }, + }, + Action: Action(func(a *app.App, c config.ConfigImpl) error { + return a.DeprecatedSyncCharts(c) + }), + }) +} diff --git a/cmd/diff.go b/cmd/diff.go new file mode 100644 index 00000000..c6a26817 --- /dev/null +++ b/cmd/diff.go @@ -0,0 +1,88 @@ +package cmd + +import ( + "github.com/helmfile/helmfile/pkg/app" + "github.com/helmfile/helmfile/pkg/config" + "github.com/urfave/cli" +) + +func addDiffSubcommand(cliApp *cli.App) { + cliApp.Commands = append(cliApp.Commands, cli.Command{ + Name: "diff", + Usage: "diff releases from state file against env (helm diff)", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "args", + Value: "", + Usage: "pass args to helm exec", + }, + cli.StringSliceFlag{ + Name: "set", + Usage: "additional values to be merged into the command", + }, + cli.StringSliceFlag{ + Name: "values", + Usage: "additional value files to be merged into the command", + }, + cli.BoolFlag{ + Name: "skip-deps", + Usage: `skip running "helm repo update" and "helm dependency build"`, + }, + cli.BoolFlag{ + Name: "detailed-exitcode", + Usage: "return a non-zero exit code when there are changes", + }, + cli.BoolFlag{ + Name: "include-tests", + Usage: "enable the diffing of the helm test hooks", + }, + cli.BoolTFlag{ + Name: "skip-needs", + Usage: `do not automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided. Defaults to true when --include-needs or --include-transitive-needs is not provided`, + }, + cli.BoolFlag{ + Name: "include-needs", + Usage: `automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided`, + }, + cli.BoolFlag{ + Name: "skip-diff-on-install", + Usage: "Skips running helm-diff on releases being newly installed on this apply. Useful when the release manifests are too huge to be reviewed, or it's too time-consuming to diff at all", + }, + cli.StringSliceFlag{ + Name: "suppress", + Usage: "suppress specified Kubernetes objects in the output. Can be provided multiple times. For example: --suppress KeycloakClient --suppress VaultSecret", + }, + cli.BoolFlag{ + Name: "suppress-secrets", + Usage: "suppress secrets in the output. highly recommended to specify on CI/CD use-cases", + }, + cli.BoolFlag{ + Name: "show-secrets", + Usage: "do not redact secret values in the output. should be used for debug purpose only", + }, + cli.IntFlag{ + Name: "concurrency", + Value: 0, + Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", + }, + cli.BoolFlag{ + Name: "validate", + Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions", + }, + + cli.IntFlag{ + Name: "context", + Value: 0, + Usage: "output NUM lines of context around changes", + }, + cli.StringFlag{ + Name: "output", + Value: "", + Usage: "output format for diff plugin", + }, + }, + Action: Action(func(a *app.App, c config.ConfigImpl) error { + return a.Diff(c) + }), + }) +} diff --git a/cmd/root.go b/cmd/root.go index a5e4821e..c8d4b7b7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -27,6 +27,9 @@ func RootCommand() *cli.App { // add subcommands addDepsSubcommand(cliApp) addReposSubcommand(cliApp) + addChartsSubcommand(cliApp) + addDiffSubcommand(cliApp) + addTemplateSubcommand(cliApp) return cliApp } diff --git a/cmd/template.go b/cmd/template.go new file mode 100644 index 00000000..36b50017 --- /dev/null +++ b/cmd/template.go @@ -0,0 +1,73 @@ +package cmd + +import ( + "github.com/helmfile/helmfile/pkg/app" + "github.com/helmfile/helmfile/pkg/config" + "github.com/urfave/cli" +) + +func addTemplateSubcommand(cliApp *cli.App) { + cliApp.Commands = append(cliApp.Commands, cli.Command{ + Name: "template", + Usage: "template releases from state file against env (helm template)", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "args", + Value: "", + Usage: "pass args to helm template", + }, + cli.StringSliceFlag{ + Name: "set", + Usage: "additional values to be merged into the command", + }, + cli.StringSliceFlag{ + Name: "values", + Usage: "additional value files to be merged into the command", + }, + cli.StringFlag{ + Name: "output-dir", + Usage: "output directory to pass to helm template (helm template --output-dir)", + }, + cli.StringFlag{ + Name: "output-dir-template", + Usage: "go text template for generating the output directory. Default: {{ .OutputDir }}/{{ .State.BaseName }}-{{ .State.AbsPathSHA1 }}-{{ .Release.Name}}", + }, + cli.IntFlag{ + Name: "concurrency", + Value: 0, + Usage: "maximum number of concurrent downloads of release charts", + }, + cli.BoolFlag{ + Name: "validate", + Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions", + }, + cli.BoolFlag{ + Name: "include-crds", + Usage: "include CRDs in the templated output", + }, + cli.BoolFlag{ + Name: "skip-tests", + Usage: "skip tests from templated output", + }, + cli.BoolFlag{ + Name: "include-needs", + Usage: `automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided`, + }, + cli.BoolFlag{ + Name: "include-transitive-needs", + Usage: `like --include-needs, but also includes transitive needs (needs of needs). Does nothing when when --selector/-l flag is not provided. Overrides exclusions of other selectors and conditions.`, + }, + cli.BoolFlag{ + Name: "skip-deps", + Usage: `skip running "helm repo update" and "helm dependency build"`, + }, + cli.BoolFlag{ + Name: "skip-cleanup", + Usage: "Stop cleaning up temporary values generated by helmfile and helm-secrets. Useful for debugging. Don't use in production for security", + }, + }, + Action: Action(func(a *app.App, c config.ConfigImpl) error { + return a.Template(c) + }), + }) +} diff --git a/main.go b/main.go index 14057132..21bb7501 100644 --- a/main.go +++ b/main.go @@ -14,174 +14,6 @@ func main() { rootCmd := cmd.RootCommand() subCommands := []cli.Command{ - { - Name: "charts", - Usage: "DEPRECATED: sync releases from state file (helm upgrade --install)", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "args", - Value: "", - Usage: "pass args to helm exec", - }, - cli.StringSliceFlag{ - Name: "set", - Usage: "additional values to be merged into the command", - }, - cli.StringSliceFlag{ - Name: "values", - Usage: "additional value files to be merged into the command", - }, - cli.IntFlag{ - Name: "concurrency", - Value: 0, - Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", - }, - }, - Action: cmd.Action(func(a *app.App, c config.ConfigImpl) error { - return a.DeprecatedSyncCharts(c) - }), - }, - { - Name: "diff", - Usage: "diff releases from state file against env (helm diff)", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "args", - Value: "", - Usage: "pass args to helm exec", - }, - cli.StringSliceFlag{ - Name: "set", - Usage: "additional values to be merged into the command", - }, - cli.StringSliceFlag{ - Name: "values", - Usage: "additional value files to be merged into the command", - }, - cli.BoolFlag{ - Name: "skip-deps", - Usage: `skip running "helm repo update" and "helm dependency build"`, - }, - cli.BoolFlag{ - Name: "detailed-exitcode", - Usage: "return a non-zero exit code when there are changes", - }, - cli.BoolFlag{ - Name: "include-tests", - Usage: "enable the diffing of the helm test hooks", - }, - cli.BoolTFlag{ - Name: "skip-needs", - Usage: `do not automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided. Defaults to true when --include-needs or --include-transitive-needs is not provided`, - }, - cli.BoolFlag{ - Name: "include-needs", - Usage: `automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided`, - }, - cli.BoolFlag{ - Name: "skip-diff-on-install", - Usage: "Skips running helm-diff on releases being newly installed on this apply. Useful when the release manifests are too huge to be reviewed, or it's too time-consuming to diff at all", - }, - cli.StringSliceFlag{ - Name: "suppress", - Usage: "suppress specified Kubernetes objects in the output. Can be provided multiple times. For example: --suppress KeycloakClient --suppress VaultSecret", - }, - cli.BoolFlag{ - Name: "suppress-secrets", - Usage: "suppress secrets in the output. highly recommended to specify on CI/CD use-cases", - }, - cli.BoolFlag{ - Name: "show-secrets", - Usage: "do not redact secret values in the output. should be used for debug purpose only", - }, - cli.IntFlag{ - Name: "concurrency", - Value: 0, - Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", - }, - cli.BoolFlag{ - Name: "validate", - Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions", - }, - - cli.IntFlag{ - Name: "context", - Value: 0, - Usage: "output NUM lines of context around changes", - }, - cli.StringFlag{ - Name: "output", - Value: "", - Usage: "output format for diff plugin", - }, - }, - Action: cmd.Action(func(a *app.App, c config.ConfigImpl) error { - return a.Diff(c) - }), - }, - { - Name: "template", - Usage: "template releases from state file against env (helm template)", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "args", - Value: "", - Usage: "pass args to helm template", - }, - cli.StringSliceFlag{ - Name: "set", - Usage: "additional values to be merged into the command", - }, - cli.StringSliceFlag{ - Name: "values", - Usage: "additional value files to be merged into the command", - }, - cli.StringFlag{ - Name: "output-dir", - Usage: "output directory to pass to helm template (helm template --output-dir)", - }, - cli.StringFlag{ - Name: "output-dir-template", - Usage: "go text template for generating the output directory. Default: {{ .OutputDir }}/{{ .State.BaseName }}-{{ .State.AbsPathSHA1 }}-{{ .Release.Name}}", - }, - cli.IntFlag{ - Name: "concurrency", - Value: 0, - Usage: "maximum number of concurrent downloads of release charts", - }, - cli.BoolFlag{ - Name: "validate", - Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions", - }, - cli.BoolFlag{ - Name: "include-crds", - Usage: "include CRDs in the templated output", - }, - cli.BoolFlag{ - Name: "skip-tests", - Usage: "skip tests from templated output", - }, - cli.BoolFlag{ - Name: "include-needs", - Usage: `automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when when --selector/-l flag is not provided`, - }, - cli.BoolFlag{ - Name: "include-transitive-needs", - Usage: `like --include-needs, but also includes transitive needs (needs of needs). Does nothing when when --selector/-l flag is not provided. Overrides exclusions of other selectors and conditions.`, - }, - cli.BoolFlag{ - Name: "skip-deps", - Usage: `skip running "helm repo update" and "helm dependency build"`, - }, - cli.BoolFlag{ - Name: "skip-cleanup", - Usage: "Stop cleaning up temporary values generated by helmfile and helm-secrets. Useful for debugging. Don't use in production for security", - }, - }, - Action: cmd.Action(func(a *app.App, c config.ConfigImpl) error { - return a.Template(c) - }), - }, { Name: "write-values", Usage: "write values files for releases. Similar to `helmfile template`, write values files instead of manifests.",