controller

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationKeyDisplayName = "openchoreo.dev/display-name"
	AnnotationKeyDescription = "openchoreo.dev/description"
)
View Source
const (
	TypeAccepted    = "Accepted"
	TypeProgressing = "Progressing"
	TypeAvailable   = "Available"
	TypeCreated     = "Created"
	TypeReady       = "Ready"
	TypeTerminating = "Terminating"
)

States for conditions

Variables

This section is empty.

Functions

func GetBuildName added in v0.2.0

func GetBuildName(obj client.Object) string

GetBuildName returns the build name that the object belongs to.

func GetBuildPlane added in v0.3.0

func GetComponentName

func GetComponentName(obj client.Object) string

GetComponentName returns the component name that the object belongs to.

func GetDataPlane added in v0.2.0

func GetDataPlaneByEnvironment added in v0.2.0

func GetDataPlaneByEnvironment(ctx context.Context, c client.Client, env *openchoreov1alpha1.Environment) (*openchoreov1alpha1.DataPlane, error)

GetDataPlaneByEnvironment retrieves the DataPlane object for the given Environment. It uses the DataPlaneRef field in the Environment to find the DataPlane object.

func GetDataPlaneName added in v0.2.0

func GetDataPlaneName(obj client.Object) string

GetDataPlaneName returns the data plane name that the object belongs to.

func GetDataplaneOfEnv added in v0.2.0

func GetDeployableArtifact added in v0.2.0

func GetDeployableArtifact(ctx context.Context, c client.Client, obj client.Object) (*openchoreov1alpha1.DeployableArtifact, error)

func GetDeployableArtifactName

func GetDeployableArtifactName(obj client.Object) string

GetDeployableArtifactName returns the deployable artifact name that the object belongs to.

func GetDeploymentByEnvironment

func GetDeploymentByEnvironment(ctx context.Context, c client.Client, obj client.Object, envName string) (*openchoreov1alpha1.Deployment, error)

func GetDeploymentByName

func GetDeploymentByName(ctx context.Context, c client.Client, obj client.Object, deploymentName string) (*openchoreov1alpha1.Deployment, error)

func GetDeploymentName

func GetDeploymentName(obj client.Object) string

GetDeploymentName returns the deployment name that the object belongs to.

func GetDeploymentTrackName

func GetDeploymentTrackName(obj client.Object) string

GetDeploymentTrackName returns the deployment track name that the object belongs to.

func GetDescription

func GetDescription(obj client.Object) string

GetDescription returns the description of the object.

func GetDisplayName

func GetDisplayName(obj client.Object) string

GetDisplayName returns the display name of the object.

func GetEnvironmentByName

func GetEnvironmentByName(ctx context.Context, c client.Client, obj client.Object, envName string) (*openchoreov1alpha1.Environment, error)

func GetEnvironmentName

func GetEnvironmentName(obj client.Object) string

GetEnvironmentName returns the environment name that the object belongs to.

func GetName

func GetName(obj client.Object) string

GetName returns the name of the object. This is specific to the Choreo, and it is not the Kubernetes object name.

func GetOrganizationName

func GetOrganizationName(obj client.Object) string

GetOrganizationName returns the organization name that the object belongs to.

func GetProjectName

func GetProjectName(obj client.Object) string

GetProjectName returns the project name that the object belongs to.

func HasPatchChanges added in v0.3.0

func HasPatchChanges(original, desired client.Object) (bool, []byte, error)

HasPatchChanges determines if two Kubernetes objects have differences by comparing their patch data.

func HierarchyWatchHandler

func HierarchyWatchHandler[From client.Object, To client.Object](
	c client.Client,
	hierarchyFunc HierarchyFunc[To],
) func(ctx context.Context, obj client.Object) []reconcile.Request

HierarchyWatchHandler is a function that creates a watch handler for a specific hierarchy. It can be used to watch from parent object for child object updates. The hierarchyFunc should return the target object that is being watched given the source object.

func IgnoreHierarchyNotFoundError

func IgnoreHierarchyNotFoundError(err error) error

IgnoreHierarchyNotFoundError returns nil if the given error is a HierarchyNotFoundError. This is useful during the reconciliation process to ignore the error if the parent object is not found and avoid retrying.

func MarkFalseCondition added in v0.3.0

func MarkFalseCondition(obj ConditionedObject, ct ConditionType, reason ConditionReason, message string) (changed bool)

func MarkTrueCondition added in v0.3.0

func MarkTrueCondition(obj ConditionedObject, ct ConditionType, reason ConditionReason, message string) (changed bool)

func MarkUnknownCondition added in v0.3.0

func MarkUnknownCondition(obj ConditionedObject, ct ConditionType, reason ConditionReason, message string) (changed bool)

func Merge added in v0.3.0

func Merge[T any](base, overlay *T) (*T, error)

Merge applies a strategic merge patch to the base object using the overlay object. This function uses Kubernetes strategic merge patch semantics to combine two objects of the same type.

Parameters:

  • base: the original object to merge into
  • overlay: the object containing changes to apply

Returns:

  • *T: the merged result object, or nil if either input is nil
  • error: any error that occurred during marshaling, patching, or unmarshaling

Example usage:

base := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}}
overlay := &v1.Pod{Spec: v1.PodSpec{RestartPolicy: v1.RestartPolicyAlways}}
merged, err := controller.Merge(base, overlay)
if err != nil {
    return fmt.Errorf("failed to merge: %w", err)
}

func NeedConditionUpdate

func NeedConditionUpdate(currentConditions, updatedConditions []metav1.Condition) bool

NeedConditionUpdate checks if the conditions need to be updated based on the current and updated conditions.

func NewCondition

func NewCondition(conditionType ConditionType, status metav1.ConditionStatus, reason ConditionReason,
	message string, observedGeneration int64) metav1.Condition

NewCondition creates a new condition with the last transition time set to the current time.

func NewHierarchyNotFoundError

func NewHierarchyNotFoundError(obj client.Object, parentObj client.Object, parentHierarchyObjs ...client.Object) error

NewHierarchyNotFoundError creates a new error with the given object and parent object details. The parentObj is the immediate parent of the obj The parentHierarchyObjs are the hierarchy of objects from the parentObj to the top level object starting from the top level object. Example: NewHierarchyNotFoundError(deployment, deploymentTrack, organization, project, component)

func UpdateCondition

func UpdateCondition(
	ctx context.Context,
	c client.StatusWriter,
	resource client.Object,
	conditions *[]metav1.Condition,
	conditionType string,
	status metav1.ConditionStatus,
	reason, message string,
) error

UpdateCondition updates or adds a condition to any resource that has a Status with Conditions

func UpdateStatusConditions

func UpdateStatusConditions[T ConditionedObject](
	ctx context.Context,
	c client.Client,
	current, updated T,
) error

UpdateStatusConditions will compare the current and updated conditions and update the status conditions if needed.

func UpdateStatusConditionsAndRequeue

func UpdateStatusConditionsAndRequeue[T ConditionedObject](
	ctx context.Context, c client.Client, current, updated T,
) (ctrl.Result, error)

UpdateStatusConditionsAndRequeue updates status conditions and requests a requeue. This indicates that the controller should requeue the request for further processing. It returns an error if the status update fails.

func UpdateStatusConditionsAndRequeueAfter

func UpdateStatusConditionsAndRequeueAfter[T ConditionedObject](
	ctx context.Context, c client.Client, current, updated T, duration time.Duration,
) (ctrl.Result, error)

UpdateStatusConditionsAndRequeueAfter updates status conditions and requeues after the specified duration. It returns an error if the status update fails.

func UpdateStatusConditionsAndReturn

func UpdateStatusConditionsAndReturn[T ConditionedObject](
	ctx context.Context, c client.Client, current, updated T,
) (ctrl.Result, error)

UpdateStatusConditionsAndReturn updates status conditions without requeuing. It returns an error if the update fails.

func UpdateStatusConditionsAndReturnError

func UpdateStatusConditionsAndReturnError[T ConditionedObject](
	ctx context.Context, c client.Client, current, updated T, err error,
) (ctrl.Result, error)

UpdateStatusConditionsAndReturnError updates status conditions and returns the given error. It returns an update error if the conditions update fails. It prioritizes the status update error over the provided error, if any.

func UpdateStatusConditionsWithPatch

func UpdateStatusConditionsWithPatch[T ConditionedObject](
	ctx context.Context,
	c client.Client,
	current, updated T,
) error

UpdateStatusConditionsWithPatch updates status conditions using a patch operation with retry on conflicts. This is more robust for handling concurrent updates to the same resource.

Types

type ConditionReason

type ConditionReason string

ConditionReason represents the machine-readable reason for a condition's status. Use CamelCase format (e.g., MinimumReplicasUnavailable, MinimumReplicasMet).

type ConditionType

type ConditionType string

ConditionType represents the type of condition describing a specific state of the resource. Use CamelCase format (e.g., Ready, Available).

func (ConditionType) String

func (c ConditionType) String() string

String returns the string representation of the condition type.

type ConditionedObject

type ConditionedObject interface {
	client.Object

	GetConditions() []metav1.Condition
	SetConditions(conditions []metav1.Condition)
}

ConditionedObject describes a Kubernetes resource that has a mutable Conditions field in its Status

type HierarchyFunc

type HierarchyFunc[T any] func(ctx context.Context, c client.Client, obj client.Object) (T, error)

HierarchyFunc is a generic function type that takes a context, client, and object as input and returns an object of type T and an error. This is used for MakeHierarchyWatchHandler to define the function that will be called to get the target object.

type HierarchyNotFoundError

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

HierarchyNotFoundError is an error type that is used to indicate that a parent object in the hierarchy is not found.

func (*HierarchyNotFoundError) Error

func (e *HierarchyNotFoundError) Error() string

Jump to

Keyboard shortcuts

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