children

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

pkg/children

children reads, enriches, and exposes the live Kubernetes state of every child resource that a Katalog operator manages. It is the bridge between a Katalog's YAML declarations and the running cluster — translating template source lists into a structured map that status field expressions can navigate.

The single public entry point is ReadChildren. Everything else in the package supports it.

children := children.ReadChildren(ctx, kube, obj, resolver, crd)
// → map["deployments"]["my-api"] = { ... live object ... , "_pods": [...], "_warnings": [...] }

Developer documentation

I want to… Go to
Understand what ReadChildren produces and how to use it in status expressions docs/01-overview.md
Understand how child resources are read from the cluster docs/02-reading.md
Understand name resolution and forEach expansion docs/03-names-foreach.md
Understand enrichment layers (_pods, _warnings, _endpoints, _pv) docs/04-enrichment.md
Understand the built-in kind registry (GVRs, metadata, RBAC detection) docs/05-builtins.md
Add a new enrichment layer docs/04-enrichment.md#adding-a-new-layer

File layout

File Responsibility
children.go Package doc and ReadChildren entry point
read.go readResourceGroup, firstValue, mergeTemplates
names.go Name resolution (resolvedChildName, *Names helpers)
foreach.go ExpandForEach* — template expansion over list fields
foreach_customresources.go ExpandForEachCustomResources for dynamic resource types
enrich_pods.go _pods enrichment and pod summary building
enrich_endpoints.go _endpoints enrichment via EndpointSlice
enrich_warnings.go _warnings enrichment — workload + pod-level Warning events
enrich_pvc.go _pv enrichment for PersistentVolumeClaims
enrich_pv.go _pvc enrichment for PersistentVolumes
enrich_replicasets.go _owner enrichment for ReplicaSets; _replicaSets for Deployments
enrich_cronjobs.go _activeJobs, _lastJob, _lastSuccessfulJob for CronJobs
enrich_statefulsets.go _pvcs enrichment for StatefulSets
enrich_storageclass.go _storageClass enrichment for PersistentVolumeClaims
enrich_service_pods.go _backingPods enrichment for Services
enrich_ingress.go _loadBalancerIPs, _tlsSecrets enrichment for Ingresses
enrich_node.go _node enrichment for Pods
enrich_hpa.go _currentMetrics, _scaleTarget enrichment for HPAs
gvr.go All built-in GVR variables and ChildGVRs()
builtins.go Built-in kind registry — API metadata, RBAC detection, enrichment lookup

Documentation

Overview

pkg/children/builtins.go

Single authoritative registry for every Kubernetes built-in resource kind Orkestra knows about. Adding one entry here is the only change required to:

  • Resolve GVR for children and GVR lookups
  • Generate RBAC rules (ClusterRole) for any katalog that uses the resource
  • Detect usage in onReconcile / onCreate / onDelete template blocks
  • Expand kind shorthands (e.g. "hpa" → "horizontalpodautoscaler")
  • Derive the canonical PascalCase Kind name
  • Drive readiness and deletion-protection logic

Keys are lowercase singular Kind names (e.g. "deployment", "namespace"). Accessor functions live in builtins_accessors.go.

NOTE: If a new kind supports context enrichment, also add an entry to enrichmentMeta (in this same file) — it is intentionally a parallel map so enrichment concerns stay separate from Kubernetes API identity.

pkg/children/builtins_accessors.go

Accessor functions over the builtInRegistry defined in builtins.go. These are the public API for querying built-in kind metadata. To add a new built-in kind, edit builtins.go — not this file.

Package children reads and enriches child Kubernetes resources that are declared in a Katalog's operatorBox. It is the bridge between the template resolver (which holds the owner CR's fields) and the Kubernetes API (which holds the live state of every child resource).

The single entry point is ReadChildren. It:

  1. Merges onCreate and onReconcile template declarations.
  2. For each declared resource type, reads the live objects from Kubernetes.
  3. Applies enrichment layers (pods, endpoints, warnings, PV).
  4. Returns a structured map injected into the template resolver under "children".

File layout

  • children.go — this file; package doc and ReadChildren entry point
  • read.go — readResourceGroup, firstValue, mergeTemplates
  • names.go — name resolution (resolvedChildName, *Names helpers)
  • foreach.go — forEach expansion for all built-in resource types
  • foreach_customresources.go — forEach expansion for custom resources
  • enrich_pods.go — _pods enrichment and pod summary building
  • enrich_endpoints.go — _endpoints enrichment
  • enrich_warnings.go — _warnings enrichment (workload + pod events)
  • enrich_pvc.go — _pv enrichment for PersistentVolumeClaims
  • enrich_pv.go — _pvc enrichment for PersistentVolumes
  • enrich_replicasets.go — _owner for ReplicaSets; _replicaSets for Deployments
  • enrich_cronjobs.go — _activeJobs, _lastJob, _lastSuccessfulJob for CronJobs
  • enrich_statefulsets.go — _pvcs for StatefulSets
  • enrich_storageclass.go — _storageClass for PersistentVolumeClaims
  • enrich_service_pods.go — _backingPods for Services
  • enrich_ingress.go — _loadBalancerIPs, _tlsSecrets for Ingresses
  • enrich_node.go — _node for Pods
  • enrich_hpa.go — _currentMetrics, _scaleTarget for HPAs

See docs/ for a progressive walkthrough of each layer.

pkg/children/foreach.go

forEach expansion — expands template sources with a forEach declaration into N resolved sources, one per element in the list field.

forEach works on every resource type. The expansion happens before the resource-specific run_*.go function is called — each run_*.go function receives an already-expanded slice and is unaware of forEach.

Expansion sequence in runTemplateReconcile:

deployments := ExpandForEachDeployments(resolver, t.Deployments)
runDeployments(ctx, kube, resolver, obj, deployments, update)

YAML:

onReconcile:
  deployments:
    - name: "{{ .metadata.name }}-{{ .item }}"
      image: "{{ .spec.image }}"
      forEach:
        field: spec.regions
        as: item

For CR with spec.regions: ["us-east-1", "eu-west-1"]: Produces two DeploymentTemplateSources:

{Name: "my-app-us-east-1", Image: "nginx:latest", ...}
{Name: "my-app-eu-west-1", Image: "nginx:latest", ...}

The expansion resolves ALL template expressions immediately — the returned slice contains static (non-template) values ready for the registry functions.

when: and anyOf: on forEach sources are evaluated per-item — each expanded source may pass or fail conditions independently.

pkg/children/gvr.go

Index

Constants

This section is empty.

Variables

View Source
var (
	DeploymentGVR              = gvrOrPanic("deployment")
	ServiceGVR                 = gvrOrPanic("service")
	SecretGVR                  = gvrOrPanic("secret")
	ConfigMapGVR               = gvrOrPanic("configmap")
	JobGVR                     = gvrOrPanic("job")
	CronJobGVR                 = gvrOrPanic("cronjob")
	PodGVR                     = gvrOrPanic("pod")
	ServiceAccountGVR          = gvrOrPanic("serviceaccount")
	StatefulSetGVR             = gvrOrPanic("statefulset")
	IngressGVR                 = gvrOrPanic("ingress")
	PersistentVolumeClaimGVR   = gvrOrPanic("persistentvolumeclaim")
	PersistentVolumeGVR        = gvrOrPanic("persistentvolume")
	HorizontalPodAutoscalerGVR = gvrOrPanic("horizontalpodautoscaler")
	PodDisruptionBudgetGVR     = gvrOrPanic("poddisruptionbudget")
	DaemonSetGVR               = gvrOrPanic("daemonset")
	ReplicaSetGVR              = gvrOrPanic("replicaset")
	NetworkPolicyGVR           = gvrOrPanic("networkpolicy")
	RoleGVR                    = gvrOrPanic("role")
	RoleBindingGVR             = gvrOrPanic("rolebinding")
	ClusterRoleGVR             = gvrOrPanic("clusterrole")
	ClusterRoleBindingGVR      = gvrOrPanic("clusterrolebinding")
	NamespaceGVR               = gvrOrPanic("namespace")
	NodeGVR                    = gvrOrPanic("node")
	EndpointSliceGVR           = gvrOrPanic("endpointslice")
	EventGVR                   = gvrOrPanic("event")
	StorageClassGVR            = gvrOrPanic("storageclass")
)

Functions

func AllBuiltInKinds

func AllBuiltInKinds() []string

AllBuiltInKinds returns all canonical Kind names, sorted alphabetically.

func ChildGVRs

func ChildGVRs() []struct {
	GVR schema.GroupVersionResource
	Key string
}

ChildGVRs returns all built‑in child resource GVRs with their keys.

func ExpandForEachCronJobs

func ExpandForEachCronJobs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.CronJobTemplateSource,
) []orktypes.CronJobTemplateSource

func ExpandForEachCustomResources

func ExpandForEachCustomResources(resolver *orktmpl.Resolver, srcs []orktypes.CustomResourceTemplateSource) []orktypes.CustomResourceTemplateSource

ExpandForEachCustomResources expands any CustomResource entries that declare a ForEach. It returns a new slice with expanded items. Items without ForEach are copied verbatim.

func ExpandForEachHPAs

func ExpandForEachHPAs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.HPATemplateSource,
) []orktypes.HPATemplateSource

func ExpandForEachIngresses

func ExpandForEachIngresses(
	resolver *orktmpl.Resolver,
	srcs []orktypes.IngressTemplateSource,
) []orktypes.IngressTemplateSource

func ExpandForEachJobs

func ExpandForEachJobs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.JobTemplateSource,
) []orktypes.JobTemplateSource

func ExpandForEachPDBs

func ExpandForEachPDBs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.PDBTemplateSource,
) []orktypes.PDBTemplateSource

func ExpandForEachPVCs

func ExpandForEachPVCs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.PVCTemplateSource,
) []orktypes.PVCTemplateSource

func ExpandForEachPVs

func ExpandForEachPVs(
	resolver *orktmpl.Resolver,
	srcs []orktypes.PVTemplateSource,
) []orktypes.PVTemplateSource

func ExpandForEachPods

func ExpandForEachPods(
	resolver *orktmpl.Resolver,
	srcs []orktypes.PodTemplateSource,
) []orktypes.PodTemplateSource

func ExpandForEachRoles

func ExpandForEachRoles(
	resolver *orktmpl.Resolver,
	srcs []orktypes.RoleTemplateSource,
) []orktypes.RoleTemplateSource

func ExpandForEachSecrets

func ExpandForEachSecrets(
	resolver *orktmpl.Resolver,
	srcs []orktypes.SecretTemplateSource,
) []orktypes.SecretTemplateSource

func ExpandForEachServices

func ExpandForEachServices(
	resolver *orktmpl.Resolver,
	srcs []orktypes.ServiceTemplateSource,
) []orktypes.ServiceTemplateSource

func GVRForBuiltIn

func GVRForBuiltIn(kind string) (schema.GroupVersionResource, bool)

GVRForBuiltIn returns the GroupVersionResource for a built-in kind.

func IsBuiltIn

func IsBuiltIn(kind string) bool

IsBuiltIn reports whether kind is a known Kubernetes built-in (case-insensitive).

func IsValidEnrichmentTarget

func IsValidEnrichmentTarget(name string) bool

IsValidEnrichmentTarget reports whether the given name is a supported context-enrichment target.

func ReadChildren

func ReadChildren(
	ctx context.Context,
	kube kubeclient.KubeClient,
	obj domain.Object,
	resolver *orktmpl.Resolver,
	crd orktypes.CRDEntry,
) map[string]interface{}

ReadChildren reads all child resources declared in the Katalog's onCreate templates and returns a structured map for use in status field expressions.

