status

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package status provides a generic way to report status and conditions for any resource of type client.Object.

The Reporter struct centralizes the management of status and condition updates for any resource type that implements client.Object. This approach consolidates the previously scattered updateStatus functions found in DSCI and DSC controllers into a single, reusable component.

Reporter handles the reporting of a resource's condition based on the operational state and errors encountered during processing. It uses a closure, DetermineCondition, defined by the developer to determine how conditions should be updated, particularly in response to errors. This closure is similar to its previous incarnation "update func(saved)", which appends the target object's conditions, with the only difference being access to an optional error to make changes in the condition to be reported based on the occurred error.

Example:

createReporter initializes a new status reporter for a DSCInitialization resource. It encapsulates the logic for updating the condition based on errors encountered during the resource's lifecycle operations.

func createReporter(cli client.Client, object *dsciv1.DSCInitialization, condition *conditionsv1.Condition) *status.Reporter[*dsciv1.DSCInitialization] {
	return status.NewStatusReporter[*dsciv1.DSCInitialization](
		cli,
		object,
		func(err error) status.SaveStatusFunc[*dsciv1.DSCInitialization] {
			return func(saved *dsciv1.DSCInitialization) {
				if err != nil {
					condition.Status = corev1.ConditionFalse
					condition.Message = err.Error()
					condition.Reason = status.CapabilityFailed
					var missingOperatorErr *feature.MissingOperatorError
					if errors.As(err, &missingOperatorErr) {
						condition.Reason = status.MissingOperatorReason
					}
				}
				conditionsv1.SetStatusCondition(&saved.Status.Conditions, *condition)
			}
		},
	)
}

doServiceMeshStuff manages the Service Mesh configuration process during DSCInitialization reconcile. It creates a reporter and reports any conditions derived from the service mesh configuration process.

func (r *DSCInitializationReconciler) doStdoServiceMeshStuffff(instance *dsciv1.DSCInitialization) error {
	reporter := createReporter(r.Client, instance, &conditionsv1.Condition{
		Type:    status.CapabilityServiceMesh,
		Status:  corev1.ConditionTrue,
		Reason:  status.ConfiguredReason,
		Message: "Service Mesh configured",
	})

	serviceMeshErr := createServiceMesh(instance)
	_, reportError := reporter.ReportCondition(serviceMeshErr)

	return multierror.Append(serviceMeshErr, reportError) // return all errors
}

Package status contains different conditions, phases and progresses, being used by DataScienceCluster and DSCInitialization's controller

Index

Constants

View Source
const (
	// PhaseIgnored is used when a resource is ignored
	// is an example of a constant that is not used anywhere in the code.
	PhaseIgnored = "Ignored"
	// PhaseNotReady is used when waiting for system to be ready after reconcile is successful
	// is an example of a constant that is not used anywhere in the code.
	PhaseNotReady = "Not Ready"
	// PhaseClusterExpanding is used when cluster is expanding capacity
	// is an example of a constant that is not used anywhere in the code.
	PhaseClusterExpanding = "Expanding Capacity"
	// PhaseDeleting is used when cluster is deleting
	// is an example of a constant that is not used anywhere in the code.
	PhaseDeleting = "Deleting"
	// PhaseConnecting is used when cluster is connecting to external cluster
	// is an example of a constant that is not used anywhere in the code.
	PhaseConnecting = "Connecting"
	// PhaseOnboarding is used when consumer is Onboarding
	// is an example of a constant that is not used anywhere in the code.
	PhaseOnboarding = "Onboarding"

	// PhaseProgressing is used when SetProgressingCondition() is called.
	PhaseProgressing = "Progressing"
	// PhaseError is used when SetErrorCondition() is called.
	PhaseError = "Error"
	// PhaseReady is used when SetCompleteCondition is called.
	PhaseReady = "Ready"
)

These constants represent the overall Phase as used by .Status.Phase.

