Skip to content

Commit

Permalink
Add selectablefield marker
Browse files Browse the repository at this point in the history
  • Loading branch information
everesio committed Sep 6, 2024
1 parent ed70d11 commit e079927
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
32 changes: 32 additions & 0 deletions pkg/crd/markers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var CRDMarkers = []*definitionWithHelp{

must(markers.MakeDefinition("kubebuilder:metadata", markers.DescribesType, Metadata{})).
WithHelp(Metadata{}.Help()),

must(markers.MakeDefinition("kubebuilder:selectablefield", markers.DescribesType, SelectableField{})).
WithHelp(SelectableField{}.Help()),
}

// TODO: categories and singular used to be annotations types
Expand Down Expand Up @@ -388,3 +391,32 @@ func (s Metadata) ApplyToCRD(crd *apiext.CustomResourceDefinition, _ string) err

return nil
}

// +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
}
28 changes: 22 additions & 6 deletions pkg/crd/markers/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/crd/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/genall/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e079927

Please sign in to comment.