deployer

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: Apache-2.0 Imports: 34 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// ReferenceLabelKind is added to each policy deployed by a ClusterSummary
	// instance to a managed Cluster. Indicates the Kind (ConfigMap or Secret)
	// containing the policy.
	ReferenceKindLabel = "projectsveltos.io/reference-kind"

	// ReferenceNameLabel is added to each policy deployed by a ClusterSummary
	// instance to a managed Cluster. Indicates the name of the ConfigMap/Secret
	// containing the policy.
	ReferenceNameLabel = "projectsveltos.io/reference-name"

	// ReferenceNamespaceLabel is added to each policy deployed by a ClusterSummary
	// instance to a managed Cluster. Indicates the namespace of the ConfigMap/Secret
	// containing the policy.
	ReferenceNamespaceLabel = "projectsveltos.io/reference-namespace"

	// PolicyHash is the annotation set on a policy when deployed in a managed
	// cluster.
	PolicyHash = "projectsveltos.io/hash"

	// OwnerTier is the annotation set on a policy when deployed in a managed
	// cluster. Contains the tier of the profile instance that deployed it.
	OwnerTier = "projectsveltos.io/owner-tier"

	// OwnerName is the annotation set on a policy when deployed in a managed
	// cluster. Contains the name of the profile instance that deployed it.
	OwnerName = "projectsveltos.io/owner-name"

	// OwnerKind is the annotation set on a policy when deployed in a managed
	// cluster. Contains the Kind of the profile instance that deployed it.
	OwnerKind = "projectsveltos.io/owner-kind"
)
View Source
const (
	ReasonLabel = "projectsveltos.io/reason"
)

Variables

This section is empty.

Functions

func AddAnnotation added in v1.0.1

func AddAnnotation(obj metav1.Object, annotationKey, annotationValue string)

AddAnnotation adds annotation to an object

func AddLabel added in v1.0.1

func AddLabel(obj metav1.Object, labelKey, labelValue string)

AddLabel adds label to an object

func AddMetadata added in v1.0.1

func AddMetadata(policy *unstructured.Unstructured, resourceVersion string, profile client.Object,
	extraLabels, extraAnnotations map[string]string)

func ComputePolicyHash added in v1.0.1

func ComputePolicyHash(policy *unstructured.Unstructured) (string, error)

ComputePolicyHash compute policy hash.

func CreateNamespace added in v1.0.1

func CreateNamespace(ctx context.Context, clusterClient client.Client,
	isDryRun bool, namespaceName string) error

CreateNamespace creates a namespace if it does not exist already No action in DryRun mode.

func CustomSplit added in v1.0.1

func CustomSplit(text string) ([]string, error)

func DeployResourceSummaryInCluster added in v1.0.1

func DeployResourceSummaryInCluster(ctx context.Context, c client.Client, resourceSummaryName types.NamespacedName,
	clusterNamespace, clusterName, requestor string, clusterType libsveltosv1beta1.ClusterType,
	resources []libsveltosv1beta1.Resource, kustomizeResources []libsveltosv1beta1.Resource,
	helmResources []libsveltosv1beta1.HelmResources, driftExclusions []libsveltosv1beta1.DriftExclusion,
	logger logr.Logger) error

func GenerateConflictResourceReport added in v1.0.1

func GenerateConflictResourceReport(ctx context.Context, dr dynamic.ResourceInterface,
	resource *libsveltosv1beta1.Resource) *libsveltosv1beta1.ResourceReport

func GenerateResourceReport added in v1.0.1

func GenerateResourceReport(policyHash string, resourceInfo *ResourceInfo,
	policy *unstructured.Unstructured, resource *libsveltosv1beta1.Resource) *libsveltosv1beta1.ResourceReport

func GetClient

func GetClient(ctx context.Context, l logr.Logger, c client.Client, numOfWorker int) *deployer

GetClient return a deployer client, implementing the DeployerInterface

func GetKey

func GetKey(clusterNamespace, clusterName, applicant, featureID string, clusterType sveltosv1beta1.ClusterType, cleanup bool) string

GetKey returns a unique ID for a request provided: - clusterNamespace and clusterName which are the namespace/name of the cluster where feature needs to be deployed; - featureID is a unique identifier for the feature that needs to be deployed.

func GetOwnerMessage added in v0.4.0

func GetOwnerMessage(ctx context.Context, dr dynamic.ResourceInterface,
	objectName string) (string, error)

GetOwnerMessage returns a message listing why this object is deployed. The message lists: - which is currently causing it to be deployed (owner) - which Secret/ConfigMap contains it

func GetPolicyInfo added in v1.0.1

func GetPolicyInfo(policy *libsveltosv1beta1.Resource) string

func GetResource added in v1.0.1

func GetResource(policy *unstructured.Unstructured, ignoreForConfigurationDrift bool,
	referencedObject *corev1.ObjectReference, profile client.Object, tier int32, featureID string,
	logger logr.Logger) (resource *libsveltosv1beta1.Resource, policyHash string)

GetResource returns sveltos Resource and the resource hash

func GetUnstructured added in v1.0.1

func GetUnstructured(section []byte, logger logr.Logger) ([]*unstructured.Unstructured, error)

func HandleDeployUnstructuredErrors added in v1.0.1

func HandleDeployUnstructuredErrors(conflictErrorMsg, errorMsg string, isDryRun bool) error

func HasHigherOwnershipPriority added in v1.0.1

func HasHigherOwnershipPriority(currentOwnerTier, claimingTier int32) bool

Determines if a ClusterProfile/Profile can take ownership of a resource currently managed by another ClusterProfile/Profile. This function considers the tier of the claiming ClusterProfile/Profile (represented by 'claimingTier') and the current owner information (`currentOwner`). Ownership can be transferred if the claiming profile belongs to a lower tier than the current owner. In case of tiers being equal, the function returns false to maintain the current ownership.

Args:

currentOwnerTier:  The tier of the ClusterProfile/Profile currently with ownership
claimingTier: The tier of the ClusterProfile/Profile trying to take ownership

Returns:

  • true if the claiming ClusterProfile/Profile has higher ownership priority (lower tier),
  • false otherwise.

func HasIgnoreConfigurationDriftAnnotation added in v1.0.1

func HasIgnoreConfigurationDriftAnnotation(resource *unstructured.Unstructured) bool

HasIgnoreConfigurationDriftAnnotation verifies whether resource has `projectsveltos.io/driftDetectionIgnore` annotation. Any resource with such annotation set won't be tracked for configuration drift.

func TransformDriftExclusionsToPatches added in v1.0.1

func TransformDriftExclusionsToPatches(driftExclusions []libsveltosv1beta1.DriftExclusion) []libsveltosv1beta1.Patch

TransformDriftExclusionsToPatches transforms a slice of driftExclusion to a slice of Patch Operation on each Patch is always set to remove (the goal of a DriftExclusion is to not consider, so to remove, a path during configuration drift evaluation).

func UndeployStaleResource added in v1.0.1

func UndeployStaleResource(ctx context.Context, skipAnnotationKey, skipAnnotationValue string, c client.Client,
	profile client.Object, leavePolicies, isDryRunMode bool, r unstructured.Unstructured,
	currentPolicies map[string]libsveltosv1beta1.Resource, logger logr.Logger) (*libsveltosv1beta1.ResourceReport, error)

func UpdateResource added in v1.0.1

func UpdateResource(ctx context.Context, dr dynamic.ResourceInterface, isDriftDetection, isDryRun bool,
	driftExclusions []libsveltosv1beta1.DriftExclusion, object *unstructured.Unstructured, subresources []string,
	logger logr.Logger) (*unstructured.Unstructured, error)

UpdateResource creates or updates a resource in a Cluster. No action in DryRun mode.

Types

type ConflictError added in v0.4.0

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

func NewConflictError added in v0.30.0

func NewConflictError(msg string) *ConflictError

func (*ConflictError) Error added in v0.4.0

func (e *ConflictError) Error() string

type DeployerInterface

