-
Notifications
You must be signed in to change notification settings - Fork 425
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
Support for selectable fields for custom resources #1039
Comments
Since adding a new CRD marker is very simple, I could create a PR. I would propose the following changes.
must(markers.MakeDefinition("kubebuilder:selectablefield", markers.DescribesType, SelectableField{})).
WithHelp(SelectableField{}.Help()),
// +controllertools:marker:generateHelp:category=CRD
// SelectableField adds a field that may be used with field selectors.
type SelectableField struct {
// JSONPath specifies the jsonpath expression which is used to produce a field selector value.
JSONPath string `marker:"JSONPath"`
}
func (s SelectableField) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, version string) error {
var selectableFields *[]apiext.SelectableField
for i := range crd.Versions {
ver := &crd.Versions[i]
if ver.Name != version {
continue
}
selectableFields = &ver.SelectableFields
break
}
if selectableFields == nil {
return fmt.Errorf("selectable field applied to version %q not in CRD", version)
}
*selectableFields = append(*selectableFields, apiext.SelectableField{
JSONPath: s.JSONPath,
})
return nil
}
func (SelectableField) Help() *markers.DefinitionHelp {
return &markers.DefinitionHelp{
Category: "CRD",
DetailedHelp: markers.DetailedHelp{
Summary: "adds a field that may be used with field selectors.",
Details: "",
},
FieldHelp: map[string]markers.DetailedHelp{
"JSONPath": {
Summary: "specifies the jsonpath expression which is used to produce a field selector value.",
Details: "",
},
},
}
} |
/kind feature |
I look into the details on the PR, but feel free to open a PR for it |
PR #1050 |
PR was merged #1050 |
@sbueringer Thank you ! |
Thank you as well! :) |
Thanks for implementing this 🙇 This will greatly improve operations on some of the CRDs that we use (and kubebuilder's lack of support for this code marker has been the only missing point for us). One thing that I believe should still be added is a mention about this in https://book.kubebuilder.io/reference/markers/crd, right? Is this just a matter of pulling in the latest controller tools to kubebuilder or we need to update https://github.com/kubernetes-sigs/kubebuilder/tree/master/docs/book/src/reference/markers ? |
@pmalek Just created the v0.16.4 release. Not sure what is needed on the kubebuilder side (cc @camilamacedo86) |
Kubernetes 1.31 introduces the ability to define field selectors for custom resources.
You can find more details in the official documentation crd-selectable-fields
This issue is a feature request to add support for this functionality to controller-tools, including the addition markers and extending the documentation to explain how the feature should be used.
The text was updated successfully, but these errors were encountered: