Skip to content

Commit

Permalink
✨ Make the anonymous value of the groupName marker optional
Browse files Browse the repository at this point in the history
Upstream introduced the use of empty groupName markers in k/k PR 125162.
This breaks groupName parsing because its field is non-optional. Add an
additional mustOptional function that takes anonymous field definitions
and turns them into optional ones.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
  • Loading branch information
twz123 committed Jul 4, 2024
1 parent 5f4eea8 commit 31c93d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/crd/markers/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func init() {
AllDefinitions = append(AllDefinitions,
must(markers.MakeDefinition("groupName", markers.DescribesPackage, "")).
mustOptional(markers.MakeDefinition("groupName", markers.DescribesPackage, "")).
WithHelp(markers.SimpleHelp("CRD", "specifies the API group name for this package.")),

must(markers.MakeDefinition("versionName", markers.DescribesPackage, "")).
Expand Down
14 changes: 14 additions & 0 deletions pkg/crd/markers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package markers

import (
"fmt"
"reflect"

"sigs.k8s.io/controller-tools/pkg/markers"
Expand Down Expand Up @@ -56,6 +57,19 @@ func must(def *markers.Definition, err error) *definitionWithHelp {
}
}

func mustOptional(def *markers.Definition, err error) *definitionWithHelp {
def = markers.Must(def, err)
if !def.AnonymousField() {
def = markers.Must(def, fmt.Errorf("not an anonymous field: %v", def))
}
field := def.Fields[""]
field.Optional = true
def.Fields[""] = field
return &definitionWithHelp{
Definition: def,
}
}

// AllDefinitions contains all marker definitions for this package.
var AllDefinitions []*definitionWithHelp

Expand Down

0 comments on commit 31c93d2

Please sign in to comment.