Skip to content

Commit 2c8c9d0

Browse files
committed
fix kube-apiserver panic when CRD Kind contains only one letter
Signed-off-by: SataQiu <[email protected]>
1 parent 3a8d130 commit 2c8c9d0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/installer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ func splitSubresource(path string) (string, string, error) {
10701070

10711071
// GetArticleForNoun returns the article needed for the given noun.
10721072
func GetArticleForNoun(noun string, padding string) string {
1073-
if noun[len(noun)-2:] != "ss" && noun[len(noun)-1:] == "s" {
1073+
if !strings.HasSuffix(noun, "ss") && strings.HasSuffix(noun, "s") {
10741074
// Plurals don't have an article.
10751075
// Don't catch words like class
10761076
return fmt.Sprintf("%v", padding)

staging/src/k8s.io/apiserver/pkg/endpoints/installer_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ func TestGetArticleForNoun(t *testing.T) {
8080
padding: " ",
8181
want: " a ",
8282
},
83+
{
84+
noun: "S",
85+
padding: " ",
86+
want: " a ",
87+
},
88+
{
89+
noun: "O",
90+
padding: " ",
91+
want: " an ",
92+
},
8393
}
8494
for _, tt := range tests {
8595
if got := GetArticleForNoun(tt.noun, tt.padding); got != tt.want {

0 commit comments

Comments
 (0)