Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add nodeDrainGracePeriod for RosaMachinePool #4863

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions exp/api/v1beta2/rosamachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions exp/controllers/rosamachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down