Skip to content

unify marker definitions to markers package #74

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

Merged

Conversation

sivchari
Copy link
Member

Each linter definitions marker constant in themself, then there are some duplicated markers. In the future, we should add other marker definition to diagnose markers. So it's good to determine the location to define marker right now.

/kind cleanup

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 30, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 30, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this really belongs in this package? The package itself is about extracting markers rather than containing the constants of markers used in the project.

I agree with doing this (was actually thinking about it this morning), but perhaps we want to have a sepate consts style package for containing these marker constants?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been just thinking where the location is better than under helpers. And I decided to make the markers package under pkg directory, then reflect it in the latest commit.

@@ -158,3 +152,7 @@ func hasStatusField(sTyp *ast.StructType, jsonTags extractjsontags.StructFieldTa

return false
}

func kubebuilderFormatWithValue(value string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably mention that it's the root marker, or have an option to pass in a marker?

Copy link
Member Author

Choose a reason for hiding this comment

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

These formatted functions are also unified as Format.

@sivchari sivchari force-pushed the unify-marker-definition branch from b6233b0 to ecb63f5 Compare April 30, 2025 15:22
Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Ok this is better keeping them separate, I'm still wondering if we should rename the package to consts to not conflict with the markershelper but I'm not gonna block on that

KubebuilderItemsFormatMarker = "kubebuilder:validation:items:Format"
)

func Format(marker, value string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe FormatMarkerWithValue?

)

func Format(marker, value string) string {
return fmt.Sprintf("%s:=%s", marker, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this format always correct? What about markers that have multiple parameters like kubebuilder:validation:XValidation?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it is not

Copy link
Member Author

Choose a reason for hiding this comment

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

In addition, kubebuilder supports := and =, then the enum uses ; to concat value, but multiuple parameter uses , to do. So it's not time to determine this API. Reverted it once.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 30, 2025
@sivchari sivchari force-pushed the unify-marker-definition branch 2 times, most recently from f3a0ba8 to 4a8844a Compare May 2, 2025 10:09
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2025
Comment on lines 157 to 159
func kubebuilderFormatWithValue(format string) string {
return fmt.Sprintf("%s:=%s", markers.KubebuilderRootMarker, format)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better. Note though, that not all markers support the := syntax, so this isn't universal. Anything with Kubebuilder in the name does support := though

Suggested change
func kubebuilderFormatWithValue(format string) string {
return fmt.Sprintf("%s:=%s", markers.KubebuilderRootMarker, format)
}
func formatKubeBuilderMarkerWithValue(marker, value string) string {
return fmt.Sprintf("%s:=%s", marker, format)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

@JoelSpeed
Copy link
Contributor

If we can apply my suggestion then I'm good to get this merged, thanks for working on this one!

Signed-off-by: sivchari <shibuuuu5@gmail.com>
@sivchari sivchari force-pushed the unify-marker-definition branch from 4a8844a to 4de5446 Compare May 3, 2025 03:44
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 5, 2025
@JoelSpeed
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: everettraven, JoelSpeed, sivchari

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2025
@k8s-ci-robot k8s-ci-robot merged commit 86c7d73 into kubernetes-sigs:main May 7, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants