crdutils

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package crdutils provides utilities for working with CRDs outside of Kubernetes context. It allows to load CRD objects from YAML files, apply defaults and validate them using the CRD's schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTempFile

func CreateTempFile(t *testing.T, data string) string

Types

type CRDContext

type CRDContext[P CRDObject] struct {
	// contains filtered or unexported fields
}

CRDContext holds structs necessary to default and validate a particular CRD. The type parameter P must be a pointer to a struct representing the CRD. It doesn't currently support CRD versioning.

func NewCRDContext

func NewCRDContext[P CRDObject](crd *extv1.CustomResourceDefinition) (*CRDContext[P], error)

NewCRDContext creates a new CRDContext from extv1.CustomResourceDefinition.

func (*CRDContext[P]) ApplyDefaults

func (c *CRDContext[P]) ApplyDefaults(data []byte) ([]byte, unstructured.Unstructured, error)

ApplyDefaults applies default values to an unstructured object using the provided structural schema. It uses internal k8s api server machinery and can only process unstructured objects, so it requires to unmarshal and marshal again.

func (*CRDContext[P]) FromFile

func (c *CRDContext[P]) FromFile(path string) (P, error)

FromFile loads a CRD object from a YAML file at the given path.

func (*CRDContext[P]) FromYAML

func (c *CRDContext[P]) FromYAML(data string) (P, error)

FromYAML loads a CRD object from a YAML string, applies defaults and validations, and returns a typed object.

func (*CRDContext[P]) IsNamespaced

func (c *CRDContext[P]) IsNamespaced() bool

func (*CRDContext[P]) Validate

func (c *CRDContext[P]) Validate(obj CRDObject, unstr *unstructured.Unstructured) error

Validate validates an object using the CRD's schema validator and standard metadata and lists validations.

type CRDObject

type CRDObject interface {
	// don't confuse with func GetObjectMeta() metav1.Object defined by k8s apimachinery
	GetObjectMetaStruct() *metav1.ObjectMeta
}

Jump to

Keyboard shortcuts

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