Skip to content

Commit

Permalink
Make VitessCell scalable by HPA
Browse files Browse the repository at this point in the history
Signed-off-by: Sina Siadat <[email protected]>
  • Loading branch information
siadat committed Aug 30, 2024
1 parent 224d6c1 commit 718d930
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions deploy/crds/planetscale.com_vitesscells.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ spec:
properties:
available:
type: string
labelSelector:
type: string
replicas:
format: int32
minimum: 0
type: integer
serviceName:
type: string
type: object
Expand Down Expand Up @@ -768,4 +774,8 @@ spec:
served: true
storage: true
subresources:
scale:
labelSelectorPath: .status.gateway.labelSelector
specReplicasPath: .spec.gateway.replicas
statusReplicasPath: .status.gateway.replicas
status: {}
24 changes: 24 additions & 0 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,30 @@ <h3 id="planetscale.com/v2.VitessCellGatewayStatus">VitessCellGatewayStatus
<p>ServiceName is the name of the Service for this cell&rsquo;s vtgate.</p>
</td>
</tr>
<tr>
<td>
<code>labelSelector</code></br>
<em>
string
</em>
</td>
<td>
<p>LabelSelector is required by the Scale subresource, which is used by
HorizontalPodAutoscaler when reading pod metrics.</p>
</td>
</tr>
<tr>
<td>
<code>replicas</code></br>
<em>
int32
</em>
</td>
<td>
<p>Replicas is required by the Scale subresource, which is used by
HorizontalPodAutoscaler to determine the current number of replicas.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.VitessCellImages">VitessCellImages
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/planetscale/v2/vitesscell_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/vitesscell/reconcile_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 718d930

Please sign in to comment.