mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #59579 from fbac/kubectl-cani-exitcode
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add exit code 1 on not allowed to kubectl auth can-i What this PR does / why we need it: kubectl auth can-i verb resource always returns 0 status, even if the user can't <verb> <resource> With this commit, kubectl will return exit code 1 when a verb is not allowed. It doesn't affect quiet option. Release note: ```release-note Fix kubectl auth can-i exit code. It will return 1 if the user is not allowed and 0 if it's allowed. ```
This commit is contained in:
commit
fa20f87f1f
@ -5278,6 +5278,12 @@ runTests() {
|
|||||||
|
|
||||||
output_message=$(kubectl auth can-i list jobs.batch/bar -n foo --quiet 2>&1 "${kube_flags[@]}")
|
output_message=$(kubectl auth can-i list jobs.batch/bar -n foo --quiet 2>&1 "${kube_flags[@]}")
|
||||||
kube::test::if_empty_string "${output_message}"
|
kube::test::if_empty_string "${output_message}"
|
||||||
|
|
||||||
|
output_message=$(kubectl auth can-i get pods --subresource=log 2>&1 "${kube_flags[@]}"; echo $?)
|
||||||
|
kube::test::if_has_string "${output_message}" '0'
|
||||||
|
|
||||||
|
output_message=$(kubectl auth can-i get pods --subresource=log --quiet 2>&1 "${kube_flags[@]}"; echo $?)
|
||||||
|
kube::test::if_has_string "${output_message}" '0'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# kubectl auth reconcile
|
# kubectl auth reconcile
|
||||||
|
@ -97,7 +97,7 @@ func NewCmdCanI(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
|
|||||||
|
|
||||||
allowed, err := o.RunAccessCheck()
|
allowed, err := o.RunAccessCheck()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if o.Quiet && !allowed {
|
if !allowed {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user