instance

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package instance provides shared logic for instance controllers (Falco, Metacollector). It manages common operations such as resource reconciliation, name generation, field diffing, and status patching.

Index

Constants

View Source
const (
	// ReasonApplyConfigurationError indicates an error generating the apply configuration.
	ReasonApplyConfigurationError = "ApplyConfigurationError"
	// ReasonMarshalConfigurationError indicates an error marshaling the configuration.
	ReasonMarshalConfigurationError = "MarshalConfigurationError"
	// ReasonOwnerReferenceError indicates an error setting the owner reference.
	ReasonOwnerReferenceError = "OwnerReferenceError"
	// ReasonExistingResourceError indicates an error fetching existing resource.
	ReasonExistingResourceError = "ExistingResourceError"
	// ReasonApplyPatchErrorOnCreate indicates an error applying patch during creation.
	ReasonApplyPatchErrorOnCreate = "ApplyPatchErrorOnCreate"
	// ReasonApplyPatchErrorOnUpdate indicates an error applying patch during update.
	ReasonApplyPatchErrorOnUpdate = "ApplyPatchErrorOnUpdate"
	// ReasonResourceCreated indicates the resource was created successfully.
	ReasonResourceCreated = "ResourceCreated"
	// ReasonResourceUpdated indicates the resource was updated successfully.
	ReasonResourceUpdated = "ResourceUpdated"
	// ReasonResourceUpToDate indicates the resource is already up to date.
	ReasonResourceUpToDate = "ResourceUpToDate"
	// ReasonResourceComparisonError indicates an error comparing resources.
	ReasonResourceComparisonError = "ResourceComparisonError"
)

Reconciled condition reasons.

View Source
const (
	// ReasonResourceGenerateError indicates an error generating a sub-resource.
	ReasonResourceGenerateError = "ResourceGenerateError"
	// ReasonResourceApplyError indicates an error applying a sub-resource.
	ReasonResourceApplyError = "ResourceApplyError"
	// ReasonSubResourceCreated indicates a sub-resource was created successfully.
	ReasonSubResourceCreated = "SubResourceCreated"
	// ReasonSubResourceUpdated indicates a sub-resource was updated successfully.
	ReasonSubResourceUpdated = "SubResourceUpdated"
)

Sub-resource event reasons.

View Source
const (
	// ReasonDeletionError indicates an error during deletion cleanup.
	ReasonDeletionError = "DeletionError"
	// ReasonInstanceDeleted indicates the instance was deleted successfully.
	ReasonInstanceDeleted = "InstanceDeleted"
)

Deletion event reasons.

View Source
const (
	// ReasonDeploymentNotFound indicates the deployment was not found.
	ReasonDeploymentNotFound = "DeploymentNotFound"
	// ReasonDeploymentAvailable indicates the deployment is available.
	ReasonDeploymentAvailable = "DeploymentAvailable"
	// ReasonDeploymentUnavailable indicates the deployment is unavailable.
	ReasonDeploymentUnavailable = "DeploymentUnavailable"
	// ReasonDeploymentFetchError indicates an error fetching the deployment status.
	ReasonDeploymentFetchError = "DeploymentFetchError"
)

Available condition reasons (Deployment).

View Source
const (
	// ReasonDaemonSetNotFound indicates the daemonset was not found.
	ReasonDaemonSetNotFound = "DaemonSetNotFound"
	// ReasonDaemonSetAvailable indicates the daemonset is available.
	ReasonDaemonSetAvailable = "DaemonSetAvailable"
	// ReasonDaemonSetUnavailable indicates the daemonset is unavailable.
	ReasonDaemonSetUnavailable = "DaemonSetUnavailable"
	// ReasonDaemonSetFetchError indicates an error fetching the daemonset status.
	ReasonDaemonSetFetchError = "DaemonSetFetchError"
)

DaemonSet available condition reasons (Falco-specific).

