fix(cf): repair scale-to-zero issue
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/description/ScaleCloudFoundryServerGroupDescription.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/description/ScaleCloudFoundryServerGroupDescription.java
@@ -25,7 +25,6 @@ import javax.annotation.Nullable;
@Data
@EqualsAndHashCode(callSuper = true)
public class ScaleCloudFoundryServerGroupDescription extends AbstractCloudFoundryServerGroupDescription {
- @Nullable
ServerGroup.Capacity capacity;
@Nullable

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperation.java
@@ -27,6 +27,7 @@ import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
import lombok.RequiredArgsConstructor;
import java.util.List;
+import java.util.Optional;
import static com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops.CloudFoundryOperationUtils.describeProcessState;
@@ -56,17 +57,20 @@ public class ScaleCloudFoundryServerGroupAtomicOperation implements AtomicOperat
ProcessStats.State state = operationPoller.waitForOperation(
() -> client.getApplications().getProcessState(description.getServerGroupId()),
- inProgressState -> (inProgressState == ProcessStats.State.RUNNING || inProgressState == ProcessStats.State.CRASHED),
+ inProgressState -> (
+ inProgressState == ProcessStats.State.RUNNING
+ || inProgressState == ProcessStats.State.CRASHED
+ || inProgressState == ProcessStats.State.DOWN),
null, getTask(), description.getServerGroupName(), PHASE);
- if (state != ProcessStats.State.RUNNING) {
+ if (state == ProcessStats.State.RUNNING ||
+ (state == ProcessStats.State.DOWN && description.getCapacity().getDesired() == 0)) {
+ getTask().updateStatus(PHASE, "Resized '" + description.getServerGroupName() + "'");
+ } else {
getTask().updateStatus(PHASE, "Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
getTask().fail();
- return null;
}
- getTask().updateStatus(PHASE, "Resized '" + description.getServerGroupName() + "'");
-
return null;
}
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperationTest.java
@@ -73,4 +73,19 @@ class ScaleCloudFoundryServerGroupAtomicOperationTest extends AbstractCloudFound
.has(status("Resizing 'myapp'"), atIndex(1))
.has(status("Failed to start 'myapp' which instead crashed"), atIndex(2));
}
+
+ @Test
+ void scaleDownToZero() {
+ desc.setCapacity(new ServerGroup.Capacity(1, 1, 0));
+ OperationPoller poller = mock(OperationPoller.class);
+
+ //noinspection unchecked
+ when(poller.waitForOperation(any(Supplier.class), any(), anyLong(), any(), any(), any())).thenReturn(ProcessStats.State.DOWN);
+
+ ScaleCloudFoundryServerGroupAtomicOperation op = new ScaleCloudFoundryServerGroupAtomicOperation(poller, desc);
+
+ assertThat(runOperation(op).getHistory())
+ .has(status("Resizing 'myapp'"), atIndex(1))
+ .has(status("Resized 'myapp'"), atIndex(2));
+ }
}

fix(cf): repair scale-to-zero issue (#3257)

Co-Authored-By: Stu Pollock <spollock@pivotal.io>