apply

package
v1.12.0-alpha.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// LabelRenderHash is the label that record the hash value of the rendering resource.
	LabelRenderHash = "oam.dev/render-hash"
)

Variables

This section is empty.

Functions

func AddSharer added in v1.5.0

func AddSharer(sharedBy string, key string) string

AddSharer adds the owner key to a shared-by list, unless the owner is already there in either form. The key is written as given.

func CanonicalOwnerKey

func CanonicalOwnerKey(key string) string

CanonicalOwnerKey returns an owner key as <kind>/<namespace>/<name>. A key without a kind (<namespace>/<name>, or <name> in the default namespace) was written before owner kinds existed and belongs to Config.DefaultOwnerKind; with no default kind it is returned as is.

func ComputeSpecHash added in v1.10.0

func ComputeSpecHash(spec interface{}) (string, error)

ComputeSpecHash computes the hash value of a k8s resource spec

func Configure

func Configure(c Config)

Configure sets this package's Config for the process. Hosts call it at start-up.

func ContainsSharer added in v1.5.0

func ContainsSharer(sharedBy string, key string) bool

ContainsSharer reports whether a shared-by list contains the owner, in either key form

func FirstSharer added in v1.5.0

func FirstSharer(sharedBy string) string

FirstSharer is the owner key that controls a shared resource: the first in the list, skipping empty entries, which a hand-written or legacy annotation can hold. "" if there is no sharer.

func RemoveSharer added in v1.5.0

func RemoveSharer(sharedBy string, key string) string

RemoveSharer removes the owner, in every key form, from a shared-by list

Types

type APIApplicator

type APIApplicator struct {
	// contains filtered or unexported fields
}

APIApplicator implements Applicator

func NewAPIApplicator

func NewAPIApplicator(c client.Client) *APIApplicator

NewAPIApplicator creates an Applicator that applies state to an object or creates the object if not exist.

func (*APIApplicator) Apply

func (a *APIApplicator) Apply(ctx context.Context, desired client.Object, ao ...ApplyOption) error

Apply applies new state to an object or create it if not exist

type Applicator

type Applicator interface {
	Apply(context.Context, client.Object, ...ApplyOption) error
}

Applicator applies new state to an object or create it if not exist. It uses the same mechanism as `kubectl apply`, that is, for each resource being applied, computing a three-way diff merge in client side based on its current state, modified stated, and last-applied-state which is tracked through an specific annotation. If the resource doesn't exist before, Apply will create it.

type ApplyOption

type ApplyOption func(act *applyAction, existing, desired client.Object) error

ApplyOption is called before applying state to the object. ApplyOption is still called even if the object does NOT exist. If the object does not exist, `existing` will be assigned as `nil`. nolint

func DisableUpdateAnnotation added in v1.2.4

func DisableUpdateAnnotation() ApplyOption

DisableUpdateAnnotation disable write last config to annotation

func DryRunAll added in v1.5.0

func DryRunAll() ApplyOption

DryRunAll executing all validation, etc without persisting the change to storage.

func MakeCustomApplyOption added in v1.1.7

func MakeCustomApplyOption(f func(existing, desired client.Object) error) ApplyOption

MakeCustomApplyOption let user can generate applyOption that restrict change apply action.

func MustBeControllableBy

func MustBeControllableBy(u types.UID) ApplyOption

MustBeControllableBy requires that the new object is controllable by an object with the supplied UID. An object is controllable if its controller reference includes the supplied UID.

func MustBeControlledBy

func MustBeControlledBy(owner Owner) ApplyOption

MustBeControlledBy requires that an existing object is controlled by owner. An existing object nobody controls is only adopted under take-over.

func NotUpdateRenderHashEqual added in v1.1.7

func NotUpdateRenderHashEqual() ApplyOption

NotUpdateRenderHashEqual if the render hash of new object equal to the old hash, should not apply.

func Quiet added in v1.6.0

func Quiet() ApplyOption

Quiet means disable the logger

func ReadOnly added in v1.7.0

func ReadOnly() ApplyOption

ReadOnly skip apply fo the resource

func SharedBy

func SharedBy(owner Owner) ApplyOption

SharedBy lets owner share the resource with whoever else already shares it.

func TakeOver added in v1.7.0

func TakeOver() ApplyOption

TakeOver allow take over resources without app owner

func TakeOverIf

func TakeOverIf(accept func(existing client.Object) bool) ApplyOption

TakeOverIf is TakeOver for the existing objects the predicate accepts: the caller names the shape it may claim and leaves every other unowned object to the refusal. It must run before MustBeControlledBy.

func WithUpdateStrategy added in v1.9.0

func WithUpdateStrategy(strategy v1alpha1.ResourceUpdateStrategy) ApplyOption

WithUpdateStrategy set the update strategy for the apply operation

type Config

type Config struct {
	// ReplaceOnUpdate updates an existing updatable resource by replacing it rather than
	// patching it, unless the call sets a strategy. Default false
	// (KubeVela: ApplyResourceByReplace).
	ReplaceOnUpdate func() bool
	// LegacyOwnerValidation lets an existing resource with no owner be adopted without
	// take-over. Default false (KubeVela: LegacyResourceOwnerValidation).
	LegacyOwnerValidation func() bool
	// Scheme resolves the kind of a typed object passed without TypeMeta. Default:
	// client-go's types plus core.oam.dev.
	Scheme *runtime.Scheme
	// DefaultOwnerKind is the kind of owner keys written without one (<namespace>/<name>,
	// or <name>), from before owner kinds existed. Default "": such keys are compared as
	// written (KubeVela: Application).
	DefaultOwnerKind string
	// Migration: owner labels (see pkg/resourcekeeper's package doc).
	// LegacyControlledBy reads marks older than owner.oam.dev/* labels and returns their
	// owner's key ("" for nobody). Ownership checks consult it only when the owner's own
	// ControlledBy finds nobody, so a resource not yet re-labelled is still its owner's.
	// Default: none (KubeVela: app.oam.dev/* labels, as Application/<namespace>/<name>).
	LegacyControlledBy func(client.Object) string
}

Config holds the behaviour the host binary decides for this package. Switches are functions, evaluated on every call, so a host can back them with feature gates that change at runtime. A nil switch takes the default documented on it, which matches KubeVela's gate default.

func CurrentConfig

func CurrentConfig() Config

CurrentConfig returns the Config in effect (the zero Config if Configure was never called).

type Owner

type Owner interface {
	Kind() string
	Key() string
	ControlledBy(obj client.Object) string
}

Owner is whoever may control a resource: its Kind names it in errors, its Key identifies it, and ControlledBy reports who controls an object, in that same key format ("" for nobody). resourcetracker.Tracked satisfies it.

Jump to

Keyboard shortcuts

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