Skip to content

Commit

Permalink
Support maxUnavailable in rollout
Browse files Browse the repository at this point in the history
Signed-off-by: kerthcet <[email protected]>
  • Loading branch information
kerthcet committed Mar 26, 2024
1 parent 0bd32ca commit a7db8d3
Show file tree
Hide file tree
Showing 19 changed files with 789 additions and 200 deletions.
12 changes: 8 additions & 4 deletions api/leaderworkerset/v1/leaderworkerset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const (

// Worker pods will have an annotation that is the leader pod's name.
LeaderPodNameAnnotationKey string = "leaderworkerset.sigs.k8s.io/leader-name"

// SHAed leaderWorkerTemplate value for version tracking.
// This will be applied to all API objects including:
// leaderStatefulset, leaderPods, workerStatefulsets, workerPods.
TemplateRevisionHashKey string = "leaderworkerset.sigs.k8s.io/template-revision-hash"
)

// One group consists of a single leader and M workers, and the total number of pods in a group is M+1.
Expand Down Expand Up @@ -123,7 +128,7 @@ type RollingUpdateConfiguration struct {
// The maximum number of replica that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of total replicas at the start of update (ex: 10%).
// Absolute number is calculated from percentage by rounding down.
// This can not be 0 if MaxSurge is 0.
// This can not be 0 because it will pass through to statefulset which doesn't allow 0 value.
// By default, a fixed value of 1 is used.
// Example: when this is set to 30%, the old replicas can be scaled down by 30%
// immediately when the rolling update starts. Once new replicas are ready, old replicas
Expand All @@ -139,16 +144,15 @@ type RollingUpdateConfiguration struct {
// replicas.
// Value can be an absolute number (ex: 5) or a percentage of total replicas at
// the start of the update (ex: 10%).
// This can not be 0 if MaxUnavailable is 0.
// Absolute number is calculated from percentage by rounding up.
// By default, a value of 1 is used.
// By default, a value of 0 is used.
// Example: when this is set to 30%, the new replicas can be scaled up by 30%
// immediately when the rolling update starts. Once old replicas have been killed,
// new replicas can be scaled up further, ensuring that total number of replicas running
// at any time during the update is at most 130% of original replicas.
//
// +kubebuilder:validation:XIntOrString
// +kubebuilder:default=1
// +kubebuilder:default=0
MaxSurge intstr.IntOrString `json:"maxSurge,omitempty"`
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ func setupControllers(mgr ctrl.Manager, certsReady chan struct{}) {
setupLog.Info("waiting for the cert generation to complete")
<-certsReady
setupLog.Info("certs ready")
if err := (&controllers.LeaderWorkerSetReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Record: mgr.GetEventRecorderFor("leaderworkerset"),
}).SetupWithManager(mgr); err != nil {

if err := controllers.NewLeaderWorkerSetReconciler(
mgr.GetClient(),
mgr.GetScheme(),
mgr.GetEventRecorderFor("leaderworkerset"),
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "LeaderWorkerSet")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15276,15 +15276,14 @@ spec:
anyOf:
- type: integer
- type: string
default: 1
default: 0
description: |-
The maximum number of replicas that can be scheduled above the original number of
replicas.
Value can be an absolute number (ex: 5) or a percentage of total replicas at
the start of the update (ex: 10%).
This can not be 0 if MaxUnavailable is 0.
Absolute number is calculated from percentage by rounding up.
By default, a value of 1 is used.
By default, a value of 0 is used.
Example: when this is set to 30%, the new replicas can be scaled up by 30%
immediately when the rolling update starts. Once old replicas have been killed,
new replicas can be scaled up further, ensuring that total number of replicas running
Expand All @@ -15299,7 +15298,7 @@ spec:
The maximum number of replica that can be unavailable during the update.
Value can be an absolute number (ex: 5) or a percentage of total replicas at the start of update (ex: 10%).
Absolute number is calculated from percentage by rounding down.
This can not be 0 if MaxSurge is 0.
This can not be 0 because it will pass through to statefulset which doesn't allow 0 value.
By default, a fixed value of 1 is used.
Example: when this is set to 30%, the old replicas can be scaled down by 30%
immediately when the rolling update starts. Once new replicas are ready, old replicas
Expand Down
5 changes: 5 additions & 0 deletions config/samples/leaderworkerset_v1_leaderworkerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ metadata:
app.kubernetes.io/created-by: lws
name: leaderworkerset-sample
spec:
rolloutStrategy:
rollingUpdateConfiguration:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
replicas: 3
leaderWorkerTemplate:
size: 4
Expand Down
Loading

0 comments on commit a7db8d3

Please sign in to comment.