knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/kind2resource.go (about) 1 /* 2 Copyright 2018 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package apis 18 19 import ( 20 "strings" 21 22 "k8s.io/apimachinery/pkg/runtime/schema" 23 ) 24 25 // KindToResource converts a GroupVersionKind to a GroupVersionResource 26 // through the world's simplest (worst) pluralizer. 27 func KindToResource(gvk schema.GroupVersionKind) schema.GroupVersionResource { 28 return schema.GroupVersionResource{ 29 Group: gvk.Group, 30 Version: gvk.Version, 31 Resource: pluralizeKind(gvk.Kind), 32 } 33 } 34 35 // Takes a kind and pluralizes it. This is super terrible, but I am 36 // not aware of a generic way to do this. 37 // I am not alone in thinking this and I haven't found a better solution: 38 // This seems relevant: 39 // https://github.com/kubernetes/kubernetes/issues/18622 40 func pluralizeKind(kind string) string { 41 ret := strings.ToLower(kind) 42 if strings.HasSuffix(ret, "s") { 43 return ret + "es" 44 } 45 return ret + "s" 46 }