Skip to content

Commit

Permalink
build: add ability to set explicit name for policies (kumahq#5595)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
  • Loading branch information
michaelbeaumont authored and bartsmykla committed Jan 14, 2023
1 parent 0199911 commit 352f19d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions pkg/core/resources/model/display_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ func PluralType(resType string) string {
return resType + "s"
}
}

func PluralDisplayName(resType string) string {
return DisplayName(PluralType(resType))
}
7 changes: 6 additions & 1 deletion tools/policy-gen/generator/pkg/parse/policyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func newPolicyConfig(pkg, name string, markers map[string]string, hasTo, hasFrom
Name: name,
NameLower: strings.ToLower(name),
SingularDisplayName: core_model.DisplayName(name),
PluralDisplayName: core_model.PluralDisplayName(name),
PluralDisplayName: core_model.PluralType(core_model.DisplayName(name)),
AlternativeNames: []string{strings.ToLower(name)},
HasTo: hasTo,
HasFrom: hasFrom,
Expand All @@ -132,6 +132,11 @@ func newPolicyConfig(pkg, name string, markers map[string]string, hasTo, hasFrom
res.SkipGetDefault = v
}

if v, ok := markers["kuma:policy:singular_display_name"]; ok {
res.SingularDisplayName = v
res.PluralDisplayName = core_model.PluralType(v)
}

if v, ok := markers["kuma:policy:plural"]; ok {
res.Plural = v
} else {
Expand Down
2 changes: 1 addition & 1 deletion tools/resource-gen/genutils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func ToResourceInfo(desc protoreflect.MessageDescriptor) ResourceInfo {
}
}
if out.PluralDisplayName == "" {
out.PluralDisplayName = core_model.PluralDisplayName(r.Type)
out.PluralDisplayName = core_model.PluralType(core_model.DisplayName(r.Type))
}
// Working around the fact we don't really differentiate policies from the rest of resources:
// Anything global can't be a policy as it need to be on a mesh. Anything with locked Ws config is something internal and therefore not a policy
Expand Down

0 comments on commit 352f19d

Please sign in to comment.