Skip to content

🌱 Enable optionalorrequired linter and add required/optional markers#3183

Open
lentzi90 wants to merge 1 commit into
kubernetes-sigs:mainfrom
Nordix:lentzi90/kal-optionalrequired
Open

🌱 Enable optionalorrequired linter and add required/optional markers#3183
lentzi90 wants to merge 1 commit into
kubernetes-sigs:mainfrom
Nordix:lentzi90/kal-optionalrequired

Conversation

@lentzi90
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

This commit enables the optionalorrequired linter in .golangci-kal.yml and updates all API type definitions in v1beta2 to use the standardized +required and +optional markers instead of +kubebuilder:validation:Required.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 27, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit a71c03c
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-cluster-api-openstack/deploys/6a1d7234c852520008a7c67b
😎 Deploy Preview https://deploy-preview-3183--kubernetes-sigs-cluster-api-openstack.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.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[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 neolit123 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

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 27, 2026
Comment thread api/v1beta2/types.go Outdated
Name string `json:"name"`

// description is a human-readable description for the port.
// +required
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is perhaps the most controversial thing in the PR. We don't have omitempty, so I am making it required. If the field was set by humans I would do it the other way, but this is always set by the controller so I think it makes more sense this way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The concern I have with required here is that it's a schema-level constraint, but "the controller always sets this" is a runtime guarantee. Those two things operate at different levels. Specifically:

  1. Required fields can cause validation errors between object creation and the first reconcile
  2. If the controller ever fails mid-reconcile and writes a partial status, required fields could cause issues
  3. If at the future for whatever reason we need to change the controller behavior, we will have to go through an api change.

For this specific change, I don't think we are hit by 1 + 2 as this is a sub-struct under status that is not required and I guess all those fields are set by OpenStack once a port is created and therefore the controller can fully populate them, but i do think there might be some edge-cases that we are hit by this. ( Also macAddress below is already set to optional, I'm wondering why. )

I was looking a bit into k8s/capi best-practises/conventions that go over similar stuff. I found this once populated on capi's conventions.

In general I'm not fully confident i can evaluate this and the impact it might have. It feels to me that opting for required is a bit "strict" and could cause problems down the road, but I dont have the experience/knowledge to really substantiate it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input @nikParasyr ! I really appreciate it and I think you pointed out two good reasons to switch this to optional.

  1. CAPI guidance that status fields MUST be optional
  2. the MAC address below

With this in mind I think it was a mistake that this was missing omitempty. We should simply make it optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now changed to optional. The omitempty will be required/added when we enable the optionalfields linter.

@lentzi90
Copy link
Copy Markdown
Contributor Author

lentzi90 commented Jun 1, 2026

/cc @nikParasyr

@k8s-ci-robot k8s-ci-robot requested a review from nikParasyr June 1, 2026 05:41
@bnallapeta
Copy link
Copy Markdown
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2026
Copy link
Copy Markdown
Contributor

@nikParasyr nikParasyr left a comment

Choose a reason for hiding this comment

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

A bit hesitant to lgtm this one. made a comment with my concerns

Comment thread api/v1beta2/types.go Outdated
Name string `json:"name"`

// description is a human-readable description for the port.
// +required
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The concern I have with required here is that it's a schema-level constraint, but "the controller always sets this" is a runtime guarantee. Those two things operate at different levels. Specifically:

  1. Required fields can cause validation errors between object creation and the first reconcile
  2. If the controller ever fails mid-reconcile and writes a partial status, required fields could cause issues
  3. If at the future for whatever reason we need to change the controller behavior, we will have to go through an api change.

For this specific change, I don't think we are hit by 1 + 2 as this is a sub-struct under status that is not required and I guess all those fields are set by OpenStack once a port is created and therefore the controller can fully populate them, but i do think there might be some edge-cases that we are hit by this. ( Also macAddress below is already set to optional, I'm wondering why. )

I was looking a bit into k8s/capi best-practises/conventions that go over similar stuff. I found this once populated on capi's conventions.

In general I'm not fully confident i can evaluate this and the impact it might have. It feels to me that opting for required is a bit "strict" and could cause problems down the road, but I dont have the experience/knowledge to really substantiate it.

This commit enables the `optionalorrequired` linter in
`.golangci-kal.yml` and updates all API type definitions in v1beta2 to
use the standardized `+required` and `+optional` markers instead of
`+kubebuilder:validation:Required`.

Signed-off-by: Lennart Jern <lennart.jern@est.tech>
@lentzi90 lentzi90 force-pushed the lentzi90/kal-optionalrequired branch from 83e4142 to a71c03c Compare June 1, 2026 11:51
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

4 participants