Skip to content

Commit

Permalink
Merge pull request #4998 from serngawy/mgmtConfig
Browse files Browse the repository at this point in the history
✨ ROSA: Add upgrade config to ROSAMachinePool
  • Loading branch information
k8s-ci-robot committed Jun 10, 2024
2 parents 3a28a4d + 6d42d41 commit f04cb3e
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,59 @@ spec:
items:
type: string
type: array
updateConfig:
description: UpdateConfig specifies update configurations.
properties:
rollingUpdate:
description: RollingUpdate specifies MaxUnavailable & MaxSurge
number of nodes during update.
properties:
maxSurge:
anyOf:
- type: integer
- type: string
default: 1
description: |-
MaxSurge is the maximum number of nodes that can be provisioned above the desired number of nodes.
Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
Absolute number is calculated from percentage by rounding up.
MaxSurge can not be 0 if MaxUnavailable is 0, default is 1.
Both MaxSurge & MaxUnavailable must use the same units (absolute value or percentage).
Example: when MaxSurge is set to 30%, new nodes can be provisioned immediately
when the rolling update starts, such that the total number of old and new
nodes do not exceed 130% of desired nodes. Once old nodes have been
deleted, new nodes can be provisioned, ensuring that total number of nodes
running at any time during the update is at most 130% of desired nodes.
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
x-kubernetes-int-or-string: true
maxUnavailable:
anyOf:
- type: integer
- type: string
default: 0
description: |-
MaxUnavailable is the maximum number of nodes that can be unavailable during the update.
Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
Absolute number is calculated from percentage by rounding down.
MaxUnavailable can not be 0 if MaxSurge is 0, default is 0.
Both MaxUnavailable & MaxSurge must use the same units (absolute value or percentage).
Example: when MaxUnavailable is set to 30%, old nodes can be deleted down to 70% of
desired nodes immediately when the rolling update starts. Once new nodes
are ready, more old nodes be deleted, followed by provisioning new nodes,
ensuring that the total number of nodes available at all times during the
update is at least 70% of desired nodes.
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
x-kubernetes-int-or-string: true
type: object
type: object
version:
description: |-
Version specifies the OpenShift version of the nodes associated with this machinepool.
Expand Down
55 changes: 55 additions & 0 deletions exp/api/v1beta2/rosamachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta2
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -105,6 +106,11 @@ type RosaMachinePoolSpec struct {
//
// +optional
NodeDrainGracePeriod *metav1.Duration `json:"nodeDrainGracePeriod,omitempty"`

// UpdateConfig specifies update configurations.
//
// +optional
UpdateConfig *RosaUpdateConfig `json:"updateConfig,omitempty"`
}

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

// RosaUpdateConfig specifies update configuration
type RosaUpdateConfig struct {
// RollingUpdate specifies MaxUnavailable & MaxSurge number of nodes during update.
//
// +optional
RollingUpdate *RollingUpdate `json:"rollingUpdate,omitempty"`
}

