crd

package
v0.14.0 Latest Latest
Warning

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

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

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

View Source
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

View Source
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")
)
View Source
var DefaultFileGenerator = NewFileGenerator()
View Source
var DefaultHTTPGenerator = NewHTTPGenerator(http.DefaultClient)

DefaultHTTPGenerator is an opinionated HTTPGenerator.

View Source
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 HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

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.

func (*KCLPackage) GenerateC

func (s *KCLPackage) GenerateC(ctx context.Context) error

GenerateC generates KCL schemas from Kubernetes CRDs and writes them to the package path concurrently. Any errors will be collected and will only be returned after all processing is complete.

type NoGenerator

type NoGenerator struct{}

NoGenerator always returns empty lists.

func NewNoGenerator

func NewNoGenerator() *NoGenerator

NewNoGenerator creates a new NoGenerator.

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