common

package
v0.6.43 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LifecycleDeleteAnnotation is the lifecycle annotation key for a deletion operation.
	// Keep it the same as cli-utils for backwards compatibility.
	LifecycleDeleteAnnotation = "client.lifecycle.config.k8s.io/deletion"

	// PreventDeletion is the value used with LifecycleDeletionAnnotation
	// to prevent deleting a resource. Keep it the same as cli-utils
	// for backwards compatibility.
	PreventDeletion = "detach"

	// ClientFieldManager is a name associated with the actor or entity
	// that is making changes to the object. Keep it the same as cli-utils
	// for backwards compatibility.
	ClientFieldManager = "application/apply-patch"
)
View Source
const (
	// OwningInventoryKey is the key used to store the owning service id
	// in the annotations of a resource.
	OwningInventoryKey = "config.k8s.io/owning-inventory"

	// TrackingIdentifierKey is the key used to store the unique identifier
	// of a resource in the annotations of a resource.
	// This is used to make sure that the owning inventory was not copied from another resource.
	TrackingIdentifierKey = "config.k8s.io/tracking-identifier"
)
View Source
const (
	// SyncPhaseHookDeletePolicy allows users to customize resource deletion behavior.
	SyncPhaseHookDeletePolicy = "deployment.plural.sh/sync-hook-delete-policy"

	// HelmHookDeletePolicyAnnotation allows users to customize resource deletion behavior.
	HelmHookDeletePolicyAnnotation = "helm.sh/hook-delete-policy"

	// HookDeletePolicySucceeded means the resource should be deleted if the hook succeeds.
	// Used both in SyncPhaseHookDeletePolicy and HelmHookDeletePolicyAnnotation to simplify checks.
	HookDeletePolicySucceeded = "hook-succeeded"

	// HookDeletePolicyFailed means the resource should be deleted if the hook fails.
	// Used both in SyncPhaseHookDeletePolicy and HelmHookDeletePolicyAnnotation for simplify checks.
	HookDeletePolicyFailed = "hook-failed"
)
View Source
const (
	// SyncOptionsAnnotation specifies sync options for a given resource.
	SyncOptionsAnnotation = "deployment.plural.sh/sync-options"

	// ArgoSyncOptionsAnnotation specifies sync options for a given resource.
	ArgoSyncOptionsAnnotation = "argocd.argoproj.io/sync-options"

	// SyncOptionForce escalates a failed sync to delete and recreate.
	// If replace=true is also set, escalation happens when replace fails.
	SyncOptionForce = "force=true"

	// SyncOptionReplace uses replace instead of apply.
	// It removes fields missing from the desired state.
	// With force=true, a failed replace escalates to delete and recreate.
	SyncOptionReplace = "replace=true"

	// ResyncInProgressAnnotation contains an annotation for a resource that was deleted forcefully
	// and will be recreated in the next reconciling.
	ResyncInProgressAnnotation = "deployment.plural.sh/resync"
)
View Source
const (
	// SyncPhaseAnnotation allows users to customize resource apply phases when needed.
	SyncPhaseAnnotation = "deployment.plural.sh/sync-hook"

	// SyncPhasePreSync is the earliest phase that a resource can be in.
	SyncPhasePreSync SyncPhase = "pre-sync"

	// SyncPhaseSync is the default phase that a resource is in. It is applied after the PreSync phase succeeds.
	SyncPhaseSync SyncPhase = "sync"

	// SyncPhasePostSync is the latest phase that a resource can be in. It is applied after the Sync phase succeeds.
	SyncPhasePostSync SyncPhase = "post-sync"

	// SyncPhaseSyncFail is the phase applied when the Sync phase fails.
	SyncPhaseSyncFail SyncPhase = "sync-fail"

	// SyncPhaseSkip means the resource will be skipped during the sync process.
	SyncPhaseSkip SyncPhase = "skip"

	// HelmHookAnnotation is the annotation key used to store the helm hook type
	// that should be applied during specific phases of the applying lifecycle.
	HelmHookAnnotation = "helm.sh/hook"

	// HelmHookPreInstall resources are applied before the installation of resources.
	HelmHookPreInstall = "pre-install"

	// HelmHookPostInstall resources are applied after the installation of resources.
	HelmHookPostInstall = "post-install"

	// HelmHookPreUpgrade resources are applied before the upgrade of resources.
	HelmHookPreUpgrade = "pre-upgrade"

	// HelmHookPostUpgrade resources are applied after the upgrade of resources.
	HelmHookPostUpgrade = "post-upgrade"
)
View Source
const (
	// SyncWaveAnnotation allows users to customize resource apply ordering when needed.
	SyncWaveAnnotation = "deployment.plural.sh/sync-wave"

	// ArgoSyncWaveAnnotation indicates which wave of the sync the resource or hook should be in.
	ArgoSyncWaveAnnotation = "argocd.argoproj.io/sync-wave"

	// HelmHookWeightAnnotation is the annotation key used to store the Helm hook weight.
	HelmHookWeightAnnotation = "helm.sh/hook-weight"

	// SyncWaveDefault should be after the last priority from kindSyncPriorities.
	SyncWaveDefault = 4
)

