diff --git a/apis/spaces/v1beta1/conditions.go b/apis/spaces/v1beta1/conditions.go index 0ce6333..6e0d0b3 100644 --- a/apis/spaces/v1beta1/conditions.go +++ b/apis/spaces/v1beta1/conditions.go @@ -53,6 +53,18 @@ const ( // ReasonRestorePending indicates that the control plane restore is pending. ReasonRestorePending xpcommonv1.ConditionReason = "RestorePending" + + // ConditionTypeRunning indicates whether the workloads on the Control Plane + // are running or not. + ConditionTypeRunning xpcommonv1.ConditionType = "CrossplaneRunning" + // ReasonPausing indicates that the crossplane and provider workloads are being paused. + ReasonPausing xpcommonv1.ConditionReason = "Pausing" + // ReasonPaused indicates that the crossplane and provider workloads have been paused. + ReasonPaused xpcommonv1.ConditionReason = "Paused" + // ReasonStarting indicates that the crossplane and provider workloads are being started. + ReasonStarting xpcommonv1.ConditionReason = "Starting" + // ReasonStarted indicates that the crossplane and provider workloads have been started. + ReasonStarted xpcommonv1.ConditionReason = "Started" ) // Healthy returns a condition that indicates the control plane is healthy. @@ -203,3 +215,50 @@ func RestorePending() xpcommonv1.Condition { Message: "Control plane restore is pending", } } + +// PauseInProgress returns a condition that indicates that the crossplane and +// provider workloads are being paused. +func PauseInProgress() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypeRunning, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonPausing, + Message: "The crossplane and provider workloads are being paused", + } +} + +// PauseCompleted returns a condition that indicates that the crossplane and +// provider workloads have been paused. +func PauseCompleted() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypeRunning, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonPaused, + Message: "The crossplane and provider workloads have been paused", + } +} + +// StartInProgress returns a condition that indicates that the crossplane and +// provider workloads are being restarted. +func StartInProgress() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypeRunning, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonStarting, + Message: "The crossplane and provider workloads are being started", + } +} + +// StartCompleted returns a condition that indicates that the crossplane and +// provider workloads have been restarted. +func StartCompleted() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypeRunning, + Status: corev1.ConditionTrue, + LastTransitionTime: metav1.Now(), + Reason: ReasonStarted, + } +} diff --git a/apis/spaces/v1beta1/controlplane_types.go b/apis/spaces/v1beta1/controlplane_types.go index 8995b50..9dbeb05 100644 --- a/apis/spaces/v1beta1/controlplane_types.go +++ b/apis/spaces/v1beta1/controlplane_types.go @@ -102,6 +102,19 @@ const ( CrossplaneUpgradeRapid CrossplaneUpgradeChannel = "Rapid" ) +// CrossplaneState is the running state for the crossplane and provider workloads. +type CrossplaneState string + +const ( + // CrossplaneStateRunning switches the crossplane and provider workloads to + // the running state by scaling up them. + CrossplaneStateRunning CrossplaneState = "Running" + + // CrossplaneStatePaused switches the crossplane and provider workloads to + // the paused state by scaling down them. + CrossplaneStatePaused CrossplaneState = "Paused" +) + // CrossplaneAutoUpgradeSpec defines the auto upgrade policy for Crossplane. type CrossplaneAutoUpgradeSpec struct { // Channel defines the upgrade channels for Crossplane. We support the following channels where 'Stable' is the @@ -129,6 +142,15 @@ type CrossplaneSpec struct { // +optional // +kubebuilder:default={"channel":"Stable"} AutoUpgradeSpec *CrossplaneAutoUpgradeSpec `json:"autoUpgrade,omitempty"` + + // State defines the state for crossplane and provider workloads. We support + // the following states where 'Running' is the default: + // - Running: Starts/Scales up all crossplane and provider workloads in the ControlPlane + // - Paused: Pauses/Scales down all crossplane and provider workloads in the ControlPlane + // +optional + // +kubebuilder:validation:Enum=Running;Paused + // +kubebuilder:default=Running + State *CrossplaneState `json:"state,omitempty"` } // A SecretReference is a reference to a secret in an arbitrary namespace. diff --git a/apis/spaces/v1beta1/zz_generated.deepcopy.go b/apis/spaces/v1beta1/zz_generated.deepcopy.go index e8f4468..710a9b8 100644 --- a/apis/spaces/v1beta1/zz_generated.deepcopy.go +++ b/apis/spaces/v1beta1/zz_generated.deepcopy.go @@ -169,6 +169,11 @@ func (in *CrossplaneSpec) DeepCopyInto(out *CrossplaneSpec) { *out = new(CrossplaneAutoUpgradeSpec) (*in).DeepCopyInto(*out) } + if in.State != nil { + in, out := &in.State, &out.State + *out = new(CrossplaneState) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CrossplaneSpec.