Skip to content

Commit f04cb3e

Browse files
authored
Merge pull request #4998 from serngawy/mgmtConfig
✨ ROSA: Add upgrade config to ROSAMachinePool
2 parents 3a28a4d + 6d42d41 commit f04cb3e

File tree

7 files changed

+195
-3
lines changed

7 files changed

+195
-3
lines changed

config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,59 @@ spec:
161161
items:
162162
type: string
163163
type: array
164+
updateConfig:
165+
description: UpdateConfig specifies update configurations.
166+
properties:
167+
rollingUpdate:
168+
description: RollingUpdate specifies MaxUnavailable & MaxSurge
169+
number of nodes during update.
170+
properties:
171+
maxSurge:
172+
anyOf:
173+
- type: integer
174+
- type: string
175+
default: 1
176+
description: |-
177+
MaxSurge is the maximum number of nodes that can be provisioned above the desired number of nodes.
178+
Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
179+
Absolute number is calculated from percentage by rounding up.
180+
181+
182+
MaxSurge can not be 0 if MaxUnavailable is 0, default is 1.
183+
Both MaxSurge & MaxUnavailable must use the same units (absolute value or percentage).
184+
185+
186+
Example: when MaxSurge is set to 30%, new nodes can be provisioned immediately
187+
when the rolling update starts, such that the total number of old and new
188+
nodes do not exceed 130% of desired nodes. Once old nodes have been
189+
deleted, new nodes can be provisioned, ensuring that total number of nodes
190+
running at any time during the update is at most 130% of desired nodes.
191+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
192+
x-kubernetes-int-or-string: true
193+
maxUnavailable:
194+
anyOf:
195+
- type: integer
196+
- type: string
197+
default: 0
198+
description: |-
199+
MaxUnavailable is the maximum number of nodes that can be unavailable during the update.
200+
Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
201+
Absolute number is calculated from percentage by rounding down.
202+
203+
204+
MaxUnavailable can not be 0 if MaxSurge is 0, default is 0.
205+
Both MaxUnavailable & MaxSurge must use the same units (absolute value or percentage).
206+
207+
208+
Example: when MaxUnavailable is set to 30%, old nodes can be deleted down to 70% of
209+
desired nodes immediately when the rolling update starts. Once new nodes
210+
are ready, more old nodes be deleted, followed by provisioning new nodes,
211+
ensuring that the total number of nodes available at all times during the
212+
update is at least 70% of desired nodes.
213+
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
214+
x-kubernetes-int-or-string: true
215+
type: object
216+
type: object
164217
version:
165218
description: |-
166219
Version specifies the OpenShift version of the nodes associated with this machinepool.

exp/api/v1beta2/rosamachinepool_types.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta2
1919
import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/util/intstr"
2223

2324
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2425
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -105,6 +106,11 @@ type RosaMachinePoolSpec struct {
105106
//
106107
// +optional
107108
NodeDrainGracePeriod *metav1.Duration `json:"nodeDrainGracePeriod,omitempty"`
109+
110+
// UpdateConfig specifies update configurations.
111+
//
112+
// +optional
113+
UpdateConfig *RosaUpdateConfig `json:"updateConfig,omitempty"`
108114
}
109115

110116
// RosaTaint represents a taint to be applied to a node.
@@ -134,6 +140,55 @@ type RosaMachinePoolAutoScaling struct {
134140
MaxReplicas int `json:"maxReplicas,omitempty"`
135141
}
136142

