Skip to content

Commit

Permalink
Add support for passing more flags while rendering helm template
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Mar 11, 2024
1 parent 06032ff commit c74b558
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
13 changes: 7 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ builds:

archives:
- format: tar.gz
replacements:
darwin: Darwin
linux: Linux
386: i386
amd64: x86_64
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
name_template: >-
{{- .ProjectName }}_
{{- .Version }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
files:
- plugin.yaml
- LICENSE
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ local.run: local.build ## Generates the artifact and start the service in the cu
./${APP_NAME}

publish: local.check ## Builds and publishes the app
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --rm-dist
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --clean

mock.publish: local.check ## Builds and mocks app release
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip-publish --rm-dist
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip=publish --clean

lint: ## Lint's application for errors, it is a linters aggregator (https://github.com/golangci/golangci-lint).
if [ -z "${DEV}" ]; then golangci-lint run --color always ; else docker run --rm -v $(APP_DIR):/app -w /app golangci/golangci-lint:v1.46.2-alpine golangci-lint run --color always ; fi
Expand Down
7 changes: 7 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func registerFlags(cmd *cobra.Command) {
"log level for the plugin helm drift (defaults to info)")
cmd.PersistentFlags().BoolVarP(&drifts.NoColor, "no-color", "", false,
"enabling this would render summary with no color")
cmd.PersistentFlags().BoolVarP(&drifts.SkipCRDS, "skip-crds", "", false,
"setting this would set '--skip-crds' for helm template command while generating templates")
cmd.PersistentFlags().BoolVarP(&drifts.Validate, "validate", "", false,
"setting this would set '--validate' for helm template command while generating templates")
cmd.PersistentFlags().StringVarP(&drifts.Version, "version", "", "",
"specify a version constraint for the chart version to use, the value passed here would be used to set "+
"--version for helm template command while generating templates")
}

// Registers flags to support command run/all.
Expand Down
53 changes: 28 additions & 25 deletions pkg/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@ const (

// Drift represents GetDrift.
type Drift struct {
Values []string
StringValues []string
FileValues []string
ValueFiles ValueFiles
SkipTests bool
SkipValidation bool
SkipClean bool
Summary bool
Regex string
LogLevel string
FromRelease bool
NoColor bool
JSON bool
YAML bool
ExitWithError bool
Report bool
TempPath string
CustomDiff string
All bool
IsDefaultNamespace bool
ConsiderHooks bool
Kind []string
SkipKinds []string
IgnoreHookTypes []string
Name string
ValueFiles ValueFiles `json:"value_files,omitempty" yaml:"value_files,omitempty"`
SkipTests bool `json:"skip_tests,omitempty" yaml:"skip_tests,omitempty"`
SkipValidation bool `json:"skip_validation,omitempty" yaml:"skip_validation,omitempty"`
SkipClean bool `json:"skip_clean,omitempty" yaml:"skip_clean,omitempty"`
Summary bool `json:"summary,omitempty" yaml:"summary,omitempty"`
FromRelease bool `json:"from_release,omitempty" yaml:"from_release,omitempty"`
NoColor bool `json:"no_color,omitempty" yaml:"no_color,omitempty"`
JSON bool `json:"json,omitempty" yaml:"json,omitempty"`
YAML bool `json:"yaml,omitempty" yaml:"yaml,omitempty"`
ExitWithError bool `json:"exit_with_error,omitempty" yaml:"exit_with_error,omitempty"`
Report bool `json:"report,omitempty" yaml:"report,omitempty"`
All bool `json:"all,omitempty" yaml:"all,omitempty"`
IsDefaultNamespace bool `json:"is_default_namespace,omitempty" yaml:"is_default_namespace,omitempty"`
ConsiderHooks bool `json:"consider_hooks,omitempty" yaml:"consider_hooks,omitempty"`
SkipCRDS bool `json:"skipCRDS,omitempty" yaml:"skipCRDS,omitempty"`
Validate bool `json:"validate,omitempty" yaml:"validate,omitempty"`
Kind []string `json:"kind,omitempty" yaml:"kind,omitempty"`
SkipKinds []string `json:"skip_kinds,omitempty" yaml:"skip_kinds,omitempty"`
IgnoreHookTypes []string `json:"ignore_hook_types,omitempty" yaml:"ignore_hook_types,omitempty"`
Values []string `json:"values,omitempty" yaml:"values,omitempty"`
StringValues []string `json:"string_values,omitempty" yaml:"string_values,omitempty"`
FileValues []string `json:"file_values,omitempty" yaml:"file_values,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Regex string `json:"regex,omitempty" yaml:"regex,omitempty"`
LogLevel string `json:"log_level,omitempty" yaml:"log_level,omitempty"`
TempPath string `json:"temp_path,omitempty" yaml:"temp_path,omitempty"`
CustomDiff string `json:"custom_diff,omitempty" yaml:"custom_diff,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
release string
chart string
namespace string
Expand Down
1 change: 0 additions & 1 deletion pkg/from_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"

// Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
Expand Down
12 changes: 12 additions & 0 deletions pkg/from_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ func (drift *Drift) getChartFromTemplate() ([]byte, error) {
flags = append(flags, "--skip-tests")
}

if drift.SkipCRDS {
flags = append(flags, "--skip-crds")
}

if drift.Validate {
flags = append(flags, "--validate")
}

if len(drift.Version) != 0 {
flags = append(flags, "--version", drift.Version)
}

args := []string{"template", drift.release, drift.chart}
args = append(args, flags...)

Expand Down

0 comments on commit c74b558

Please sign in to comment.