mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Switch from using a function to just pure map in create token
Signed-off-by: Maciej Szulik <soltysh@gmail.com>
This commit is contained in:
parent
3030b1dc6a
commit
87139335b0
@ -98,14 +98,10 @@ var (
|
|||||||
`)
|
`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func boundObjectKindToAPIVersions() map[string]string {
|
var boundObjectKinds = map[string]string{
|
||||||
kinds := map[string]string{
|
"Pod": "v1",
|
||||||
"Pod": "v1",
|
"Secret": "v1",
|
||||||
"Secret": "v1",
|
"Node": "v1",
|
||||||
"Node": "v1",
|
|
||||||
}
|
|
||||||
|
|
||||||
return kinds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTokenOpts(ioStreams genericiooptions.IOStreams) *TokenOptions {
|
func NewTokenOpts(ioStreams genericiooptions.IOStreams) *TokenOptions {
|
||||||
@ -149,7 +145,7 @@ func NewCmdCreateToken(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)
|
|||||||
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.")
|
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.")
|
||||||
|
|
||||||
cmd.Flags().StringVar(&o.BoundObjectKind, "bound-object-kind", o.BoundObjectKind, "Kind of an object to bind the token to. "+
|
cmd.Flags().StringVar(&o.BoundObjectKind, "bound-object-kind", o.BoundObjectKind, "Kind of an object to bind the token to. "+
|
||||||
"Supported kinds are "+strings.Join(sets.List(sets.KeySet(boundObjectKindToAPIVersions())), ", ")+". "+
|
"Supported kinds are "+strings.Join(sets.List(sets.KeySet(boundObjectKinds)), ", ")+". "+
|
||||||
"If set, --bound-object-name must be provided.")
|
"If set, --bound-object-name must be provided.")
|
||||||
cmd.Flags().StringVar(&o.BoundObjectName, "bound-object-name", o.BoundObjectName, "Name of an object to bind the token to. "+
|
cmd.Flags().StringVar(&o.BoundObjectName, "bound-object-name", o.BoundObjectName, "Name of an object to bind the token to. "+
|
||||||
"The token will expire when the object is deleted. "+
|
"The token will expire when the object is deleted. "+
|
||||||
@ -226,8 +222,8 @@ func (o *TokenOptions) Validate() error {
|
|||||||
return fmt.Errorf("--bound-object-uid can only be set if --bound-object-kind is provided")
|
return fmt.Errorf("--bound-object-uid can only be set if --bound-object-kind is provided")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, ok := boundObjectKindToAPIVersions()[o.BoundObjectKind]; !ok {
|
if _, ok := boundObjectKinds[o.BoundObjectKind]; !ok {
|
||||||
return fmt.Errorf("supported --bound-object-kind values are %s", strings.Join(sets.List(sets.KeySet(boundObjectKindToAPIVersions())), ", "))
|
return fmt.Errorf("supported --bound-object-kind values are %s", strings.Join(sets.List(sets.KeySet(boundObjectKinds)), ", "))
|
||||||
}
|
}
|
||||||
if len(o.BoundObjectName) == 0 {
|
if len(o.BoundObjectName) == 0 {
|
||||||
return fmt.Errorf("--bound-object-name is required if --bound-object-kind is provided")
|
return fmt.Errorf("--bound-object-name is required if --bound-object-kind is provided")
|
||||||
@ -250,7 +246,7 @@ func (o *TokenOptions) Run() error {
|
|||||||
if len(o.BoundObjectKind) > 0 {
|
if len(o.BoundObjectKind) > 0 {
|
||||||
request.Spec.BoundObjectRef = &authenticationv1.BoundObjectReference{
|
request.Spec.BoundObjectRef = &authenticationv1.BoundObjectReference{
|
||||||
Kind: o.BoundObjectKind,
|
Kind: o.BoundObjectKind,
|
||||||
APIVersion: boundObjectKindToAPIVersions()[o.BoundObjectKind],
|
APIVersion: boundObjectKinds[o.BoundObjectKind],
|
||||||
Name: o.BoundObjectName,
|
Name: o.BoundObjectName,
|
||||||
UID: types.UID(o.BoundObjectUID),
|
UID: types.UID(o.BoundObjectUID),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user