diff --git a/deploy/crds/planetscale.com_vitesscells.yaml b/deploy/crds/planetscale.com_vitesscells.yaml index d81f76c3..dfed37fb 100644 --- a/deploy/crds/planetscale.com_vitesscells.yaml +++ b/deploy/crds/planetscale.com_vitesscells.yaml @@ -738,6 +738,12 @@ spec: properties: available: type: string + labelSelector: + type: string + replicas: + format: int32 + minimum: 0 + type: integer serviceName: type: string type: object @@ -768,4 +774,8 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.gateway.labelSelector + specReplicasPath: .spec.gateway.replicas + statusReplicasPath: .status.gateway.replicas status: {} diff --git a/docs/api/index.html b/docs/api/index.html index 41caa361..43797cd9 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -3614,6 +3614,30 @@

VitessCellGatewayStatus

ServiceName is the name of the Service for this cell’s vtgate.

+ + +labelSelector
+ +string + + + +

LabelSelector is required by the Scale subresource, which is used by +HorizontalPodAutoscaler when reading pod metrics.

+ + + + +replicas
+ +int32 + + + +

Replicas is required by the Scale subresource, which is used by +HorizontalPodAutoscaler to determine the current number of replicas.

+ +

VitessCellImages diff --git a/pkg/apis/planetscale/v2/vitesscell_types.go b/pkg/apis/planetscale/v2/vitesscell_types.go index d65645a6..eb2458ce 100644 --- a/pkg/apis/planetscale/v2/vitesscell_types.go +++ b/pkg/apis/planetscale/v2/vitesscell_types.go @@ -39,6 +39,7 @@ import ( // just like a Deployment can manage Pods that run on multiple Nodes. // +kubebuilder:resource:path=vitesscells,shortName=vtc // +kubebuilder:subresource:status +// +kubebuilder:subresource:scale:specpath=.spec.gateway.replicas,statuspath=.status.gateway.replicas,selectorpath=.status.gateway.labelSelector type VitessCell struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -252,6 +253,13 @@ type VitessCellGatewayStatus struct { Available corev1.ConditionStatus `json:"available,omitempty"` // ServiceName is the name of the Service for this cell's vtgate. ServiceName string `json:"serviceName,omitempty"` + // LabelSelector is required by the Scale subresource, which is used by + // HorizontalPodAutoscaler when reading pod metrics. + LabelSelector string `json:"labelSelector,omitempty"` + // Replicas is required by the Scale subresource, which is used by + // HorizontalPodAutoscaler to determine the current number of replicas. + // +kubebuilder:validation:Minimum=0 + Replicas int32 `json:"replicas,omitempty"` } // VitessCellStatus defines the observed state of VitessCell diff --git a/pkg/controller/vitesscell/reconcile_vtgate.go b/pkg/controller/vitesscell/reconcile_vtgate.go index 136e5055..112165a4 100644 --- a/pkg/controller/vitesscell/reconcile_vtgate.go +++ b/pkg/controller/vitesscell/reconcile_vtgate.go @@ -161,6 +161,12 @@ func (r *ReconcileVitessCell) reconcileVtgate(ctx context.Context, vtc *planetsc curObj := obj.(*appsv1.Deployment) status := &vtc.Status.Gateway + if replicas :=curObj.Spec.Replicas; replicas != nil { + status.Replicas = *replicas + } + if selector := curObj.Spec.Selector; selector != nil { + status.LabelSelector = selector.String() + } if available := conditions.Deployment(curObj.Status.Conditions, appsv1.DeploymentAvailable); available != nil { status.Available = available.Status }