deployer

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 10

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 CAPI
	// 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"
)

Variables

This section is empty.

Functions

func AddOwnerReference added in v0.4.0

func AddOwnerReference(object, owner client.Object)

AddOwnerReference adds Sveltos resource owning a resource as an object's OwnerReference. OwnerReferences are used as ref count. Different Sveltos resources might match same cluster and reference same ConfigMap. This means a policy contained in a ConfigMap is deployed in a Cluster because of different Sveltos resources. When cleaning up, a policy can be removed only if no more Sveltos resources are listed as OwnerReferences.

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 IsOnlyOwnerReference added in v0.4.0

func IsOnlyOwnerReference(object, owner client.Object) bool

IsOnlyOwnerReference returns true if clusterprofile is the only ownerreference for object

func IsOwnerReference added in v0.4.0

func IsOwnerReference(object, owner client.Object) bool

IsOwnerReference returns true is owner is one of the OwnerReferences for object

func RemoveOwnerReference added in v0.4.0

func RemoveOwnerReference(object, owner client.Object)

RemoveOwnerReference removes Sveltos resource as an OwnerReference from object. OwnerReferences are used as ref count. Different Sveltos resources might match same cluster and reference same ConfigMap. This means a policy contained in a ConfigMap is deployed in a Cluster because of different SveltosResources. When cleaning up, a policy can be removed only if no more SveltosResources are listed as OwnerReferences.

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
	// CAPI 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]string
}

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 {
	// indicates whethere resource currently exists (only
	// existing resources have a Version set)
	ResourceVersion string

	// Resource's OwnerReferences
	OwnerReferences []corev1.ObjectReference

	// Current profile owner's tier
	OwnerTier string

	Hash string
}

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.

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