View Source
const (
	// MessageDeploymentNotFound is the message when deployment is not found.
	MessageDeploymentNotFound = "Deployment has not been created or has been deleted"
	// MessageDeploymentAvailable is the message when deployment is available.
	MessageDeploymentAvailable = "Deployment is available"
	// MessageDeploymentUnavailable is the message when deployment is unavailable.
	MessageDeploymentUnavailable = "Deployment is unavailable"
	// MessageDaemonSetNotFound is the message when daemonset is not found.
	MessageDaemonSetNotFound = "DaemonSet has not been created or has been deleted"
	// MessageDaemonSetAvailable is the message when daemonset is available.
	MessageDaemonSetAvailable = "DaemonSet is available"
	// MessageDaemonSetUnavailable is the message when daemonset is unavailable.
	MessageDaemonSetUnavailable = "DaemonSet is unavailable"
	// MessageResourceCreated is the message when resource is created.
	MessageResourceCreated = "Resource created successfully"
	// MessageResourceUpdated is the message when resource is updated.
	MessageResourceUpdated = "Resource updated successfully"
	// MessageFormatResourceUpdated is the format for resource updated message with changed fields.
	MessageFormatResourceUpdated = "Resource updated successfully (changed: %s)"
	// MessageResourceUpToDate is the message when resource is up to date.
	MessageResourceUpToDate = "Resource is up to date"
	// MessageFalcoInstanceDeleted is the message when a Falco instance is deleted.
	MessageFalcoInstanceDeleted = "Falco instance deleted successfully"
	// MessageFormatComponentInstanceDeleted is the format for the message when a Component instance is deleted.
	MessageFormatComponentInstanceDeleted = "Component instance (%s) deleted successfully"
)

Condition messages.

View Source
const (
	// MessageFormatDeploymentFetchError is the format for deployment fetch error message.
	MessageFormatDeploymentFetchError = "Unable to fetch deployment for status: %s"
	// MessageFormatDaemonSetFetchError is the format for daemonset fetch error message.
	MessageFormatDaemonSetFetchError = "Unable to fetch daemonset for status: %s"
	// MessageFormatApplyConfigurationError is the format for apply configuration error message.
	MessageFormatApplyConfigurationError = "Unable to generate apply configuration: %s"
	// MessageFormatMarshalConfigurationError is the format for marshal configuration error message.
	MessageFormatMarshalConfigurationError = "Unable to marshal apply configuration: %s"
	// MessageFormatOwnerReferenceError is the format for owner reference error message.
	MessageFormatOwnerReferenceError = "Unable to set owner reference: %s"
	// MessageFormatExistingResourceError is the format for existing resource error message.
	MessageFormatExistingResourceError = "Unable to fetch existing resource: %s"
	// MessageFormatApplyPatchErrorOnCreate is the format for apply patch error on create message.
	MessageFormatApplyPatchErrorOnCreate = "Unable to create resource by patch: %s"
	// MessageFormatApplyPatchErrorOnUpdate is the format for apply patch error on update message.
	MessageFormatApplyPatchErrorOnUpdate = "Unable to update resource by patch: %s"
	// MessageFormatResourceComparisonError is the format for resource comparison error message.
	MessageFormatResourceComparisonError = "Unable to compare existing and desired resources: %s"
	// MessageFormatResourceGenerateError is the format for resource generation error message.
	MessageFormatResourceGenerateError = "Unable to generate desired resource: %s"
	// MessageFormatResourceApplyError is the format for resource apply error message.
	MessageFormatResourceApplyError = "Unable to apply %s: %s"
	// MessageFormatSubResourceCreated is the format for sub-resource created message.
	MessageFormatSubResourceCreated = "%s %s created successfully"
	// MessageFormatSubResourceUpdated is the format for sub-resource updated message.
	MessageFormatSubResourceUpdated = "%s %s updated (changed: %s)"
	// MessageFormatDeletionError is the format for deletion error message.
	MessageFormatDeletionError = "Unable to delete %s during cleanup: %s"
	// MessageFormatDualDeploymentCleanup is the format for dual deployment cleanup message.
	MessageFormatDualDeploymentCleanup = "Deleted %s due to resource type switch"
)

