pkg

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SchemaErrorDetailsDisabled = true

Functions

func AddKubeaddFlags

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

AddKubeaddFlags adds the default flags for kubedd to cmd

func Contains

func Contains(key string, patterns []string) bool

func NewKubeCheckerImpl

func NewKubeCheckerImpl() *kubeCheckerImpl

func RegexMatch

func RegexMatch(s string, pattern string) bool

func RegisterArrayUniqueItemsChecker

func RegisterArrayUniqueItemsChecker(fn SliceUniqueItemsChecker)

RegisterArrayUniqueItemsChecker is used to register a customized function used to check if JSON array have unique items.

func VisitJSON

func VisitJSON(schema *openapi3.Schema, value interface{}, settings SchemaSettings) openapi3.MultiError

Types

type Cluster

type Cluster struct {
	Name    string
	Version string
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(kubeconfig string, kubecontext string) *Cluster

func (*Cluster) FetchK8sObjects

func (c *Cluster) FetchK8sObjects(gvks []schema.GroupVersionKind, conf *Config) []unstructured.Unstructured

func (*Cluster) ServerVersion

func (c *Cluster) ServerVersion() (string, error)

type Config

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

	// TargetKubernetesVersion represents the version of Kubernetes
	// to which we want to migrate
	TargetKubernetesVersion string

	// SourceKubernetesVersion represents the version of Kubernetes
	// on which kubernetes objects are running currently
	SourceKubernetesVersion string

	// TargetSchemaLocation is the base URL of target kubernetes version.
	// It can be either a remote location or a local directory
	TargetSchemaLocation string

	// SourceSchemaLocation is the base URL of source kubernetes versions.
	// It can be either a remote location or a local directory
	SourceSchemaLocation string

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

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

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

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

	// 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

	// IgnoreKeysFromDeprecation is the list of keys to be skipped for depreciation check
	IgnoreKeysFromDeprecation []string

	// IgnoreKeysFromValidation is the list of keys to be skipped for validation check
	IgnoreKeysFromValidation []string

	// SelectNamespaces is the list of namespaces to be validated, by default all namespaces are validated
	SelectNamespaces []string

	// IgnoreNamespaces is the list of namespaces to be skipped for validation, by default none are skipped
	IgnoreNamespaces []string

	// SelectKinds is the list of kinds to be validated, by default all kinds are validated
	SelectKinds []string

	// IgnoreKinds is the list of kinds to be skipped for validation, by default none are skipped
	IgnoreKinds []string

	// IgnoreNullErrors is the flag to ignore null value errors
	IgnoreNullErrors bool
}

A Config object contains various configuration data for kubedd

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a Config with default values

type GroupVersions

type GroupVersions struct {
	GroupVersions   []string
	GAGroupVersions []string
}

type KindInfo

type KindInfo struct {
	Version      string
	Group        string
	RestPath     string
	ComponentKey string
	IsGA         bool
}

type KubeChecker

type KubeChecker interface {
	IsApiVersionSupported(releaseVersion, apiVersion, kind string) bool
	Parser
	Validator
}

type OutputManager

type OutputManager interface {
	PutBulk(r []ValidationResult) error
	Put(r ValidationResult) error
	Flush() error
}

OutputManager controls how results of the `kubedd` evaluation will be recorded and reported to the end user. This interface is kept private to ensure all implementations are closed within this package.

func GetOutputManager

func GetOutputManager(outFmt string, noColor bool) OutputManager

type Parser

type Parser interface {
	LoadFromUrl(releaseVersion string, force bool) error
	LoadFromPath(releaseVersion string, filePath string, force bool) error
}

type STDOutputManager

type STDOutputManager struct {
	// contains filtered or unexported fields
}

STDOutputManager reports `kubedd` results to stdout.

func (*STDOutputManager) DeprecationTableBodyOutput

func (s *STDOutputManager) DeprecationTableBodyOutput(results []ValidationResult, currentVersion bool)

func (*STDOutputManager) Flush

func (s *STDOutputManager) Flush() error

func (*STDOutputManager) Put

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

func (*STDOutputManager) PutBulk

func (s *STDOutputManager) PutBulk(results []ValidationResult) error

func (*STDOutputManager) SummaryTableBodyOutput

func (s *STDOutputManager) SummaryTableBodyOutput(results []ValidationResult)

func (*STDOutputManager) ValidationErrorTableBodyOutput

func (s *STDOutputManager) ValidationErrorTableBodyOutput(results []ValidationResult, currentVersion bool)

type SchemaError

type SchemaError struct {
	Value interface{}

	Schema      *openapi3.Schema
	SchemaField string
	Reason      string
	Origin      error
	// contains filtered or unexported fields
}

func (*SchemaError) Error

func (err *SchemaError) Error() string

func (*SchemaError) JSONPointer

func (err *SchemaError) JSONPointer() []string

type SchemaSettings

type SchemaSettings struct {
	MultiError bool
}

type SliceUniqueItemsChecker

type SliceUniqueItemsChecker func(items []interface{}) bool

SliceUniqueItemsChecker is an function used to check if an given slice have unique items.

type SummarySchemaError added in v0.1.2

type SummarySchemaError struct {
	Path        string
	SchemaField string
	Reason      string
	Origin      error
}

type SummaryValidationResult added in v0.1.2

type SummaryValidationResult struct {
	FileName               string
	Kind                   string
	APIVersion             string
	ResourceName           string
	ResourceNamespace      string
	Deleted                bool
	Deprecated             bool
	LatestAPIVersion       string
	IsVersionSupported     int
	ErrorsForOriginal      []*SummarySchemaError
	ErrorsForLatest        []*SummarySchemaError
	DeprecationForOriginal []*SummarySchemaError
	DeprecationForLatest   []*SummarySchemaError
}

type ValidFormat

type ValidFormat struct{}

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

func (ValidFormat) IsFormat

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

IsFormat always returns true and meets the gojsonschema.FormatChecker interface

type ValidationResult

type ValidationResult struct {
	FileName               string
	Kind                   string
	APIVersion             string
	ValidatedAgainstSchema bool
	Errors                 []gojsonschema.ResultError
	ErrorsForOriginal      []*openapi3.SchemaError
	ErrorsForLatest        []*openapi3.SchemaError
	DeprecationForOriginal []*SchemaError
	DeprecationForLatest   []*SchemaError
	ResourceName           string
	ResourceNamespace      string
	Deleted                bool
	Deprecated             bool
	LatestAPIVersion       string
	IsVersionSupported     int
}

ValidationResult contains the details from validating a given Kubernetes resource

func FilterValidationResults

func FilterValidationResults(result ValidationResult, conf *Config) ValidationResult

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

type Validator

type Validator interface {
	ValidateJson(spec string, releaseVersion string) (ValidationResult, error)
	ValidateYaml(spec string, releaseVersion string) (ValidationResult, error)
	ValidateObject(spec map[string]interface{}, releaseVersion string) (ValidationResult, error)
	GetKinds(releaseVersion string) ([]schema.GroupVersionKind, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL