-
Notifications
You must be signed in to change notification settings - Fork 27
Fix modernize linter errors #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Tim Ramlot <[email protected]>
|
|
||
| Spec CertificateRequestPolicySpec `json:"spec,omitempty"` | ||
| Status CertificateRequestPolicyStatus `json:"status,omitempty"` | ||
| Spec CertificateRequestPolicySpec `json:"spec"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec probably should not have been optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should do this, but it's technically a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should not be an issue imo, a CertificateRequestPolicy without Spec should have resulted in an error before too.
| Status CertificateRequestPolicyStatus `json:"status,omitempty"` | ||
| Spec CertificateRequestPolicySpec `json:"spec"` | ||
| // +optional | ||
| Status CertificateRequestPolicyStatus `json:"status,omitzero"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erikgb I believe in the marshalled object, it would be cleaner to not have a status field if it is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree.
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
| metav1.TypeMeta `json:",inline"` | ||
| // +optional | ||
| metav1.ObjectMeta `json:"metadata"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/2335-vanilla-crd-openapi-subset-structural-schemas#metadata, it looks like the metadata field is not required.
I think it is fine to always have this field in the marshalled resource.
erikgb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
And a soft LGTM. Just a question on what looks like an unintentional change.
@inteon, can you please review cert-manager/makefile-modules#468 and cert-manager/makefile-modules#467? I believe it will make the adoption of this new linter a lot more effective.
|
|
||
| Spec CertificateRequestPolicySpec `json:"spec,omitempty"` | ||
| Status CertificateRequestPolicyStatus `json:"status,omitempty"` | ||
| Spec CertificateRequestPolicySpec `json:"spec"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should do this, but it's technically a breaking change.
| Status CertificateRequestPolicyStatus `json:"status,omitempty"` | ||
| Spec CertificateRequestPolicySpec `json:"spec"` | ||
| // +optional | ||
| Status CertificateRequestPolicyStatus `json:"status,omitzero"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree.
| Items []CertificateRequestPolicy `json:"items"` | ||
| // +optional | ||
| metav1.ListMeta `json:"metadata"` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintentional change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is unintentional? the extra newline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks, just verifying. I think it is OK.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modernizes the codebase by enabling the modernize linter and applying its recommendations. The changes replace deprecated Go patterns with their modern equivalents, improving code clarity and consistency with current Go best practices.
Key changes:
- Replaced manual loop-based slice searches with
slices.Contains - Updated
interface{}to use the modernanytype alias - Migrated from
reflect.TypeOf()to the more efficientreflect.TypeFor[]() - Updated CRD JSON tags and added required field validation
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/internal/webhook/validator.go | Simplified plugin name validation using slices.Contains |
| pkg/internal/approver/validation/validator.go | Replaced interface{} with any in variable declaration |
| pkg/internal/approver/validation/serviceaccount.go | Updated CEL interface methods to use any and reflect.TypeFor[]() |
| pkg/internal/approver/constraints/evaluator.go | Updated function signature to use any instead of interface{} |
| pkg/apis/policy/v1alpha1/types_certificaterequestpolicy.go | Updated JSON tags and added field markers for proper API validation |
| deploy/crds/policy.cert-manager.io_certificaterequestpolicies.yaml | Added required field validation for spec field |
| deploy/charts/approver-policy/templates/crd-policy.cert-manager.io_certificaterequestpolicies.yaml | Added required field validation for spec field |
| .golangci.yaml | Removed exclusion rule that disabled the modernize linter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
erikgb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sane to me! Thanks @inteon!
/lgtm
@erikgb found this really cool new linter
modernize.I tried my best to fix all issues it found.