Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
37c0c142
Commit
37c0c142
authored
Jan 04, 2017
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
snip pkg/util/strings dependency
parent
38d57e5a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
67 deletions
+100
-67
BUILD
pkg/genericapiserver/api/BUILD
+0
-1
installer.go
pkg/genericapiserver/api/installer.go
+30
-3
installer_test.go
pkg/genericapiserver/api/installer_test.go
+70
-0
strings.go
pkg/util/strings/strings.go
+0
-17
strings_test.go
pkg/util/strings/strings_test.go
+0
-46
No files found.
pkg/genericapiserver/api/BUILD
View file @
37c0c142
...
@@ -35,7 +35,6 @@ go_library(
...
@@ -35,7 +35,6 @@ go_library(
"//pkg/runtime:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/schema:go_default_library",
"//pkg/runtime/schema:go_default_library",
"//pkg/util/errors:go_default_library",
"//pkg/util/errors:go_default_library",
"//pkg/util/strings:go_default_library",
"//vendor:github.com/emicklei/go-restful",
"//vendor:github.com/emicklei/go-restful",
],
],
)
)
...
...
pkg/genericapiserver/api/installer.go
View file @
37c0c142
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"sort"
"sort"
"strings"
"strings"
"time"
"time"
"unicode"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
...
@@ -40,7 +41,6 @@ import (
...
@@ -40,7 +41,6 @@ import (
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
"k8s.io/kubernetes/pkg/genericapiserver/api/request"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/runtime/schema"
utilstrings
"k8s.io/kubernetes/pkg/util/strings"
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful"
)
)
...
@@ -654,7 +654,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -654,7 +654,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
handler
=
handlers
.
CreateResource
(
creater
,
reqScope
,
a
.
group
.
Typer
,
admit
)
handler
=
handlers
.
CreateResource
(
creater
,
reqScope
,
a
.
group
.
Typer
,
admit
)
}
}
handler
=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
resource
,
handler
)
handler
=
metrics
.
InstrumentRouteFunc
(
action
.
Verb
,
resource
,
handler
)
article
:=
utilstrings
.
G
etArticleForNoun
(
kind
,
" "
)
article
:=
g
etArticleForNoun
(
kind
,
" "
)
doc
:=
"create"
+
article
+
kind
doc
:=
"create"
+
article
+
kind
if
hasSubresource
{
if
hasSubresource
{
doc
=
"create "
+
subresource
+
" of"
+
article
+
kind
doc
=
"create "
+
subresource
+
" of"
+
article
+
kind
...
@@ -670,7 +670,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -670,7 +670,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
addParams
(
route
,
action
.
Params
)
addParams
(
route
,
action
.
Params
)
ws
.
Route
(
route
)
ws
.
Route
(
route
)
case
"DELETE"
:
// Delete a resource.
case
"DELETE"
:
// Delete a resource.
article
:=
utilstrings
.
G
etArticleForNoun
(
kind
,
" "
)
article
:=
g
etArticleForNoun
(
kind
,
" "
)
doc
:=
"delete"
+
article
+
kind
doc
:=
"delete"
+
article
+
kind
if
hasSubresource
{
if
hasSubresource
{
doc
=
"delete "
+
subresource
+
" of"
+
article
+
kind
doc
=
"delete "
+
subresource
+
" of"
+
article
+
kind
...
@@ -1080,3 +1080,30 @@ func splitSubresource(path string) (string, string, error) {
...
@@ -1080,3 +1080,30 @@ func splitSubresource(path string) (string, string, error) {
}
}
return
resource
,
subresource
,
nil
return
resource
,
subresource
,
nil
}
}
// 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"
{
// Plurals don't have an article.
// Don't catch words like class
return
fmt
.
Sprintf
(
"%v"
,
padding
)
}
article
:=
"a"
if
isVowel
(
rune
(
noun
[
0
]))
{
article
=
"an"
}
return
fmt
.
Sprintf
(
"%s%s%s"
,
padding
,
article
,
padding
)
}
// isVowel returns true if the rune is a vowel (case insensitive).
func
isVowel
(
c
rune
)
bool
{
vowels
:=
[]
rune
{
'a'
,
'e'
,
'i'
,
'o'
,
'u'
}
for
_
,
value
:=
range
vowels
{
if
value
==
unicode
.
ToLower
(
c
)
{
return
true
}
}
return
false
}
pkg/genericapiserver/api/installer_test.go
View file @
37c0c142
...
@@ -56,3 +56,73 @@ func TestScopeNamingGenerateLink(t *testing.T) {
...
@@ -56,3 +56,73 @@ func TestScopeNamingGenerateLink(t *testing.T) {
t
.
Errorf
(
"Unexpected error %v"
,
err
)
t
.
Errorf
(
"Unexpected error %v"
,
err
)
}
}
}
}
func
TestIsVowel
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
arg
rune
want
bool
}{
{
name
:
"yes"
,
arg
:
'E'
,
want
:
true
,
},
{
name
:
"no"
,
arg
:
'n'
,
want
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
if
got
:=
isVowel
(
tt
.
arg
);
got
!=
tt
.
want
{
t
.
Errorf
(
"%q. IsVowel() = %v, want %v"
,
tt
.
name
,
got
,
tt
.
want
)
}
}
}
func
TestGetArticleForNoun
(
t
*
testing
.
T
)
{
type
args
struct
{
}
tests
:=
[]
struct
{
noun
string
padding
string
want
string
}{
{
noun
:
"Frog"
,
padding
:
" "
,
want
:
" a "
,
},
{
noun
:
"frogs"
,
padding
:
" "
,
want
:
" "
,
},
{
noun
:
"apple"
,
padding
:
""
,
want
:
"an"
,
},
{
noun
:
"Apples"
,
padding
:
" "
,
want
:
" "
,
},
{
noun
:
"Ingress"
,
padding
:
" "
,
want
:
" an "
,
},
{
noun
:
"Class"
,
padding
:
" "
,
want
:
" a "
,
},
}
for
_
,
tt
:=
range
tests
{
if
got
:=
getArticleForNoun
(
tt
.
noun
,
tt
.
padding
);
got
!=
tt
.
want
{
t
.
Errorf
(
"%q. GetArticleForNoun() = %v, want %v"
,
tt
.
noun
,
got
,
tt
.
want
)
}
}
}
pkg/util/strings/strings.go
View file @
37c0c142
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
strings
package
strings
import
(
import
(
"fmt"
"path"
"path"
"strings"
"strings"
"unicode"
"unicode"
...
@@ -48,22 +47,6 @@ func ShortenString(str string, n int) string {
...
@@ -48,22 +47,6 @@ func ShortenString(str string, n int) string {
}
}
}
}
// 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"
{
// Plurals don't have an article.
// Don't catch words like class
return
fmt
.
Sprintf
(
"%v"
,
padding
)
}
article
:=
"a"
if
isVowel
(
rune
(
noun
[
0
]))
{
article
=
"an"
}
return
fmt
.
Sprintf
(
"%s%s%s"
,
padding
,
article
,
padding
)
}
// isVowel returns true if the rune is a vowel (case insensitive).
// isVowel returns true if the rune is a vowel (case insensitive).
func
isVowel
(
c
rune
)
bool
{
func
isVowel
(
c
rune
)
bool
{
vowels
:=
[]
rune
{
'a'
,
'e'
,
'i'
,
'o'
,
'u'
}
vowels
:=
[]
rune
{
'a'
,
'e'
,
'i'
,
'o'
,
'u'
}
...
...
pkg/util/strings/strings_test.go
View file @
37c0c142
...
@@ -95,49 +95,3 @@ func TestIsVowel(t *testing.T) {
...
@@ -95,49 +95,3 @@ func TestIsVowel(t *testing.T) {
}
}
}
}
}
}
func
TestGetArticleForNoun
(
t
*
testing
.
T
)
{
type
args
struct
{
}
tests
:=
[]
struct
{
noun
string
padding
string
want
string
}{
{
noun
:
"Frog"
,
padding
:
" "
,
want
:
" a "
,
},
{
noun
:
"frogs"
,
padding
:
" "
,
want
:
" "
,
},
{
noun
:
"apple"
,
padding
:
""
,
want
:
"an"
,
},
{
noun
:
"Apples"
,
padding
:
" "
,
want
:
" "
,
},
{
noun
:
"Ingress"
,
padding
:
" "
,
want
:
" an "
,
},
{
noun
:
"Class"
,
padding
:
" "
,
want
:
" a "
,
},
}
for
_
,
tt
:=
range
tests
{
if
got
:=
GetArticleForNoun
(
tt
.
noun
,
tt
.
padding
);
got
!=
tt
.
want
{
t
.
Errorf
(
"%q. GetArticleForNoun() = %v, want %v"
,
tt
.
noun
,
got
,
tt
.
want
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment