Documentation
¶
Index ¶
- func CalculateFlatSchemaDiff(o, n FlatSchema) (map[string]FieldDiff, error)
- func DefaultValueChangeValidation(diff FieldDiff) (bool, error)
- func EnumChangeValidation(diff FieldDiff) (bool, error)
- func MaximumChangeValidation(diff FieldDiff) (bool, error)
- func MaximumItemsChangeValidation(diff FieldDiff) (bool, error)
- func MaximumLengthChangeValidation(diff FieldDiff) (bool, error)
- func MaximumPropertiesChangeValidation(diff FieldDiff) (bool, error)
- func MinimumChangeValidation(diff FieldDiff) (bool, error)
- func MinimumItemsChangeValidation(diff FieldDiff) (bool, error)
- func MinimumLengthChangeValidation(diff FieldDiff) (bool, error)
- func MinimumPropertiesChangeValidation(diff FieldDiff) (bool, error)
- func NoExistingFieldRemoved(old, new v1.CustomResourceDefinition) error
- func NoScopeChange(old, new v1.CustomResourceDefinition) error
- func NoStoredVersionRemoved(old, new v1.CustomResourceDefinition) error
- func RequiredFieldChangeValidation(diff FieldDiff) (bool, error)
- type ChangeValidation
- type ChangeValidator
- type FieldDiff
- type FlatSchema
- type Preflight
- type ValidateFunc
- type Validation
- type ValidationFunc
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateFlatSchemaDiff ¶
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 DefaultValueChangeValidation ¶ added in v0.63.0
DefaultValueChangeValidation adds a validation check to ensure that default values are not changed in a CRD schema: - No new value can be added as default that did not previously have a default value present - Default value of a field cannot be changed - Existing default value for a field cannot be removed This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to a field's default value) - An error if either of the above criteria are not met
func EnumChangeValidation ¶
EnumChangeValidation ensures that: - No enums are added to a field that did not previously have enum restrictions - No enums are removed from a field This function returns: - A boolean representation of whether or not the change has been fully handled (i.e the only change was to enum values) - An error if either of the above validations are not satisfied
func MaximumChangeValidation ¶ added in v0.63.0
MaximumChangeValidation adds a validation check to ensure that existing fields can have their maximum constraints updated in a CRD schema based on the following: - No maximum constraint can be added if one did not exist previously - Maximum constraints can not decrease in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to maximum constraints) - An error if either of the above criteria are not met
func MaximumItemsChangeValidation ¶ added in v0.63.0
MaximumItemsChangeValidation adds a validation check to ensure that existing fields can have their maximum item constraints updated in a CRD schema based on the following: - No maximum item constraint can be added if one did not exist previously - Maximum item constraints can not decrease in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to maximum item constraints) - An error if either of the above criteria are not met
func MaximumLengthChangeValidation ¶ added in v0.63.0
MaximumLengthChangeValidation adds a validation check to ensure that existing fields can have their maximum length constraints updated in a CRD schema based on the following: - No maximum length constraint can be added if one did not exist previously - Maximum length constraints can not decrease in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to maximum length constraints) - An error if either of the above criteria are not met
func MaximumPropertiesChangeValidation ¶ added in v0.63.0
MaximumPropertiesChangeValidation adds a validation check to ensure that existing fields can have their maximum properties constraints updated in a CRD schema based on the following: - No maximum properties constraint can be added if one did not exist previously - Maximum properties constraints can not increase in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to maximum properties constraints) - An error if either of the above criteria are not met
func MinimumChangeValidation ¶ added in v0.63.0
MinimumChangeValidation adds a validation check to ensure that existing fields can have their minimum constraints updated in a CRD schema based on the following: - No minimum constraint can be added if one did not exist previously - Minimum constraints can not increase in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to minimum constraints) - An error if either of the above criteria are not met
func MinimumItemsChangeValidation ¶ added in v0.63.0
MinimumItemsChangeValidation adds a validation check to ensure that existing fields can have their minimum item constraints updated in a CRD schema based on the following: - No minimum item constraint can be added if one did not exist previously - Minimum item constraints can not increase in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to minimum item constraints) - An error if either of the above criteria are not met
func MinimumLengthChangeValidation ¶ added in v0.63.0
MinimumLengthChangeValidation adds a validation check to ensure that existing fields can have their minimum length constraints updated in a CRD schema based on the following: - No minimum length constraint can be added if one did not exist previously - Minimum length constraints can not increase in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to minimum length constraints) - An error if either of the above criteria are not met
func MinimumPropertiesChangeValidation ¶ added in v0.63.0
MinimumPropertiesChangeValidation adds a validation check to ensure that existing fields can have their minimum properties constraints updated in a CRD schema based on the following: - No minimum properties constraint can be added if one did not exist previously - Minimum properties constraints can not increase in value This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to minimum properties constraints) - An error if either of the above criteria are not met
func NoExistingFieldRemoved ¶
func NoExistingFieldRemoved(old, new v1.CustomResourceDefinition) error
func NoScopeChange ¶
func NoScopeChange(old, new v1.CustomResourceDefinition) error
func NoStoredVersionRemoved ¶
func NoStoredVersionRemoved(old, new v1.CustomResourceDefinition) error
func RequiredFieldChangeValidation ¶ added in v0.63.0
RequiredFieldChangeValidation adds a validation check to ensure that existing required fields can be marked as optional in a CRD schema: - No new values can be added as required that did not previously have any required fields present - Existing values can be removed from the required field This function returns: - A boolean representation of whether or not the change has been fully handled (i.e. the only change was to required field values) - An error if either of the above criteria are not met
Types ¶
type ChangeValidation ¶
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 ¶
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 ¶
func (cv *ChangeValidator) Name() string
func (*ChangeValidator) Validate ¶
func (cv *ChangeValidator) Validate(old, new v1.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 ¶
type FieldDiff struct { Old *v1.JSONSchemaProps New *v1.JSONSchemaProps }
type FlatSchema ¶
type FlatSchema map[string]*v1.JSONSchemaProps
FlatSchema is a flat representation of a CRD schema.
func FlattenSchema ¶
func FlattenSchema(schema *v1.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]*v1.JSONSchemaProps{ "^": {}, "^.spec": {}, "^.spec.foo": {}, "^.spec.bar": {}, }
where "^" represents the "root" schema
type Preflight ¶
type Preflight struct {
// contains filtered or unexported fields
}
Preflight is an implementation of preflight.Check to make it easier to add crd upgrade validation as a preflight check
func NewPreflight ¶
func NewPreflight(df cmdcore.DepsFactory, enabled bool) *Preflight
func (*Preflight) SetEnabled ¶
type ValidateFunc ¶
type ValidateFunc func(old, new v1.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 ¶
type Validation interface { // Validate contains the actual validation logic. An error being // returned means validation has failed Validate(old, new v1.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 ¶
func NewValidationFunc(name string, vfunc ValidateFunc) Validation
type ValidationFunc ¶
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 ¶
func (vf *ValidationFunc) Name() string
func (*ValidationFunc) Validate ¶
func (vf *ValidationFunc) Validate(old, new v1.CustomResourceDefinition) error
type Validator ¶
type Validator struct {
Validations []Validation
}