|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/spf13/cobra" |
| 5 | + |
| 6 | + "kusionstack.io/helm-kcl/pkg/app" |
| 7 | + "kusionstack.io/helm-kcl/pkg/config" |
| 8 | +) |
| 9 | + |
| 10 | +// NewTemplateCmd returm template subcmd |
| 11 | +func NewTemplateCmd() *cobra.Command { |
| 12 | + templateOptions := config.NewTemplateOptions() |
| 13 | + |
| 14 | + cmd := &cobra.Command{ |
| 15 | + Use: "template", |
| 16 | + Short: "Template releases defined in the KCL state file", |
| 17 | + PreRun: func(*cobra.Command, []string) { |
| 18 | + app.ExpandTLSPaths() |
| 19 | + }, |
| 20 | + RunE: func(*cobra.Command, []string) error { |
| 21 | + err := app.New().Template(config.NewTemplateImpl(templateOptions)) |
| 22 | + if err != nil { |
| 23 | + return err |
| 24 | + } |
| 25 | + return nil |
| 26 | + }, |
| 27 | + SilenceUsage: true, |
| 28 | + } |
| 29 | + |
| 30 | + f := cmd.Flags() |
| 31 | + f.StringVar(&templateOptions.File, "file", "", "input kcl file to pass to helm kcl template") |
| 32 | + f.StringArrayVar(&templateOptions.Set, "set", nil, "additional values to be merged into the helm command --set flag") |
| 33 | + f.StringArrayVar(&templateOptions.Values, "values", nil, "additional value files to be merged into the helm command --values flag") |
| 34 | + f.StringVar(&templateOptions.OutputDir, "output-dir", "", "output directory to pass to helm template (helm template --output-dir)") |
| 35 | + f.StringVar(&templateOptions.OutputDirTemplate, "output-dir-template", "", "go text template for generating the output directory. Default: {{ .OutputDir }}/{{ .State.BaseName }}-{{ .State.AbsPathSHA1 }}-{{ .Release.Name}}") |
| 36 | + f.IntVar(&templateOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") |
| 37 | + f.BoolVar(&templateOptions.Validate, "validate", false, "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requires access to a Kubernetes cluster to obtain information necessary for validating, like the template of available API versions") |
| 38 | + f.BoolVar(&templateOptions.IncludeCRDs, "include-crds", false, "include CRDs in the templated output") |
| 39 | + f.BoolVar(&templateOptions.SkipTests, "skip-tests", false, "skip tests from templated output") |
| 40 | + f.BoolVar(&templateOptions.SkipNeeds, "skip-needs", true, `do not automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when --selector/-l flag is not provided. Defaults to true when --include-needs or --include-transitive-needs is not provided`) |
| 41 | + f.BoolVar(&templateOptions.IncludeNeeds, "include-needs", false, `automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when --selector/-l flag is not provided`) |
| 42 | + f.BoolVar(&templateOptions.IncludeTransitiveNeeds, "include-transitive-needs", false, `like --include-needs, but also includes transitive needs (needs of needs). Does nothing when --selector/-l flag is not provided. Overrides exclusions of other selectors and conditions.`) |
| 43 | + f.BoolVar(&templateOptions.SkipDeps, "skip-deps", false, `skip running "helm repo update" and "helm dependency build"`) |
| 44 | + f.BoolVar(&templateOptions.SkipCleanup, "skip-cleanup", false, "Stop cleaning up temporary values generated by helmfile and helm-secrets. Useful for debugging. Don't use in production for security") |
| 45 | + f.StringVar(&templateOptions.PostRenderer, "post-renderer", "", `pass --post-renderer to "helm template" or "helm upgrade --install"`) |
| 46 | + |
| 47 | + if !app.IsHelm3() { |
| 48 | + app.AddCommonCmdOptions(f) |
| 49 | + } |
| 50 | + |
| 51 | + return cmd |
| 52 | +} |
0 commit comments