Condition message formats (for use with fmt.Sprintf).

View Source
const (
	// ReasonDualDeploymentCleanup indicates a dual deployment was cleaned up during resource type switch.
	ReasonDualDeploymentCleanup = "DualDeploymentCleanup"
)

Dual deployment cleanup reasons.

Variables

This section is empty.

Functions

func ClusterScopedResourceHandler

func ClusterScopedResourceHandler(ctx context.Context, obj client.Object) []reconcile.Request

ClusterScopedResourceHandler handles cluster-scoped resources like ClusterRole and ClusterRoleBinding. It returns a list of reconcile.Requests for the instance associated with the resource.

func EnsureFinalizer

func EnsureFinalizer(ctx context.Context, cl client.Client, obj client.Object, finalizerName string) (bool, error)

EnsureFinalizer ensures the finalizer is set on the object and returns true if the object was updated.

func EnsureResource

func EnsureResource(ctx context.Context, cl client.Client, recorder events.EventRecorder,
	owner client.Object, fieldManager string,
	resource runtime.Object, options GenerateOptions) error

EnsureResource prepares a runtime.Object for server-side apply, diffs it against the live object, and applies it when needed.

func HandleDeletion

func HandleDeletion(ctx context.Context, cl client.Client, recorder events.EventRecorder,
	obj client.Object, finalizerName string, clusterScopedGVKs []schema.GroupVersionKind,
	deletedMessage string) (bool, error)

HandleDeletion handles the deletion of an instance by cleaning up cluster-scoped resources and removing the finalizer.

func MergeApplyConfiguration

func MergeApplyConfiguration(kind string, baseResource runtime.Object, userOverrides *unstructured.Unstructured) (*unstructured.Unstructured, error)

MergeApplyConfiguration merges a base structured resource with user-defined overrides using structured merge diff, and returns the result as unstructured. The kind parameter must be an apps/v1 resource kind (e.g., "Deployment", "DaemonSet").

func PrepareResource

func PrepareResource(
	cl client.Client,
	owner client.Object,
	resource runtime.Object,
	options GenerateOptions,
) (*unstructured.Unstructured, error)

PrepareResource converts a runtime.Object into an unstructured resource ready for server-side apply. It optionally sets the controller reference and sets the name based on the resource scope.

func ResolveVersion

func ResolveVersion(obj client.Object, defs *resources.InstanceDefaults) string

ResolveVersion determines the version to use for an instance controller. Resolution priority (highest wins):

  1. PodTemplateSpec container image tag (if the main container is present).
  2. spec.version from the CR.
  3. Default version from the instance defaults.

Types

type Availability

type Availability struct {
	ConditionStatus     metav1.ConditionStatus
	Reason              string
	Message             string
	DesiredReplicas     int32
	AvailableReplicas   int32
	UnavailableReplicas int32
}

Availability holds the computed availability state of a workload.

func ComputeDaemonSetAvailability

func ComputeDaemonSetAvailability(ctx context.Context, reader client.Reader,
	key client.ObjectKey) (Availability, error)

ComputeDaemonSetAvailability fetches the DaemonSet and computes availability.

func ComputeDeploymentAvailability

func ComputeDeploymentAvailability(ctx context.Context, reader client.Reader,
	key client.ObjectKey, specReplicas *int32) (Availability, error)

ComputeDeploymentAvailability fetches the Deployment and computes availability.

type GenerateOptions

type GenerateOptions struct {
	// SetControllerRef indicates whether to set the controller reference.
	SetControllerRef bool
	// IsClusterScoped indicates whether the resource is cluster-scoped.
	IsClusterScoped bool
}

GenerateOptions defines options for resource generation.

Jump to

Keyboard shortcuts

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