mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Updating the semantics of MaxSurge and unavailability
This commit is contained in:
parent
f8a9943d90
commit
c651c1ae30
@ -60,25 +60,27 @@ type RollingUpdaterConfig struct {
|
|||||||
// CleanupPolicy defines the cleanup action to take after the deployment is
|
// CleanupPolicy defines the cleanup action to take after the deployment is
|
||||||
// complete.
|
// complete.
|
||||||
CleanupPolicy RollingUpdaterCleanupPolicy
|
CleanupPolicy RollingUpdaterCleanupPolicy
|
||||||
// The maximum number of pods that can be unavailable during the update.
|
// MaxUnavailable is the maximum number of pods that can be unavailable during the update.
|
||||||
// Value can be an absolute number (ex: 5) or a percentage of total pods at
|
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
|
||||||
// the start of update (ex: 10%). Absolute number is calculated from
|
// Absolute number is calculated from percentage by rounding up.
|
||||||
// percentage by rounding up. This can not be 0 if MaxSurge is 0. By
|
// This can not be 0 if MaxSurge is 0.
|
||||||
// default, a fixed value of 1 is used. Example: when this is set to 30%,
|
// By default, a fixed value of 1 is used.
|
||||||
// the old RC can be scaled down by 30% immediately when the rolling update
|
// Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods
|
||||||
// starts. Once new pods are ready, old RC can be scaled down further,
|
// immediately when the rolling update starts. Once new pods are ready, old RC
|
||||||
// followed by scaling up the new RC, ensuring that at least 70% of original
|
// can be scaled down further, followed by scaling up the new RC, ensuring
|
||||||
// number of pods are available at all times during the update.
|
// that the total number of pods available at all times during the update is at
|
||||||
|
// least 70% of desired pods.
|
||||||
MaxUnavailable util.IntOrString
|
MaxUnavailable util.IntOrString
|
||||||
// The maximum number of pods that can be scheduled above the original
|
// MaxSurge is the maximum number of pods that can be scheduled above the desired number of pods.
|
||||||
// number of pods. Value can be an absolute number (ex: 5) or a percentage of total
|
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
|
||||||
// pods at the start of the update (ex: 10%). This can not be 0 if
|
// This can not be 0 if MaxUnavailable is 0.
|
||||||
// MaxUnavailable is 0. Absolute number is calculated from percentage by
|
// Absolute number is calculated from percentage by rounding up.
|
||||||
// rounding up. By default, a value of 1 is used. Example: when this is set
|
// By default, a value of 1 is used.
|
||||||
// to 30%, the new RC can be scaled up by 30% immediately when the rolling
|
// Example: when this is set to 30%, the new RC can be scaled up immediately
|
||||||
// update starts. Once old pods have been killed, new RC can be scaled up
|
// when the rolling update starts, such that the total number of old and new pods do not exceed
|
||||||
|
// 130% of desired pods. Once old pods have been killed, new RC can be scaled up
|
||||||
// further, ensuring that total number of pods running at any time during
|
// further, ensuring that total number of pods running at any time during
|
||||||
// the update is atmost 130% of original pods.
|
// the update is atmost 130% of desired pods.
|
||||||
MaxSurge util.IntOrString
|
MaxSurge util.IntOrString
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,12 +199,12 @@ func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error {
|
|||||||
oldRc.Name, originalReplicasAnnotation, oldRc.Annotations[originalReplicasAnnotation])
|
oldRc.Name, originalReplicasAnnotation, oldRc.Annotations[originalReplicasAnnotation])
|
||||||
}
|
}
|
||||||
// The maximum pods which can go unavailable during the update.
|
// The maximum pods which can go unavailable during the update.
|
||||||
maxUnavailable, err := extractMaxValue(config.MaxUnavailable, "maxUnavailable", original)
|
maxUnavailable, err := extractMaxValue(config.MaxUnavailable, "maxUnavailable", desired)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// The maximum scaling increment.
|
// The maximum scaling increment.
|
||||||
maxSurge, err := extractMaxValue(config.MaxSurge, "maxSurge", original)
|
maxSurge, err := extractMaxValue(config.MaxSurge, "maxSurge", desired)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -480,8 +482,8 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// func extractMaxValue is a helper to extract config max values as either
|
// func extractMaxValue is a helper to extract config max values as either
|
||||||
// absolute numbers or based on percentages of the original rc.
|
// absolute numbers or based on percentages of the given value.
|
||||||
func extractMaxValue(field util.IntOrString, name string, original int) (int, error) {
|
func extractMaxValue(field util.IntOrString, name string, value int) (int, error) {
|
||||||
switch field.Kind {
|
switch field.Kind {
|
||||||
case util.IntstrInt:
|
case util.IntstrInt:
|
||||||
if field.IntVal < 0 {
|
if field.IntVal < 0 {
|
||||||
@ -497,7 +499,7 @@ func extractMaxValue(field util.IntOrString, name string, original int) (int, er
|
|||||||
if v < 0 {
|
if v < 0 {
|
||||||
return 0, fmt.Errorf("%s must be >= 0", name)
|
return 0, fmt.Errorf("%s must be >= 0", name)
|
||||||
}
|
}
|
||||||
return int(math.Ceil(float64(original) * (float64(v)) / 100)), nil
|
return int(math.Ceil(float64(value) * (float64(v)) / 100)), nil
|
||||||
}
|
}
|
||||||
return 0, fmt.Errorf("invalid kind %q for %s", field.Kind, name)
|
return 0, fmt.Errorf("invalid kind %q for %s", field.Kind, name)
|
||||||
}
|
}
|
||||||
|
@ -538,7 +538,7 @@ Scaling foo-v1 down to 0
|
|||||||
down{oldReady: 10, newReady: 20, to: 0},
|
down{oldReady: 10, newReady: 20, to: 0},
|
||||||
},
|
},
|
||||||
output: `Created foo-v2
|
output: `Created foo-v2
|
||||||
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)
|
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)
|
||||||
Scaling foo-v2 up to 20
|
Scaling foo-v2 up to 20
|
||||||
Scaling foo-v1 down to 0
|
Scaling foo-v1 down to 0
|
||||||
`,
|
`,
|
||||||
|
Loading…
Reference in New Issue
Block a user