Skip to content

Commit

Permalink
ControlPlanes: add provisioned condition
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <[email protected]>
  • Loading branch information
turkenh committed Jul 8, 2024
1 parent b04a03d commit 6140cf0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
44 changes: 43 additions & 1 deletion apis/spaces/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const (
// ReasonUnhealthy indicates that the control plane is unhealthy.
ReasonUnhealthy xpcommonv1.ConditionReason = "UnhealthyControlPlane"

// ConditionTypeControlPlaneProvisioned indicates that the control plane is provisioned.
ConditionTypeControlPlaneProvisioned xpcommonv1.ConditionType = "ControlPlaneProvisioned"
// ReasonProvisioned indicates that the control plane is provisioned.
ReasonProvisioned xpcommonv1.ConditionReason = "Provisioned"
// ReasonProvisioningError indicates that the control plane provisioning has failed.
ReasonProvisioningError xpcommonv1.ConditionReason = "ProvisioningError"

// ConditionTypeSourceSynced indicates that the git source is in sync.
ConditionTypeSourceSynced xpcommonv1.ConditionType = "SourceSynced"
// ReasonSourceCompleted indicates that the git sync has been completed.
Expand Down Expand Up @@ -48,6 +55,7 @@ const (
ReasonRestorePending xpcommonv1.ConditionReason = "RestorePending"
)

// Healthy returns a condition that indicates the control plane is healthy.
func Healthy() xpcommonv1.Condition {
return xpcommonv1.Condition{
Type: ConditionTypeHealthy,
Expand All @@ -57,12 +65,46 @@ func Healthy() xpcommonv1.Condition {
}
}

func Unhealthy(err error) xpcommonv1.Condition {
// Unhealthy returns a condition that indicates the control plane is unhealthy.
func Unhealthy() xpcommonv1.Condition {
return xpcommonv1.Condition{
Type: ConditionTypeHealthy,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonUnhealthy,
}
}

// ControlPlaneProvisioned returns a condition that indicates the control plane
// has been provisioned.
func ControlPlaneProvisioned() xpcommonv1.Condition {
return xpcommonv1.Condition{
Type: ConditionTypeControlPlaneProvisioned,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: ReasonProvisioned,
}
}

// ControlPlaneProvisionInProgress returns a condition that indicates the control
// plane is still being provisioned.
func ControlPlaneProvisionInProgress() xpcommonv1.Condition {
return xpcommonv1.Condition{
Type: ConditionTypeControlPlaneProvisioned,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonProvisioned,
}
}

// ControlPlaneProvisioningError returns a condition that indicates the control
// plane provisioning has failed.
func ControlPlaneProvisioningError(err error) xpcommonv1.Condition {
return xpcommonv1.Condition{
Type: ConditionTypeControlPlaneProvisioned,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonProvisioningError,
Message: err.Error(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion apis/spaces/v1beta1/controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ type Restore struct {
// A ControlPlaneStatus represents the observed state of a ControlPlane.
type ControlPlaneStatus struct {
xpv1.ResourceStatus `json:",inline"`

// Message is a human-readable message indicating details about why the
// ControlPlane is in this condition.
Message string `json:"message,omitempty"`
ControlPlaneID string `json:"controlPlaneID,omitempty"`
HostClusterID string `json:"hostClusterID,omitempty"`
Expand Down

0 comments on commit 6140cf0

Please sign in to comment.