Spec validation option (#1865)

Co-authored-by: Rahul Bhati <rjbhati009@gmail.com>
Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
Harsh Thakur
2021-02-08 11:14:38 +05:30
committed by GitHub
co-authored by Rahul Bhati Vishal
parent f28799cc4c
commit 6f9bad3d05
5 changed files with 29 additions and 12 deletions
+3
View File
@@ -70,6 +70,7 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
deleteResources := input.Bool(flagkey.SpecDelete) deleteResources := input.Bool(flagkey.SpecDelete)
watchResources := input.Bool(flagkey.SpecWatch) watchResources := input.Bool(flagkey.SpecWatch)
waitForBuild := input.Bool(flagkey.SpecWait) waitForBuild := input.Bool(flagkey.SpecWait)
validateSpecs := util.GetValidationFlag(input)
var watcher *fsnotify.Watcher var watcher *fsnotify.Watcher
var pbw *packageBuildWatcher var pbw *packageBuildWatcher
@@ -115,10 +116,12 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
return errors.Wrap(err, "error reading specs") return errors.Wrap(err, "error reading specs")
} }
if validateSpecs {
err = Validate(input) err = Validate(input)
if err != nil { if err != nil {
return errors.Wrap(err, "abort applying resources") return errors.Wrap(err, "abort applying resources")
} }
}
// make changes to the cluster based on the specs // make changes to the cluster based on the specs
pkgMetas, as, err := applyResources(opts.Client(), specDir, fr, deleteResources) pkgMetas, as, err := applyResources(opts.Client(), specDir, fr, deleteResources)
+1 -1
View File
@@ -48,7 +48,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Apply), RunE: wrapper.Wrapper(Apply),
} }
wrapper.SetFlags(applyCmd, flag.FlagSet{ 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{ destroyCmd := &cobra.Command{
+1
View File
@@ -184,6 +184,7 @@ var (
SpecWatch = Flag{Type: Bool, Name: flagkey.SpecWatch, Usage: "Watch local files for change, and re-apply specs as necessary"} 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"} 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"} 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} 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"} SupportNoZip = Flag{Type: Bool, Name: flagkey.SupportNoZip, Usage: "Save dump information into multiple files instead of single zip file"}
+1
View File
@@ -137,6 +137,7 @@ const (
SpecWatch = "watch" SpecWatch = "watch"
SpecDelete = "delete" SpecDelete = "delete"
SpecDry = "dry" SpecDry = "dry"
SpecValidate = "validation"
SupportOutput = Output SupportOutput = Output
SupportNoZip = "nozip" SupportNoZip = "nozip"
+12
View File
@@ -316,6 +316,18 @@ func GetSpecDir(input cli.Input) string {
return specDir 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 // UpdateMapFromStringSlice parses key, val from "key=val" string array and updates passed map
func UpdateMapFromStringSlice(dataMap *map[string]string, params []string) bool { func UpdateMapFromStringSlice(dataMap *map[string]string, params []string) bool {
updated := false updated := false