Fix the code according to the code review comments
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com> Kubernetes-commit: 967fdbd3d52b67ed5c72f2b4888adae1f04489e1
This commit is contained in:
parent
d614c60b0c
commit
faf015bc84
|
@ -140,7 +140,7 @@ func NewCmdWhoAmI(restClientGetter genericclioptions.RESTClientGetter, streams g
|
||||||
}
|
}
|
||||||
|
|
||||||
var notEnabledErr = fmt.Errorf(
|
var notEnabledErr = fmt.Errorf(
|
||||||
"the selfsubjectreviews API is not enabled in the cluster or you do not have permission to call: " +
|
"the selfsubjectreviews API is not enabled in the cluster or you do not have permission to call\n" +
|
||||||
"enable APISelfSubjectReview feature gate and authentication.k8s.io/v1alpha1 API")
|
"enable APISelfSubjectReview feature gate and authentication.k8s.io/v1alpha1 API")
|
||||||
|
|
||||||
// Run prints all user attributes.
|
// Run prints all user attributes.
|
||||||
|
@ -148,14 +148,11 @@ func (o WhoAmIOptions) Run() error {
|
||||||
sar := &authenticationv1alpha1.SelfSubjectReview{}
|
sar := &authenticationv1alpha1.SelfSubjectReview{}
|
||||||
response, err := o.authClient.SelfSubjectReviews().Create(context.TODO(), sar, metav1.CreateOptions{})
|
response, err := o.authClient.SelfSubjectReviews().Create(context.TODO(), sar, metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
if errors.IsForbidden(err) || errors.IsNotFound(err) {
|
||||||
case errors.IsForbidden(err), errors.IsNotFound(err):
|
|
||||||
return notEnabledErr
|
return notEnabledErr
|
||||||
default:
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.resourcePrinterFunc(response, o.Out)
|
return o.resourcePrinterFunc(response, o.Out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue