Skip to content

Commit

Permalink
change SkipCrdSchemaMiss into IgnoreMissingSchemas and the related fl…
Browse files Browse the repository at this point in the history
…ag as well
  • Loading branch information
emirozer committed Jun 28, 2019
1 parent 94a9ef3 commit 81733bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/spf13/viper"
"github.com/xeipuuv/gojsonschema"
"gopkg.in/yaml.v2"

"github.com/instrumenta/kubeval/log"
)

// Version represents the version of Kubernetes
Expand All @@ -36,9 +38,9 @@ var OpenShift bool
// the schema. The API allows them, but kubectl does not
var Strict bool

// SkipCrdSchemaMiss tells kubeval whether skip validation
// step of CustomResourceDefinitions
var SkipCrdSchemaMiss bool
// IgnoreMissingSchemas tells kubeval whether to skip validation
// for resource definitions without an available schema
var IgnoreMissingSchemas bool

// ValidFormat is a type for quickly forcing
// new formats on the gojsonschema loader
Expand Down Expand Up @@ -153,6 +155,9 @@ func determineAPIVersion(body interface{}) (string, error) {
func validateResource(data []byte, fileName string, schemaCache map[string]*gojsonschema.Schema) (ValidationResult, error) {
var spec interface{}
result := ValidationResult{}
if IgnoreMissingSchemas {
log.Warn("Skipping missing schema validation!")
}
result.FileName = fileName
err := yaml.Unmarshal(data, &spec)
if err != nil {
Expand Down Expand Up @@ -203,7 +208,7 @@ func validateResource(data []byte, fileName string, schemaCache map[string]*gojs
gojsonschema.FormatCheckers.Add("int32", ValidFormat{})
gojsonschema.FormatCheckers.Add("int-or-string", ValidFormat{})

if SkipCrdSchemaMiss {
if IgnoreMissingSchemas {
return result, nil
}

Expand Down
2 changes: 1 addition & 1 deletion kubeval/kubeval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestStrictCatchesAdditionalErrors(t *testing.T) {
}

func TestSkipCrdSchemaMiss(t *testing.T) {
SkipCrdSchemaMiss = true
IgnoreMissingSchemas = true
filePath, _ := filepath.Abs("../fixtures/test_crd.yaml")
fileContents, _ := ioutil.ReadFile(filePath)
results, _ := Validate(fileContents, "test_crd.yaml")
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ func init() {
RootCmd.Flags().StringVarP(&kubeval.SchemaLocation, "schema-location", "", kubeval.DefaultSchemaLocation, "Base URL used to download schemas. Can also be specified with the environment variable KUBEVAL_SCHEMA_LOCATION")
RootCmd.Flags().BoolVarP(&kubeval.OpenShift, "openshift", "", false, "Use OpenShift schemas instead of upstream Kubernetes")
RootCmd.Flags().BoolVarP(&kubeval.Strict, "strict", "", false, "Disallow additional properties not in schema")
RootCmd.Flags().BoolVarP(&kubeval.IgnoreMissingSchemas, "ignore-missing-schemas", "", false, "Skip validation for resource definitions without a schema")
RootCmd.SetVersionTemplate(`{{.Version}}`)
RootCmd.Flags().BoolVarP(&kubeval.SkipCrdSchemaMiss, "skip-crd-schema-miss", "", false, "Skip validation for CRD's without schema")
RootCmd.Flags().BoolVarP(&Version, "version", "", false, "Display the kubeval version information and exit")
viper.BindPFlag("schema_location", RootCmd.Flags().Lookup("schema-location"))
RootCmd.PersistentFlags().StringP("filename", "f", "stdin", "filename to be displayed when testing manifests read from stdin")
viper.BindPFlag("filename", RootCmd.PersistentFlags().Lookup("filename"))
Expand Down

0 comments on commit 81733bf

Please sign in to comment.