...

Package kubeval

import "github.com/instrumenta/kubeval/kubeval"
Overview
Index

Overview ▾

Constants

DefaultSchemaLocation is the default location to search for schemas

const DefaultSchemaLocation = "https://kubernetesjsonschema.dev"

OpenShiftSchemaLocation is the alternative location for OpenShift specific schemas

const OpenShiftSchemaLocation = "https://raw.githubusercontent.com/garethr/openshift-json-schema/master"

func AddKubevalFlags

func AddKubevalFlags(cmd *cobra.Command, config *Config) *cobra.Command

AddKubevalFlags adds the default flags for kubeval to cmd

func GetOutputManager

func GetOutputManager(outFmt string) outputManager

func NewSchemaCache

func NewSchemaCache() map[string]*gojsonschema.Schema

NewSchemaCache returns a new schema cache to be used with ValidateWithCache

type Config

A Config object contains various configuration data for kubeval

type Config struct {
    // DefaultNamespace is the namespace to assume in resources
    // if no namespace is set in `metadata:namespace` (as used with
    // `kubectl apply --namespace ...` or `helm install --namespace ...`,
    // for example)
    DefaultNamespace string

    // KubernetesVersion represents the version of Kubernetes
    // for which we should load the schema
    KubernetesVersion string

    // SchemaLocation is the base URL from which to search for schemas.
    // It can be either a remote location or a local directory
    SchemaLocation string

    // AdditionalSchemaLocations is a list of alternative base URLs from
    // which to search for schemas, given that the desired schema was not
    // found at SchemaLocation
    AdditionalSchemaLocations []string

    // OpenShift represents whether to test against
    // upstream Kubernetes or the OpenShift schemas
    OpenShift bool

    // Strict tells kubeval whether to prohibit properties not in
    // the schema. The API allows them, but kubectl does not
    Strict bool

    // IgnoreMissingSchemas tells kubeval whether to skip validation
    // for resource definitions without an available schema
    IgnoreMissingSchemas bool

    // ExitOnError tells kubeval whether to halt processing upon the
    // first error encountered or to continue, aggregating all errors
    ExitOnError bool

    // KindsToSkip is a list of kubernetes resources types with which to skip
    // schema validation
    KindsToSkip []string

    // KindsToReject is a list of case-sensitive prohibited kubernetes resources types
    KindsToReject []string

    // FileName is the name to be displayed when testing manifests read from stdin
    FileName string

    // OutputFormat is the name of the output formatter which will be used when
    // reporting results to the user.
    OutputFormat string

    // Quiet indicates whether non-results output should be emitted to the applications
    // log.
    Quiet bool

    // InsecureSkipTLSVerify controls whether to skip TLS certificate validation
    // when retrieving schema content over HTTPS
    InsecureSkipTLSVerify bool
}

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a Config with default values

type STDOutputManager

STDOutputManager reports `kubeval` results to stdout.

type STDOutputManager struct {
}

func (*STDOutputManager) Flush

func (s *STDOutputManager) Flush() error

func (*STDOutputManager) Put

func (s *STDOutputManager) Put(result ValidationResult) error

type ValidFormat

ValidFormat is a type for quickly forcing new formats on the gojsonschema loader

type ValidFormat struct{}

func (ValidFormat) IsFormat

func (f ValidFormat) IsFormat(input interface{}) bool

IsFormat always returns true and meets the gojsonschema.FormatChecker interface

type ValidationResult

ValidationResult contains the details from validating a given Kubernetes resource

type ValidationResult struct {
    FileName               string
    Kind                   string
    APIVersion             string
    ValidatedAgainstSchema bool
    Errors                 []gojsonschema.ResultError
    ResourceName           string
    ResourceNamespace      string
}

func Validate

func Validate(input []byte, conf ...*Config) ([]ValidationResult, error)

Validate a Kubernetes YAML file, parsing out individual resources and validating them all according to the relevant schemas

func ValidateWithCache

func ValidateWithCache(input []byte, schemaCache map[string]*gojsonschema.Schema, conf ...*Config) ([]ValidationResult, error)

ValidateWithCache validates a Kubernetes YAML file, parsing out individual resources and validating them all according to the relevant schemas Allows passing a kubeval.NewSchemaCache() to cache schemas in-memory between validations

func (*ValidationResult) QualifiedName

func (v *ValidationResult) QualifiedName() string

QualifiedName returns a string of the [namespace.]name of the k8s resource

func (*ValidationResult) VersionKind

func (v *ValidationResult) VersionKind() string

VersionKind returns a string representation of this result's apiVersion and kind