Documentation
¶
Index ¶
- func CalculateFlatSchemaDiff(o, n FlatSchema) (map[string]FieldDiff, error)
- func Default(diff FieldDiff) (bool, error)
- func Enum(diff FieldDiff) (bool, error)
- func MaxItems(diff FieldDiff) (bool, error)
- func MaxLength(diff FieldDiff) (bool, error)
- func MaxProperties(diff FieldDiff) (bool, error)
- func Maximum(diff FieldDiff) (bool, error)
- func MinItems(diff FieldDiff) (bool, error)
- func MinLength(diff FieldDiff) (bool, error)
- func MinProperties(diff FieldDiff) (bool, error)
- func Minimum(diff FieldDiff) (bool, error)
- func NoExistingFieldRemoved(old, new apiextensionsv1.CustomResourceDefinition) error
- func NoScopeChange(old, new apiextensionsv1.CustomResourceDefinition) error
- func NoStoredVersionRemoved(old, new apiextensionsv1.CustomResourceDefinition) error
- func Required(diff FieldDiff) (bool, error)
- func Type(diff FieldDiff) (bool, error)
- type ChangeValidation
- type ChangeValidator
- type FieldDiff
- type FlatSchema
- type Option
- type Preflight
- type ServedVersionValidator
- type ValidateFunc
- type Validation
- type ValidationFunc
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateFlatSchemaDiff ¶ added in v1.3.0
func CalculateFlatSchemaDiff(o, n FlatSchema) (map[string]FieldDiff, error)
CalculateFlatSchemaDiff finds fields in a FlatSchema that are different and returns a mapping of field --> old and new field schemas. If a field exists in the old FlatSchema but not the new an empty diff mapping and an error is returned.
func MaxProperties ¶
func MinProperties ¶
func NoExistingFieldRemoved ¶ added in v1.3.0
func NoExistingFieldRemoved(old, new apiextensionsv1.CustomResourceDefinition) error
func NoScopeChange ¶ added in v1.3.0
func NoScopeChange(old, new apiextensionsv1.CustomResourceDefinition) error
func NoStoredVersionRemoved ¶ added in v1.3.0
func NoStoredVersionRemoved(old, new apiextensionsv1.CustomResourceDefinition) error
Types ¶
type ChangeValidation ¶ added in v1.3.0
ChangeValidation is a function that accepts a FieldDiff as a parameter and should return: - a boolean representation of whether or not the change - an error if the change would be unsafe has been fully handled (i.e no additional changes exist)
type ChangeValidator ¶ added in v1.3.0
type ChangeValidator struct { // Validations is a slice of ChangeValidations // to run against each changed field Validations []ChangeValidation }
ChangeValidator is a Validation implementation focused on handling updates to existing fields in a CRD
func (*ChangeValidator) Name ¶ added in v1.3.0
func (cv *ChangeValidator) Name() string
func (*ChangeValidator) Validate ¶ added in v1.3.0
func (cv *ChangeValidator) Validate(old, new apiextensionsv1.CustomResourceDefinition) error
Validate will compare each version in the provided existing and new CRDs. Since the ChangeValidator is tailored to handling updates to existing fields in each version of a CRD. As such the following is assumed: - Validating the removal of versions during an update is handled outside of this validator. If a version in the existing version of the CRD does not exist in the new version that version of the CRD is skipped in this validator. - Removal of existing fields is unsafe. Regardless of whether or not this is handled by a validator outside this one, if a field is present in a version provided by the existing CRD but not present in the same version provided by the new CRD this validation will fail.
Additionally, any changes that are not validated and handled by the known ChangeValidations are deemed as unsafe and returns an error.
type FieldDiff ¶ added in v1.3.0
type FieldDiff struct { Old *apiextensionsv1.JSONSchemaProps New *apiextensionsv1.JSONSchemaProps }
type FlatSchema ¶ added in v1.3.0
type FlatSchema map[string]*apiextensionsv1.JSONSchemaProps
FlatSchema is a flat representation of a CRD schema.
func FlattenSchema ¶ added in v1.3.0
func FlattenSchema(schema *apiextensionsv1.JSONSchemaProps) FlatSchema
FlattenSchema takes in a CRD version OpenAPIV3Schema and returns a flattened representation of it. For example, a CRD with a schema of: ```yaml
... spec: type: object properties: foo: type: string bar: type: string ...
``` would be represented as:
map[string]*apiextensionsv1.JSONSchemaProps{ "^": {}, "^.spec": {}, "^.spec.foo": {}, "^.spec.bar": {}, }
where "^" represents the "root" schema
type Preflight ¶
type Preflight struct {
// contains filtered or unexported fields
}
func NewPreflight ¶
func NewPreflight(crdCli apiextensionsv1client.CustomResourceDefinitionInterface, opts ...Option) *Preflight
type ServedVersionValidator ¶
type ServedVersionValidator struct {
Validations []ChangeValidation
}
func (*ServedVersionValidator) Name ¶
func (c *ServedVersionValidator) Name() string
func (*ServedVersionValidator) Validate ¶
func (c *ServedVersionValidator) Validate(old, new apiextensionsv1.CustomResourceDefinition) error
type ValidateFunc ¶ added in v1.3.0
type ValidateFunc func(old, new apiextensionsv1.CustomResourceDefinition) error
ValidateFunc is a function to validate a CustomResourceDefinition for safe upgrades. It accepts the old and new CRDs and returns an error if performing an upgrade from old -> new is unsafe.
type Validation ¶ added in v1.3.0
type Validation interface { // Validate contains the actual validation logic. An error being // returned means validation has failed Validate(old, new apiextensionsv1.CustomResourceDefinition) error // Name returns a human-readable name for the validation Name() string }
Validation is a representation of a validation to run against a CRD being upgraded
func NewValidationFunc ¶ added in v1.3.0
func NewValidationFunc(name string, vfunc ValidateFunc) Validation
type ValidationFunc ¶ added in v1.3.0
type ValidationFunc struct {
// contains filtered or unexported fields
}
ValidationFunc is a helper to wrap a ValidateFunc as an implementation of the Validation interface
func (*ValidationFunc) Name ¶ added in v1.3.0
func (vf *ValidationFunc) Name() string
func (*ValidationFunc) Validate ¶ added in v1.3.0
func (vf *ValidationFunc) Validate(old, new apiextensionsv1.CustomResourceDefinition) error
type Validator ¶ added in v1.3.0
type Validator struct {
Validations []Validation
}
func (*Validator) Validate ¶ added in v1.3.0
func (v *Validator) Validate(old, new apiextensionsv1.CustomResourceDefinition) error