generate

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

pkg/generat/crd_generator.go

CRD generator — derives a CustomResourceDefinition from a Katalog.

The Katalog is the single source of truth. Everything needed to produce a valid CRD is already declared:

apiTypes        → group, version, kind, plural, scope
validation      → required fields (deny rules with operator: exists)
mutation        → optional fields with defaults + type inference
template exprs  → additional spec fields referenced as {{ .spec.* }}
status.fields   → status subresource schema + printer columns
conversion      → webhook config (when conversion paths are declared)

Usage:

gen := generator.NewCRDGenerator(katalogEntry)
crd, err := gen.Generate()
yaml.NewEncoder(os.Stdout).Encode(crd)

CLI:

ork generate crd --katalog katalog.yaml -o crd.yaml

pkg/generate/helper.go

pkg/generate/registry_generator.go

Index

Constants

View Source
const (
	// RuntimePackage is the fixed output directory for all generated runtime files.
	// Both the registry and declarative hook implementations are written here.
	// The Orkestra runtime imports this package directly.
	RuntimePackage = "pkg/runtime"

	// RegistryFile is the generated file containing:
	//   - ObjectRegistry
	//   - ListRegistry
	//   - HookRegistry
	//   - ReconcilerRegistry
	//   - RegisterScheme()
	//
	// It is regenerated on every `ork generate runtime` invocation.
	RegistryFile = "zz_generated_runtime_registry.go"

	// ExamplesDir is the output directory for generated example manifests.
	// Each CRD receives a minimal example YAML manifest for onboarding and testing.
	ExamplesDir = "_runtime/examples"

	// DocsDir is the output directory for generated Markdown documentation.
	// Includes per-CRD docs, an index, and dependency graph documentation.
	DocsDir = "_runtime/docs"

	// TestDir is the output directory for generated test scaffolding.
	// Contains unit test stubs and integration test templates for each CRD.
	TestDir = "_runtime/test"

	// DashDir is the output directory for generated Grafana dashboards.
	// Each CRD receives a dashboard JSON file with metrics panels.
	DashDir = "_runtime/dashboards"
)

Variables

This section is empty.

Functions

func Bundle

func Bundle(kfg *konfig.Konfig, rules []rbacv1.PolicyRule, namespace, outputFile string) error

func ConfigMap

func ConfigMap(inputFile, namespace, outputFile string) error

func Dashboards

func Dashboards(c []orktypes.CRDEntry, dryRun bool) error

func Docs

func Docs(c []orktypes.CRDEntry, dryRun bool) error

func Examples

func Examples(crds []orktypes.CRDEntry, dryRun bool) error

func RBAC

func RBAC(kfg *konfig.Konfig, rules []rbacv1.PolicyRule, namespace, outputFile string) error

func RenderConfigMapToString

func RenderConfigMapToString(inputFile, namespace string) (string, error)

func RenderRBACToString

func RenderRBACToString(kfg *konfig.Konfig, rules []rbacv1.PolicyRule, namespace string) (string, error)

func Runtime

func Runtime(m *merger.Merger, dryRun bool) error

Runtime generates zz_generated_runtime_registry.go from the merged Katalog.

When generation is needed (and why):

Typed CRDs (apiTypes.location set)
  The compiled Go type must be registered so the informer and REST client
  can decode API server responses. Without this, List/Watch calls fail with
  "not suitable for converting" errors.

Go hooks (reconciler.hooks declared)
  The hook function lives in an external package. The generator writes the
  import and wires it into HookRegistry so addHooks() can find it.

Custom constructors (reconciler.default: false)
  Same as Go hooks — external function needs import and ReconcilerRegistry entry.

When generation is NOT needed:

Dynamic template CRDs (only onCreate/onReconcile/onDelete declared)
  GenericReconciler.runTemplateReconcile() reads the Katalog's OperatorBoxConfig
  directly at runtime and calls the OrkestraRegistry functions itself.
  No generated file. No ork generate runtime. Just ork run.

func Tests

func Tests(crds []orktypes.CRDEntry, dryRun bool) error

Types

type CRDGenerator

type CRDGenerator struct {
	// contains filtered or unexported fields
}

CRDGenerator produces a CRD from a CRDEntry.

func NewCRDGenerator

func NewCRDGenerator(crd orktypes.CRDEntry) *CRDGenerator

NewCRDGenerator creates a generator for one CRD entry.

func (*CRDGenerator) Generate

Generate produces the complete CRD object.

type CRDMeta

type CRDMeta struct {
	Name        string
	Description string

	Group      string
	Version    string
	Kind       string
	Plural     string
	Namespaced bool
	Namespace  string

	Workers int
	Resync  string

	DependsOn []string

	Reconciler struct {
		Default  bool
		Function string // for custom reconcilers
	}

	Queue struct {
		MaxQueueDepth int
		Default       bool
	}

	API struct {
		Object string
		List   string
		Alias  string
		Import string
	}
}

Docs and dashboards

type CRGenerator

type CRGenerator struct {
	// contains filtered or unexported fields
}

CRGenerator produces an example CR from a CRDEntry.

func NewCRGenerator

func NewCRGenerator(crd orktypes.CRDEntry) *CRGenerator

NewCRGenerator creates a CR generator for one CRD entry.

func (*CRGenerator) Generate

func (g *CRGenerator) Generate() map[string]interface{}

Generate produces an example CR as a plain map (ready for YAML encoding). Required fields are filled with typed placeholders. Optional fields show their default values.

type DashboardTemplateData

type DashboardTemplateData struct {
	Timestamp time.Time
	CRD       CRDMeta
}

type DocsTemplateData

type DocsTemplateData struct {
	Timestamp time.Time
	CRDs      []CRDMeta
	CRD       CRDMeta // for per‑CRD templates
}

Jump to

Keyboard shortcuts

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