Skip to content

Conversation

@camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Dec 24, 2025

Change ClusterCatalog Priority field from int32 to *int32 to properly
represent an optional field with a default value.

  • Update Priority to *int32 with json:"priority,omitempty"
  • Fix kubebuilder markers: Minimum/Maximum capitalization
  • Add Format:=int32 marker for OpenAPI schema

The kubebuilder default marker ensures the API server sets Priority
to 0 when omitted, while the pointer type allows proper detection of
user-specified vs defaulted values.

@camilamacedo86 camilamacedo86 requested a review from a team as a code owner December 24, 2025 17:06
Copilot AI review requested due to automatic review settings December 24, 2025 17:06
@openshift-ci openshift-ci bot requested review from anik120 and bentito December 24, 2025 17:06
@openshift-ci
Copy link

openshift-ci bot commented Dec 24, 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 camilamacedo86, thetechnick 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

//
// +kubebuilder:default:=0
// +kubebuilder:validation:minimum:=-2147483648
// +kubebuilder:validation:maximum:=2147483647
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above ones are invalid.
Therefore, we are fixing the validation here.

@netlify
Copy link

netlify bot commented Dec 24, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit c88aa54
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/694c1fbf7ce38100089484b3
😎 Deploy Preview https://deploy-preview-2413--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

// +kubebuilder:validation:Format:=int32
// +optional
Priority int32 `json:"priority"`
Priority *int32 `json:"priority,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Pointer = distinguish between "not set" (nil) vs "set to 0"
  • omitempty = don't show field in YAML when not set (cleaner)
  • kubebuilder default = API server fills in 0 when user omits it

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we can make this change since it changes the serialization of the field

Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Jan 2, 2026

Choose a reason for hiding this comment

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

We should use a pointer.
It theoretically would be a breaking change, but because we are setting 0 by default, we do not change the behaviour

@joelanford @everettraven @JoelSpeed WDYT?

Choose a reason for hiding this comment

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

Changing this to a pointer could break folks who've already built against this API. They are assuming that they do not have to validate today that priority is a non-nil pointer, your default is preventing this from being an issue for now, but what if we later forget that this wasn't always a pointer and decide to remove the default? Now there could be code out there that we cause NPEs in, because they were based on previous assumptions

This change seems innocuous at the moment because of the defaulting, but sets us up for bad times in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to distinguish between (1) not set and (2) set to 0? What is the use case?

We should be careful given that we introduce omitempty tag here, we can land into the following scenario:

  • client creates resource with nil priority, but on the k8s api side, it is persisted with 0, because that is the default value.
  • when fetching now the resource from the k8s api server, the priority is never nil, therefore, we are not able to distinguish if it was set by the creator or not.

Also,

  • client sets the priority to 2 at the creation
  • later by mistake client does not emit priority field at update - it is going to be reset to 0 and that could be confusing for users.

Choose a reason for hiding this comment

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

when fetching now the resource from the k8s api server, the priority is never nil, therefore, we are not able to distinguish if it was set by the creator or not.

You can't currently do that either. Without omitempty and no pointer, you'll read 0 from a structured client and have no idea if that is even persisted in the API server, it may be, it may not

Currently, the API doesn't successfully round trip all values. I'm not convinced fixing this is the right thing to do though, especially given this is a v1 API.

  Change ClusterCatalog Priority field from int32 to *int32 to properly
  represent an optional field with a default value.

  - Update Priority to *int32 with json:"priority,omitempty"
  - Fix kubebuilder markers: Minimum/Maximum capitalization
  - Add Format:=int32 marker for OpenAPI schema
  - Add GetPriority() helper method for safe nil handling
  - Update resolver to use GetPriority() instead of direct access
  - Update tests to use ptr.To[int32]() for pointer values

  The kubebuilder default marker ensures the API server sets Priority
  to 0 when omitted, while the pointer type allows proper detection of
  user-specified vs defaulted values.

Assisted-by: CLAUDE

This comment was marked as outdated.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// The lowest possible value is -2147483648.
// The highest possible value is 2147483647.
//
// +kubebuilder:default:=0
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The +kubebuilder:default:=0 marker combined with the pointer type *int32 creates a contradiction. When this default is applied by the API server, the Go code will receive a non-nil pointer to 0 whether the user explicitly set priority to 0 or omitted it entirely. This defeats the purpose of using a pointer type, which is typically to distinguish between "not set" (nil) and "set to zero value" (non-nil pointer to 0). Consider removing the default marker if the goal is to detect user-specified vs omitted values, or changing back to a non-pointer type if a default value should always be present.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@JoelSpeed @everettraven Is not that accurate?

Choose a reason for hiding this comment

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

Is 0 a valid choice for priority?

If it is, then using a pointer is correct whether there is a default or not.

If you decide you also want to default to zero, that should have no impact on the pointer/omitempty status of the field.

If you did not have a pointer, but did have omitempty (to be expected now), then you'd not be able to correctly roundtrip the 0 value here

I think copilot is wrong here

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.82%. Comparing base (bd540c9) to head (c88aa54).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2413   +/-   ##
=======================================
  Coverage   68.82%   68.82%           
=======================================
  Files         100      100           
  Lines        7641     7648    +7     
=======================================
+ Hits         5259     5264    +5     
- Misses       1947     1948    +1     
- Partials      435      436    +1     
Flag Coverage Δ
e2e 43.96% <100.00%> (+0.14%) ⬆️
experimental-e2e 13.72% <50.00%> (+0.04%) ⬆️
unit 57.09% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joelanford
Copy link
Member

/hold

We always expect priority to be set or defaulted, so the field is never nil. Let's make sure we discuss the intent and implications here. I suspect we want to leave this the way it is.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants