Skip to content

Commit b2bebfb

Browse files
authored
Merge pull request #4863 from serngawy/ndPeriod
✨ Add nodeDrainGracePeriod for RosaMachinePool
2 parents 8f83231 + 77a4432 commit b2bebfb

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ spec:
8282
type: string
8383
description: Labels specifies labels for the Kubernetes node objects
8484
type: object
85+
nodeDrainGracePeriod:
86+
description: NodeDrainGracePeriod is grace period for how long Pod
87+
Disruption Budget-protected workloads will be respected during upgrades.
88+
After this grace period, any workloads protected by Pod Disruption
89+
Budgets that have not been successfully drained from a node will
90+
be forcibly evicted. The nodeDrainGracePeriod can be defined in
91+
minutes, hours ex; 30m, 10h. The max value can be assigned is 10080m|168h
92+
(1 week).
93+
pattern: ^(([0-9])+[m|h])$
94+
type: string
8595
nodePoolName:
8696
description: NodePoolName specifies the name of the nodepool in Rosa
8797
must be a valid DNS-1035 label, so it must consist of lower case

exp/api/v1beta2/rosamachinepool_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ type RosaMachinePoolSpec struct {
8989
// ProviderIDList contain a ProviderID for each machine instance that's currently managed by this machine pool.
9090
// +optional
9191
ProviderIDList []string `json:"providerIDList,omitempty"`
92+
93+
// NodeDrainGracePeriod is grace period for how long Pod Disruption Budget-protected workloads will be
94+
// respected during upgrades. After this grace period, any workloads protected by Pod Disruption
95+
// Budgets that have not been successfully drained from a node will be forcibly evicted. The nodeDrainGracePeriod
96+
// can be defined in minutes, hours ex; 30m, 10h. The max value can be assigned is 10080m|168h (1 week).
97+
// +kubebuilder:validation:Pattern="^(([0-9])+[m|h])$"
98+
// +optional
99+
NodeDrainGracePeriod string `json:"nodeDrainGracePeriod,omitempty"`
92100
}
93101

94102
// RosaTaint represents a taint to be applied to a node.

exp/controllers/rosamachinepool_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ func validateMachinePoolSpec(machinePoolScope *scope.RosaMachinePoolScope) (*str
401401
return &message, nil
402402
}
403403

404+
if machinePoolScope.RosaMachinePool.Spec.NodeDrainGracePeriod != "" {
405+
nodeDrainDuration, err := time.ParseDuration(machinePoolScope.RosaMachinePool.Spec.NodeDrainGracePeriod)
406+
if err != nil {
407+
return nil, err
408+
}
409+
// Check if node grace period duration is > 10080m (168h - 1 week)
410+
if nodeDrainDuration.Minutes() > 10080 {
411+
message := "Max supported NodeDrainGracePeriod duration is 10080m|168h (1 week)"
412+
return &message, nil
413+
}
414+
}
415+
404416
// TODO: add more input validations
405417
return nil, nil
406418
}
@@ -450,6 +462,13 @@ func nodePoolBuilder(rosaMachinePoolSpec expinfrav1.RosaMachinePoolSpec, machine
450462
npBuilder.Version(cmv1.NewVersion().ID(ocm.CreateVersionID(rosaMachinePoolSpec.Version, ocm.DefaultChannelGroup)))
451463
}
452464

465+
if rosaMachinePoolSpec.NodeDrainGracePeriod != "" {
466+
duration, _ := time.ParseDuration(rosaMachinePoolSpec.NodeDrainGracePeriod)
467+
valueBuilder := cmv1.NewValue()
468+
valueBuilder.Value(duration.Minutes()).Unit("minutes")
469+
npBuilder.NodeDrainGracePeriod(valueBuilder)
470+
}
471+
453472
return npBuilder
454473
}
455474

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/onsi/ginkgo/v2 v2.13.1
3030
github.com/onsi/gomega v1.30.0
3131
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
32-
github.com/openshift-online/ocm-sdk-go v0.1.406
32+
github.com/openshift-online/ocm-sdk-go v0.1.409
3333
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364
3434
github.com/pkg/errors v0.9.1
3535
github.com/prometheus/client_golang v1.18.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1
481481
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
482482
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 h1:WV67GNazQuGDaLX3kBbz0859NYPOQCsDCY5XUScF85M=
483483
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909/go.mod h1:7FaAb07S63RF4sFMLSLtQaJLvPdaRnhAT4dBLD8/5kM=
484-
github.com/openshift-online/ocm-sdk-go v0.1.406 h1:DB97+wipdP1IK6D2CTINqCjs9obJSLzgwpfsx+94lBQ=
485-
github.com/openshift-online/ocm-sdk-go v0.1.406/go.mod h1:8ECJertR5BiblaX5f2siXHXpi+ydYZjoROlVMppmmV4=
484+
github.com/openshift-online/ocm-sdk-go v0.1.409 h1:M7GB1iURdXTFJ6N5cvMxLz0L7wWwdnUvwDOCDFZ7L1s=
485+
github.com/openshift-online/ocm-sdk-go v0.1.409/go.mod h1:8ECJertR5BiblaX5f2siXHXpi+ydYZjoROlVMppmmV4=
486486
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364 h1:j1aGLgZhO5xXpYgGAjmraioHTvCK7+gXZXoN9cnpnkw=
487487
github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364/go.mod h1:kSNsBW8P9KfLCsZYGIrr/aKbLDct8I5gW0e4cCRrr0o=
488488
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=

0 commit comments

Comments
 (0)