Skip to content

Add opportunistic_maintenance_strategy to GKE node_config host_maintenance_policy - #18492

Open
DrFaust92 wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
DrFaust92:opportunistic-maintenance
Open

Add opportunistic_maintenance_strategy to GKE node_config host_maintenance_policy#18492
DrFaust92 wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
DrFaust92:opportunistic-maintenance

Conversation

@DrFaust92

Copy link
Copy Markdown
Contributor

Adds the beta-only opportunistic_maintenance_strategy block under node_config.host_maintenance_policy, shared by google_container_cluster and google_container_node_pool. This exposes GKE's opportunistic maintenance feature — the Terraform equivalent of the gcloud container node-pools create --opportunistic-maintenance flag.

Fields (all beta, ForceNew):

  • node_idle_time_window — idle time before maintenance is triggered
  • maintenance_availability_window — window in which opportunistic maintenance may run
  • min_nodes_per_pool — minimum available nodes; blocks maintenance below this

Maps to the API's HostMaintenancePolicy.opportunisticMaintenanceStrategy (container/v1beta1), which is absent from GA — so it sits under the existing beta guard on host_maintenance_policy. min_nodes_per_pool uses ForceSendFields so an explicit 0 is sent rather than dropped by omitempty.

Also documents host_maintenance_policy in the cluster docs (it was previously undocumented).

Testing

Verified end-to-end against a real GKE project:

  • CPU node pool → API returns 400: opportunistic maintenance strategy is supported with TPU or GPU node pools only, confirming the field is parsed and validated by the API.
  • GPU (nvidia-tesla-t4) node pool → the full config is accepted by the API.

Because opportunistic maintenance requires a GPU/TPU node pool and a host-maintenance allowlist, TestAccContainerNodePool_withOpportunisticMaintenance is t.Skip'd by default (consistent with the existing TestAccContainerNodePool_withHostMaintenancePolicy) and intended to be run manually in an allowlisted project with GPU capacity.

Note for maintainers

host_maintenance_policy is beta-only (absent from the GA container/v1 API and Go client), but its schema block is currently not beta-guarded — only its expand/flatten wiring is. So the field (and now opportunistic_maintenance_strategy) appears in the GA provider schema while being inert there. This is pre-existing behavior — maintenance_interval already does this — and I followed the existing pattern rather than change it in this PR. Happy to additionally wrap the whole host_maintenance_policy schema block in the beta guard if you'd prefer to fix the leak (note that would remove the field from the GA schema, a minor breaking change for any GA config that references it).

container: added `opportunistic_maintenance_strategy` to `host_maintenance_policy` in `node_config` for `google_container_cluster` and `google_container_node_pool` (beta)

Adds the beta-only opportunistic_maintenance_strategy block under
node_config.host_maintenance_policy for google_container_cluster and
google_container_node_pool, exposing the GKE opportunistic maintenance
feature (gcloud `--opportunistic-maintenance`). Fields: node_idle_time_window,
maintenance_availability_window, min_nodes_per_pool.
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Aug 2, 2026
@github-actions
github-actions Bot requested a review from c2thorn August 2, 2026 15:27
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@c2thorn, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@c2thorn c2thorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather beta-guard the field, similar to ephemeral_storage_config, although I acknowledge the other field not doing so.

No need to make a larger breaking change, let's just not introduce this specific field to GA.

Keep opportunistic_maintenance_strategy out of the GA provider (schema +
cluster/node-pool meta.yaml), matching the ephemeral_storage_config pattern.
Expand/flatten were already inside the beta-only host_maintenance_policy
helpers. Verified via mmv1 generation: GA renders 0 occurrences, beta unchanged.
@DrFaust92

Copy link
Copy Markdown
Contributor Author

Done — beta-guarded opportunistic_maintenance_strategy so it's not introduced to GA (schema + the cluster/node-pool meta.yaml entries), matching the ephemeral_storage_config pattern. The expand/flatten paths were already inside the beta-only host_maintenance_policy helpers. Left the existing maintenance_interval/host_maintenance_policy GA exposure alone as you noted.

Verified locally via mmv1 generation: GA renders 0 opportunistic_maintenance_strategy occurrences (schema, meta.yaml, and the acceptance test all excluded), beta unchanged.

@github-actions
github-actions Bot requested a review from c2thorn August 4, 2026 23:00
@modular-magician modular-magician added service/container and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Aug 5, 2026
@modular-magician

modular-magician commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 8066006:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 1 file changed, 16 insertions(+)
google-beta provider View Diff 5 files changed, 194 insertions(+), 1 deletion(-)
terraform-google-conversion View Diff 1 file changed, 3 insertions(+)

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_container_cluster (602 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_container_cluster" "primary" {
  node_config {
    host_maintenance_policy {
      opportunistic_maintenance_strategy {
        maintenance_availability_window = # value needed
        min_nodes_per_pool              = # value needed
        node_idle_time_window           = # value needed
      }
    }
  }
  node_pool {
    node_config {
      host_maintenance_policy {
        opportunistic_maintenance_strategy {
          maintenance_availability_window = # value needed
          min_nodes_per_pool              = # value needed
          node_idle_time_window           = # value needed
        }
      }
    }
  }
}

Missing doc report (experimental)

The following resources have fields missing in documents.

  • google_container_cluster
    • Expected Document Path: /website/docs/r/container_cluster.html.markdown
    • Fields: [node_pool.node_config.host_maintenance_policy.opportunistic_maintenance_strategy node_pool.node_config.host_maintenance_policy.opportunistic_maintenance_strategy.maintenance_availability_window node_pool.node_config.host_maintenance_policy.opportunistic_maintenance_strategy.min_nodes_per_pool node_pool.node_config.host_maintenance_policy.opportunistic_maintenance_strategy.node_idle_time_window]
  • google_container_node_pool
    • Expected Document Path: /website/docs/r/container_node_pool.html.markdown
    • Fields: [node_config.host_maintenance_policy.opportunistic_maintenance_strategy node_config.host_maintenance_policy.opportunistic_maintenance_strategy.maintenance_availability_window node_config.host_maintenance_policy.opportunistic_maintenance_strategy.min_nodes_per_pool node_config.host_maintenance_policy.opportunistic_maintenance_strategy.node_idle_time_window]

Test report

Important

Manual Verification Required

VCR cannot automatically execute the following tests added in this PR. Please verify them manually:

🔴 TestAccContainerNodePool_withOpportunisticMaintenance

Analytics

Total Tests Passed Skipped Affected
321 305 16 0
Affected Service Packages
  • container

Learn how VCR tests work


Step 1: Replaying Mode

🟢 All tests passed in Replaying mode! No Recording was needed.

Caution

Issues requiring attention before PR completion

🔴 Manual Verification Required: New tests were added that are skipped in presubmit tests. See the "Manual Verification Required" section at the top for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the replaying VCR build log

@DrFaust92, @c2thorn VCR tests complete for 8066006!

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

@c2thorn This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants