v1alpha1

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultRetryDelay = time.Second

DefaultRetryDelay is the default delay between retries when not specified.

Variables

This section is empty.

Functions

func ContainsStorageRef added in v0.1.4

func ContainsStorageRef(doc []byte) bool

ContainsStorageRef reports whether the JSON document contains a storage reference map.

Behavior:

  • Returns false for empty or invalid JSON.
  • Walks nested objects/arrays to detect any map with $bubuStorageRef.

func DefaultResource added in v0.1.4

func DefaultResource[T client.Object](obj runtime.Object, kind string, log logr.Logger, fn func(T) error) error

DefaultResource wraps webhook defaulting handlers with shared type assertion and logging logic.

func EnforceMaxBytes added in v0.1.4

func EnforceMaxBytes(field string, raw []byte, max int, hint string) error

EnforceMaxBytes returns an error when raw exceeds max.

Behavior:

  • Compares len(raw) against max bytes.
  • Appends hint to error message for context-specific guidance.

Arguments:

  • field string: field name for error message (e.g., "spec.with").
  • raw []byte: the payload to check.
  • max int: maximum allowed bytes.
  • hint string: additional guidance appended to error (can be empty).

Returns:

  • nil if len(raw) <= max.
  • Error describing the size violation.

func EnsureJSONObject added in v0.1.4

func EnsureJSONObject(field string, b []byte) error

EnsureJSONObject returns an error when b is non-empty and not a valid JSON object.

Behavior:

  • Validates JSON syntax when b is non-empty.
  • Checks if b starts with '{' (JSON object).
  • Returns error if b is non-empty and starts with array '[' or primitive.
  • Callers should trim leading whitespace before invoking.

Arguments:

  • field string: field name for error message (e.g., "spec.with").
  • b []byte: the byte slice to check.

Returns:

  • nil if b is empty or starts with '{'.
  • Error if b is a non-object JSON value.

func PickMaxInlineBytes added in v0.1.4

func PickMaxInlineBytes(cfg *config.ControllerConfig) int

PickMaxInlineBytes returns the maximum inline payload size (in bytes) enforced by webhook validation.

Behavior:

  • Uses cfg.Engram.EngramControllerConfig.DefaultMaxInlineSize if set.
  • Falls back to config.DefaultControllerConfig() if cfg is nil.
  • Falls back to 1024 bytes if the config value is zero.

Arguments:

  • cfg *config.ControllerConfig: may be nil.

Returns:

  • Maximum allowed inline bytes (at least 1024).

func ResolveControllerConfig added in v0.1.4

func ResolveControllerConfig(log logr.Logger, mgr *config.OperatorConfigManager, cfg *config.ControllerConfig) *config.ControllerConfig

ResolveControllerConfig returns the effective controller configuration.

Behavior:

  • Checks ConfigManager first for live configuration.
  • Falls back to embedded cfg if ConfigManager returns nil.
  • Uses DefaultControllerConfig() as final fallback.
  • Logs at V(1) level when falling back for observability.

Arguments:

  • log logr.Logger: for logging fallback events.
  • mgr *config.OperatorConfigManager: optional ConfigManager for live config.
  • cfg *config.ControllerConfig: optional embedded config fallback.

Returns:

  • Non-nil *config.ControllerConfig from the highest priority source.

func ResolveReferencePolicy added in v0.1.4

func ResolveReferencePolicy(cfg *config.ControllerConfig) string

ResolveReferencePolicy returns the effective cross-namespace reference policy.

func ResolveRetryPolicy added in v0.1.3

func ResolveRetryPolicy(cfg *config.ControllerConfig, policy *bubuv1alpha1.RetryPolicy) *bubuv1alpha1.RetryPolicy

ResolveRetryPolicy applies controller defaults to a retry policy when it is omitted.

Behavior:

  • If policy is nil, creates a new empty RetryPolicy.
  • Sets MaxRetries to cfg.MaxRetries (or 3 if cfg is nil or MaxRetries < 0).
  • Sets Delay to DefaultRetryDelay (1s) if nil or empty.
  • Sets Backoff strategy to Exponential if nil.

Arguments:

  • cfg *config.ControllerConfig: controller configuration; may be nil.
  • policy *bubuv1alpha1.RetryPolicy: policy to resolve; may be nil.

Returns:

  • Non-nil *bubuv1alpha1.RetryPolicy with all fields populated.

func ScrubStorageRefMetadata added in v0.1.4

func ScrubStorageRefMetadata(doc []byte) ([]byte, error)

ScrubStorageRefMetadata removes storage ref metadata keys from any storage ref maps.

Behavior:

  • Removes $bubuStorageContentType, $bubuStorageSchema, and $bubuStorageSchemaVersion when a map contains $bubuStorageRef.
  • Returns the original document for empty input.
  • Returns an error for invalid JSON.

func TrimLeadingSpace added in v0.1.4

func TrimLeadingSpace(b []byte) []byte

TrimLeadingSpace removes leading ASCII whitespace characters from b.

Behavior:

  • Strips space, newline, tab, and carriage return from the start of b.
  • Returns the remaining slice without allocating new memory.

Arguments:

  • b []byte: the byte slice to trim.

Returns:

  • The input slice with leading whitespace removed.

func ValidateCreateResource added in v0.1.4

func ValidateCreateResource[T client.Object](ctx context.Context, obj runtime.Object, kind string, log logr.Logger, fn func(context.Context, T) error) (admission.Warnings, error)

ValidateCreateResource wraps webhook create validators with consistent type assertion and logging.

func ValidateCrossNamespaceReference added in v0.1.4

func ValidateCrossNamespaceReference(
	ctx context.Context,
	reader client.Reader,
	cfg *config.ControllerConfig,
	from client.Object,
	fromGroup string,
	fromKind string,
	toGroup string,
	toKind string,
	toNamespace string,
	toName string,
	refLabel string,
) error

ValidateCrossNamespaceReference enforces cross-namespace policy for a reference.

Returns nil when the reference is same-namespace or allowed by policy.

func ValidateDeleteResource added in v0.1.4

func ValidateDeleteResource[T client.Object](obj runtime.Object, kind string, log logr.Logger, fn func(T) error) (admission.Warnings, error)

ValidateDeleteResource wraps webhook delete validators with consistent type assertion and logging.

func ValidateJSONAgainstSchema added in v0.1.4

func ValidateJSONAgainstSchema(doc []byte, schema []byte, schemaName string) error

ValidateJSONAgainstSchema is a shared wrapper for schema validation across webhooks.

Behavior:

  • Delegates to the internal validator, which normalizes schemas and allows storage refs.

Arguments:

  • doc []byte: the JSON document to validate.
  • schema []byte: the JSON Schema bytes.
  • schemaName string: human-readable name for error messages.

Returns:

  • nil if validation passes.
  • Error describing normalization/validation failures.

func ValidateJSONSchemaDefinition added in v0.1.4

func ValidateJSONSchemaDefinition(schema []byte, schemaName string) error

ValidateJSONSchemaDefinition validates that a JSON Schema is syntactically valid.

Behavior:

  • Normalizes the schema to support inline required flags.
  • Uses gojsonschema to parse the schema without validating a document.

Arguments:

  • schema []byte: JSON-encoded JSON Schema.
  • schemaName string: human-readable name for error messages.

Returns:

  • nil if schema is valid.
  • Error describing schema parsing failures.

func ValidateReferenceMaps added in v0.1.4

func ValidateReferenceMaps(doc []byte, field string) error

ValidateReferenceMaps ensures configmap/secret/storage ref maps are well-formed.

Behavior:

  • Parses doc JSON into an interface tree.
  • Walks maps/slices, validating any reference maps encountered.
  • Returns the first error with a JSON path context.

Arguments:

  • doc []byte: JSON document bytes.
  • field string: field label for error messages.

Returns:

  • nil if no invalid reference maps are found.
  • Error with field/path details otherwise.

func ValidateUpdateResource added in v0.1.4

func ValidateUpdateResource[T client.Object](ctx context.Context, oldObj, newObj runtime.Object, kind string, log logr.Logger, fn func(context.Context, T, T) error) (admission.Warnings, error)

ValidateUpdateResource wraps webhook update validators with type assertion, deletion short-circuit, and logging. The DeletionTimestamp check is performed before logging to suppress noisy log entries for resources undergoing deletion. fn receives both the typed old and new objects; returning nil from fn skips further validation (e.g., spec unchanged).

Types

type EngramCustomDefaulter

type EngramCustomDefaulter struct {
}

EngramCustomDefaulter struct is responsible for setting default values on the custom resource of the Kind Engram when those are created or updated.

+kubebuilder:object:generate=false NOTE: This is an internal webhook helper and is not registered in the API scheme. It does not implement runtime.Object, so no DeepCopy generation is needed or applied.

func (*EngramCustomDefaulter) Default

Default implements admission.Defaulter for Engram resources.

Behavior:

  • Currently a no-op; Engram defaults are intentionally minimal.
  • Controller handles defaulting at reconcile time.

Arguments:

  • ctx context.Context: unused but required by interface.
  • engram *bubushv1alpha1.Engram: the Engram being defaulted.

Returns:

  • nil (always succeeds; no defaults applied).

type EngramCustomValidator

type EngramCustomValidator struct {
	Client        client.Reader
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

EngramCustomValidator struct is responsible for validating the Engram resource when it is created, updated, or deleted.

+kubebuilder:object:generate=false NOTE: This is an internal webhook helper and is not registered in the API scheme. It does not implement runtime.Object, so no DeepCopy generation is needed or applied.

func (*EngramCustomValidator) ValidateCreate

ValidateCreate implements admission.Validator for Engram creation.

Behavior:

  • Validates templateRef.name is set and template exists.
  • Validates with block is a JSON object and within size limits.

Arguments:

  • ctx context.Context: for template lookup.
  • engram *bubushv1alpha1.Engram: the Engram being created.

Returns:

  • nil, nil if validation passes.
  • nil, error if validation errors exist.

func (*EngramCustomValidator) ValidateDelete

ValidateDelete implements admission.Validator for Engram deletion.

Behavior:

  • Always allows deletion (no-op validation).
  • Exists as scaffold placeholder; delete verb not enabled in annotation.

Arguments:

  • ctx context.Context: unused.
  • engram *bubushv1alpha1.Engram: the Engram being deleted.

Returns:

  • nil, nil (deletion always allowed).

func (*EngramCustomValidator) ValidateUpdate

func (v *EngramCustomValidator) ValidateUpdate(ctx context.Context, oldEngram, engram *bubushv1alpha1.Engram) (admission.Warnings, error)

ValidateUpdate implements admission.Validator for Engram updates.

Behavior:

  • Skips validation for resources undergoing deletion (DeletionTimestamp set).
  • Rejects spec changes while deletion is in progress (only finalizer edits allowed).
  • Skips validation when spec is semantically unchanged; normalises RawExtension fields before comparison to prevent false mismatches after SSA round-trips.
  • Validates templateRef.name is set and template exists.
  • Validates with block is a JSON object and within size limits.

Arguments:

  • ctx context.Context: for template lookup.
  • oldEngram *bubushv1alpha1.Engram: previous Engram state.
  • engram *bubushv1alpha1.Engram: proposed Engram state.

Returns:

  • nil, nil if validation passes or is skipped.
  • nil, error if validation errors exist.

type EngramWebhook

type EngramWebhook struct {
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

func (*EngramWebhook) SetupWebhookWithManager

func (wh *EngramWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error

SetupWebhookWithManager registers the webhook for Engram in the manager.

Behavior:

  • Creates both defaulter and validator webhooks for Engram resources.
  • Uses mgr.GetAPIReader() for template lookups to avoid cache staleness.

Arguments:

  • mgr ctrl.Manager: the controller-runtime manager.

Returns:

  • nil on success.
  • Error if webhook registration fails.

type ImpulseCustomDefaulter

type ImpulseCustomDefaulter struct {
}

ImpulseCustomDefaulter struct is responsible for setting default values on the custom resource of the Kind Impulse when those are created or updated.

NOTE: This is an internal webhook helper and is not registered in the API scheme. It does not implement runtime.Object, so no DeepCopy generation is needed or applied.

func (*ImpulseCustomDefaulter) Default

Default implements webhook.CustomDefaulter for Impulse resources.

Behavior:

  • Currently a no-op; Impulse defaults are intentionally minimal.
  • Controller handles defaulting at reconcile time.

Arguments:

  • ctx context.Context: unused but required by interface.
  • obj *bubushv1alpha1.Impulse: the Impulse to default.

Returns:

  • nil always (no defaulting logic).

type ImpulseCustomValidator

type ImpulseCustomValidator struct {
	Client        client.Client
	APIReader     client.Reader
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

ImpulseCustomValidator struct is responsible for validating the Impulse resource when it is created, updated, or deleted.

NOTE: This is an internal webhook helper and is not registered in the API scheme. It does not implement runtime.Object, so no DeepCopy generation is needed or applied.

func (*ImpulseCustomValidator) ValidateCreate

ValidateCreate implements webhook.CustomValidator for Impulse creation.

Behavior:

  • Validates spec fields, with/mapping blocks, and workload mode.

Arguments:

  • ctx context.Context: for template lookup.
  • impulse *bubushv1alpha1.Impulse: the Impulse being created.

Returns:

  • nil, nil if validation passes.
  • nil, error if validation errors exist.

func (*ImpulseCustomValidator) ValidateDelete

ValidateDelete implements webhook.CustomValidator for Impulse deletion.

Behavior:

  • Always allows deletion (no-op validation).
  • Exists as scaffold placeholder; delete verb not enabled in annotation.

Arguments:

  • ctx context.Context: unused.
  • obj *bubushv1alpha1.Impulse: the Impulse being deleted.

Returns:

  • nil, nil (deletion always allowed).

func (*ImpulseCustomValidator) ValidateUpdate

func (v *ImpulseCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj *bubushv1alpha1.Impulse) (admission.Warnings, error)

ValidateUpdate implements webhook.CustomValidator for Impulse updates.

Behavior:

  • Validates spec fields, with/mapping blocks, and workload mode.
  • Short-circuits for deletion or spec-unchanged updates.

Arguments:

  • ctx context.Context: for template lookup.
  • oldObj *bubushv1alpha1.Impulse: previous Impulse state.
  • newObj *bubushv1alpha1.Impulse: proposed Impulse state.

Returns:

  • nil, nil if validation passes.
  • nil, error if validation errors exist.

type ImpulseWebhook

type ImpulseWebhook struct {
	client.Client
	APIReader     client.Reader
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

func (*ImpulseWebhook) SetupWebhookWithManager

func (wh *ImpulseWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error

SetupWebhookWithManager registers the webhook for Impulse in the manager.

Behavior:

  • Stores the manager's API reader and cached client for validation lookups.
  • Creates both defaulter and validator webhooks for Impulse resources.

Arguments:

  • mgr ctrl.Manager: the controller-runtime manager.

Returns:

  • nil on success.
  • Error if webhook registration fails.

type StoryCustomDefaulter

type StoryCustomDefaulter struct {
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

StoryCustomDefaulter struct is responsible for setting default values on the custom resource of the Kind Story when those are created or updated.

NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods, as it is used only for temporary operations and does not need to be deeply copied.

func (*StoryCustomDefaulter) Default

Default implements admission.Defaulter for Story resources.

Behavior:

  • Resolves RetryPolicy for Story-level and step-level retries.
  • Sets MaxRetries, Delay, and Backoff if not specified.

Arguments:

  • ctx context.Context: unused but required by interface.
  • story *bubushv1alpha1.Story: the Story being defaulted.

Returns:

  • nil on success.

type StoryCustomValidator

type StoryCustomValidator struct {
	Client        client.Client
	APIReader     client.Reader
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

StoryCustomValidator struct is responsible for validating the Story resource when it is created, updated, or deleted.

NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods, as this struct is used only for temporary operations and does not need to be deeply copied.

func (*StoryCustomValidator) ValidateCreate

func (v *StoryCustomValidator) ValidateCreate(ctx context.Context, story *bubushv1alpha1.Story) (admission.Warnings, error)

ValidateCreate implements admission.Validator for Story creation.

Behavior:

  • Validates spec fields, size limits, steps shape, graph acyclicity, and transports.
  • Uses 5-second timeout for template/Engram lookups.

Arguments:

  • ctx context.Context: for API lookups.
  • story *bubushv1alpha1.Story: the Story being created.

Returns:

  • nil, nil if validation passes.
  • nil, error if validation errors exist.

func (*StoryCustomValidator) ValidateDelete

ValidateDelete implements admission.Validator for Story deletion.

Behavior:

  • Always allows deletion (no-op validation).
  • Exists as scaffold placeholder; delete verb not enabled in annotation.

Arguments:

  • ctx context.Context: unused.
  • story *bubushv1alpha1.Story: the Story being deleted.

Returns:

  • nil, nil (deletion always allowed).

func (*StoryCustomValidator) ValidateUpdate

func (v *StoryCustomValidator) ValidateUpdate(ctx context.Context, oldStory, story *bubushv1alpha1.Story) (admission.Warnings, error)

ValidateUpdate implements admission.Validator for Story updates.

Behavior:

  • Skips validation if resource is being deleted (DeletionTimestamp set).
  • Skips validation if spec is unchanged (metadata-only update).
  • Uses 5-second timeout for template/Engram lookups.

Arguments:

  • ctx context.Context: for API lookups.
  • oldStory *bubushv1alpha1.Story: previous Story state.
  • story *bubushv1alpha1.Story: proposed Story state.

Returns:

  • nil, nil if validation passes or is skipped.
  • nil, error if validation errors exist.

type StoryWebhook

type StoryWebhook struct {
	client.Client
	APIReader     client.Reader
	Config        *config.ControllerConfig
	ConfigManager *config.OperatorConfigManager
}

StoryWebhook sets up the webhook for Story in the manager.

func (*StoryWebhook) SetupWebhookWithManager

func (wh *StoryWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error

SetupWebhookWithManager registers the webhook for Story in the manager.

Behavior:

  • Stores the manager's API reader and cached client for validation lookups.
  • Creates both defaulter and validator webhooks for Story resources.
  • Injects Config and ConfigManager into both handlers.

Arguments:

  • mgr ctrl.Manager: the controller-runtime manager.

Returns:

  • nil on success.
  • Error if webhook registration fails.

Jump to

Keyboard shortcuts

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