Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions kubeval/formats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kubeval

import (
"github.com/xeipuuv/gojsonschema"
)

// ValidFormat is a type for quickly forcing
// new formats on the gojsonschema loader
type ValidFormat struct{}

// IsFormat always returns true and meets the
// gojsonschema.FormatChecker interface
func (f ValidFormat) IsFormat(input interface{}) bool {
return true
}

func init() {
// Without forcing these types the schema fails to load
// Need to work out proper handling for these types
gojsonschema.FormatCheckers.Add("int64", ValidFormat{})
gojsonschema.FormatCheckers.Add("byte", ValidFormat{})
gojsonschema.FormatCheckers.Add("int32", ValidFormat{})
gojsonschema.FormatCheckers.Add("int-or-string", ValidFormat{})
}
27 changes: 5 additions & 22 deletions kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,14 @@ import (
"github.com/instrumenta/kubeval/log"
)

// ValidFormat is a type for quickly forcing
// new formats on the gojsonschema loader
type ValidFormat struct{}

// IsFormat always returns true and meets the
// gojsonschema.FormatChecker interface
func (f ValidFormat) IsFormat(input interface{}) bool {
return true
}

// ValidationResult contains the details from
// validating a given Kubernetes resource
type ValidationResult struct {
FileName string
Kind string
APIVersion string
ValidatedAgainstSchema bool
Errors []gojsonschema.ResultError
FileName string
Kind string
APIVersion string
ValidatedAgainstSchema bool
Errors []gojsonschema.ResultError
}

func determineSchema(kind, apiVersion string, config *Config) string {
Expand Down Expand Up @@ -150,13 +140,6 @@ func validateAgainstSchema(body interface{}, resource *ValidationResult, schemaC
return handleMissingSchema(fmt.Errorf("Failed initalizing schema %s: see first error", schemaRef), config)
}

// Without forcing these types the schema fails to load
// Need to Work out proper handling for these types
gojsonschema.FormatCheckers.Add("int64", ValidFormat{})
gojsonschema.FormatCheckers.Add("byte", ValidFormat{})
gojsonschema.FormatCheckers.Add("int32", ValidFormat{})
gojsonschema.FormatCheckers.Add("int-or-string", ValidFormat{})

documentLoader := gojsonschema.NewGoLoader(body)
results, err := schema.Validate(documentLoader)
if err != nil {
Expand Down