Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit c651c1a

Browse files
committed
Updating the semantics of MaxSurge and unavailability
1 parent f8a9943 commit c651c1a

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

pkg/kubectl/rolling_updater.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,27 @@ type RollingUpdaterConfig struct {
6060
// CleanupPolicy defines the cleanup action to take after the deployment is
6161
// complete.
6262
CleanupPolicy RollingUpdaterCleanupPolicy
63-
// The maximum number of pods that can be unavailable during the update.
64-
// Value can be an absolute number (ex: 5) or a percentage of total pods at
65-
// the start of update (ex: 10%). Absolute number is calculated from
66-
// percentage by rounding up. This can not be 0 if MaxSurge is 0. By
67-
// default, a fixed value of 1 is used. Example: when this is set to 30%,
68-
// the old RC can be scaled down by 30% immediately when the rolling update
69-
// starts. Once new pods are ready, old RC can be scaled down further,
70-
// followed by scaling up the new RC, ensuring that at least 70% of original
71-
// number of pods are available at all times during the update.
63+
// MaxUnavailable is the maximum number of pods that can be unavailable during the update.
64+
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
65+
// Absolute number is calculated from percentage by rounding up.
66+
// This can not be 0 if MaxSurge is 0.
67+
// By default, a fixed value of 1 is used.
68+
// Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods
69+
// immediately when the rolling update starts. Once new pods are ready, old RC
70+
// can be scaled down further, followed by scaling up the new RC, ensuring
71+
// that the total number of pods available at all times during the update is at
72+
// least 70% of desired pods.
7273
MaxUnavailable util.IntOrString
73-
// The maximum number of pods that can be scheduled above the original
74-
// number of pods. Value can be an absolute number (ex: 5) or a percentage of total
75-
// pods at the start of the update (ex: 10%). This can not be 0 if
76-
// MaxUnavailable is 0. Absolute number is calculated from percentage by
77-
// rounding up. By default, a value of 1 is used. Example: when this is set
78-
// to 30%, the new RC can be scaled up by 30% immediately when the rolling
79-
// update starts. Once old pods have been killed, new RC can be scaled up
74+
// MaxSurge is the maximum number of pods that can be scheduled above the desired number of pods.
75+
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
76+
// This can not be 0 if MaxUnavailable is 0.
77+
// Absolute number is calculated from percentage by rounding up.
78+
// By default, a value of 1 is used.
79+
// Example: when this is set to 30%, the new RC can be scaled up immediately
80+
// when the rolling update starts, such that the total number of old and new pods do not exceed
81+
// 130% of desired pods. Once old pods have been killed, new RC can be scaled up
8082
// further, ensuring that total number of pods running at any time during
81-
// the update is atmost 130% of original pods.
83+
// the update is atmost 130% of desired pods.
8284
MaxSurge util.IntOrString
8385
}
8486

@@ -197,12 +199,12 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error {
197199
oldRc.Name, originalReplicasAnnotation, oldRc.Annotations[originalReplicasAnnotation])
198200
}
199201
// The maximum pods which can go unavailable during the update.
200-
maxUnavailable, err := extractMaxValue(config.MaxUnavailable, "maxUnavailable", original)
202+
maxUnavailable, err := extractMaxValue(config.MaxUnavailable, "maxUnavailable", desired)
201203
if err != nil {
202204
return err
203205
}
204206
// The maximum scaling increment.
205-
maxSurge, err := extractMaxValue(config.MaxSurge, "maxSurge", original)
207+
maxSurge, err := extractMaxValue(config.MaxSurge, "maxSurge", desired)
206208
if err != nil {
207209
return err
208210
}
@@ -480,8 +482,8 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
480482
}
481483

482484
// func extractMaxValue is a helper to extract config max values as either
483-
// absolute numbers or based on percentages of the original rc.
484-
func extractMaxValue(field util.IntOrString, name string, original int) (int, error) {
485+
// absolute numbers or based on percentages of the given value.
486+
func extractMaxValue(field util.IntOrString, name string, value int) (int, error) {
485487
switch field.Kind {
486488
case util.IntstrInt:
487489
if field.IntVal < 0 {
@@ -497,7 +499,7 @@ func extractMaxValue(field util.IntOrString, name string, original int) (int, er
497499
if v < 0 {
498500
return 0, fmt.Errorf("%s must be >= 0", name)
499501
}
500-
return int(math.Ceil(float64(original) * (float64(v)) / 100)), nil
502+
return int(math.Ceil(float64(value) * (float64(v)) / 100)), nil
501503
}
502504
return 0, fmt.Errorf("invalid kind %q for %s", field.Kind, name)
503505
}

pkg/kubectl/rolling_updater_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ Scaling foo-v1 down to 0
538538
down{oldReady: 10, newReady: 20, to: 0},
539539
},
540540
output: `Created foo-v2
541-
Scaling up foo-v2 from 0 to 20, scaling down foo-v1 from 10 to 0 (keep 10 pods available, don't exceed 40 pods)
541+
Scaling up foo-v2 from 0 to 20, scaling down foo-v1 from 10 to 0 (keep 10 pods available, don't exceed 70 pods)
542542
Scaling foo-v2 up to 20
543543
Scaling foo-v1 down to 0
544544
`,

0 commit comments

Comments
 (0)