Documentation
¶
Index ¶
- Constants
- func AddSharer(sharedBy string, key string) string
- func CanonicalOwnerKey(key string) string
- func ComputeSpecHash(spec interface{}) (string, error)
- func Configure(c Config)
- func ContainsSharer(sharedBy string, key string) bool
- func FirstSharer(sharedBy string) string
- func RemoveSharer(sharedBy string, key string) string
- type APIApplicator
- type Applicator
- type ApplyOption
- func DisableUpdateAnnotation() ApplyOption
- func DryRunAll() ApplyOption
- func MakeCustomApplyOption(f func(existing, desired client.Object) error) ApplyOption
- func MustBeControllableBy(u types.UID) ApplyOption
- func MustBeControlledBy(owner Owner) ApplyOption
- func NotUpdateRenderHashEqual() ApplyOption
- func Quiet() ApplyOption
- func ReadOnly() ApplyOption
- func SharedBy(owner Owner) ApplyOption
- func TakeOver() ApplyOption
- func TakeOverIf(accept func(existing client.Object) bool) ApplyOption
- func WithUpdateStrategy(strategy v1alpha1.ResourceUpdateStrategy) ApplyOption
- type Config
- type Owner
Constants ¶
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
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 ¶
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
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
ContainsSharer reports whether a shared-by list contains the owner, in either key form
func FirstSharer ¶ added in v1.5.0
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
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 ¶
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 ¶
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 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).