Skip to content

Commit 7c727a3

Browse files
CKS: Fix transition exception when scaling Stopped k8s clusters (#11598)
* add new k8s cluster transition * apply suggestion * apply suggestion
1 parent 036fd00 commit 7c727a3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesCluster.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum State {
5858
Stopping("Resources for the Kubernetes cluster are being destroyed"),
5959
Stopped("All resources for the Kubernetes cluster are destroyed, Kubernetes cluster may still have ephemeral resource like persistent volumes provisioned"),
6060
Scaling("Transient state in which resources are either getting scaled up/down"),
61+
ScalingStoppedCluster("Transient state in which the service offerings of stopped clusters are getting scaled"),
6162
Upgrading("Transient state in which cluster is getting upgraded"),
6263
Alert("State to represent Kubernetes clusters which are not in expected desired state (operationally in active control place, stopped cluster VM's etc)."),
6364
Recovering("State in which Kubernetes cluster is recovering from alert state"),
@@ -89,8 +90,11 @@ enum State {
8990
s_fsm.addTransition(State.Running, Event.AutoscaleRequested, State.Scaling);
9091
s_fsm.addTransition(State.Running, Event.ScaleUpRequested, State.Scaling);
9192
s_fsm.addTransition(State.Running, Event.ScaleDownRequested, State.Scaling);
93+
s_fsm.addTransition(State.Stopped, Event.ScaleUpRequested, State.ScalingStoppedCluster);
9294
s_fsm.addTransition(State.Scaling, Event.OperationSucceeded, State.Running);
9395
s_fsm.addTransition(State.Scaling, Event.OperationFailed, State.Alert);
96+
s_fsm.addTransition(State.ScalingStoppedCluster, Event.OperationSucceeded, State.Stopped);
97+
s_fsm.addTransition(State.ScalingStoppedCluster, Event.OperationFailed, State.Alert);
9498

9599
s_fsm.addTransition(State.Running, Event.UpgradeRequested, State.Upgrading);
96100
s_fsm.addTransition(State.Upgrading, Event.OperationSucceeded, State.Running);

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterScaleWorker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ private void validateKubernetesClusterScaleSizeParameters() throws CloudRuntimeE
284284

285285
private void scaleKubernetesClusterOffering() throws CloudRuntimeException {
286286
validateKubernetesClusterScaleOfferingParameters();
287-
if (!kubernetesCluster.getState().equals(KubernetesCluster.State.Scaling)) {
287+
List<KubernetesCluster.State> scalingStates = List.of(KubernetesCluster.State.Scaling, KubernetesCluster.State.ScalingStoppedCluster);
288+
if (!scalingStates.contains(kubernetesCluster.getState())) {
288289
stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.ScaleUpRequested);
289290
}
290291
if (KubernetesCluster.State.Created.equals(originalState)) {
@@ -475,6 +476,8 @@ public boolean scaleCluster() throws CloudRuntimeException {
475476
scaleKubernetesClusterOffering();
476477
} else if (clusterSizeScalingNeeded) {
477478
scaleKubernetesClusterSize();
479+
} else {
480+
return true;
478481
}
479482
stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationSucceeded);
480483
return true;

0 commit comments

Comments
 (0)