Skip to content

Conversation

@MenD32
Copy link

@MenD32 MenD32 commented Dec 16, 2025

Context

Currently, OCP's machine API doesn't support the reservation affinity feature of GCP's instances, thus making reservation use more complicated on OCP in comparison to GCP. This feature is critical for clients with heavy workloads that have already reserved instances for continuous use. (e.g. AI training workloads).

This PR lays the groundwork to support GCP reservation in openshift's machine API.

@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Dec 16, 2025
@openshift-ci-robot
Copy link

@MenD32: This pull request explicitly references no jira issue.

Details

In response to this:

Context

Currently, OCP's machine API doesn't support the reservation affinity feature of GCP's instances, thus making reservation use more complicated on OCP in comparison to GCP. This feature is critical for clients with heavy workloads that have already reserved instances for continuous use. (e.g. AI training workloads).

This PR lays the groundwork to support GCP reservation in openshift's machine API.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 16, 2025

Hello @MenD32! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

Adds a new GCPReservationAffinity type and an optional ReservationAffinity field to GCPMachineProviderSpec, and updates generated deepcopy, Swagger, and OpenAPI code to include and handle the new type.

Changes

Cohort / File(s) Change Summary
GCP reservation affinity types & spec field
machine/v1beta1/types_gcpprovider.go
Adds GCPReservationAffinity struct with fields ConsumeReservationType, Key, and Values (JSON tags and kubebuilder enum/validation), and adds ReservationAffinity *GCPReservationAffinity to GCPMachineProviderSpec.
DeepCopy implementations
machine/v1beta1/zz_generated.deepcopy.go
Adds DeepCopyInto and DeepCopy for GCPReservationAffinity; updates GCPMachineProviderSpec.DeepCopyInto to deep-copy optional ReservationAffinity.
Swagger doc updates
machine/v1beta1/zz_generated.swagger_doc_generated.go
Adds swagger doc entry for reservationAffinity in GCPMachineProviderSpec and adds GCPReservationAffinity SwaggerDoc mapping.
OpenAPI schema updates
openapi/generated_openapi/zz_generated.openapi.go
Adds OpenAPI schema function for GCPReservationAffinity, wires reservationAffinity property into GCPMachineProviderSpec schema, and registers the new type in GetOpenAPIDefinitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • Ensure DeepCopy handles pointer, slice, and pointer-to-string fields correctly.
    • Verify OpenAPI schema property requirements and types (required vs optional for consumeReservationType).
    • Confirm Swagger docs match struct field names and descriptions.
    • Check JSON tags and kubebuilder validation annotation consistency.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented
The command is terminated due to an error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 16, 2025
@openshift-ci openshift-ci bot requested review from JoelSpeed and mandre December 16, 2025 11:29
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 16, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign everettraven for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between bfa868a and 84292a0.

📒 Files selected for processing (1)
  • machine/v1beta1/types_gcpprovider.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • machine/v1beta1/types_gcpprovider.go
🔇 Additional comments (1)
machine/v1beta1/types_gcpprovider.go (1)

211-213: LGTM!

The field addition is well-designed: properly documented, correctly marked as optional, and uses a pointer type for optionality.

Signed-off-by: Amit Mendelevitch <amendele@redhat.com>
@MenD32 MenD32 force-pushed the feat/gcp-machine-reservation-affinity branch from 84292a0 to 8059e5a Compare December 16, 2025 11:44
@JoelSpeed
Copy link
Contributor

Is this feature supported in the upstream cluster-api-provider-gcp?

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@MenD32
Copy link
Author

MenD32 commented Dec 16, 2025

Is this feature supported in the upstream cluster-api-provider-gcp?

In order for it to be supported, it must be first integrated into the API (adding that feature to the reconciler is my next PR)

@JoelSpeed
Copy link
Contributor

@MenD32 To clarify, I meant is the feature supported in https://github.com/kubernetes-sigs/cluster-api-provider-gcp/, which has no dependency on this API that you have raised a PR for

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
machine/v1beta1/types_gcpprovider.go (1)

82-96: Acknowledge NO_RESERVATION fix; conditional validation still needed.

Good progress—the NO_RESERVATION enum value has been added since the previous review, completing the enum set.

However, the conditional validation concern remains: when ConsumeReservationType is SPECIFIC_RESERVATION, both Key and Values must be non-empty, but kubebuilder tags cannot enforce this. Consider using CEL validation rules (via +kubebuilder:validation:XValidation) to express this constraint declaratively without requiring a webhook service.

Example CEL rule:

// +kubebuilder:validation:XValidation:rule="self.consumeReservationType != 'SPECIFIC_RESERVATION' || (has(self.key) && self.key != '' && size(self.values) > 0)",message="key and values are required when consumeReservationType is SPECIFIC_RESERVATION"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3902ba8 and 4d0a70e.