143+
// RosaUpdateConfig specifies update configuration
144+
type RosaUpdateConfig struct {
145+
// RollingUpdate specifies MaxUnavailable & MaxSurge number of nodes during update.
146+
//
147+
// +optional
148+
RollingUpdate *RollingUpdate `json:"rollingUpdate,omitempty"`
149+
}
150+
151+
// RollingUpdate specifies MaxUnavailable & MaxSurge number of nodes during update.
152+
type RollingUpdate struct {
153+
// MaxUnavailable is the maximum number of nodes that can be unavailable during the update.
154+
// Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
155+
// Absolute number is calculated from percentage by rounding down.
156+
//
157+
// MaxUnavailable can not be 0 if MaxSurge is 0, default is 0.
158+
// Both MaxUnavailable & MaxSurge must use the same units (absolute value or percentage).
159+
//
160+
// Example: when MaxUnavailable is set to 30%, old nodes can be deleted down to 70% of
161+
// desired nodes immediately when the rolling update starts. Once new nodes
162+
// are ready, more old nodes be deleted, followed by provisioning new nodes,
163+
// ensuring that the total number of nodes available at all times during the
164+
// update is at least 70% of desired nodes.
165+
//
166+
// +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
167+
// +kubebuilder:validation:XIntOrString
168+
// +kubebuilder:default=0
169+
// +optional
170+
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
171+
172+
// MaxSurge is the maximum number of nodes that can be provisioned above the desired number of nodes.
173+
// Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
174+
// Absolute number is calculated from percentage by rounding up.
175+
//
176+
// MaxSurge can not be 0 if MaxUnavailable is 0, default is 1.
177+
// Both MaxSurge & MaxUnavailable must use the same units (absolute value or percentage).
178+
//
179+
// Example: when MaxSurge is set to 30%, new nodes can be provisioned immediately
180+
// when the rolling update starts, such that the total number of old and new
181+
// nodes do not exceed 130% of desired nodes. Once old nodes have been
182+
// deleted, new nodes can be provisioned, ensuring that total number of nodes
183+
// running at any time during the update is at most 130% of desired nodes.
184+
//
185+
// +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
186+
// +kubebuilder:validation:XIntOrString
187+
// +kubebuilder:default=1
188+
// +optional
189+
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
190+
}
191+
137192
// RosaMachinePoolStatus defines the observed state of RosaMachinePool.
138193
type RosaMachinePoolStatus struct {
139194
// Ready denotes that the RosaMachinePool nodepool has joined

exp/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/controllers/rosamachinepool_controller.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
apierrors "k8s.io/apimachinery/pkg/api/errors"
1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1919
"k8s.io/apimachinery/pkg/runtime/schema"
20+
"k8s.io/apimachinery/pkg/util/intstr"
2021
"k8s.io/client-go/tools/record"
2122
"k8s.io/klog/v2"
2223
"k8s.io/utils/ptr"
@@ -477,6 +478,21 @@ func nodePoolBuilder(rosaMachinePoolSpec expinfrav1.RosaMachinePoolSpec, machine
477478
npBuilder.NodeDrainGracePeriod(valueBuilder)
478479
}
479480

481+
if rosaMachinePoolSpec.UpdateConfig != nil {
482+
configMgmtBuilder := cmv1.NewNodePoolManagementUpgrade()
483+
484+
if rosaMachinePoolSpec.UpdateConfig.RollingUpdate != nil {
485+
if rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxSurge != nil {
486+
configMgmtBuilder = configMgmtBuilder.MaxSurge(rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxSurge.String())
487+
}
488+
if rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxUnavailable != nil {
489+
configMgmtBuilder = configMgmtBuilder.MaxUnavailable(rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxUnavailable.String())
490+
}
491+
}
492+
493+
npBuilder = npBuilder.ManagementUpgrade(configMgmtBuilder)
494+
}
495+
480496
return npBuilder
481497
}
482498

@@ -518,6 +534,17 @@ func nodePoolToRosaMachinePoolSpec(nodePool *cmv1.NodePool) expinfrav1.RosaMachi
518534
Duration: time.Minute * time.Duration(nodePool.NodeDrainGracePeriod().Value()),
519535
}
520536
}
537+
if nodePool.ManagementUpgrade() != nil {
538+
spec.UpdateConfig = &expinfrav1.RosaUpdateConfig{
539+
RollingUpdate: &expinfrav1.RollingUpdate{},
540+
}
541+
if nodePool.ManagementUpgrade().MaxSurge() != "" {
542+
spec.UpdateConfig.RollingUpdate.MaxSurge = ptr.To(intstr.Parse(nodePool.ManagementUpgrade().MaxSurge()))
543+
}
544+
if nodePool.ManagementUpgrade().MaxUnavailable() != "" {
545+
spec.UpdateConfig.RollingUpdate.MaxSurge = ptr.To(intstr.Parse(nodePool.ManagementUpgrade().MaxUnavailable()))
546+
}
547+
}
521548

522549
return spec
523550
}

exp/controllers/rosamachinepool_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
. "github.com/onsi/gomega"
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/util/intstr"
910
"k8s.io/utils/ptr"
1011

1112
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
@@ -25,6 +26,11 @@ func TestNodePoolToRosaMachinePoolSpec(t *testing.T) {
2526
NodeDrainGracePeriod: &metav1.Duration{
2627
Duration: time.Minute * 10,
2728
},
29+
UpdateConfig: &expinfrav1.RosaUpdateConfig{
30+
RollingUpdate: &expinfrav1.RollingUpdate{
31+
MaxSurge: &intstr.IntOrString{IntVal: 3},
32+
},
33+
},
2834
}
2935

3036
machinePoolSpec := expclusterv1.MachinePoolSpec{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/onsi/ginkgo/v2 v2.17.1
3333
github.com/onsi/gomega v1.32.0
3434
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
35-
github.com/openshift-online/ocm-sdk-go v0.1.414
35+
github.com/openshift-online/ocm-sdk-go v0.1.422
3636
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364
3737
github.com/pkg/errors v0.9.1
3838
github.com/prometheus/client_golang v1.19.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1
383383
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
384384
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 h1:WV67GNazQuGDaLX3kBbz0859NYPOQCsDCY5XUScF85M=
385385
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909/go.mod h1:7FaAb07S63RF4sFMLSLtQaJLvPdaRnhAT4dBLD8/5kM=
386-
github.com/openshift-online/ocm-sdk-go v0.1.414 h1:pvsczJlartURjMOhHYxC6idsSCrixwMJZRuBQWDAIOM=
387-
github.com/openshift-online/ocm-sdk-go v0.1.414/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
386+
github.com/openshift-online/ocm-sdk-go v0.1.422 h1:NWXLNTg7sLgUJRM3tyuk/QuVbUCRuMH+aLlbCKNzXWc=
387+
github.com/openshift-online/ocm-sdk-go v0.1.422/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
388388
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364 h1:j1aGLgZhO5xXpYgGAjmraioHTvCK7+gXZXoN9cnpnkw=
389389
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364/go.mod h1:kSNsBW8P9KfLCsZYGIrr/aKbLDct8I5gW0e4cCRrr0o=
390390
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=

0 commit comments

Comments
 (0)