mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #9130 from andronat/fix_5840
Print multiple validation errors
This commit is contained in:
commit
087cf7d2e2
@ -29,6 +29,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
@ -56,6 +57,13 @@ func CheckErr(err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errors.IsInvalid(err) {
|
||||||
|
details := err.(*errors.StatusError).Status().Details
|
||||||
|
prefix := fmt.Sprintf("The %s %q is invalid:", details.Kind, details.Name)
|
||||||
|
errs := statusCausesToAggrError(details.Causes)
|
||||||
|
fatal(MultilineError(prefix, errs))
|
||||||
|
}
|
||||||
|
|
||||||
// handle multiline errors
|
// handle multiline errors
|
||||||
if clientcmd.IsConfigurationInvalid(err) {
|
if clientcmd.IsConfigurationInvalid(err) {
|
||||||
fatal(MultilineError("Error in configuration: ", err))
|
fatal(MultilineError("Error in configuration: ", err))
|
||||||
@ -71,6 +79,14 @@ func CheckErr(err error) {
|
|||||||
fatal(msg)
|
fatal(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate {
|
||||||
|
errs := make([]error, len(scs))
|
||||||
|
for i, sc := range scs {
|
||||||
|
errs[i] = fmt.Errorf("%s: %s", sc.Field, sc.Message)
|
||||||
|
}
|
||||||
|
return utilerrors.NewAggregate(errs)
|
||||||
|
}
|
||||||
|
|
||||||
// StandardErrorMessage translates common errors into a human readable message, or returns
|
// StandardErrorMessage translates common errors into a human readable message, or returns
|
||||||
// false if the error is not one of the recognized types. It may also log extended
|
// false if the error is not one of the recognized types. It may also log extended
|
||||||
// information to glog.
|
// information to glog.
|
||||||
|
Loading…
Reference in New Issue
Block a user