View Source
const (
	// ReconcileFailed is used when multiple DSCI instance exists or DSC reconcile failed/removal failed.
	ReconcileFailed                       = "ReconcileFailed"
	ReconcileInit                         = "ReconcileInit"
	ReconcileCompleted                    = "ReconcileCompleted"
	ReconcileCompletedWithComponentErrors = "ReconcileCompletedWithComponentErrors"
	ReconcileCompletedMessage             = "Reconcile completed successfully"

	// ConditionReconcileComplete represents extra Condition Type, used by .Condition.Type.
	ConditionReconcileComplete conditionsv1.ConditionType = "ReconcileComplete"
)

List of constants to show different reconciliation messages and statuses.

View Source
const (
	CapabilityServiceMesh              conditionsv1.ConditionType = "CapabilityServiceMesh"
	CapabilityServiceMeshAuthorization conditionsv1.ConditionType = "CapabilityServiceMeshAuthorization"
	CapabilityDSPv2Argo                conditionsv1.ConditionType = "CapabilityDSPv2Argo"
)
View Source
const (
	MissingOperatorReason string = "MissingOperator"
	ConfiguredReason      string = "Configured"
	RemovedReason         string = "Removed"
	CapabilityFailed      string = "CapabilityFailed"
	ArgoWorkflowExist     string = "ArgoWorkflowExist"
)
View Source
const (
	ReadySuffix = "Ready"
)

Variables

This section is empty.

Functions

func RemoveComponentCondition added in v2.1.0

func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component string)

RemoveComponentCondition remove Condition of giving component.

func SetCompleteCondition

func SetCompleteCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetCompleteCondition sets the ConditionReconcileComplete to True and other Conditions to indicate that the reconciliation process has completed successfully.

func SetComponentCondition added in v2.1.0

func SetComponentCondition(conditions *[]conditionsv1.Condition, component string, reason string, message string, status corev1.ConditionStatus)

SetComponentCondition appends Condition Type with const ReadySuffix for given component when component finished reconcile.

func SetCondition added in v2.14.0

func SetCondition(conditions *[]conditionsv1.Condition, conditionType string, reason string, message string, status corev1.ConditionStatus)

SetCondition is a general purpose function to update any type of condition.

func SetErrorCondition

func SetErrorCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetErrorCondition sets the ConditionReconcileComplete to False in case of any errors during the reconciliation process.

func SetProgressingCondition

func SetProgressingCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetProgressingCondition sets the ProgressingCondition to True and other conditions to false or Unknown. Used when we are just starting to reconcile, and there are no existing conditions.

func UpdateWithRetry added in v2.10.1

func UpdateWithRetry[T client.Object](ctx context.Context, cli client.Client, original T, update SaveStatusFunc[T]) (T, error)

UpdateWithRetry updates the status of object using passed function and retries on conflict.

Types

type DetermineCondition added in v2.11.0

type DetermineCondition[T client.Object] func(err error) SaveStatusFunc[T]

DetermineCondition is a function that allow to define how condition should be set. It can use err if available to set faulty condition. It should return a SaveStatusFunc which will be used to update the status of the object.

type ModelRegistryStatus added in v2.18.0

type ModelRegistryStatus struct {
	RegistriesNamespace string `json:"registriesNamespace,omitempty"`
}

ModelRegistryStatus struct holds the status for the ModelRegistry component.

type Reporter added in v2.10.1

type Reporter[T client.Object] struct {
	// contains filtered or unexported fields
}

Reporter handles condition reporting for a given object. The logic of how the given condition should be calculated is defined by the determineCondition function.

func NewStatusReporter added in v2.10.1

func NewStatusReporter[T client.Object](cli client.Client, object T, determine DetermineCondition[T]) *Reporter[T]

NewStatusReporter creates r new Reporter with all required fields.

func (*Reporter[T]) ReportCondition added in v2.10.1

func (r *Reporter[T]) ReportCondition(ctx context.Context, optionalErr error) (T, error)

ReportCondition updates the status of the object using the determineCondition function.

type SaveStatusFunc added in v2.10.1

type SaveStatusFunc[T client.Object] func(saved T)

SaveStatusFunc is a function that allow to define custom logic of updating status of a concrete resource object.

Jump to

Keyboard shortcuts

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