type DeployerInterface interface {
	// RegisterFeatureID allows registering a feature ID.
	// If a featureID is already registered, it returns an error.
	RegisterFeatureID(
		featureID string,
	) error

	// Deploy creates a request to deploy/cleanup a feature in a given
	// cluster (identified by clusterNamespace, clusterName).
	// cleanup indicates whether request is for feature to be provisioned
	// or removed.
	// When worker is available to fulfill such request, RequestHandler
	// will be invoked in the worker context.
	// If featureID is not registered, an error will be returned.
	// Applicant is an identifier of whatever is making this request.
	// It can be left empty (in case there is no need to differentiate between
	// different applicants).
	Deploy(
		ctx context.Context,
		clusterNamespace, clusterName, applicant, featureID string,
		clusterType libsveltosv1beta1.ClusterType,
		cleanup bool,
		f RequestHandler,
		m MetricHandler,
		o Options,
	) error

	// IsInProgress returns true, if featureID for clusterNamespace/clusterName
	// requested by applicant is currently in progress.
	// cleanup indicates whether request for feature to be provisioned or
	// removed is currently in progress.
	IsInProgress(
		clusterNamespace, clusterName, applicant, featureID string,
		clusterType libsveltosv1beta1.ClusterType,
		cleanup bool,
	) bool

	// GetResult returns result for a given request.
	GetResult(
		ctx context.Context,
		clusterNamespace, clusterName, applicant, featureID string,
		clusterType libsveltosv1beta1.ClusterType,
		cleanup bool,
	) Result

	// CleanupEntries removes any entry (from any internal data structure) for
	// given feature
	CleanupEntries(clusterNamespace, clusterName, applicant, featureID string,
		clusterType libsveltosv1beta1.ClusterType, cleanup bool)
}

type MetricHandler

type MetricHandler func(elapsed time.Duration,
	clusterNamespace, clusterName, featureID string,
	clusterType libsveltosv1beta1.ClusterType, logger logr.Logger)

type Options added in v0.3.0

type Options struct {
	HandlerOptions map[string]any
}

type RequestHandler

type RequestHandler func(ctx context.Context, c client.Client,
	clusterNamespace, clusterName, applicant, featureID string,
	clusterType libsveltosv1beta1.ClusterType, o Options, logger logr.Logger) error

type ResourceInfo added in v0.30.0

type ResourceInfo struct {
	CurrentResource *unstructured.Unstructured

	// Current profile owner's tier
	OwnerTier string

	Hash string
}

func CanDeployResource added in v1.0.1

func CanDeployResource(ctx context.Context, dr dynamic.ResourceInterface, policy *unstructured.Unstructured,
	referencedObject *corev1.ObjectReference, profile client.Object, profileTier int32, logger logr.Logger,
) (resourceInfo *ResourceInfo, requeueOldOwner bool, err error)

CanDeployResource verifies whether resource can be deployed. Following checks are performed:

- if resource is currently already deployed in the managed cluster, if owned by this (Cluster)Profile/referenced resource => it can be updated - if resource is currently already deployed in the managed cluster and owned by same (Cluster)Profile but different referenced resource => it cannot be updated - if resource is currently already deployed in the managed cluster but owned by different (Cluster)Profile => it can be updated only if current (Cluster)Profile tier is lower than profile currently deploying the resource

If resource cannot be deployed, return a ConflictError. If any other error occurs while doing those verification, the error is returned

func ValidateObjectForUpdate added in v0.4.0

func ValidateObjectForUpdate(ctx context.Context, dr dynamic.ResourceInterface,
	object *unstructured.Unstructured, referenceKind, referenceNamespace, referenceName string,
	profile client.Object) (*ResourceInfo, error)

validateObjectForUpdate finds if object currently exists. If object exists: - verifies this object was created by same referenced object (specified by referenceKind, referenceNamespace, referenceName); - verifies this object was deployed because of the same profile instance (specified by profile instance). Returns an error otherwise. This is needed to prevent misconfigurations. An example would be when different ConfigMaps are referenced by ClusterProfile(s) or RoleRequest(s) and contain same policy namespace/name (content might be different) and are about to be deployed in the same cluster; Return an error if validation fails. Return also whether the object currently exists or not. If object exists, return value of PolicyHash annotation.

func (*ResourceInfo) GetOwnerReferences added in v0.43.0

func (r *ResourceInfo) GetOwnerReferences() []corev1.ObjectReference

func (*ResourceInfo) GetResourceVersion added in v0.43.0

func (r *ResourceInfo) GetResourceVersion() string

type Result

type Result struct {
	ResultStatus
	Err error
}

type ResultStatus

type ResultStatus int64
const (
	Deployed ResultStatus = iota
	InProgress
	Failed
	Removed
	Unavailable
)

func (ResultStatus) String

func (r ResultStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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