Skip to content

Commit 1723b18

Browse files
authored
interface: add maxConcurrency for StageConfig in UpdateRun (#309)
1 parent 08ad61a commit 1723b18

7 files changed

+79
-1
lines changed

apis/placement/v1beta1/stageupdate_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"k8s.io/apimachinery/pkg/api/meta"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/util/intstr"
2223
"sigs.k8s.io/controller-runtime/pkg/client"
2324

2425
"github.com/kubefleet-dev/kubefleet/apis"
@@ -275,6 +276,17 @@ type StageConfig struct {
275276
// +kubebuilder:validation:Optional
276277
SortingLabelKey *string `json:"sortingLabelKey,omitempty"`
277278

279+
// MaxConcurrency specifies the maximum number of clusters that can be updated concurrently within this stage.
280+
// Value can be an absolute number (ex: 5) or a percentage of the total clusters in the stage (ex: 50%).
281+
// Fractional results are rounded down. A minimum of 1 update is enforced.
282+
// If not specified, all clusters in the stage are updated sequentially (effectively maxConcurrency = 1).
283+
// Defaults to 1.
284+
// +kubebuilder:default=1
285+
// +kubebuilder:validation:XIntOrString
286+
// +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
287+
// +kubebuilder:validation:Optional
288+
MaxConcurrency *intstr.IntOrString `json:"maxConcurrency,omitempty"`
289+
278290
// The collection of tasks that each stage needs to complete successfully before moving to the next stage.
279291
// Each task is executed in parallel and there cannot be more than one task of the same type.
280292
// +kubebuilder:validation:MaxItems=2

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,19 @@ spec:
18711871
type: object
18721872
type: object
18731873
x-kubernetes-map-type: atomic
1874+
maxConcurrency:
1875+
anyOf:
1876+
- type: integer
1877+
- type: string
1878+
default: 1
1879+
description: |-
1880+
MaxConcurrency specifies the maximum number of clusters that can be updated concurrently within this stage.
1881+
Value can be an absolute number (ex: 5) or a percentage of the total clusters in the stage (ex: 50%).
1882+
Absolute number is calculated from percentage by rounding up.
1883+
If not specified, all clusters in the stage are updated sequentially (effectively maxConcurrency = 1).
1884+
Defaults to 1.
1885+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
1886+
x-kubernetes-int-or-string: true
18741887
name:
18751888
description: The name of the stage. This MUST be unique
18761889
within the same StagedUpdateStrategy.

config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdatestrategies.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ spec:
273273
type: object
274274
type: object
275275
x-kubernetes-map-type: atomic
276+
maxConcurrency:
277+
anyOf:
278+
- type: integer
279+
- type: string
280+
default: 1
281+
description: |-
282+
MaxConcurrency specifies the maximum number of clusters that can be updated concurrently within this stage.
283+
Value can be an absolute number (ex: 5) or a percentage of the total clusters in the stage (ex: 50%).
284+
Absolute number is calculated from percentage by rounding up.
285+
If not specified, all clusters in the stage are updated sequentially (effectively maxConcurrency = 1).
286+
Defaults to 1.
287+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
288+
x-kubernetes-int-or-string: true
276289
name:
277290
description: The name of the stage. This MUST be unique within
278291
the same StagedUpdateStrategy.

config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,19 @@ spec:
790790
type: object
791791
type: object
792792
x-kubernetes-map-type: atomic
793+
maxConcurrency:
794+
anyOf:
795+
- type: integer
796+
- type: string
797+
default: 1
798+
description: |-
799+
MaxConcurrency specifies the maximum number of clusters that can be updated concurrently within this stage.
800+
Value can be an absolute number (ex: 5) or a percentage of the total clusters in the stage (ex: 50%).
801+
Absolute number is calculated from percentage by rounding up.
802+
If not specified, all clusters in the stage are updated sequentially (effectively maxConcurrency = 1).
803+
Defaults to 1.
804+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
805+
x-kubernetes-int-or-string: true
793806
name:
794807
description: The name of the stage. This MUST be unique
795808
within the same StagedUpdateStrategy.

config/crd/bases/placement.kubernetes-fleet.io_stagedupdatestrategies.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ spec:
135135
type: object
136136
type: object
137137
x-kubernetes-map-type: atomic
138+
maxConcurrency:
139+
anyOf:
140+
- type: integer
141+
- type: string
142+
default: 1
143+
description: |-
144+
MaxConcurrency specifies the maximum number of clusters that can be updated concurrently within this stage.
145+
Value can be an absolute number (ex: 5) or a percentage of the total clusters in the stage (ex: 50%).
146+
Absolute number is calculated from percentage by rounding up.
147+
If not specified, all clusters in the stage are updated sequentially (effectively maxConcurrency = 1).
148+
Defaults to 1.
149+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
150+
x-kubernetes-int-or-string: true
138151
name:
139152
description: The name of the stage. This MUST be unique within
140153
the same StagedUpdateStrategy.

pkg/controllers/updaterun/validation_integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/api/meta"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/types"
32+
"k8s.io/apimachinery/pkg/util/intstr"
3233

3334
clusterv1beta1 "github.com/kubefleet-dev/kubefleet/apis/cluster/v1beta1"
3435
placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
@@ -303,6 +304,10 @@ var _ = Describe("UpdateRun validation tests", func() {
303304
"region": "no-exist",
304305
},
305306
},
307+
MaxConcurrency: &intstr.IntOrString{
308+
Type: intstr.Int,
309+
IntVal: 1,
310+
},
306311
})
307312
Expect(k8sClient.Status().Update(ctx, updateRun)).Should(Succeed())
308313

@@ -316,6 +321,10 @@ var _ = Describe("UpdateRun validation tests", func() {
316321
"region": "no-exist",
317322
},
318323
},
324+
MaxConcurrency: &intstr.IntOrString{
325+
Type: intstr.Int,
326+
IntVal: 1,
327+
},
319328
})
320329
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "the number of stages in the updateRun has changed")
321330
})

0 commit comments

Comments
 (0)