// RollingUpdate specifies MaxUnavailable & MaxSurge number of nodes during update.
type RollingUpdate struct {
// MaxUnavailable is the maximum number of nodes that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
// Absolute number is calculated from percentage by rounding down.
//
// MaxUnavailable can not be 0 if MaxSurge is 0, default is 0.
// Both MaxUnavailable & MaxSurge must use the same units (absolute value or percentage).
//
// Example: when MaxUnavailable is set to 30%, old nodes can be deleted down to 70% of
// desired nodes immediately when the rolling update starts. Once new nodes
// are ready, more old nodes be deleted, followed by provisioning new nodes,
// ensuring that the total number of nodes available at all times during the
// update is at least 70% of desired nodes.
//
// +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
// +kubebuilder:validation:XIntOrString
// +kubebuilder:default=0
// +optional
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`

// MaxSurge is the maximum number of nodes that can be provisioned above the desired number of nodes.
// Value can be an absolute number (ex: 5) or a percentage of desired nodes (ex: 10%).
// Absolute number is calculated from percentage by rounding up.
//
// MaxSurge can not be 0 if MaxUnavailable is 0, default is 1.
// Both MaxSurge & MaxUnavailable must use the same units (absolute value or percentage).
//
// Example: when MaxSurge is set to 30%, new nodes can be provisioned immediately
// when the rolling update starts, such that the total number of old and new
// nodes do not exceed 130% of desired nodes. Once old nodes have been
// deleted, new nodes can be provisioned, ensuring that total number of nodes
// running at any time during the update is at most 130% of desired nodes.
//
// +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
// +kubebuilder:validation:XIntOrString
// +kubebuilder:default=1
// +optional
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
}

// RosaMachinePoolStatus defines the observed state of RosaMachinePool.
type RosaMachinePoolStatus struct {
// Ready denotes that the RosaMachinePool nodepool has joined
Expand Down
51 changes: 51 additions & 0 deletions exp/api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions exp/controllers/rosamachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -477,6 +478,21 @@ func nodePoolBuilder(rosaMachinePoolSpec expinfrav1.RosaMachinePoolSpec, machine
npBuilder.NodeDrainGracePeriod(valueBuilder)
}

if rosaMachinePoolSpec.UpdateConfig != nil {
configMgmtBuilder := cmv1.NewNodePoolManagementUpgrade()

if rosaMachinePoolSpec.UpdateConfig.RollingUpdate != nil {
if rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxSurge != nil {
configMgmtBuilder = configMgmtBuilder.MaxSurge(rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxSurge.String())
}
if rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxUnavailable != nil {
configMgmtBuilder = configMgmtBuilder.MaxUnavailable(rosaMachinePoolSpec.UpdateConfig.RollingUpdate.MaxUnavailable.String())
}
}

npBuilder = npBuilder.ManagementUpgrade(configMgmtBuilder)
}

return npBuilder
}

Expand Down Expand Up @@ -518,6 +534,17 @@ func nodePoolToRosaMachinePoolSpec(nodePool *cmv1.NodePool) expinfrav1.RosaMachi
Duration: time.Minute * time.Duration(nodePool.NodeDrainGracePeriod().Value()),
}
}
if nodePool.ManagementUpgrade() != nil {
spec.UpdateConfig = &expinfrav1.RosaUpdateConfig{
RollingUpdate: &expinfrav1.RollingUpdate{},
}
if nodePool.ManagementUpgrade().MaxSurge() != "" {
spec.UpdateConfig.RollingUpdate.MaxSurge = ptr.To(intstr.Parse(nodePool.ManagementUpgrade().MaxSurge()))
}
if nodePool.ManagementUpgrade().MaxUnavailable() != "" {
spec.UpdateConfig.RollingUpdate.MaxSurge = ptr.To(intstr.Parse(nodePool.ManagementUpgrade().MaxUnavailable()))
}
}

return spec
}
Expand Down
6 changes: 6 additions & 0 deletions exp/controllers/rosamachinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"

expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
Expand All @@ -25,6 +26,11 @@ func TestNodePoolToRosaMachinePoolSpec(t *testing.T) {
NodeDrainGracePeriod: &metav1.Duration{
Duration: time.Minute * 10,
},
UpdateConfig: &expinfrav1.RosaUpdateConfig{
RollingUpdate: &expinfrav1.RollingUpdate{
MaxSurge: &intstr.IntOrString{IntVal: 3},
},
},
}

machinePoolSpec := expclusterv1.MachinePoolSpec{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
github.com/openshift-online/ocm-sdk-go v0.1.414
github.com/openshift-online/ocm-sdk-go v0.1.422
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 h1:WV67GNazQuGDaLX3kBbz0859NYPOQCsDCY5XUScF85M=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909/go.mod h1:7FaAb07S63RF4sFMLSLtQaJLvPdaRnhAT4dBLD8/5kM=
github.com/openshift-online/ocm-sdk-go v0.1.414 h1:pvsczJlartURjMOhHYxC6idsSCrixwMJZRuBQWDAIOM=
github.com/openshift-online/ocm-sdk-go v0.1.414/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/openshift-online/ocm-sdk-go v0.1.422 h1:NWXLNTg7sLgUJRM3tyuk/QuVbUCRuMH+aLlbCKNzXWc=
github.com/openshift-online/ocm-sdk-go v0.1.422/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364 h1:j1aGLgZhO5xXpYgGAjmraioHTvCK7+gXZXoN9cnpnkw=
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364/go.mod h1:kSNsBW8P9KfLCsZYGIrr/aKbLDct8I5gW0e4cCRrr0o=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
Expand Down

0 comments on commit f04cb3e

Please sign in to comment.