diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml index 7fe083bcdb..63af6ab635 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml @@ -82,6 +82,16 @@ spec: type: string description: Labels specifies labels for the Kubernetes node objects type: object + nodeDrainGracePeriod: + description: NodeDrainGracePeriod is grace period for how long Pod + Disruption Budget-protected workloads will be respected during upgrades. + After this grace period, any workloads protected by Pod Disruption + Budgets that have not been successfully drained from a node will + be forcibly evicted. The nodeDrainGracePeriod can be defined in + minutes, hours ex; 30m, 10h. The max value can be assigned is 10080m|168h + (1 week). + pattern: ^(([0-9])+[m|h])$ + type: string nodePoolName: description: NodePoolName specifies the name of the nodepool in Rosa must be a valid DNS-1035 label, so it must consist of lower case diff --git a/exp/api/v1beta2/rosamachinepool_types.go b/exp/api/v1beta2/rosamachinepool_types.go index 1facd90116..d4e86ddb7b 100644 --- a/exp/api/v1beta2/rosamachinepool_types.go +++ b/exp/api/v1beta2/rosamachinepool_types.go @@ -89,6 +89,14 @@ type RosaMachinePoolSpec struct { // ProviderIDList contain a ProviderID for each machine instance that's currently managed by this machine pool. // +optional ProviderIDList []string `json:"providerIDList,omitempty"` + + // NodeDrainGracePeriod is grace period for how long Pod Disruption Budget-protected workloads will be + // respected during upgrades. After this grace period, any workloads protected by Pod Disruption + // Budgets that have not been successfully drained from a node will be forcibly evicted. The nodeDrainGracePeriod + // can be defined in minutes, hours ex; 30m, 10h. The max value can be assigned is 10080m|168h (1 week). + // +kubebuilder:validation:Pattern="^(([0-9])+[m|h])$" + // +optional + NodeDrainGracePeriod string `json:"nodeDrainGracePeriod,omitempty"` } // RosaTaint represents a taint to be applied to a node. diff --git a/exp/controllers/rosamachinepool_controller.go b/exp/controllers/rosamachinepool_controller.go index 8d1936c309..219d4c8c05 100644 --- a/exp/controllers/rosamachinepool_controller.go +++ b/exp/controllers/rosamachinepool_controller.go @@ -395,6 +395,18 @@ func validateMachinePoolSpec(machinePoolScope *scope.RosaMachinePoolScope) (*str return &message, nil } + if machinePoolScope.RosaMachinePool.Spec.NodeDrainGracePeriod != "" { + nodeDrainDuration, err := time.ParseDuration(machinePoolScope.RosaMachinePool.Spec.NodeDrainGracePeriod) + if err != nil { + return nil, err + } + // Check if node grace period duration is > 10080m (168h - 1 week) + if nodeDrainDuration.Minutes() > 10080 { + message := "Max supported NodeDrainGracePeriod duration is 10080m|168h (1 week)" + return &message, nil + } + } + // TODO: add more input validations return nil, nil } @@ -444,6 +456,13 @@ func nodePoolBuilder(rosaMachinePoolSpec expinfrav1.RosaMachinePoolSpec, machine npBuilder.Version(cmv1.NewVersion().ID(ocm.CreateVersionID(rosaMachinePoolSpec.Version, ocm.DefaultChannelGroup))) } + if rosaMachinePoolSpec.NodeDrainGracePeriod != "" { + duration, _ := time.ParseDuration(rosaMachinePoolSpec.NodeDrainGracePeriod) + valueBuilder := cmv1.NewValue() + valueBuilder.Value(duration.Minutes()).Unit("minutes") + npBuilder.NodeDrainGracePeriod(valueBuilder) + } + return npBuilder } diff --git a/go.mod b/go.mod index d7798934a3..54d3a6882a 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/onsi/ginkgo/v2 v2.13.1 github.com/onsi/gomega v1.30.0 github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 - github.com/openshift-online/ocm-sdk-go v0.1.406 + github.com/openshift-online/ocm-sdk-go v0.1.409 github.com/openshift/rosa v1.2.35-rc1.0.20240301152457-ad986cecd364 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 diff --git a/go.sum b/go.sum index 30d5f3c791..3cbb352ea6 100644 --- a/go.sum +++ b/go.sum @@ -481,8 +481,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.406 h1:DB97+wipdP1IK6D2CTINqCjs9obJSLzgwpfsx+94lBQ= -github.com/openshift-online/ocm-sdk-go v0.1.406/go.mod h1:8ECJertR5BiblaX5f2siXHXpi+ydYZjoROlVMppmmV4= +github.com/openshift-online/ocm-sdk-go v0.1.409 h1:M7GB1iURdXTFJ6N5cvMxLz0L7wWwdnUvwDOCDFZ7L1s= +github.com/openshift-online/ocm-sdk-go v0.1.409/go.mod h1:8ECJertR5BiblaX5f2siXHXpi+ydYZjoROlVMppmmV4= 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=