Skip to content

Commit

Permalink
feat(cli): allow to disable kubectl validation (#186)
Browse files Browse the repository at this point in the history
Adds --validate flag to tk apply, to allow invoking kubectl without schema validation (kubectl apply --validate=false)

Fixes #115
  • Loading branch information
cezkuj authored and sh0rez committed Jan 27, 2020
1 parent 363d02c commit ba1a3af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/tk/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func applyCmd() *cobra.Command {
}
vars := workflowFlags(cmd.Flags())
force := cmd.Flags().Bool("force", false, "force applying (kubectl apply --force)")
validate := cmd.Flags().Bool("validate", true, "validation of resources (kubectl --validate=false)")
autoApprove := cmd.Flags().Bool("dangerous-auto-approve", false, "skip interactive approval. Only for automation!")
getExtCode := extCodeParser(cmd.Flags())

Expand All @@ -52,6 +53,7 @@ func applyCmd() *cobra.Command {
tanka.WithTargets(stringsToRegexps(vars.targets)...),
tanka.WithExtCode(getExtCode()),
tanka.WithApplyForce(*force),
tanka.WithApplyValidate(*validate),
tanka.WithApplyAutoApprove(*autoApprove),
)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/kubernetes/client/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (k Kubectl) apply(data manifest.List, opts ApplyOpts) error {
argv = append(argv, "--force")
}

if !opts.Validate {
argv = append(argv, "--validate=false")
}

cmd := exec.Command("kubectl", argv...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down
3 changes: 3 additions & 0 deletions pkg/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type ApplyOpts struct {
// force allows to ignore checks and force the operation
Force bool

// validate allows to enable/disable kubectl validation
Validate bool

// autoApprove allows to skip the interactive approval
AutoApprove bool
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/tanka/tanka.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func WithApplyForce(b bool) Modifier {
}
}

// WithApplyValidate allows to invoke `kubectl apply` with the `--validate=false` flag
func WithApplyValidate(b bool) Modifier {
return func(opts *options) {
opts.apply.Validate = b
}
}

// WithApplyAutoApprove allows to skip the interactive approval
func WithApplyAutoApprove(b bool) Modifier {
return func(opts *options) {
Expand Down

0 comments on commit ba1a3af

Please sign in to comment.