From fdb1a8e8de8048025ecc636c306bc9907a7eabea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Wed, 24 Jul 2024 11:23:00 +0300 Subject: [PATCH] Add ReconciliationPolicy to ControlPlane API to managing the reconciliation/pause policies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın --- apis/spaces/v1beta1/conditions.go | 59 ++++++++++++++++++++ apis/spaces/v1beta1/controlplane_types.go | 21 +++++++ apis/spaces/v1beta1/zz_generated.deepcopy.go | 20 +++++++ 3 files changed, 100 insertions(+) diff --git a/apis/spaces/v1beta1/conditions.go b/apis/spaces/v1beta1/conditions.go index 0ce6333..5c336a8 100644 --- a/apis/spaces/v1beta1/conditions.go +++ b/apis/spaces/v1beta1/conditions.go @@ -53,6 +53,17 @@ const ( // ReasonRestorePending indicates that the control plane restore is pending. ReasonRestorePending xpcommonv1.ConditionReason = "RestorePending" + + // ConditionTypePaused indicates that the control plane has been paused. + ConditionTypePaused xpcommonv1.ConditionType = "Paused" + // ReasonPauseInProgress indicates that the control plane is being paused. + ReasonPauseInProgress xpcommonv1.ConditionReason = "InProgress" + // ReasonPauseCompleted indicates that the control plane has been paused. + ReasonPauseCompleted xpcommonv1.ConditionReason = "Completed" + // ReasonPauseRestartInProgress indicates that the control plane is being restarted. + ReasonPauseRestartInProgress xpcommonv1.ConditionReason = "RestartInProgress" + // ReasonPauseRestarted indicates that the control plane has been restarted. + ReasonPauseRestarted xpcommonv1.ConditionReason = "Restarted" ) // Healthy returns a condition that indicates the control plane is healthy. @@ -203,3 +214,51 @@ func RestorePending() xpcommonv1.Condition { Message: "Control plane restore is pending", } } + +// PauseInProgress returns a condition that indicates that the control plane +// is being paused. +func PauseInProgress() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypePaused, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonPauseInProgress, + Message: "Control plane is being paused", + } +} + +// PauseCompleted returns a condition that indicates that the control plane +// has been paused. +func PauseCompleted() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypePaused, + Status: corev1.ConditionTrue, + LastTransitionTime: metav1.Now(), + Reason: ReasonPauseCompleted, + Message: "Control plane has been paused", + } +} + +// PauseRestartInProgress returns a condition that indicates that the control +// plane is being restarted. +func PauseRestartInProgress() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypePaused, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonPauseRestartInProgress, + Message: "Control plane is being restarted", + } +} + +// PauseRestarted returns a condition that indicates that the control +// plane has been restarted. +func PauseRestarted() xpcommonv1.Condition { + return xpcommonv1.Condition{ + Type: ConditionTypePaused, + Status: corev1.ConditionFalse, + LastTransitionTime: metav1.Now(), + Reason: ReasonPauseRestarted, + Message: "Control plane has been restarted", + } +} diff --git a/apis/spaces/v1beta1/controlplane_types.go b/apis/spaces/v1beta1/controlplane_types.go index 8995b50..cf067f2 100644 --- a/apis/spaces/v1beta1/controlplane_types.go +++ b/apis/spaces/v1beta1/controlplane_types.go @@ -60,6 +60,9 @@ const ( AuthSecretKeySSHKnownHosts = "knownHosts" CASecretKeyCAFile = "ca.crt" + + PauseControlNone = "None" + PauseControlAllCrossplane = "AllCrossplane" ) const ( @@ -202,6 +205,11 @@ type ControlPlaneSpec struct { // +optional // +kubebuilder:validation:XValidation:rule="!has(oldSelf.finishedAt) || oldSelf.finishedAt == self.finishedAt",message="finishedAt is immutable once set" Restore *Restore `json:"restore,omitempty"` + + // ReconciliationPolicy specifies the reconciliation policies on the + // crossplane and the workloads that work on the ControlPlane + // +optional + ReconciliationPolicy *ReconciliationPolicy `json:"reconciliationPolicy,omitempty"` } // Restore specifies details about the backup to restore from. @@ -222,6 +230,19 @@ type Restore struct { FinishedAt *metav1.Time `json:"finishedAt,omitempty"` } +// ReconciliationPolicy represents the reconciliation policies. +type ReconciliationPolicy struct { + // PausedControllers controls whether the ControlPlane is paused or not. + // It has two valid values. + // AllCrossplane: Pauses/Scales Down all crossplane and provider workloads + // in the ControlPlane + // None: Restarts/Scales Up all crossplane and provider workloads in the + // ControlPlane + // +kubebuilder:validation:Enum=None;AllCrossplane + // +kubebuilder:default=None + PausedControllers string `json:"pausedControllers,omitempty"` +} + // A ControlPlaneStatus represents the observed state of a ControlPlane. type ControlPlaneStatus struct { xpv1.ResourceStatus `json:",inline"` diff --git a/apis/spaces/v1beta1/zz_generated.deepcopy.go b/apis/spaces/v1beta1/zz_generated.deepcopy.go index e8f4468..9ea6cae 100644 --- a/apis/spaces/v1beta1/zz_generated.deepcopy.go +++ b/apis/spaces/v1beta1/zz_generated.deepcopy.go @@ -108,6 +108,11 @@ func (in *ControlPlaneSpec) DeepCopyInto(out *ControlPlaneSpec) { *out = new(Restore) (*in).DeepCopyInto(*out) } + if in.ReconciliationPolicy != nil { + in, out := &in.ReconciliationPolicy, &out.ReconciliationPolicy + *out = new(ReconciliationPolicy) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneSpec. @@ -181,6 +186,21 @@ func (in *CrossplaneSpec) DeepCopy() *CrossplaneSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ReconciliationPolicy) DeepCopyInto(out *ReconciliationPolicy) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReconciliationPolicy. +func (in *ReconciliationPolicy) DeepCopy() *ReconciliationPolicy { + if in == nil { + return nil + } + out := new(ReconciliationPolicy) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Restore) DeepCopyInto(out *Restore) { *out = *in