ssa

package
v2.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package ssa provides helpers for Server-Side Apply (SSA) workflows, including TypeConverter initialisation, diff-before-apply, and structured-merge-diff-based object merging.

Index

Constants

View Source
const FieldManager = "gateway-operator"

FieldManager is the field manager name used by the operator for Server-Side Apply operations.

Variables

This section is empty.

Functions

func ApplyIfChanged

func ApplyIfChanged(
	ctx context.Context,
	logger logr.Logger,
	cl client.Client,
	tc managedfields.TypeConverter,
	desired client.Object,
	fieldManager string,
) (op.Result, error)

ApplyIfChanged performs a diff-before-apply using structured-merge-diff:

  1. Fetch the existing object from the API server.
  2. Convert both existing and desired to typed.TypedValue via TypeConverter.
  3. Compare using TypedValue.Compare().
  4. Issue a Server-Side Apply only when a difference is detected.

This prevents infinite reconcile loops on API server versions that incorrectly bump resourceVersion on no-op SSA patches.

func ApplyStatusIfChanged

func ApplyStatusIfChanged(
	ctx context.Context,
	logger logr.Logger,
	cl client.Client,
	tc managedfields.TypeConverter,
	desired client.Object,
	fieldManager string,
) (op.Result, error)

ApplyStatusIfChanged is like ApplyIfChanged but operates on the status subresource. It compares fields owned by fieldManager under the "status" subresource via SMD and issues a Status().Apply only when a difference is detected, preventing spurious status patches on every reconcile.

func MergeObjects

func MergeObjects(tc managedfields.TypeConverter, base, userOverlay runtime.Object) (*unstructured.Unstructured, error)

MergeObjects merges userOverlay into base using structured-merge-diff. User-provided values in userOverlay win on conflicts; the base supplies default values for fields the user has not specified. Returns an *unstructured.Unstructured so the caller can use the result directly with ApplyIfChanged or convert it to a typed struct.

func NewTypeConverter

func NewTypeConverter(mgr ctrl.Manager, groupVersions []schema.GroupVersion) (managedfields.TypeConverter, error)

NewTypeConverter builds a TypeConverter from the API server's live OpenAPI v3 schemas. Only schemas for the specified GroupVersions are fetched, reducing startup latency compared to downloading the full schema set.

groupVersions should list every GV whose objects will be passed to MergeObjects or ApplyIfChanged. For core types use schema.GroupVersion{Group: "", Version: "v1"}. Call this once during SetupWithManager.

Types

This section is empty.

Jump to

Keyboard shortcuts

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