Skip to content

Commit 8f49326

Browse files
Merge pull request #145 from amandahla/OCM-24713-node-drain-grace-period
OCM-24713 | feat(machine-pool): add node_drain_grace_period attribute
2 parents 0860fe7 + a7a0d4a commit 8f49326

7 files changed

Lines changed: 108 additions & 9 deletions

File tree

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ gitleaks: $(GITLEAKS)
7272
# Intended single OpenShift Prow presubmit after openshift/release switches from verify + verify-gen.
7373
.PHONY: pre-push-checks
7474
pre-push-checks: tools
75-
@$(MAKE) --no-print-directory verify
76-
@$(MAKE) --no-print-directory verify-gen
77-
@$(MAKE) --no-print-directory lint
78-
@$(MAKE) --no-print-directory unit-tests
7975
@$(MAKE) --no-print-directory license-check
8076
@$(MAKE) --no-print-directory docs-lint
77+
@$(MAKE) --no-print-directory verify-gen
78+
@$(MAKE) --no-print-directory unit-tests
79+
@$(MAKE) --no-print-directory lint
80+
@$(MAKE) --no-print-directory verify
8181

8282
# Prow today (until consolidated): verify-format → make verify, verify-gen → make verify-gen.
8383
# https://github.com/openshift/release/tree/master/ci-operator/config/terraform-redhat/terraform-rhcs-rosa-hcp

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ We recommend you install the following CLI tools:
157157
| <a name="input_kubelet_configs"></a> [kubelet\_configs](#input\_kubelet\_configs) | Provides a generic approach to add multiple kubelet configs after the creation of the cluster. This variable allows users to specify configurations for multiple kubelet configs in a flexible and customizable manner, facilitating the management of resources post-cluster deployment. For additional details regarding the variables used, refer to the [kubelet-configs sub-module](./modules/kubelet-configs). For non-primitive variables (such as maps, lists, and objects), supply the JSON-encoded string. | `map(any)` | `{}` | no |
158158
| <a name="input_log_forwarders"></a> [log\_forwarders](#input\_log\_forwarders) | Provides a typed map to add multiple log forwarders after cluster creation. Each entry maps to one rhcs\_log\_forwarder and must specify exactly one destination (s3 or cloudwatch), plus at least one non-empty applications or groups entry. For additional details, refer to the [log-forwarder sub-module](./modules/log-forwarder). Requires terraform-redhat/rhcs provider version that includes the rhcs\_log\_forwarder resource. | <pre>map(object({<br/> s3 = optional(object({<br/> bucket_name = string<br/> bucket_prefix = optional(string)<br/> }))<br/> cloudwatch = optional(object({<br/> log_group_name = string<br/> log_distribution_role_arn = string<br/> }))<br/> applications = optional(list(string))<br/> groups = optional(list(object({<br/> id = string<br/> version = optional(string)<br/> })))<br/> }))</pre> | `{}` | no |
159159
| <a name="input_machine_cidr"></a> [machine\_cidr](#input\_machine\_cidr) | Block of IP addresses used by OpenShift while installing the cluster, for example "10.0.0.0/16". | `string` | `null` | no |
160-
| <a name="input_machine_pools"></a> [machine\_pools](#input\_machine\_pools) | Provides a typed map to add multiple machine pools after cluster creation. Each key is an arbitrary label; each value aligns with the [machine-pool](./modules/machine-pool) submodule (required: name, subnet\_id, openshift\_version, aws\_node\_pool). Optional fields match that module's optional inputs; omit autoscaling to use a fixed replica count with autoscaling disabled. | <pre>map(object({<br/> name = string<br/> subnet_id = string<br/> openshift_version = string<br/> aws_node_pool = object({<br/> instance_type = string<br/> tags = map(string)<br/> additional_security_group_ids = optional(list(string))<br/> capacity_reservation_id = optional(string)<br/> capacity_reservation_preference = optional(string)<br/> })<br/> autoscaling = optional(object({<br/> enabled = bool<br/> min_replicas = number<br/> max_replicas = number<br/> }))<br/> replicas = optional(number)<br/> auto_repair = optional(bool)<br/> taints = optional(list(object({<br/> key = string<br/> value = string<br/> schedule_type = string<br/> })))<br/> labels = optional(map(string))<br/> tuning_configs = optional(list(string))<br/> upgrade_acknowledgements_for = optional(string)<br/> kubelet_configs = optional(string)<br/> ignore_deletion_error = optional(bool)<br/> }))</pre> | `{}` | no |
160+
| <a name="input_machine_pools"></a> [machine\_pools](#input\_machine\_pools) | Provides a typed map to add multiple machine pools after cluster creation. Each key is an arbitrary label; each value aligns with the [machine-pool](./modules/machine-pool) submodule (required: name, subnet\_id, openshift\_version, aws\_node\_pool). Optional fields match that module's optional inputs; omit autoscaling to use a fixed replica count with autoscaling disabled. | <pre>map(object({<br/> name = string<br/> subnet_id = string<br/> openshift_version = string<br/> aws_node_pool = object({<br/> instance_type = string<br/> tags = map(string)<br/> additional_security_group_ids = optional(list(string))<br/> capacity_reservation_id = optional(string)<br/> capacity_reservation_preference = optional(string)<br/> node_drain_grace_period = optional(number)<br/> })<br/> autoscaling = optional(object({<br/> enabled = bool<br/> min_replicas = number<br/> max_replicas = number<br/> }))<br/> replicas = optional(number)<br/> auto_repair = optional(bool)<br/> taints = optional(list(object({<br/> key = string<br/> value = string<br/> schedule_type = string<br/> })))<br/> labels = optional(map(string))<br/> tuning_configs = optional(list(string))<br/> upgrade_acknowledgements_for = optional(string)<br/> kubelet_configs = optional(string)<br/> ignore_deletion_error = optional(bool)<br/> }))</pre> | `{}` | no |
161161
| <a name="input_managed_oidc"></a> [managed\_oidc](#input\_managed\_oidc) | OIDC type managed or unmanaged oidc. Only active when create\_oidc also enabled. This value should not be updated, please create a new resource instead | `bool` | `true` | no |
162162
| <a name="input_no_proxy"></a> [no\_proxy](#input\_no\_proxy) | A comma-separated list of destination domain names, domains, IP addresses or other network CIDRs to exclude proxying. | `string` | `null` | no |
163163
| <a name="input_oidc_config_id"></a> [oidc\_config\_id](#input\_oidc\_config\_id) | The unique identifier associated with users authenticated through OpenID Connect (OIDC) within the ROSA cluster. If create\_oidc is false this attribute is required. | `string` | `null` | no |

modules/machine-pool/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ module "mp" {
3737
| Name | Version |
3838
| ---- | ------- |
3939
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
40-
| <a name="requirement_rhcs"></a> [rhcs](#requirement\_rhcs) | >= 1.7.3 |
40+
| <a name="requirement_rhcs"></a> [rhcs](#requirement\_rhcs) | >= 1.7.7 |
4141

4242
## Providers
4343

4444
| Name | Version |
4545
| ---- | ------- |
46-
| <a name="provider_rhcs"></a> [rhcs](#provider\_rhcs) | >= 1.7.3 |
46+
| <a name="provider_rhcs"></a> [rhcs](#provider\_rhcs) | >= 1.7.7 |
4747

4848
## Modules
4949

@@ -61,7 +61,7 @@ No modules.
6161
| ---- | ----------- | ---- | ------- | :------: |
6262
| <a name="input_auto_repair"></a> [auto\_repair](#input\_auto\_repair) | Configures auto repair option for the pool. | `bool` | `true` | no |
6363
| <a name="input_autoscaling"></a> [autoscaling](#input\_autoscaling) | Configures autoscaling for the pool. | <pre>object({<br/> enabled = bool<br/> min_replicas = number<br/> max_replicas = number<br/> })</pre> | <pre>{<br/> "enabled": false,<br/> "max_replicas": null,<br/> "min_replicas": null<br/>}</pre> | no |
64-
| <a name="input_aws_node_pool"></a> [aws\_node\_pool](#input\_aws\_node\_pool) | Configures aws settings for the pool. | <pre>object({<br/> instance_type = string<br/> tags = map(string)<br/> additional_security_group_ids = optional(list(string))<br/> capacity_reservation_id = optional(string)<br/> capacity_reservation_preference = optional(string)<br/> })</pre> | n/a | yes |
64+
| <a name="input_aws_node_pool"></a> [aws\_node\_pool](#input\_aws\_node\_pool) | Configures aws settings for the pool. | <pre>object({<br/> instance_type = string<br/> tags = map(string)<br/> additional_security_group_ids = optional(list(string))<br/> capacity_reservation_id = optional(string)<br/> capacity_reservation_preference = optional(string)<br/> node_drain_grace_period = optional(number)<br/> })</pre> | n/a | yes |
6565
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Identifier of the cluster. | `string` | n/a | yes |
6666
| <a name="input_ignore_deletion_error"></a> [ignore\_deletion\_error](#input\_ignore\_deletion\_error) | Ignore machine pool deletion error. Assists when cluster resource is managed within the same file for the destroy use case | `bool` | `false` | no |
6767
| <a name="input_kubelet_configs"></a> [kubelet\_configs](#input\_kubelet\_configs) | Name of the kubelet configs to attach to this machine pool. The kubelet configs must already exist | `string` | `null` | no |

modules/machine-pool/tests/aws_node_pool.tftest.hcl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mock_provider "rhcs" {
1313
defaults = {
1414
aws_node_pool = {
1515
capacity_reservation_preference = "defined_by_provider"
16+
node_drain_grace_period = null
1617
}
1718
}
1819
}
@@ -153,3 +154,83 @@ run "apply_with_capres_preference" {
153154
error_message = "Setup run should have capacity_reservation_preference = 'none'."
154155
}
155156
}
157+
158+
# Test that invalid node_drain_grace_period > 10080 fails validation
159+
run "invalid_node_drain_grace_period_fails" {
160+
command = plan
161+
162+
providers = {
163+
rhcs = rhcs.no_override
164+
}
165+
166+
variables {
167+
cluster_id = "fake-cluster-123"
168+
name = "test-pool"
169+
subnet_id = "subnet-fake123"
170+
openshift_version = "4.15.0"
171+
172+
aws_node_pool = {
173+
instance_type = "m5.xlarge"
174+
tags = {}
175+
node_drain_grace_period = 10081
176+
}
177+
}
178+
179+
expect_failures = [
180+
var.aws_node_pool,
181+
]
182+
}
183+
184+
# Test that valid node_drain_grace_period (60 minutes) passes validation and wires through to the resource
185+
run "valid_node_drain_grace_period_plan" {
186+
command = plan
187+
188+
providers = {
189+
rhcs = rhcs.no_override
190+
}
191+
192+
variables {
193+
cluster_id = "fake-cluster-123"
194+
name = "test-pool"
195+
subnet_id = "subnet-fake123"
196+
openshift_version = "4.15.0"
197+
198+
aws_node_pool = {
199+
instance_type = "m5.xlarge"
200+
tags = {}
201+
node_drain_grace_period = 60
202+
}
203+
}
204+
205+
assert {
206+
condition = rhcs_hcp_machine_pool.machine_pool.aws_node_pool.node_drain_grace_period == 60
207+
error_message = "Expected node_drain_grace_period to be wired through to rhcs_hcp_machine_pool as 60."
208+
}
209+
}
210+
211+
# Test that null node_drain_grace_period passes validation and wires through to the resource as null
212+
run "node_drain_grace_period_null_plan" {
213+
command = plan
214+
215+
providers = {
216+
rhcs = rhcs.with_override
217+
}
218+
219+
variables {
220+
cluster_id = "fake-cluster-123"
221+
name = "test-pool"
222+
subnet_id = "subnet-fake123"
223+
openshift_version = "4.15.0"
224+
225+
aws_node_pool = {
226+
instance_type = "m5.xlarge"
227+
tags = {}
228+
node_drain_grace_period = null
229+
}
230+
}
231+
232+
assert {
233+
condition = rhcs_hcp_machine_pool.machine_pool.aws_node_pool.node_drain_grace_period == null
234+
error_message = "Expected null node_drain_grace_period to be wired through to rhcs_hcp_machine_pool as null."
235+
}
236+
}

modules/machine-pool/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ variable "aws_node_pool" {
6363
additional_security_group_ids = optional(list(string))
6464
capacity_reservation_id = optional(string)
6565
capacity_reservation_preference = optional(string)
66+
node_drain_grace_period = optional(number)
6667
})
6768
nullable = false
6869
description = "Configures aws settings for the pool."
@@ -74,6 +75,22 @@ variable "aws_node_pool" {
7475
)
7576
error_message = "capacity_reservation_preference must be one of: none, open, capacity-reservations-only."
7677
}
78+
79+
validation {
80+
condition = var.aws_node_pool.node_drain_grace_period == null ? true : (
81+
var.aws_node_pool.node_drain_grace_period >= 0 &&
82+
var.aws_node_pool.node_drain_grace_period <= 10080
83+
)
84+
error_message = "node_drain_grace_period must be between 0 and 10080 minutes (7 days)."
85+
}
86+
validation {
87+
condition = var.aws_node_pool.node_drain_grace_period == null ? true : tonumber(var.aws_node_pool.node_drain_grace_period) == floor(var.aws_node_pool.node_drain_grace_period)
88+
error_message = "node_drain_grace_period value should be an integer (minutes)"
89+
}
90+
validation {
91+
condition = var.aws_node_pool.node_drain_grace_period == null ? true : var.aws_node_pool.node_drain_grace_period >= 0
92+
error_message = "node_drain_grace_period value should be a positive integer (minutes)"
93+
}
7794
}
7895

7996
variable "auto_repair" {

modules/machine-pool/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66

77
required_providers {
88
rhcs = {
9-
version = ">= 1.7.3"
9+
version = ">= 1.7.7"
1010
source = "terraform-redhat/rhcs"
1111
}
1212
}

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ variable "machine_pools" {
397397
additional_security_group_ids = optional(list(string))
398398
capacity_reservation_id = optional(string)
399399
capacity_reservation_preference = optional(string)
400+
node_drain_grace_period = optional(number)
400401
})
401402
autoscaling = optional(object({
402403
enabled = bool

0 commit comments

Comments
 (0)