core

package
v1.0.0-alpha.20 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package core provides shared primitives for the OPM rendering pipeline. Resource is the atomic output unit. Label constants and GVK weights support downstream K8s inventory and apply ordering.

This package depends on the CUE SDK and k8s.io/apimachinery; nothing below internal/cmdutil/ should import it directly (use the Unstructured adapter there).

Index

Constants

View Source
const (
	// LabelManagedBy is the standard Kubernetes label indicating the manager.
	LabelManagedBy = "app.kubernetes.io/managed-by"

	// LabelManagedByValue is the runtime-owned value for the CLI actor.
	// The controller uses LabelManagedByControllerValue instead.
	LabelManagedByValue = "opm-cli"

	// LabelManagedByControllerValue is the runtime-owned value for the controller actor.
	LabelManagedByControllerValue = "opm-controller"

	// LabelManagedByLegacyValue is the legacy value used before runtime-owned
	// labels were introduced. Recognized for backward compatibility during
	// transition but no longer stamped on new resources.
	LabelManagedByLegacyValue = "open-platform-model"

	// LabelComponent is the OPM infrastructure label that categorizes the type
	// of OPM-managed object (e.g., "inventory"). Distinct from component names
	// set by CUE transformers on application resources.
	LabelComponent = "opmodel.dev/component"

	// LabelComponentName is the label injected by the CUE catalog on all application
	// resources to record which component produced them. Value is the component name.
	// Set by module.cue in the v1alpha1 catalog:
	//   labels: "component.opmodel.dev/name": name
	// Used by inventory to track provenance for component-rename safety checks.
	LabelComponentName = "component.opmodel.dev/name"

	// LabelModuleInstanceName is the instance name label.
	LabelModuleInstanceName = "module-instance.opmodel.dev/name"

	// LabelModuleInstanceNamespace is the instance namespace label.
	LabelModuleInstanceNamespace = "module-instance.opmodel.dev/namespace"

	// LabelModuleInstanceUUID is the instance identity UUID label for resource discovery.
	LabelModuleInstanceUUID = "module-instance.opmodel.dev/uuid"
)

OPM Kubernetes label keys applied to all managed resources.

Variables

This section is empty.

Functions

func IsOPMManagedBy

func IsOPMManagedBy(value string) bool

IsOPMManagedBy reports whether a managed-by label value identifies any OPM runtime actor. This accepts the current CLI and controller values as well as the legacy value for backward compatibility with resources applied before runtime-owned labels were introduced.

Types

type Resource

type Resource struct {
	// Value is the CUE value of the rendered resource (e.g. a Kubernetes manifest).
	// Concrete and fully evaluated — safe to encode directly to YAML or JSON.
	Value cue.Value

	// Instance is the name of the ModuleInstance that produced this resource.
	Instance string

	// Component is the source component name within the instance.
	Component string

	// Transformer is the FQN of the transformer that produced this resource.
	Transformer string
}

Resource is a single rendered platform resource produced by the pipeline.

Value holds the raw CUE output from a transformer, avoiding premature conversion to Go-native formats. Callers convert to their required format (YAML, JSON, *unstructured.Unstructured, etc.) only when needed via the conversion methods below.

Instance, Component, and Transformer record provenance for inventory tracking and display.

func ResourceFromCompiled added in v0.7.0

func ResourceFromCompiled(c *kernel.Compiled) *Resource

ResourceFromCompiled adapts a library *kernel.Compiled — the kernel's terminal per-transformer output — into the operator's *Resource. The two types carry identical fields (CUE value plus instance/component/transformer provenance), so the adapter is a field copy; it exists so the kernel-backed render path can hand its compiled output to the operator's existing inventory and apply pipeline unchanged.

A nil input yields a nil result.

func (*Resource) APIVersion

func (r *Resource) APIVersion() string

APIVersion returns the resource apiVersion (e.g. "apps/v1").

func (*Resource) Annotations

func (r *Resource) Annotations() map[string]string

Annotations returns the resource annotations from metadata.annotations.

func (*Resource) GVK

func (r *Resource) GVK() schema.GroupVersionKind

GVK returns the GroupVersionKind parsed from apiVersion and kind.

func (*Resource) Kind

func (r *Resource) Kind() string

Kind returns the resource kind (e.g. "Deployment").

func (*Resource) Labels

func (r *Resource) Labels() map[string]string

Labels returns the resource labels from metadata.labels.

func (*Resource) MarshalJSON

func (r *Resource) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON byte representation of the resource's CUE value.

func (*Resource) Name

func (r *Resource) Name() string

Name returns the resource name from metadata.name.

func (*Resource) Namespace

func (r *Resource) Namespace() string

Namespace returns the resource namespace. Empty for cluster-scoped resources.

func (*Resource) String

func (r *Resource) String() string

String returns a human-readable summary: "Kind/namespace/name".

func (*Resource) ToUnstructured

func (r *Resource) ToUnstructured() (*unstructured.Unstructured, error)

ToUnstructured converts the resource to a *unstructured.Unstructured. Uses JSON as the intermediate format.

Jump to

Keyboard shortcuts

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