Skip to content

Commit 8713933

Browse files
committed
Switch from using a function to just pure map in create token
Signed-off-by: Maciej Szulik <[email protected]>
1 parent 3030b1d commit 8713933

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/create/create_token.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,10 @@ var (
9898
`)
9999
)
100100

101-
func boundObjectKindToAPIVersions() map[string]string {
102-
kinds := map[string]string{
103-
"Pod": "v1",
104-
"Secret": "v1",
105-
"Node": "v1",
106-
}
107-
108-
return kinds
101+
var boundObjectKinds = map[string]string{
102+
"Pod": "v1",
103+
"Secret": "v1",
104+
"Node": "v1",
109105
}
110106

111107
func NewTokenOpts(ioStreams genericiooptions.IOStreams) *TokenOptions {
@@ -149,7 +145,7 @@ func NewCmdCreateToken(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)
149145
cmd.Flags().DurationVar(&o.Duration, "duration", o.Duration, "Requested lifetime of the issued token. If not set or if set to 0, the lifetime will be determined by the server automatically. The server may return a token with a longer or shorter lifetime.")
150146

151147
cmd.Flags().StringVar(&o.BoundObjectKind, "bound-object-kind", o.BoundObjectKind, "Kind of an object to bind the token to. "+
152-
"Supported kinds are "+strings.Join(sets.List(sets.KeySet(boundObjectKindToAPIVersions())), ", ")+". "+
148+
"Supported kinds are "+strings.Join(sets.List(sets.KeySet(boundObjectKinds)), ", ")+". "+
153149
"If set, --bound-object-name must be provided.")
154150
cmd.Flags().StringVar(&o.BoundObjectName, "bound-object-name", o.BoundObjectName, "Name of an object to bind the token to. "+
155151
"The token will expire when the object is deleted. "+
@@ -226,8 +222,8 @@ func (o *TokenOptions) Validate() error {
226222
return fmt.Errorf("--bound-object-uid can only be set if --bound-object-kind is provided")
227223
}
228224
} else {
229-
if _, ok := boundObjectKindToAPIVersions()[o.BoundObjectKind]; !ok {
230-
return fmt.Errorf("supported --bound-object-kind values are %s", strings.Join(sets.List(sets.KeySet(boundObjectKindToAPIVersions())), ", "))
225+
if _, ok := boundObjectKinds[o.BoundObjectKind]; !ok {
226+
return fmt.Errorf("supported --bound-object-kind values are %s", strings.Join(sets.List(sets.KeySet(boundObjectKinds)), ", "))
231227
}
232228
if len(o.BoundObjectName) == 0 {
233229
return fmt.Errorf("--bound-object-name is required if --bound-object-kind is provided")
@@ -250,7 +246,7 @@ func (o *TokenOptions) Run() error {
250246
if len(o.BoundObjectKind) > 0 {
251247
request.Spec.BoundObjectRef = &authenticationv1.BoundObjectReference{
252248
Kind: o.BoundObjectKind,
253-
APIVersion: boundObjectKindToAPIVersions()[o.BoundObjectKind],
249+
APIVersion: boundObjectKinds[o.BoundObjectKind],
254250
Name: o.BoundObjectName,
255251
UID: types.UID(o.BoundObjectUID),
256252
}

0 commit comments

Comments
 (0)