Skip to content
Draft
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
29 changes: 29 additions & 0 deletions machine/v1beta1/types_gcpprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ const (
ConfidentialComputePolicyTDX ConfidentialComputePolicy = "IntelTrustedDomainExtensions"
)

// 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"`
}
Comment on lines +82 to +105
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.


// GCPMachineProviderSpec is the type that will be embedded in a Machine.Spec.ProviderSpec field
// for an GCP virtual machine. It is used by the GCP machine actuator to create a single Machine.
// Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer).
Expand Down Expand Up @@ -191,6 +216,10 @@ type GCPMachineProviderSpec struct {
// +listMapKey=key
// +optional
ResourceManagerTags []ResourceManagerTag `json:"resourceManagerTags,omitempty"`

// reservationAffinity indicates the reservation for the VM.
// +optional
ReservationAffinity *GCPReservationAffinity `json:"reservationAffinity,omitempty"`
}

// ResourceManagerTag is a tag to apply to GCP resources created for the cluster.
Expand Down
31 changes: 31 additions & 0 deletions machine/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions machine/v1beta1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 56 additions & 1 deletion openapi/generated_openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.