status

package
v2.29.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: Apache-2.0 Imports: 8 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.GetClient, 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.GetClient, 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"
)

List of constants to show different reconciliation messages and statuses.

View Source
const (
	// ConditionTypeAvailable indicates whether the resource is available.
	ConditionTypeAvailable = "Available"
	// ConditionTypeProgressing indicates whether the resource is progressing.
	ConditionTypeProgressing = "Progressing"
	// ConditionTypeDegraded indicates whether the resource is degraded.
	ConditionTypeDegraded = "Degraded"
	// ConditionTypeUpgradeable indicates whether the resource is upgradeable.
	ConditionTypeUpgradeable = "Upgradeable"
	// ConditionTypeReady indicates whether the resource is ready.
	ConditionTypeReady = "Ready"
	// ConditionTypeReconcileComplete indicates whether reconciliation is complete.
	ConditionTypeReconcileComplete = "ReconcileComplete"

	// Component-specific condition types.
	ConditionTypeProvisioningSucceeded     = "ProvisioningSucceeded"
	ConditionDeploymentsNotAvailableReason = "DeploymentsNotReady"
	ConditionDeploymentsAvailable          = "DeploymentsAvailable"
	ConditionServerlessAvailable           = "ServerlessAvailable"
	ConditionServiceMeshAvailable          = "ServiceMeshAvailable"
	ConditionArgoWorkflowAvailable         = "ArgoWorkflowAvailable"
	ConditionTypeComponentsReady           = "ComponentsReady"
	ConditionServingAvailable              = "ServingAvailable"
)
View Source
const (
	CapabilityServiceMesh              string = "CapabilityServiceMesh"
	CapabilityServiceMeshAuthorization string = "CapabilityServiceMeshAuthorization"
	CapabilityDSPv2Argo                string = "CapabilityDSPv2Argo"
)
View Source
const (
	MissingOperatorReason     string = "MissingOperator"
	ConfiguredReason          string = "Configured"
	RemovedReason             string = "Removed"
	UnmanagedReason           string = "Unmanaged"
	CapabilityFailed          string = "CapabilityFailed"
	ArgoWorkflowExist         string = "ArgoWorkflowExist"
	NoManagedComponentsReason        = "NoManagedComponents"

	DegradedReason  = "Degraded"
	AvailableReason = "Available"
	UnknownReason   = "Unknown"
	NotReadyReason  = "NotReady"
	ErrorReason     = "Error"
	ReadyReason     = "Ready"
)
View Source
const (
	ServiceMeshNotConfiguredReason  = "ServiceMeshNotConfigured"
	ServiceMeshNotConfiguredMessage = "ServiceMesh needs to be set to 'Managed' in DSCI CR"

	ServiceMeshOperatorNotInstalledReason  = "ServiceMeshOperatorNotInstalled"
	ServiceMeshOperatorNotInstalledMessage = "ServiceMesh operator must be installed for this component's configuration"

	ServerlessOperatorNotInstalledReason  = "ServerlessOperatorNotInstalled"
	ServerlessOperatorNotInstalledMessage = "Serverless operator must be installed for this component's configuration"

	ServerlessUnsupportedCertMessage = "Serverless certificate type is not supported"
)
View Source
const (
	DataSciencePipelinesDoesntOwnArgoCRDReason = "DataSciencePipelinesDoesntOwnArgoCRD"

	DataSciencePipelinesDoesntOwnArgoCRDMessage = "Failed upgrade: workflows.argoproj.io CRD already exists but not deployed by this operator " +
		"remove existing Argo workflows or set `spec.components.datasciencepipelines.managementState` to Removed to proceed"
)
View Source
const (
	MultiKueueCRDReason  = "MultiKueueCRDV1Alpha1Exist"
	MultiKueueCRDMessage = "MultiKueue CRDs MultiKueueConfig v1alpha1 and MultiKueueCluster v1Alpha1 exist, please remove them to proceed"
)

For Kueue MultiKueue CRD.

View Source
const (
	ISVCMissingCRDReason  = "InferenceServiceCRDMissing"
	ISVCMissingCRDMessage = "InferenceServices CRD does not exist, please enable serving component first"
)

For TrustyAI require ISVC CRD.

View Source
const (
	ReadySuffix = "Ready"
)

Variables

This section is empty.

Functions

func SetCompleteCondition

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

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

func SetCondition

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

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

func SetErrorCondition

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

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

func SetProgressingCondition

func SetProgressingCondition(conditions *[]common.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

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

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 Reporter

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

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

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

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