Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ spec:
value: {{ .Values.config.clientQps | quote }}
- name: KRO_CLIENT_BURST
value: {{ .Values.config.clientBurst | quote }}
{{- if .Values.config.groupResourceMap }}
- name: KRO_GROUP_RESOURCE_MAP
value: {{ .Values.config.groupResourceMap | quote }}
{{- end }}
args:
{{- if .Values.config.allowCRDDeletion }}
- --allow-crd-deletion
Expand Down
2 changes: 2 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ deployment:
config:
# Allow kro to delete CRDs
allowCRDDeletion: false
# The group=resource map for special cases (e.g., 'groupalias=groupaliases,person=people')
groupResourceMap: ""
# The maximum number of queries per second to allow
clientQps: 100
# The number of requests that can be stored for processing before the server starts enforcing the QPS limit
Expand Down
27 changes: 27 additions & 0 deletions pkg/metadata/groupversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package metadata

import (
"fmt"
"os"
"strings"

"github.com/gobuffalo/flect"
Expand Down Expand Up @@ -87,8 +88,34 @@ func GVRtoGVK(gvr schema.GroupVersionResource) schema.GroupVersionKind {
}
}

func loadSpecialCases() map[string]string {
cases := map[string]string{}

// Example: GROUP_RESOURCE_MAP="groupalias=groupaliases,person=people"
envVal := os.Getenv("KRO_GROUP_RESOURCE_MAP")
if envVal == "" {
return cases
}

pairs := strings.Split(envVal, ",")
for _, p := range pairs {
kv := strings.SplitN(strings.TrimSpace(p), "=", 2)
if len(kv) == 2 {
cases[strings.ToLower(kv[0])] = strings.ToLower(kv[1])
}
}
return cases
}

var specialCases = loadSpecialCases()

func GVKtoGVR(gvk schema.GroupVersionKind) schema.GroupVersionResource {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you're trying to do here, but wonder if it would make more sense for this to be a field on the RGD itself.

You could imagine something right here, a new optional field like Resource or PluralKind or something. I'm not sure quite what the right name is.

Copy link
Contributor

Choose a reason for hiding this comment

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

That way it doesn't require a weird env-based override on the pod

Copy link
Contributor

Choose a reason for hiding this comment

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

Then that field could (if set) be used in place of flect entirely.

Though note that we also could just fix flect upstream to pluralize your resource correctly.

Copy link
Member

Choose a reason for hiding this comment

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

@matthchr @TheCodingSheikh how about leveraging simple schema syntax and doing something like:

  kind: Peanut | plural=Peanuts

resource := flect.Pluralize(strings.ToLower(gvk.Kind))

if corrected, exists := specialCases[resource]; exists {
resource = corrected
}

return schema.GroupVersionResource{
Group: gvk.Group,
Version: gvk.Version,
Expand Down