From 2c8c9d02098a975ee3f42c6a6d29579da8502b6d Mon Sep 17 00:00:00 2001 From: SataQiu <1527062125@qq.com> Date: Sat, 6 Jun 2020 23:01:35 +0800 Subject: [PATCH] fix kube-apiserver panic when CRD Kind contains only one letter Signed-off-by: SataQiu <1527062125@qq.com> --- .../src/k8s.io/apiserver/pkg/endpoints/installer.go | 2 +- .../k8s.io/apiserver/pkg/endpoints/installer_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go b/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go index 4082124cbc2..d743d44ba67 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go @@ -1070,7 +1070,7 @@ func splitSubresource(path string) (string, string, error) { // GetArticleForNoun returns the article needed for the given noun. func GetArticleForNoun(noun string, padding string) string { - if noun[len(noun)-2:] != "ss" && noun[len(noun)-1:] == "s" { + if !strings.HasSuffix(noun, "ss") && strings.HasSuffix(noun, "s") { // Plurals don't have an article. // Don't catch words like class return fmt.Sprintf("%v", padding) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go index c661bd6fc01..d4f74817226 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go @@ -80,6 +80,16 @@ func TestGetArticleForNoun(t *testing.T) { padding: " ", want: " a ", }, + { + noun: "S", + padding: " ", + want: " a ", + }, + { + noun: "O", + padding: " ", + want: " an ", + }, } for _, tt := range tests { if got := GetArticleForNoun(tt.noun, tt.padding); got != tt.want {