Documentation
¶
Overview ¶
Package crd provides functionality for generating and managing Kubernetes Custom Resource Definitions.
This package supports various generation strategies for CRDs, including extracting them from Helm charts, loading them from file paths, or retrieving them from URLs. It provides a unified interface for obtaining and processing CRD resources from different sources.
Index ¶
Constants ¶
const ( // GeneratorTypeDefault is the default generator type. GeneratorTypeDefault GeneratorType = "" // GeneratorTypeAuto tries to automatically detect the best generator. GeneratorTypeAuto GeneratorType = "AUTO" // GeneratorTypeTemplate uses a template-based generator. GeneratorTypeTemplate GeneratorType = "TEMPLATE" // GeneratorTypeChartPath uses a chart path-based generator. GeneratorTypeChartPath GeneratorType = "CHART-PATH" // GeneratorTypePath uses either a local path or a URL-based generator. GeneratorTypePath GeneratorType = "PATH" // GeneratorTypeNone skips CRD generation. GeneratorTypeNone GeneratorType = "NONE" CRDAPIVersion string = "apiextensions.k8s.io/v1" CRDKind string = "CustomResourceDefinition" )
Variables ¶
var ( // GeneratorTypeEnum lists all valid CRD generator types. GeneratorTypeEnum = []any{ GeneratorTypeAuto, GeneratorTypeTemplate, GeneratorTypeChartPath, GeneratorTypePath, GeneratorTypeNone, } // ErrInvalidFormat indicates an unexpected or invalid format was encountered. ErrInvalidFormat = errors.New("invalid format") // ErrGenerateKCL indicates an error occurred during KCL generation. ErrGenerateKCL = errors.New("failed to generate KCL") )
var DefaultFileGenerator = NewFileGenerator()
var DefaultHTTPGenerator = NewHTTPGenerator(http.DefaultClient)
DefaultHTTPGenerator is an opinionated HTTPGenerator.
var DefaultNoGenerator = NewNoGenerator()
Functions ¶
func SplitCRDVersions ¶
func SplitCRDVersions(crd *unstructured.Unstructured) (map[string]unstructured.Unstructured, error)
SplitCRDVersions separates a CRD with multiple versions into individual CRDs. Returns a map where the key is the version name and the value is the CRD object.
Types ¶
type FileGenerator ¶
type FileGenerator struct {
*ReaderGenerator
}
FileGenerator reads CRDs from file paths and returns corresponding []*unstructured.Unstructured representations.
func NewFileGenerator ¶
func NewFileGenerator() *FileGenerator
func (*FileGenerator) FromPath ¶
func (g *FileGenerator) FromPath(path string) ([]*unstructured.Unstructured, error)
FromPath reads CRDs from the given file path and returns the corresponding []*unstructured.Unstructured representation.
func (*FileGenerator) FromPaths ¶
func (g *FileGenerator) FromPaths(paths ...string) ([]*unstructured.Unstructured, error)
FromPaths reads CRDs from the given file paths and returns the corresponding []*unstructured.Unstructured representation.
type GeneratorType ¶
type GeneratorType string
GeneratorType defines the type of CRD generator to use.
func GetGeneratorType ¶
func GetGeneratorType(t string) GeneratorType
type HTTPGenerator ¶
type HTTPGenerator struct { *ReaderGenerator HTTPClient HTTPDoer }
ReaderGenerator reads CRDs from a given location and returns corresponding []*unstructured.Unstructured representations.
func NewHTTPGenerator ¶
func NewHTTPGenerator(httpClient HTTPDoer) *HTTPGenerator
func (*HTTPGenerator) FromURL ¶
func (g *HTTPGenerator) FromURL(ctx context.Context, crdURL *url.URL) ([]*unstructured.Unstructured, error)
func (*HTTPGenerator) FromURLs ¶
func (g *HTTPGenerator) FromURLs(ctx context.Context, crdURLs ...*url.URL) ([]*unstructured.Unstructured, error)
type KCLPackage ¶
type KCLPackage struct {
// contains filtered or unexported fields
}
KCLPackage represents a KCL package that contains CRD schemas.
func NewKCLPackage ¶
func NewKCLPackage(crds []*unstructured.Unstructured, path string) *KCLPackage
NewKCLPackage creates a new KCLPackage at the specified path, containing the provided CRD resources.
func (*KCLPackage) Generate ¶
func (s *KCLPackage) Generate() error
Generate generates KCL schemas from Kubernetes CRDs and writes them to the package path.
type NoGenerator ¶
type NoGenerator struct{}
NoGenerator always returns empty lists.
func (*NoGenerator) FromData ¶
func (g *NoGenerator) FromData(_ []byte) ([]*unstructured.Unstructured, error)
FromData returns an empty list, regardless of the input data.
func (*NoGenerator) FromPaths ¶
func (g *NoGenerator) FromPaths(_ ...string) ([]*unstructured.Unstructured, error)
FromPaths returns an empty list, regardless of the input paths.
type ReaderGenerator ¶
type ReaderGenerator struct{}
ReaderGenerator reads CRDs from a given location and returns corresponding []*unstructured.Unstructured representations.
func NewReaderGenerator ¶
func NewReaderGenerator() *ReaderGenerator
NewReaderGenerator creates a new ReaderGenerator.
func (*ReaderGenerator) FromData ¶
func (g *ReaderGenerator) FromData(data []byte) ([]*unstructured.Unstructured, error)
func (*ReaderGenerator) FromReader ¶
func (g *ReaderGenerator) FromReader(r io.Reader) ([]*unstructured.Unstructured, error)