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 25, 2024
1 parent dba69fb commit 15ed653
Show file tree
Hide file tree
Showing 20 changed files with 811 additions and 206 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
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: gcr.io/k8s-staging-lws/lws
newTag: main
newName: registry.cn-shanghai.aliyuncs.com/kerthcet-public/lws
newTag: 0325-10
27 changes: 23 additions & 4 deletions config/samples/leaderworkerset_v1_leaderworkerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@ metadata:
app.kubernetes.io/created-by: lws
name: leaderworkerset-sample
spec:
replicas: 3
rolloutStrategy:
rollingUpdateConfiguration:
maxSurge: 0
maxUnavailable: 2
type: RollingUpdate
replicas: 4
leaderWorkerTemplate:
size: 4
size: 5
restartPolicy: RecreateGroupOnPodRestart
leaderTemplate:
spec:
containers:
- name: nginx
# image: nginx:1.14.2
image: nginx:1.16.1
resources:
limits:
cpu: "100m"
requests:
cpu: "60m"
ports:
- containerPort: 8080
workerTemplate:
spec:
containers:
- name: nginx
image: nginx:1.14.2
# image: nginx:1.14.2
image: nginx:1.16.1
resources:
limits:
cpu: "100m"
requests:
cpu: "50m"
cpu: "60m"
ports:
- containerPort: 8080
Loading

0 comments on commit 15ed653

Please sign in to comment.