Skip to content

Commit c2abdab

Browse files
Refine
1 parent b23190d commit c2abdab

File tree

1 file changed

+22
-31
lines changed
  • keps/sig-autoscaling/2021-scale-from-zero

1 file changed

+22
-31
lines changed

keps/sig-autoscaling/2021-scale-from-zero/README.md

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ As `replicas: 0` is now a possible state when using `minReplicas: 0` it can no l
262262
Additionally the `replicas: 0` state is problematic as updating a HPA object `minReplicas` from `0` to `1` has different behavior. If `replicas` was `0` during the update, HPA
263263
will be disabled for the resource, if it was `> 0`, HPA will continue with the new `minReplicas` value.
264264

265-
To resolve this issue the KEP is introducing an explicit `enableScaleToZero` property to explicitly enable/disable scale from/to zero.
265+
To resolve this issue the KEP is introducing an explicit `ScaledToZero` condition inside the `HorizontalPodAutoscalerStatus`. When `ScaledToZero=True` was recorded the HPA will scale
266+
up a workload from `0 ~> 1` and otherwise maintain the current behavior of performing no change.
267+
268+
When the HPA scales a workload from `1 ~> 0`, it records the `ScaledToZero=True` condition inside the status.
266269

267270
### Risks and Mitigations
268271

@@ -278,8 +281,11 @@ How will UX be reviewed, and by whom?
278281
Consider including folks who also work outside the SIG or subproject.
279282
-->
280283

281-
From an UX perspective the two stage opt-out / opt-in from scale to zero might feel a bit tedious, but the only other available option seems to be deprecating the implicit HPA pause on `replicas: 0`. While this might provide an improved
282-
UX, it would require a full deprecation cycle (12 months) before graduating this feature from alpha to beta.
284+
As `ScaledToZero` is no explicit property, applying a new Deployment with `replicas: 0` and HPA `minReplicas: 0` can be confusing as the Deployment will never scale.
285+
286+
This needs should be documented and is detectable by looking at the existing `ScalingActive` condition.
287+
288+
In the future pausing the HPA can become an explicit feature and the implicit pausing via `replicas: 0` can be deprecate to remove this confusing.
283289

284290
## Design Details
285291

@@ -290,28 +296,14 @@ required) or even code snippets. If there's any ambiguity about HOW your
290296
proposal will be implemented, this is the place to discuss them.
291297
-->
292298

293-
We would add `EnableScaleToZero *bool` to the HPA `spec.behavior`.
299+
Add `ScaledToZero` as HPA `HorizontalPodAutoscalerConditionType`
294300

295301
```golang
296-
type HorizontalPodAutoscalerBehavior struct {
297-
ScaleUp *HPAScalingRules
298-
ScaleDown *HPAScalingRules
299-
EnableScaleToZero *bool
300-
}
301-
302-
type HorizontalPodAutoscalerSpec struct {
303-
ScaleTargetRef CrossVersionObjectReference
304-
MinReplicas *int32
305-
MaxReplicas int32
306-
Metrics []MetricSpec
307-
Behavior *HorizontalPodAutoscalerBehavior
308-
}
309-
```
310-
311-
The `EnableScaleToZero` controls whether the `MinReplicas` can set to `>=0` (`true`, new behavior) or `>=1` (`false`, current behavior). The default will be `false` to preserve the current behavior.
312302

313-
If `EnableScaleToZero` has been enabled, it can only be disabled when the scaled resource has at least one replica
314-
running and `MinReplicas` is `>=1`.
303+
const (
304+
// ScaledToZero indicates that the HPA controller scaled the workload to zero.
305+
ScaledToZero HorizontalPodAutoscalerConditionType = "ScaledToZero"
306+
)
315307

316308
### Test Plan
317309

@@ -338,10 +330,10 @@ existing tests to make this code solid enough prior to committing the changes ne
338330
to implement this enhancement.
339331

340332
Most logic related to this KEP is contained in the HPA controller so the testing of
341-
the various `minReplicas`, `replicas` and `enableScaleToZero` should be achievable with unit tests.
333+
the various `minReplicas`, `replicas` and `ScaledToZero` should be achievable with unit tests.
342334

343335
Additionally integration tests should be added for enable scale to zero by, setting
344-
`enableScaleToZero: true`, setting `minReplicas: 1` and waiting for `replicas` to become `0` and another test for increasing `minReplicas: 1` and observing that `replicas` became `1` again and , setting `enableScaleToZero: false` afterwards.
336+
`ScaledToZero: true`, setting `minReplicas: 1` and waiting for `replicas` to become `0` and another test for increasing `minReplicas: 1` and observing that `replicas` became `1` again and confirming that `ScaledToZero: true` has been removed.
345337

346338
##### Prerequisite testing updates
347339

@@ -475,7 +467,7 @@ in back-to-back releases.
475467
476468
#### Alpha
477469
478-
- Implement the `enableScaleToZero` property
470+
- Implement the `ScaleToZero` condition recording
479471
- Ensure that all `minReplicas` state transitions from `0` to `1` are working as expected
480472
- E2E tests are passing without flakiness
481473
@@ -503,9 +495,7 @@ enhancement:
503495
504496
As this KEP changes the allowed values for `minReplicas`, special care is required for the downgrade case to not prevent any kind of updates for HPA objects using `minReplicas: 0`. The alpha code already accepts `minReplicas: 0` with the flag enabled or disabled since Kubernetes version 1.16 downgrades to any version >= 1.16 aren't an issue.
505497

506-
The new flag `enableScaleToZero` defaults to `false`, which was has been the previous behavior. The flag should be disabled before downgrading as otherwise the
507-
HPA for deployments with zero replicas will be disabled until replicas have been
508-
raised explicitly to at least `1`.
498+
Before downgrading all HPAs need to be set to `minReplicas: 1` to avoid any deployments being stuck at `replicas: 1`.
509499

510500
### Version Skew Strategy
511501

@@ -590,7 +580,7 @@ Any change of default behavior may be surprising to users or break existing
590580
automations, so be extremely careful here.
591581
-->
592582

593-
HPA creation/update with `minReplicas: 0` is no longer rejected, if the `enableScaleToZero` field is set to true.
583+
HPA creation/update with `minReplicas: 0` is no longer rejected.
594584

595585
###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)?
596586

@@ -649,9 +639,10 @@ rollout. Similarly, consider large clusters and how enablement/disablement
649639
will rollout across nodes.
650640
-->
651641

652-
There are no expected side-effects when the rollout fails as the new `enableScaleToZero` flag should only be enabled once the version upgraded completed and should be disabled before attempting a rollback.
642+
There are no expected side-effects when the rollout fails as the new `ScaleToZero` condition should only be enabled once the version upgraded completed.
653643

654-
In case this is missed, HPA for deployments with zero replicas will be disabled until replicas have been raised explicitly to at least `1`.
644+
If an rollback is attempted, all HPAs should be updated to `minReplicas: 1` as otherwise HPA for deployments with zero replicas will be disabled until
645+
replicas have been raised explicitly to at least `1`.
655646

656647
###### What specific metrics should inform a rollback?
657648

0 commit comments

Comments
 (0)