crdutils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 23 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

Functions

func CheckPolicies added in v1.5.0

func CheckPolicies(t *testing.T, policiesDir string, fromFile func(string) error)

func CreateTempFile

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

func ReadFileTemplate added in v1.5.0

func ReadFileTemplate(fileName string, data any) (string, error)

Read a template file and apply data to it, returning the resulting 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
}

type GenericTracingPolicy added in v1.5.0

type GenericTracingPolicy struct {
	metav1.TypeMeta
	Metadata metav1.ObjectMeta          `json:"metadata"`
	Spec     v1alpha1.TracingPolicySpec `json:"spec"`
}

func FileConfigWithTemplate added in v1.5.0

func FileConfigWithTemplate(fileName string, data any) (*GenericTracingPolicy, error)

func (*GenericTracingPolicy) GetObjectMetaStruct added in v1.5.0

func (gtp *GenericTracingPolicy) GetObjectMetaStruct() *metav1.ObjectMeta

Jump to

Keyboard shortcuts

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