Skip to content

Commit

Permalink
change everything to use new util/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jan 9, 2015
1 parent cd29ba7 commit 4fcd496
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 133 deletions.
4 changes: 2 additions & 2 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

// StatusError is an error intended for consumption by a REST API server; it can also be
Expand Down Expand Up @@ -141,7 +141,7 @@ func NewInvalid(kind, name string, errs ValidationErrorList) error {
ID: name,
Causes: causes,
},
Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, util.SliceToError(errs)),
Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errors.NewAggregate(errs)),
}}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

func expectPrefix(t *testing.T, prefix string, errs errors.ValidationErrorList) {
Expand Down Expand Up @@ -968,7 +969,7 @@ func TestValidateService(t *testing.T) {
registry.List = tc.existing
errs := ValidateService(&tc.svc, registry, api.NewDefaultContext())
if len(errs) != tc.numErrs {
t.Errorf("Unexpected error list for case %q: %v", tc.name, util.SliceToError(errs))
t.Errorf("Unexpected error list for case %q: %v", tc.name, utilerrors.NewAggregate(errs))
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/clientcmd/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

var (
Expand Down Expand Up @@ -227,7 +227,7 @@ func (config DirectClientConfig) ConfirmUsable() error {
validationErrors = append(validationErrors, validateAuthInfo(config.getAuthInfoName(), config.getAuthInfo())...)
validationErrors = append(validationErrors, validateClusterInfo(config.getClusterName(), config.getCluster())...)

return util.SliceToError(validationErrors)
return errors.NewAggregate(validationErrors)
}

func (config DirectClientConfig) getContextName() string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/clientcmd/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"

"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

var ErrNoContext = errors.New("no context chosen")
Expand Down Expand Up @@ -67,7 +68,7 @@ func Validate(config Config) error {
validationErrors = append(validationErrors, validateClusterInfo(clusterName, clusterInfo)...)
}

return util.SliceToError(validationErrors)
return utilerrors.NewAggregate(validationErrors)
}

// ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config,
Expand Down Expand Up @@ -97,7 +98,7 @@ func ConfirmUsable(config Config, passedContextName string) error {
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, config.Clusters[context.Cluster])...)
}

return util.SliceToError(validationErrors)
return utilerrors.NewAggregate(validationErrors)
}

// validateClusterInfo looks for conflicts and errors in the cluster info
Expand Down
20 changes: 10 additions & 10 deletions pkg/client/clientcmd/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

func TestConfirmUsableBadInfoButOkConfig(t *testing.T) {
Expand Down Expand Up @@ -300,14 +300,14 @@ func (c configValidationTest) testContext(contextName string, t *testing.T) {
t.Errorf("Expected error containing: %v", c.expectedErrorSubstring)
}
for _, curr := range c.expectedErrorSubstring {
if len(errs) != 0 && !strings.Contains(util.SliceToError(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, util.SliceToError(errs))
if len(errs) != 0 && !strings.Contains(errors.NewAggregate(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, errors.NewAggregate(errs))
}
}

} else {
if len(errs) != 0 {
t.Errorf("Unexpected error: %v", util.SliceToError(errs))
t.Errorf("Unexpected error: %v", errors.NewAggregate(errs))
}
}
}
Expand Down Expand Up @@ -357,14 +357,14 @@ func (c configValidationTest) testCluster(clusterName string, t *testing.T) {
t.Errorf("Expected error containing: %v", c.expectedErrorSubstring)
}
for _, curr := range c.expectedErrorSubstring {
if len(errs) != 0 && !strings.Contains(util.SliceToError(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, util.SliceToError(errs))
if len(errs) != 0 && !strings.Contains(errors.NewAggregate(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, errors.NewAggregate(errs))
}
}

} else {
if len(errs) != 0 {
t.Errorf("Unexpected error: %v", util.SliceToError(errs))
t.Errorf("Unexpected error: %v", errors.NewAggregate(errs))
}
}
}
Expand All @@ -377,14 +377,14 @@ func (c configValidationTest) testAuthInfo(authInfoName string, t *testing.T) {
t.Errorf("Expected error containing: %v", c.expectedErrorSubstring)
}
for _, curr := range c.expectedErrorSubstring {
if len(errs) != 0 && !strings.Contains(util.SliceToError(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, util.SliceToError(errs))
if len(errs) != 0 && !strings.Contains(errors.NewAggregate(errs).Error(), curr) {
t.Errorf("Expected error containing: %v, but got %v", c.expectedErrorSubstring, errors.NewAggregate(errs))
}
}

} else {
if len(errs) != 0 {
t.Errorf("Unexpected error: %v", util.SliceToError(errs))
t.Errorf("Unexpected error: %v", errors.NewAggregate(errs))
}
}
}
5 changes: 3 additions & 2 deletions pkg/proxy/proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/iptables"
"github.com/golang/glog"
)
Expand Down Expand Up @@ -575,7 +576,7 @@ func (proxier *Proxier) closePortal(service string, info *serviceInfo) error {
} else {
glog.Errorf("Some errors closing iptables portals for service %q", service)
}
return util.SliceToError(el)
return errors.NewAggregate(el)
}

