From b68010e0726ec992c61087b0bea66fc00f7d042b Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Mon, 7 Apr 2025 16:44:13 +0200 Subject: [PATCH] feat!: introducing sleeping status (#773) * feat(api): introducing sleeping status Signed-off-by: Dario Tranchitella * chore(helm)!: introducing sleeping status Marking this commit as breaking since a CustomResourceDefinition update is required for users dealing with scale to zero since the introduction of the new enum for the status field. Signed-off-by: Dario Tranchitella * docs: introducing sleeping status Signed-off-by: Dario Tranchitella --------- Signed-off-by: Dario Tranchitella --- api/v1alpha1/tenantcontrolplane_status.go | 3 ++- .../kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml | 1 + controllers/soot/manager.go | 7 +++---- controllers/telemetry_controller.go | 3 ++- docs/content/reference/api.md | 2 +- internal/resources/k8s_deployment_resource.go | 2 ++ 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/v1alpha1/tenantcontrolplane_status.go b/api/v1alpha1/tenantcontrolplane_status.go index 812223d..6b38625 100644 --- a/api/v1alpha1/tenantcontrolplane_status.go +++ b/api/v1alpha1/tenantcontrolplane_status.go @@ -183,11 +183,12 @@ type KubernetesStatus struct { Ingress *KubernetesIngressStatus `json:"ingress,omitempty"` } -// +kubebuilder:validation:Enum=Provisioning;CertificateAuthorityRotating;Upgrading;Migrating;Ready;NotReady +// +kubebuilder:validation:Enum=Provisioning;CertificateAuthorityRotating;Upgrading;Migrating;Ready;NotReady;Sleeping type KubernetesVersionStatus string var ( VersionProvisioning KubernetesVersionStatus = "Provisioning" + VersionSleeping KubernetesVersionStatus = "Sleeping" VersionCARotating KubernetesVersionStatus = "CertificateAuthorityRotating" VersionUpgrading KubernetesVersionStatus = "Upgrading" VersionMigrating KubernetesVersionStatus = "Migrating" diff --git a/charts/kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml b/charts/kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml index bb26cdc..b51b1c1 100644 --- a/charts/kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml +++ b/charts/kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml @@ -7379,6 +7379,7 @@ spec: - Migrating - Ready - NotReady + - Sleeping type: string version: description: Version is the running Kubernetes version of the Tenant Control Plane. diff --git a/controllers/soot/manager.go b/controllers/soot/manager.go index d3e7a34..93b9410 100644 --- a/controllers/soot/manager.go +++ b/controllers/soot/manager.go @@ -136,17 +136,16 @@ func (m *Manager) Reconcile(ctx context.Context, request reconcile.Request) (res return reconcile.Result{}, err } + tcpStatus := ptr.Deref(tcp.Status.Kubernetes.Version.Status, kamajiv1alpha1.VersionProvisioning) // Handling finalizer if the TenantControlPlane is marked for deletion or scaled to zero: // the clean-up function is already taking care to stop the manager, if this exists. - if tcp.GetDeletionTimestamp() != nil || ptr.Deref(tcp.Spec.ControlPlane.Deployment.Replicas, 0) == 0 { + if tcp.GetDeletionTimestamp() != nil || tcpStatus == kamajiv1alpha1.VersionSleeping { if controllerutil.ContainsFinalizer(tcp, finalizers.SootFinalizer) { return reconcile.Result{}, m.cleanup(ctx, request, tcp) } return reconcile.Result{}, nil } - - tcpStatus := *tcp.Status.Kubernetes.Version.Status // Triggering the reconciliation of the underlying controllers of // the soot manager if this is already registered. v, ok := m.sootMap[request.String()] @@ -181,7 +180,7 @@ func (m *Manager) Reconcile(ctx context.Context, request reconcile.Request) (res } // No need to start a soot manager if the TenantControlPlane is not ready: // enqueuing back is not required since we're going to get that event once ready. - if tcpStatus == kamajiv1alpha1.VersionNotReady || tcpStatus == kamajiv1alpha1.VersionCARotating { + if tcpStatus == kamajiv1alpha1.VersionNotReady || tcpStatus == kamajiv1alpha1.VersionCARotating || tcpStatus == kamajiv1alpha1.VersionSleeping { log.FromContext(ctx).Info("skipping start of the soot manager for a not ready instance") return reconcile.Result{}, nil diff --git a/controllers/telemetry_controller.go b/controllers/telemetry_controller.go index 806d333..22e1228 100644 --- a/controllers/telemetry_controller.go +++ b/controllers/telemetry_controller.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -81,7 +82,7 @@ func (m *TelemetryController) collectStats(ctx context.Context, uid string) { for _, tcp := range tcpList.Items { switch { - case tcp.Spec.ControlPlane.Deployment.Replicas == nil || *tcp.Spec.ControlPlane.Deployment.Replicas == 0: + case ptr.Deref(tcp.Status.Kubernetes.Version.Status, kamajiv1alpha1.VersionProvisioning) == kamajiv1alpha1.VersionSleeping: stats.TenantControlPlanes.Sleeping++ case tcp.Status.Kubernetes.Version.Status != nil && *tcp.Status.Kubernetes.Version.Status == kamajiv1alpha1.VersionNotReady: stats.TenantControlPlanes.NotReady++ diff --git a/docs/content/reference/api.md b/docs/content/reference/api.md index c312387..e3b181f 100644 --- a/docs/content/reference/api.md +++ b/docs/content/reference/api.md @@ -16199,7 +16199,7 @@ KubernetesVersion contains the information regarding the running Kubernetes vers Status returns the current status of the Kubernetes version, such as its provisioning state, or completed upgrade.

- Enum: Provisioning, CertificateAuthorityRotating, Upgrading, Migrating, Ready, NotReady
+ Enum: Provisioning, CertificateAuthorityRotating, Upgrading, Migrating, Ready, NotReady, Sleeping
Default: Provisioning
false diff --git a/internal/resources/k8s_deployment_resource.go b/internal/resources/k8s_deployment_resource.go index da77491..caa9195 100644 --- a/internal/resources/k8s_deployment_resource.go +++ b/internal/resources/k8s_deployment_resource.go @@ -76,6 +76,8 @@ func (r *KubernetesDeploymentResource) GetName() string { func (r *KubernetesDeploymentResource) UpdateTenantControlPlaneStatus(_ context.Context, tenantControlPlane *kamajiv1alpha1.TenantControlPlane) error { switch { + case ptr.Deref(tenantControlPlane.Spec.ControlPlane.Deployment.Replicas, 2) == 0: + tenantControlPlane.Status.Kubernetes.Version.Status = &kamajiv1alpha1.VersionSleeping case !r.isProgressingUpgrade(): tenantControlPlane.Status.Kubernetes.Version.Status = &kamajiv1alpha1.VersionReady tenantControlPlane.Status.Kubernetes.Version.Version = tenantControlPlane.Spec.Kubernetes.Version