📒 Files selected for processing (1)
  • machine/v1beta1/types_gcpprovider.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • machine/v1beta1/types_gcpprovider.go
🔇 Additional comments (1)
machine/v1beta1/types_gcpprovider.go (1)

211-213: LGTM!

The ReservationAffinity field addition is correctly implemented as an optional pointer field with appropriate JSON tags and documentation.

@MenD32
Copy link
Author

MenD32 commented Dec 16, 2025

@MenD32 To clarify, I meant is the feature supported in https://github.com/kubernetes-sigs/cluster-api-provider-gcp/, which has no dependency on this API that you have raised a PR for

Ah, thought you were talking about https://github.com/openshift/machine-api-provider-gcp.

Its not supported there (in CAPG) currently.

@JoelSpeed
Copy link
Contributor

Its not supported there (in CAPG) currently.

It must be supported in CAPG before we will allow a merge downstream. Please work with the Cluster Infrastructure team (#forum-ocp-cloud) who will be able to help you with upstream reviews

CC @sub-mod @damdo

@MenD32 MenD32 force-pushed the feat/gcp-machine-reservation-affinity branch 3 times, most recently from 9fa061f to 8a60cec Compare December 16, 2025 13:36
Signed-off-by: Amit Mendelevitch <amendele@redhat.com>
@MenD32 MenD32 force-pushed the feat/gcp-machine-reservation-affinity branch from 8a60cec to d0a831c Compare December 16, 2025 14:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8a60cec and d0a831c.

📒 Files selected for processing (4)
  • machine/v1beta1/types_gcpprovider.go (2 hunks)
  • machine/v1beta1/zz_generated.deepcopy.go (2 hunks)
  • machine/v1beta1/zz_generated.swagger_doc_generated.go (2 hunks)
  • openapi/generated_openapi/zz_generated.openapi.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • machine/v1beta1/types_gcpprovider.go
  • openapi/generated_openapi/zz_generated.openapi.go
  • machine/v1beta1/zz_generated.swagger_doc_generated.go
  • machine/v1beta1/zz_generated.deepcopy.go
🧬 Code graph analysis (3)
machine/v1beta1/types_gcpprovider.go (1)
machine/v1beta1/zz_generated.swagger_doc_generated.go (1)
  • GCPReservationAffinity (529-531)
machine/v1beta1/zz_generated.swagger_doc_generated.go (1)
machine/v1beta1/types_gcpprovider.go (1)
  • GCPReservationAffinity (83-105)
machine/v1beta1/zz_generated.deepcopy.go (1)
machine/v1beta1/types_gcpprovider.go (1)
  • GCPReservationAffinity (83-105)
🔇 Additional comments (8)
machine/v1beta1/types_gcpprovider.go (1)

220-222: LGTM!

The ReservationAffinity field is correctly defined as an optional pointer field with appropriate kubebuilder annotations and JSON tags.

machine/v1beta1/zz_generated.swagger_doc_generated.go (2)

522-531: LGTM!

The generated Swagger documentation correctly reflects the new GCPReservationAffinity type with appropriate field descriptions.


482-482: LGTM!

The reservationAffinity field documentation has been correctly added to the GCPMachineProviderSpec Swagger documentation.

machine/v1beta1/zz_generated.deepcopy.go (2)

797-801: LGTM!

The integration of ReservationAffinity into GCPMachineProviderSpec.DeepCopyInto correctly handles the optional pointer field with proper nil checks and deep copying.


895-919: LGTM!

The generated DeepCopyInto and DeepCopy methods for GCPReservationAffinity correctly implement deep copying for all fields:

  • Properly handles the Key pointer field
  • Correctly copies the Values slice
openapi/generated_openapi/zz_generated.openapi.go (3)

786-786: LGTM! Type registration follows the established pattern.

The GCPReservationAffinity type is correctly registered in the OpenAPI definitions map with proper alphabetical ordering.


40039-40044: LGTM! Field addition and dependency updates are correct.

The reservationAffinity field is properly added as an optional field (consistent with the pointer type in the source), and the GCPReservationAffinity dependency is correctly included in the dependency list.

Also applies to: 40050-40050


40195-40241: LGTM! Schema definition is mechanically correct.

The GCPReservationAffinity schema properly defines the structure with:

  • Appropriate field types and descriptions
  • Correct use of x-kubernetes-list-type: "set" for the values array
  • Documented constraints (RFC1035 compliance, length limits, conditional requirements)

The schema follows established patterns for generated OpenAPI definitions. Note that programmatic validation (such as enum constraints for consumeReservationType or conditional requirements for key/values) would typically be enforced through validation markers in the source type definitions rather than in this generated file.

Comment on lines +82 to +105
// GCPReservationAffinity describes the reservation affinity of the instance on GCP.
type GCPReservationAffinity struct {
// consumeReservationType indicates whether the instance should consume from any reservation or a specific reservation.
// Valid values are "NO_RESERVATION", "ANY_RESERVATION" and "SPECIFIC_RESERVATION".
// +required
// +kubebuilder:validation:Enum=NO_RESERVATION;ANY_RESERVATION;SPECIFIC_RESERVATION
ConsumeReservationType string `json:"consumeReservationType,omitempty"`
// key is the reservation key of the specific reservation to consume from.
// The maximum length is 63 characters, and the name must conform to RFC1035.
// Required if consumeReservationType is set to "SPECIFIC_RESERVATION".
// When consumeReservationType is not "SPECIFIC_RESERVATION", this field must be empty.
// +optional
// +kubebuilder:validation:MaxLength=63
Key *string `json:"key,omitempty"`
// values is the list of reservation values of the specific reservation to consume from.
// Each value can have a maximum length of 63 characters, and the name must conform to RFC1035.
// Required if consumeReservationType is set to "SPECIFIC_RESERVATION".
// When consumeReservationType is not "SPECIFIC_RESERVATION", this field must be empty.
// +optional
// +listType=set
// +kubebuilder:validation:items:MaxLength=63
// +kubebuilder:validation:MaxItems=50
Values []string `json:"values,omitempty"`
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Read the file to confirm the current code state
cat -n machine/v1beta1/types_gcpprovider.go | sed -n '82,105p'

Repository: openshift/api

Length of output: 1645


🏁 Script executed:

# Search for similar struct definitions with +required and omitempty to understand project conventions
rg '\+required' machine/v1beta1/types_gcpprovider.go -A 2 -B 2 | head -100

Repository: openshift/api

Length of output: 1318


🏁 Script executed:

# Look for other struct definitions in the same file to see patterns
rg 'type.*struct' machine/v1beta1/types_gcpprovider.go -A 15 | head -150

Repository: openshift/api

Length of output: 7393


Remove omitempty from required field ConsumeReservationType.

The missing NO_RESERVATION enum value has been correctly added. However, line 88 incorrectly combines +required with omitempty in the JSON tag. Other required fields in this file (e.g., ResourceManagerTag.ParentID) omit the omitempty suffix. Remove it from ConsumeReservationType:

-ConsumeReservationType string `json:"consumeReservationType,omitempty"`
+ConsumeReservationType string `json:"consumeReservationType"`

Additionally, the conditional validation constraints documented in lines 91–92 and 98–99 (that Key and Values must be non-empty when ConsumeReservationType == "SPECIFIC_RESERVATION") cannot be enforced via kubebuilder validation tags and will require validation in the provider's reconciler or via a validating admission webhook.

🤖 Prompt for AI Agents
In machine/v1beta1/types_gcpprovider.go around lines 82 to 105, the field
ConsumeReservationType is marked +required but its struct tag includes
`omitempty`; remove `omitempty` from the json tag so the field is always present
in serialized objects (i.e., change `json:"consumeReservationType,omitempty"` to
`json:"consumeReservationType"`). Also note that the conditional requirements
for Key and Values when ConsumeReservationType == "SPECIFIC_RESERVATION" cannot
be enforced via kubebuilder tags — implement those checks in the provider
reconciler or a validating admission webhook to enforce non-empty Key/Values
when SPECIFIC_RESERVATION is selected.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 16, 2025

@MenD32: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/verify d0a831c link true /test verify

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@damdo
Copy link
Member

damdo commented Dec 16, 2025

@MenD32 yes the proper flow is to open a PR against CAPG first and then come back to MAPG/OCP once that has been agreed upon.
Please also tag me and @JoelSpeed once you open the upstream CAPG PR, thanks!

@MenD32
Copy link
Author

MenD32 commented Dec 16, 2025

@MenD32 yes the proper flow is to open a PR against CAPG first and then come back to MAPG/OCP once that has been agreed upon.
Please also tag me and @JoelSpeed once you open the upstream CAPG PR, thanks!

Alright, is it ok if I keep this PR as a draft instead of closing it?

@JoelSpeed
Copy link
Contributor

Mark this as WIP and then remove the WIP title once you're ready for it to be worked again

Please reach out for an API review upstream as well

@MenD32 MenD32 changed the title NO-JIRA: Added reservation affinity support for GCP Machine Spec NO-JIRA: Added reservation affinity support for GCP Machine Spec - WIP Dec 18, 2025
@MenD32 MenD32 marked this pull request as draft December 18, 2025 09:42
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants