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 ¶
- Variables
 - func CheckPolicies(t *testing.T, policiesDir string, fromFile func(string) error)
 - func CreateTempFile(t *testing.T, data string) string
 - func ReadFileTemplate(fileName string, data any) (string, error)
 - type CRDContext
 - func (c *CRDContext[P]) ApplyDefaults(data []byte) ([]byte, unstructured.Unstructured, error)
 - func (c *CRDContext[P]) FromFile(path string) (P, error)
 - func (c *CRDContext[P]) FromYAML(data string) (P, error)
 - func (c *CRDContext[P]) IsNamespaced() bool
 - func (c *CRDContext[P]) Validate(obj CRDObject, unstr *unstructured.Unstructured) error
 
- type CRDObject
 - type GenericTracingPolicy
 
Constants ¶
This section is empty.
Variables ¶
var TPContext, _ = NewCRDContext[*GenericTracingPolicy](&client.TracingPolicyCRD.Definition)
    Functions ¶
func CheckPolicies ¶ added in v1.5.0
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