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:
co-authored by
Rahul Bhati
Vishal
parent
f28799cc4c
commit
6f9bad3d05
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -137,6 +137,7 @@ const (
|
||||
SpecWatch = "watch"
|
||||
SpecDelete = "delete"
|
||||
SpecDry = "dry"
|
||||
SpecValidate = "validation"
|
||||
|
||||
SupportOutput = Output
|
||||
SupportNoZip = "nozip"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user