From 6f9bad3d05f828f65dcc2fd734cb57143ce399d1 Mon Sep 17 00:00:00 2001 From: Harsh Thakur Date: Mon, 8 Feb 2021 11:14:38 +0530 Subject: [PATCH] Spec validation option (#1865) Co-authored-by: Rahul Bhati Co-authored-by: Vishal --- pkg/fission-cli/cmd/spec/apply.go | 9 ++++++--- pkg/fission-cli/cmd/spec/command.go | 2 +- pkg/fission-cli/flag/flag.go | 17 +++++++++-------- pkg/fission-cli/flag/key/key.go | 1 + pkg/fission-cli/util/util.go | 12 ++++++++++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pkg/fission-cli/cmd/spec/apply.go b/pkg/fission-cli/cmd/spec/apply.go index f69409ff..ea3b8772 100644 --- a/pkg/fission-cli/cmd/spec/apply.go +++ b/pkg/fission-cli/cmd/spec/apply.go @@ -70,6 +70,7 @@ func (opts *ApplySubCommand) run(input cli.Input) error { deleteResources := input.Bool(flagkey.SpecDelete) watchResources := input.Bool(flagkey.SpecWatch) waitForBuild := input.Bool(flagkey.SpecWait) + validateSpecs := util.GetValidationFlag(input) var watcher *fsnotify.Watcher var pbw *packageBuildWatcher @@ -115,9 +116,11 @@ func (opts *ApplySubCommand) run(input cli.Input) error { return errors.Wrap(err, "error reading specs") } - err = Validate(input) - if err != nil { - return errors.Wrap(err, "abort applying resources") + if validateSpecs { + err = Validate(input) + if err != nil { + return errors.Wrap(err, "abort applying resources") + } } // make changes to the cluster based on the specs diff --git a/pkg/fission-cli/cmd/spec/command.go b/pkg/fission-cli/cmd/spec/command.go index 5af68151..b45a1889 100644 --- a/pkg/fission-cli/cmd/spec/command.go +++ b/pkg/fission-cli/cmd/spec/command.go @@ -48,7 +48,7 @@ func Commands() *cobra.Command { RunE: wrapper.Wrapper(Apply), } wrapper.SetFlags(applyCmd, flag.FlagSet{ - Optional: []flag.Flag{flag.SpecDir, flag.SpecDelete, flag.SpecWait, flag.SpecWatch}, + Optional: []flag.Flag{flag.SpecDir, flag.SpecDelete, flag.SpecWait, flag.SpecWatch, flag.SpecValidation}, }) destroyCmd := &cobra.Command{ diff --git a/pkg/fission-cli/flag/flag.go b/pkg/fission-cli/flag/flag.go index 264ddfa2..893ff7bc 100644 --- a/pkg/fission-cli/flag/flag.go +++ b/pkg/fission-cli/flag/flag.go @@ -176,14 +176,15 @@ var ( PkgSrcChecksum = Flag{Type: String, Name: flagkey.PkgSrcChecksum, Usage: "SHA256 checksum of source archive when providing URL"} PkgInsecure = Flag{Type: Bool, Name: flagkey.PkgInsecure, Usage: "Skip generating SHA256 checksum for file integrity validation"} - SpecSave = Flag{Type: Bool, Name: flagkey.SpecSave, Usage: "Save to the spec directory instead of creating on cluster"} - SpecDir = Flag{Type: String, Name: flagkey.SpecDir, Usage: "Directory to store specs, defaults to ./specs"} - SpecName = Flag{Type: String, Name: flagkey.SpecName, Usage: "Name for the app, applied to resources as a Kubernetes annotation"} - SpecDeployID = Flag{Type: String, Name: flagkey.SpecDeployID, Aliases: []string{"id"}, Usage: "Deployment ID for the spec deployment config"} - SpecWait = Flag{Type: Bool, Name: flagkey.SpecWait, Usage: "Wait for package builds"} - SpecWatch = Flag{Type: Bool, Name: flagkey.SpecWatch, Usage: "Watch local files for change, and re-apply specs as necessary"} - SpecDelete = Flag{Type: Bool, Name: flagkey.SpecDelete, Usage: "Allow apply to delete resources that no longer exist in the specification"} - SpecDry = Flag{Type: Bool, Name: flagkey.SpecDry, Usage: "View the generated specs"} + SpecSave = Flag{Type: Bool, Name: flagkey.SpecSave, Usage: "Save to the spec directory instead of creating on cluster"} + SpecDir = Flag{Type: String, Name: flagkey.SpecDir, Usage: "Directory to store specs, defaults to ./specs"} + SpecName = Flag{Type: String, Name: flagkey.SpecName, Usage: "Name for the app, applied to resources as a Kubernetes annotation"} + SpecDeployID = Flag{Type: String, Name: flagkey.SpecDeployID, Aliases: []string{"id"}, Usage: "Deployment ID for the spec deployment config"} + SpecWait = Flag{Type: Bool, Name: flagkey.SpecWait, Usage: "Wait for package builds"} + SpecWatch = Flag{Type: Bool, Name: flagkey.SpecWatch, Usage: "Watch local files for change, and re-apply specs as necessary"} + SpecDelete = Flag{Type: Bool, Name: flagkey.SpecDelete, Usage: "Allow apply to delete resources that no longer exist in the specification"} + SpecDry = Flag{Type: Bool, Name: flagkey.SpecDry, Usage: "View the generated specs"} + SpecValidation = Flag{Type: String, Name: flagkey.SpecValidate, Usage: "Turns server side validations of Fission objects on/off"} SupportOutput = Flag{Type: String, Name: flagkey.SupportOutput, Short: "o", Usage: "Output directory to save dump archive/files", DefaultValue: flagkey.DefaultSpecOutputDir} SupportNoZip = Flag{Type: Bool, Name: flagkey.SupportNoZip, Usage: "Save dump information into multiple files instead of single zip file"} diff --git a/pkg/fission-cli/flag/key/key.go b/pkg/fission-cli/flag/key/key.go index f9b48d2e..3a606e67 100644 --- a/pkg/fission-cli/flag/key/key.go +++ b/pkg/fission-cli/flag/key/key.go @@ -137,6 +137,7 @@ const ( SpecWatch = "watch" SpecDelete = "delete" SpecDry = "dry" + SpecValidate = "validation" SupportOutput = Output SupportNoZip = "nozip" diff --git a/pkg/fission-cli/util/util.go b/pkg/fission-cli/util/util.go index 5bd5080a..40e7f347 100644 --- a/pkg/fission-cli/util/util.go +++ b/pkg/fission-cli/util/util.go @@ -316,6 +316,18 @@ func GetSpecDir(input cli.Input) string { return specDir } +func GetValidationFlag(input cli.Input) bool { + validationFlag := input.String(flagkey.SpecValidate) + // if flag has not been set, we return true to turn on validation by default + if len(validationFlag) == 0 { + return true + } + if validationFlag == "false" { + return false + } + return true +} + // UpdateMapFromStringSlice parses key, val from "key=val" string array and updates passed map func UpdateMapFromStringSlice(dataMap *map[string]string, params []string) bool { updated := false