crdupgradesafety

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

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 Default

func Default(diff FieldDiff) (bool, error)

func Enum

func Enum(diff FieldDiff) (bool, error)

func MaxItems

func MaxItems(diff FieldDiff) (bool, error)

func MaxLength

func MaxLength(diff FieldDiff) (bool, error)

func MaxProperties

func MaxProperties(diff FieldDiff) (bool, error)

func Maximum

func Maximum(diff FieldDiff) (bool, error)

func MinItems

func MinItems(diff FieldDiff) (bool, error)

func MinLength

func MinLength(diff FieldDiff) (bool, error)

func MinProperties

func MinProperties(diff FieldDiff) (bool, error)

func Minimum

func Minimum(diff FieldDiff) (bool, error)

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

func Required

func Required(diff FieldDiff) (bool, error)

func Type

func Type(diff FieldDiff) (bool, error)

Types

type ChangeValidation added in v1.3.0

type ChangeValidation func(diff FieldDiff) (bool, error)

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

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 Option

type Option func(p *Preflight)

func WithValidator

func WithValidator(v *Validator) Option

type Preflight

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

func (*Preflight) Install

func (p *Preflight) Install(ctx context.Context, rel *release.Release) error

func (*Preflight) Upgrade

func (p *Preflight) Upgrade(ctx context.Context, rel *release.Release) error

type ServedVersionValidator

type ServedVersionValidator struct {
	Validations []ChangeValidation
}

func (*ServedVersionValidator) Name

func (c *ServedVersionValidator) Name() string

func (*ServedVersionValidator) Validate

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

type Validator added in v1.3.0

type Validator struct {
	Validations []Validation
}

func (*Validator) Validate added in v1.3.0

Jump to

Keyboard shortcuts

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