mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
Merge pull request #123565 from ah8ad3/update-help-text-kubectl-create-token
Implement to accept zero as a default value for kubectl create token duration
This commit is contained in:
commit
6f42da171b
@ -148,7 +148,7 @@ func NewCmdCreateToken(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)
|
||||
|
||||
cmd.Flags().StringArrayVar(&o.Audiences, "audience", o.Audiences, "Audience of the requested token. If unset, defaults to requesting a token for use with the Kubernetes API server. May be repeated to request a token valid for multiple audiences.")
|
||||
|
||||
cmd.Flags().DurationVar(&o.Duration, "duration", o.Duration, "Requested lifetime of the issued token. If not set, 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. "+
|
||||
"Supported kinds are "+strings.Join(sets.StringKeySet(boundObjectKindToAPIVersions()).List(), ", ")+". "+
|
||||
@ -208,8 +208,8 @@ func (o *TokenOptions) Validate() error {
|
||||
if len(o.Namespace) == 0 {
|
||||
return fmt.Errorf("--namespace is required")
|
||||
}
|
||||
if o.Duration < 0 || (o.Duration == 0 && o.Flags.Changed("duration")) {
|
||||
return fmt.Errorf("--duration must be positive")
|
||||
if o.Duration < 0 {
|
||||
return fmt.Errorf("--duration must be greater than or equal to 0")
|
||||
}
|
||||
if o.Duration%time.Second != 0 {
|
||||
return fmt.Errorf("--duration cannot be expressed in units less than seconds")
|
||||
|
@ -219,7 +219,7 @@ status:
|
||||
test: "invalid duration",
|
||||
name: "mysa",
|
||||
duration: -1,
|
||||
expectStderr: `error: --duration must be positive`,
|
||||
expectStderr: `error: --duration must be greater than or equal to 0`,
|
||||
},
|
||||
{
|
||||
test: "invalid duration unit",
|
||||
@ -243,7 +243,22 @@ status:
|
||||
serverResponseToken: "abc",
|
||||
expectStdout: "abc",
|
||||
},
|
||||
{
|
||||
test: "zero duration act as default",
|
||||
name: "mysa",
|
||||
|
||||
duration: 0 * time.Second,
|
||||
|
||||
expectRequestPath: "/api/v1/namespaces/test/serviceaccounts/mysa/token",
|
||||
expectTokenRequest: &authenticationv1.TokenRequest{
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: "authentication.k8s.io/v1", Kind: "TokenRequest"},
|
||||
Spec: authenticationv1.TokenRequestSpec{
|
||||
ExpirationSeconds: nil,
|
||||
},
|
||||
},
|
||||
serverResponseToken: "abc",
|
||||
expectStdout: "abc",
|
||||
},
|
||||
{
|
||||
test: "server error",
|
||||
name: "mysa",
|
||||
|
Loading…
Reference in New Issue
Block a user