Variables

View Source
var (
	GroupBlacklist = containers.ToSet([]string{
		"aquasecurity.github.io",
		"status.gatekeeper.sh",
	})

	ResourceVersionBlacklist = containers.ToSet([]string{
		"componentstatuses/v1",
		"events/v1",
		"bindings/v1",
		"localsubjectaccessreviews/v1",
		"selfsubjectreviews/v1",
		"selfsubjectaccessreviews/v1",
		"selfsubjectrulesreviews/v1",
		"tokenreviews/v1",
		"subjectaccessreviews/v1",
		"metrics.k8s.io/v1beta1",
	})

	OptionalResourceVersionList = containers.ToSet([]string{
		"leases/v1",
	})
)
View Source
var ApplyPhases = containers.ToSet([]string{
	SyncPhasePreSync.String(),
	SyncPhaseSync.String(),
	SyncPhasePostSync.String(),
	SyncPhaseSyncFail.String(),
})

ApplyPhases contains all phases where resources can be applied to the cluster.

SyncPhases contains all currently supported sync phases.

Functions

func GetOwningInventory

func GetOwningInventory(obj unstructured.Unstructured) string

func GetPhaseHookDeletePolicy

func GetPhaseHookDeletePolicy(u unstructured.Unstructured) string

GetPhaseHookDeletePolicy retrieves the sync phase hook delete policy from the resource annotations.

func GetSyncWave

func GetSyncWave(u unstructured.Unstructured) int

GetSyncWave retrieves the sync wave from the resource annotations.

func GetTrackingIdentifier

func GetTrackingIdentifier(obj unstructured.Unstructured) string

func HasApplyPhase

func HasApplyPhase(u unstructured.Unstructured) bool

HasApplyPhase indicates if a resource has a phase where it can be applied to the cluster. Invalid phases or a skip phase will return false.

func HasForceSyncOption

func HasForceSyncOption(u unstructured.Unstructured) bool

func HasPhase

func HasPhase(u unstructured.Unstructured, phase SyncPhase) bool

HasPhase checks if the resource belongs to the specified sync phase.

func HasReplaceSyncOption

func HasReplaceSyncOption(u unstructured.Unstructured) bool

func HasResyncInProgressAnnotation

func HasResyncInProgressAnnotation(u *unstructured.Unstructured) bool

func HasSyncOption

func HasSyncOption(u unstructured.Unstructured, option string) bool

func HasSyncPhaseHookDeletePolicy

func HasSyncPhaseHookDeletePolicy(u unstructured.Unstructured) bool

func ParseHookDeletePolicy

func ParseHookDeletePolicy(resource unstructured.Unstructured) []string

func SplitHookDeletePolicy

func SplitHookDeletePolicy(policy string) []string

func ValidateTrackingIdentifier

func ValidateTrackingIdentifier(u unstructured.Unstructured) bool

ValidateTrackingIdentifier checks if the key created from the resource metadata is equal to the key in the tracking identifier annotation. If that is not the case, then it is likely that the annotation was copied from another resource, and we should not trust it and the owning inventory annotation.

Types

type Component

type Component struct {
	UID                  string
	ParentUID            string
	Group                string
	Version              string
	Kind                 string
	Name                 string
	Namespace            string
	Status               string
	ServiceID            string
	Manifest             bool
	DeletePhase          string
	ManifestSHA          string
	TransientManifestSHA string
	ApplySHA             string
	ServerSHA            string
}

func (*Component) ComponentAttributes

func (in *Component) ComponentAttributes() client.ComponentAttributes

func (*Component) DeletableUnstructured

func (in *Component) DeletableUnstructured() unstructured.Unstructured

func (*Component) GroupVersionKind

func (in *Component) GroupVersionKind() schema.GroupVersionKind

func (*Component) Key

func (in *Component) Key() Key

func (*Component) ShouldApply

func (in *Component) ShouldApply(newManifestSHA string) bool

ShouldApply determines if a resource should be applied. Resource should be applied if at least one of the following conditions is met: - any of the SHAs (Server, Apply, or Manifest) are not set - the current server SHA differs from stored apply SHA (indicating resource changed in cluster) - the new manifest SHA differs from stored manifest SHA (indicating the manifest has changed) - the resource is not in a running state

func (*Component) StoreKey

func (in *Component) StoreKey() StoreKey

type Components

type Components []Component

func (Components) ComponentAttributes

func (in Components) ComponentAttributes() []client.ComponentAttributes

type HookComponent

type HookComponent struct {
	UID            string
	Group          string
	Version        string
	Kind           string
	Name           string
	Namespace      string
	Status         string
	ManifestSHA    string
	ServiceID      string
	DeletePolicies []string
}

HookComponent represents hook resources that have deletion policy set.

func (*HookComponent) Failed

func (in *HookComponent) Failed() bool

func (*HookComponent) GroupVersionKind

func (in *HookComponent) GroupVersionKind() schema.GroupVersionKind

func (*HookComponent) HadDesiredState

func (in *HookComponent) HadDesiredState() bool

HadDesiredState checks if the hook had the desired state based on its stored delete policies. It uses delete policies from the store that may have changed. If possible, use HasDesiredState with live resource delete policies.

func (*HookComponent) HasDesiredState

func (in *HookComponent) HasDesiredState(policies []string) bool

HasDesiredState checks if the hook has the desired state based on its delete policies. Delete policies from the live resource can be passed as an argument to make check better. To use the delete policies from the store, use HadDesiredState.

func (*HookComponent) HasManifestChanged

func (in *HookComponent) HasManifestChanged(u unstructured.Unstructured) bool

func (*HookComponent) StoreKey

func (in *HookComponent) StoreKey() StoreKey

func (*HookComponent) Succeeded

func (in *HookComponent) Succeeded() bool

func (*HookComponent) Unstructured

func (in *HookComponent) Unstructured() unstructured.Unstructured

type Key

type Key string

func NewKey

func NewKey(group, version, kind, namespace, name string) Key

func NewKeyFromUnstructured

func NewKeyFromUnstructured(u unstructured.Unstructured) Key

func (Key) Equals

func (k Key) Equals(s string) bool

func (Key) String

func (k Key) String() string

type StoreKey

type StoreKey struct {
	GVK       schema.GroupVersionKind
	Namespace string
	Name      string
}

StoreKey is a unique identifier for a resource in the store. It is using a compound key consisting of GVK, namespace and name as CRD object instances can share the same UID across versions.

func NewStoreKeyFromComponentAttributes

func NewStoreKeyFromComponentAttributes(a client.ComponentAttributes) StoreKey

func NewStoreKeyFromUnstructured

func NewStoreKeyFromUnstructured(u unstructured.Unstructured) StoreKey

func (StoreKey) Key

func (in StoreKey) Key() Key

func (StoreKey) ReplaceGroup

func (in StoreKey) ReplaceGroup(group string) StoreKey

func (StoreKey) VersionlessKey

func (in StoreKey) VersionlessKey() Key

type SyncPhase

type SyncPhase string

func GetDeletePhase

func GetDeletePhase(u unstructured.Unstructured) SyncPhase

GetDeletePhase returns the phase in which the resource should be deleted.

func (SyncPhase) Equals

func (sp SyncPhase) Equals(s string) bool

func (SyncPhase) String

func (sp SyncPhase) String() string

Jump to

Keyboard shortcuts

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