func (proxier *Proxier) closeOnePortal(portalIP net.IP, portalPort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, name string) []error {
Expand Down Expand Up @@ -646,7 +647,7 @@ func iptablesFlush(ipt iptables.Interface) error {
if len(el) != 0 {
glog.Errorf("Some errors flushing old iptables portals: %v", el)
}
return util.SliceToError(el)
return errors.NewAggregate(el)
}

// Used below.
Expand Down
54 changes: 0 additions & 54 deletions pkg/util/error_list.go

This file was deleted.

51 changes: 0 additions & 51 deletions pkg/util/error_list_test.go

This file was deleted.

8 changes: 4 additions & 4 deletions plugin/pkg/auth/authenticator/request/union/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator"
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

// unionAuthRequestHandler authenticates requests using a chain of authenticator.Requests
Expand All @@ -35,11 +35,11 @@ func New(authRequestHandlers ...authenticator.Request) authenticator.Request {
// AuthenticateRequest authenticates the request using a chain of authenticator.Request objects. The first
// success returns that identity. Errors are only returned if no matches are found.
func (authHandler unionAuthRequestHandler) AuthenticateRequest(req *http.Request) (user.Info, bool, error) {
var errors []error
var errlist []error
for _, currAuthRequestHandler := range authHandler {
info, ok, err := currAuthRequestHandler.AuthenticateRequest(req)
if err != nil {
errors = append(errors, err)
errlist = append(errlist, err)
continue
}

Expand All @@ -48,5 +48,5 @@ func (authHandler unionAuthRequestHandler) AuthenticateRequest(req *http.Request
}
}

return nil, false, util.SliceToError(errors)
return nil, false, errors.NewAggregate(errlist)
}
10 changes: 5 additions & 5 deletions plugin/pkg/auth/authenticator/request/x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"net/http"

"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)

// UserConversion defines an interface for extracting user info from a client certificate chain
Expand Down Expand Up @@ -55,18 +55,18 @@ func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool,
return nil, false, nil
}

var errors []error
var errlist []error
for _, cert := range req.TLS.PeerCertificates {
chains, err := cert.Verify(a.opts)
if err != nil {
errors = append(errors, err)
errlist = append(errlist, err)
continue
}

for _, chain := range chains {
user, ok, err := a.user.User(chain)
if err != nil {
errors = append(errors, err)
errlist = append(errlist, err)
continue
}

Expand All @@ -75,7 +75,7 @@ func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool,
}
}
}
return nil, false, util.SliceToError(errors)
return nil, false, errors.NewAggregate(errlist)
}

// DefaultVerifyOptions returns VerifyOptions that use the system root certificates, current time,
Expand Down

0 comments on commit 4fcd496

Please sign in to comment.