提交 72d2bea2 编写于 作者: Z ZeHuaiWang 提交者: Kubernetes Prow Robot

use golint and fix typo (#4437)

* use golint and fix typo

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
上级 ab056bcb
......@@ -25,10 +25,15 @@ import (
var _ error = &errors.StatusError{}
// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
// action.
func NewUnauthorized(reason string) *errors.StatusError {
return errors.NewUnauthorized(reason)
}
// NewTokenExpired return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
func NewTokenExpired(reason string) *errors.StatusError {
return &errors.StatusError{
ErrStatus: metav1.Status{
......@@ -40,10 +45,14 @@ func NewTokenExpired(reason string) *errors.StatusError {
}
}
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func NewBadRequest(reason string) *errors.StatusError {
return errors.NewBadRequest(reason)
}
// NewInvalid return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
func NewInvalid(reason string) *errors.StatusError {
return &errors.StatusError{
ErrStatus: metav1.Status{
......@@ -55,6 +64,9 @@ func NewInvalid(reason string) *errors.StatusError {
}
}
// NewNotFound return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
func NewNotFound(reason string) *errors.StatusError {
return &errors.StatusError{
ErrStatus: metav1.Status{
......@@ -66,6 +78,9 @@ func NewNotFound(reason string) *errors.StatusError {
}
}
// NewInternal return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
func NewInternal(reason string) *errors.StatusError {
return &errors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
......@@ -78,15 +93,24 @@ func NewInternal(reason string) *errors.StatusError {
}}
}
// NewUnexpectedObject return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
func NewUnexpectedObject(obj runtime.Object) *errors.StatusError {
return &errors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Reason: metav1.StatusReasonInternalError,
Message: errors.FromObject(obj).Error(),
}}
return &errors.StatusError{
ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Reason: metav1.StatusReasonInternalError,
Message: errors.FromObject(obj).Error(),
},
}
}
// NewGenericResponse return a statusError
// which is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches
// by switch the error code.
func NewGenericResponse(code int, serverMessage string) *errors.StatusError {
reason := metav1.StatusReasonUnknown
message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
......@@ -145,6 +169,7 @@ func NewGenericResponse(code int, serverMessage string) *errors.StatusError {
}}
}
// IsTokenExpired determines if the err is an error which errStatus' message is MsgTokenExpiredError
func IsTokenExpired(err error) bool {
statusErr, ok := err.(*errors.StatusError)
if !ok {
......@@ -154,10 +179,13 @@ func IsTokenExpired(err error) bool {
return statusErr.ErrStatus.Message == MsgTokenExpiredError
}
// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
func IsAlreadyExists(err error) bool {
return errors.IsAlreadyExists(err)
}
// IsUnauthorized determines if err is an error which indicates that the request is unauthorized and
// requires authentication by the user.
func IsUnauthorized(err error) bool {
return errors.IsUnauthorized(err)
}
......@@ -41,10 +41,9 @@ func AppendError(err error, nonCriticalErrors []error) ([]error, error) {
if err != nil {
if isErrorCritical(err) {
return nonCriticalErrors, LocalizeError(err)
} else {
log.Printf("Non-critical error occurred during resource retrieval: %s", err)
nonCriticalErrors = appendMissing(nonCriticalErrors, LocalizeError(err))
}
log.Printf("Non-critical error occurred during resource retrieval: %s", err)
nonCriticalErrors = appendMissing(nonCriticalErrors, LocalizeError(err))
}
return nonCriticalErrors, nil
}
......@@ -113,6 +112,7 @@ func IsNotFoundError(err error) bool {
return status.ErrStatus.Code == http.StatusNotFound
}
// IsTokenExpiredError determines if the err is the MsgTokenExpiredError.
func IsTokenExpiredError(err error) bool {
if err == nil {
return false
......@@ -132,7 +132,7 @@ func HandleInternalError(response *restful.Response, err error) {
response.WriteErrorString(statusCode, err.Error()+"\n")
}
// Handle HTTP Errors more accurately based on the localized consts
// HandleHTTPError is used to handle HTTP Errors more accurately based on the localized consts
func HandleHTTPError(err error) int {
if err == nil {
return http.StatusInternalServerError
......
......@@ -23,7 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
)
// Gets restart count of given pod (total number of its containers restarts).
// getRestartCount return the restart count of given pod (total number of its containers restarts).
func getRestartCount(pod v1.Pod) int32 {
var restartCount int32 = 0
for _, containerStatus := range pod.Status.ContainerStatuses {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册