Documentation ¶
Index ¶
- func CalculateFlatSchemaDiff(o, n FlatSchema) (map[string]FieldDiff, error)
- func EnumChangeValidation(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
- 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 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 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
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
}