Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4fcd496d
Commit
4fcd496d
authored
Jan 08, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change everything to use new util/errors
parent
cd29ba7e
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
31 additions
and
133 deletions
+31
-133
errors.go
pkg/api/errors/errors.go
+2
-2
validation_test.go
pkg/api/validation/validation_test.go
+2
-1
client_config.go
pkg/client/clientcmd/client_config.go
+2
-2
validation.go
pkg/client/clientcmd/validation.go
+3
-2
validation_test.go
pkg/client/clientcmd/validation_test.go
+10
-10
proxier.go
pkg/proxy/proxier.go
+3
-2
error_list.go
pkg/util/error_list.go
+0
-54
error_list_test.go
pkg/util/error_list_test.go
+0
-51
union.go
plugin/pkg/auth/authenticator/request/union/union.go
+4
-4
x509.go
plugin/pkg/auth/authenticator/request/x509/x509.go
+5
-5
No files found.
pkg/api/errors/errors.go
View file @
4fcd496d
...
...
@@ -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
...
...
@@ -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
)),
}}
}
...
...
pkg/api/validation/validation_test.go
View file @
4fcd496d
...
...
@@ -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
)
{
...
...
@@ -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
,
util
errors
.
NewAggregate
(
errs
))
}
}
...
...
pkg/client/clientcmd/client_config.go
View file @
4fcd496d
...
...
@@ -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
(
...
...
@@ -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
{
...
...
pkg/client/clientcmd/validation.go
View file @
4fcd496d
...
...
@@ -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"
)
...
...
@@ -67,7 +68,7 @@ func Validate(config Config) error {
validationErrors
=
append
(
validationErrors
,
validateClusterInfo
(
clusterName
,
clusterInfo
)
...
)
}
return
util
.
SliceToError
(
validationErrors
)
return
util
errors
.
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,
...
...
@@ -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
util
errors
.
NewAggregate
(
validationErrors
)
}
// validateClusterInfo looks for conflicts and errors in the cluster info
...
...
pkg/client/clientcmd/validation_test.go
View file @
4fcd496d
...
...
@@ -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
)
{
...
...
@@ -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
))
}
}
}
...
...
@@ -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
))
}
}
}
...
...
@@ -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
))
}
}
}
pkg/proxy/proxier.go
View file @
4fcd496d
...
...
@@ -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"
)
...
...
@@ -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
{
...
...
@@ -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.
...
...
pkg/util/error_list.go
deleted
100644 → 0
View file @
cd29ba7e
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"fmt"
)
// []error is a collection of errors. This does not implement the error
// interface to avoid confusion where an empty []error would still be an
// error (non-nil). To produce a single error instance from an []error, use
// the SliceToError() method, which will return nil for an empty []error.
// This helper implements the error interface for []error, but prevents
// accidental conversion of []error to error.
type
errorList
[]
error
// Error is part of the error interface.
func
(
list
errorList
)
Error
()
string
{
if
len
(
list
)
==
0
{
return
""
}
if
len
(
list
)
==
1
{
return
list
[
0
]
.
Error
()
}
result
:=
fmt
.
Sprintf
(
"[%s"
,
list
[
0
]
.
Error
())
for
i
:=
1
;
i
<
len
(
list
);
i
++
{
result
+=
fmt
.
Sprintf
(
", %s"
,
list
[
i
]
.
Error
())
}
result
+=
"]"
return
result
}
// SliceToError converts an []error into a "normal" error, or nil if the slice is empty.
func
SliceToError
(
errs
[]
error
)
error
{
if
len
(
errs
)
==
0
{
return
nil
}
return
errorList
(
errs
)
}
pkg/util/error_list_test.go
deleted
100644 → 0
View file @
cd29ba7e
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"fmt"
"testing"
)
func
TestErrorList
(
t
*
testing
.
T
)
{
var
errList
[]
error
err
:=
SliceToError
(
errList
)
if
err
!=
nil
{
t
.
Errorf
(
"expected nil, got %v"
,
err
)
}
if
a
:=
errorList
(
errList
)
.
Error
();
a
!=
""
{
t
.
Errorf
(
"expected empty string, got %q"
,
a
)
}
testCases
:=
[]
struct
{
errs
[]
error
expected
string
}{
{[]
error
{
fmt
.
Errorf
(
"abc"
)},
"abc"
},
{[]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"123"
)},
"[abc, 123]"
},
}
for
_
,
testCase
:=
range
testCases
{
err
:=
SliceToError
(
testCase
.
errs
)
if
err
==
nil
{
t
.
Errorf
(
"expected an error, got nil: %v"
,
testCase
)
continue
}
if
err
.
Error
()
!=
testCase
.
expected
{
t
.
Errorf
(
"expected %q, got %q"
,
testCase
.
expected
,
err
.
Error
())
}
}
}
plugin/pkg/auth/authenticator/request/union/union.go
View file @
4fcd496d
...
...
@@ -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
...
...
@@ -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
err
ors
[]
error
var
err
list
[]
error
for
_
,
currAuthRequestHandler
:=
range
authHandler
{
info
,
ok
,
err
:=
currAuthRequestHandler
.
AuthenticateRequest
(
req
)
if
err
!=
nil
{
err
ors
=
append
(
errors
,
err
)
err
list
=
append
(
errlist
,
err
)
continue
}
...
...
@@ -48,5 +48,5 @@ func (authHandler unionAuthRequestHandler) AuthenticateRequest(req *http.Request
}
}
return
nil
,
false
,
util
.
SliceToError
(
errors
)
return
nil
,
false
,
errors
.
NewAggregate
(
errlist
)
}
plugin/pkg/auth/authenticator/request/x509/x509.go
View file @
4fcd496d
...
...
@@ -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
...
...
@@ -55,18 +55,18 @@ func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool,
return
nil
,
false
,
nil
}
var
err
ors
[]
error
var
err
list
[]
error
for
_
,
cert
:=
range
req
.
TLS
.
PeerCertificates
{
chains
,
err
:=
cert
.
Verify
(
a
.
opts
)
if
err
!=
nil
{
err
ors
=
append
(
errors
,
err
)
err
list
=
append
(
errlist
,
err
)
continue
}
for
_
,
chain
:=
range
chains
{
user
,
ok
,
err
:=
a
.
user
.
User
(
chain
)
if
err
!=
nil
{
err
ors
=
append
(
errors
,
err
)
err
list
=
append
(
errlist
,
err
)
continue
}
...
...
@@ -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,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment