object

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package object extends the Kubernetes unstructured object API with enhanced support for Δ-controller view objects and delta operations.

Key components:

  • Object: Enhanced Kubernetes unstructured object interface with view support.
  • Delta: Represents changes to objects (Added, Updated, Deleted, etc.).
  • Patch utilities: JSON patch implementation.
  • View object constructors: Create view objects with proper GVK.
  • Object utilities: Deep copy, comparison, content manipulation.

Example usage:

obj := object.NewViewObject("test", "MyView")
object.SetName(obj, "default", "my-instance")
object.SetContent(obj, map[string]any{"spec": data})
delta := object.Delta{
    Type: object.Added,
    Object: obj,
}

Index

Constants

View Source
const (
	Added    = DeltaType(toolscache.Added)
	Deleted  = DeltaType(toolscache.Deleted)
	Updated  = DeltaType(toolscache.Updated)
	Replaced = DeltaType(toolscache.Replaced)
	Sync     = DeltaType(toolscache.Sync)
	Upserted = DeltaType("Upserted") // for events that are either an update/replace or an add
)

Variables

View Source
var NilDelta = Delta{Object: nil}

NilDelta is a placeholder for a delta that means no change.

Functions

func ApplyStrategicMergePatch

func ApplyStrategicMergePatch(original, patch *unstructured.Unstructured) (*unstructured.Unstructured, error)

ApplyStrategicMergePatch is a partial local re-implementation of strategic merge patches.

func ConvertRuntimeObjectToClientObject

func ConvertRuntimeObjectToClientObject(runtimeObj runtime.Object) (client.Object, error)

ConvertRuntimeObjectToClientObject converts a core runtime objects into a full client.Object.

func DeepCopyAny

func DeepCopyAny(value any) any

DeepCopyAny clones an arbitrary value.

func DeepCopyInto

func DeepCopyInto(in, out Object)

DeepCopyInto copies an Object into another one.

func DeepEqual

func DeepEqual(a, b Object) bool

DeepEqual compares to Objects.

func Dump

func Dump(obj Object) string

Dump converts an unstuctured object into a human-readable form.

func GetBaseScheme

func GetBaseScheme() *runtime.Scheme

GetBaseScheme returns a base scheme. Used mostly for testing.

func GetOperator

func GetOperator(obj Object) string

GetOperator returns the operator namespace the object belongs to.

func MergeAny

func MergeAny(a, b any) (any, error)

MergeAny merges two arbitrary values.

func Patch

func Patch(obj Object, m map[string]any) error

Patch performs an in-place patch.

func SetContent

func SetContent(obj Object, content map[string]any)

SetContent is similar to SetUnstructuredContent but it preserves the GVK, the name and the namespace and deep-copies the content.

func SetName

func SetName(obj Object, ns, name string)

SetName is a shortcut to SetNamespace(ns) followed by SetNamespace(name).

Types

type Delta

type Delta struct {
	Object Object
	Type   DeltaType
}

Delta registers a change (addition, deletion, etc) on an object. By convention, Object is nil if no change occurs.

func (Delta) IsUnchanged

func (d Delta) IsUnchanged() bool

IsUnchanged checks of a delta indicates a change.

func (Delta) String

func (d Delta) String() string

type DeltaType

type DeltaType string

Event type definition.

type Object

type Object = *unstructured.Unstructured

Object is an alias for a Kubernetes unstructured object used internally as an object representation.

func DeepCopy

func DeepCopy(in Object) Object

DeepCopy copies an Object.

func New

func New() Object

New create a new object.

func NewViewObject

func NewViewObject(operator, view string) Object

NewViewObject initializes an empty object in the given view and sets the GVK.

func NewViewObjectFromNativeObject

func NewViewObjectFromNativeObject(operator, view string, clientObj client.Object) (Object, error)

NewViewObjectFromNativeObject creates a view object from a client.Object.

type ObjectList

type ObjectList = *unstructured.UnstructuredList //nolint:revive

ObjectList is an alias for a Kubernetes unstructured lists.

Jump to

Keyboard shortcuts

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