The returned map is injected into the template resolver under the "children" key. Status field expressions can then reference child resource state:

# Singular — the first/only resource of this type
{{ .children.deployment.status.readyReplicas }}
{{ .children.service.status.loadBalancer.ingress }}

# Plural — all resources of this type, by name
{{ (index .children.deployments "my-site-api").status.readyReplicas }}

ReadChildren is called after runTemplateReconcile — child resources exist at this point. Missing status fields resolve to "" (missingkey=zero), which is correct eventual consistency behaviour for newly created resources.

API cost: one GET per child resource type × count. For the common case (one Deployment + one Service), this is two GETs.

This function never returns an error that should fail the reconcile. Read failures are logged and the child is omitted from the map. Status patching proceeds with whatever children were successfully read.

func SkipObservedGenerationGVKs

func SkipObservedGenerationGVKs() []string

func SkipStatusSubresourceGVKs

func SkipStatusSubresourceGVKs() []string

func StatuslessGVKs

func StatuslessGVKs() []string

func SupportedEnrichmentGroups

func SupportedEnrichmentGroups() map[string][]string

SupportedEnrichmentGroups returns all supported enrichment targets, including built-in Kubernetes resources and synthetic Orkestra-only targets.

Types

type BuiltInKind

type BuiltInKind struct {
	Kind    string // PascalCase Kind name (e.g. "Deployment")
	Group   string // API group; empty string for core
	Version string // API version (e.g. "v1", "v2")
	Plural  string // plural resource name (e.g. "deployments")

	Namespaced bool   // true if resource is namespaced
	APIPath    string // "/api" for core, "/apis" otherwise

	// Shorthands are case-insensitive aliases resolved by LookupBuiltIn.
	// e.g. "hpa" → "horizontalpodautoscaler"
	Shorthands []string

	// Detect reports whether a CRD's operatorBox uses this resource in any
	// hook template block (onCreate / onReconcile / onDelete).
	// nil for resources that cannot appear in hook templates (e.g. Node, Event).
	Detect func(crd orktypes.CRDEntry) bool

	Statusless             bool // No meaningful status; treat as ready on existence
	SkipStatusSubresource  bool // No /status subresource; never PATCH status
	SkipObservedGeneration bool // Has status but no observedGeneration; skip generation check
	IsChild                bool // Orkestra may create this as a child resource
	OrkestraInternal       bool // Part of Orkestra's own control-plane installation
}

BuiltInKind holds the fully-qualified API metadata for a Kubernetes built-in resource kind, plus Orkestra-specific readiness and usage metadata.

func AllBuiltInKindDefs

func AllBuiltInKindDefs() []BuiltInKind

AllBuiltInKindDefs returns all entries from the built-in registry. Entries with a nil Detect field represent aliases or internal entries without RBAC detection logic. Callers that need only detectable entries should filter on Detect != nil.

func BuiltInMeta

func BuiltInMeta(kind string) BuiltInKind

BuiltInMeta returns metadata for a built-in kind. Zero value when unknown.

func LookupBuiltInByResource

func LookupBuiltInByResource(resource string) (BuiltInKind, bool)

LookupBuiltInByResource looks up a built-in by singular key, shorthand, or plural resource name. Returns (BuiltInKind, true) when found. Used by RBAC generation and any caller that works with resource strings rather than Kind names.

type EnrichmentResult

type EnrichmentResult struct {
	Found        bool
	Kind         string // canonical PascalCase name (e.g. "Deployment")
	BuiltIn      BuiltInKind
	DisplayGroup string // "core" for empty group, otherwise the group string
}

EnrichmentResult holds the result of a built-in lookup.

func LookupBuiltIn

func LookupBuiltIn(kind string) EnrichmentResult

LookupBuiltIn looks up a Kind in the built-in registry. Case-insensitive. Expands shorthands (e.g. "hpa" → "horizontalpodautoscaler").

Jump to

Keyboard shortcuts

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