kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.75k stars 894 forks source link

Documentation update. duration flag in kubectl create token #1562

Closed harryssuperman closed 4 months ago

harryssuperman commented 4 months ago

What would you like to be added:

I will like to see in the documentation with:

kubectl create token -h

not a duration with a value of 0 seconds.

Why is this needed:

If we run the command for help it will be shown following text:

 --duration=0s:
        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.

But if i run the command with 0 seconds i will get following error:

error: --duration must be positive

ah8ad3 commented 4 months ago

I think the value 0 is the default and when the user explicitly set to 0 the error shown as you mention. https://github.com/kubernetes/kubernetes/pull/119443#issuecomment-1746045958

The verification is already there. But we allow it to be 0 to use the default value set by server-side. This is also the default behavior when the --duration flag is not specified.

and also: https://github.com/kubernetes/kubernetes/pull/119443#issuecomment-1747287016

Could you check using the Changed method if the value has been explicitly set to 0 or not, and reject it if it has

But maybe the chair can talk more about this or close this issue.

sftim commented 4 months ago

I am confident this is a kubectl issue.

/sig cli

sftim commented 4 months ago

/transfer kubectl

ah8ad3 commented 4 months ago

/assign

mpuckett159 commented 4 months ago

/triage accepted To provide more context for this, the reason that the help text shows the default value being 0s is because of how Go handles unset values for certain types. Because the duration flag accepts a time.Duration type, the null value is 0s, and because when the flag is unset it is declared with no value, that means the default value is thus 0s. The problem is that the API server does not accept a 0s value for this because that is not valid. Instead, if it receives a null value for duration it sets the default value, which presently is 1h. So to fix this we are going to remove the completion logic because it is confusing, and just specify that if a user passes 0s for the duration it will be the same as setting the flag to default which will not pass anything to the API server and will instead set a default value. We should not specify what the default value is because that could change in the future and instead link to some sort of API documentation regarding that.