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
4992402f
Unverified
Commit
4992402f
authored
Feb 05, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #73595 from liggitt/authn-message
Preserve authentication webhook error message, deduplicate aggregated errors when printing
parents
c299f169
fe549a5a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
6 deletions
+104
-6
BUILD
staging/src/k8s.io/apimachinery/pkg/util/errors/BUILD
+1
-0
errors.go
staging/src/k8s.io/apimachinery/pkg/util/errors/errors.go
+33
-5
errors_test.go
...ng/src/k8s.io/apimachinery/pkg/util/errors/errors_test.go
+64
-0
webhook.go
...iserver/plugin/pkg/authenticator/token/webhook/webhook.go
+6
-1
No files found.
staging/src/k8s.io/apimachinery/pkg/util/errors/BUILD
View file @
4992402f
...
@@ -20,6 +20,7 @@ go_library(
...
@@ -20,6 +20,7 @@ go_library(
],
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/errors",
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/errors",
importpath = "k8s.io/apimachinery/pkg/util/errors",
importpath = "k8s.io/apimachinery/pkg/util/errors",
deps = ["//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library"],
)
)
filegroup(
filegroup(
...
...
staging/src/k8s.io/apimachinery/pkg/util/errors/errors.go
View file @
4992402f
...
@@ -19,6 +19,8 @@ package errors
...
@@ -19,6 +19,8 @@ package errors
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"k8s.io/apimachinery/pkg/util/sets"
)
)
// MessageCountMap contains occurrence for each error message.
// MessageCountMap contains occurrence for each error message.
...
@@ -67,12 +69,38 @@ func (agg aggregate) Error() string {
...
@@ -67,12 +69,38 @@ func (agg aggregate) Error() string {
if
len
(
agg
)
==
1
{
if
len
(
agg
)
==
1
{
return
agg
[
0
]
.
Error
()
return
agg
[
0
]
.
Error
()
}
}
result
:=
fmt
.
Sprintf
(
"[%s"
,
agg
[
0
]
.
Error
())
seenerrs
:=
sets
.
NewString
()
for
i
:=
1
;
i
<
len
(
agg
);
i
++
{
result
:=
""
result
+=
fmt
.
Sprintf
(
", %s"
,
agg
[
i
]
.
Error
())
agg
.
visit
(
func
(
err
error
)
{
msg
:=
err
.
Error
()
if
seenerrs
.
Has
(
msg
)
{
return
}
seenerrs
.
Insert
(
msg
)
if
len
(
seenerrs
)
>
1
{
result
+=
", "
}
result
+=
msg
})
if
len
(
seenerrs
)
==
1
{
return
result
}
return
"["
+
result
+
"]"
}
func
(
agg
aggregate
)
visit
(
f
func
(
err
error
))
{
for
_
,
err
:=
range
agg
{
switch
err
:=
err
.
(
type
)
{
case
aggregate
:
err
.
visit
(
f
)
case
Aggregate
:
for
_
,
nestedErr
:=
range
err
.
Errors
()
{
f
(
nestedErr
)
}
default
:
f
(
err
)
}
}
}
result
+=
"]"
return
result
}
}
// Errors is part of the Aggregate interface.
// Errors is part of the Aggregate interface.
...
...
staging/src/k8s.io/apimachinery/pkg/util/errors/errors_test.go
View file @
4992402f
...
@@ -147,6 +147,70 @@ func TestPluralAggregate(t *testing.T) {
...
@@ -147,6 +147,70 @@ func TestPluralAggregate(t *testing.T) {
}
}
}
}
func
TestDedupeAggregate
(
t
*
testing
.
T
)
{
var
slice
[]
error
=
[]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"abc"
)}
var
agg
Aggregate
agg
=
NewAggregate
(
slice
)
if
agg
==
nil
{
t
.
Errorf
(
"expected non-nil"
)
}
if
s
:=
agg
.
Error
();
s
!=
"abc"
{
t
.
Errorf
(
"expected 'abc', got %q"
,
s
)
}
if
s
:=
agg
.
Errors
();
len
(
s
)
!=
2
{
t
.
Errorf
(
"expected two-elements slice, got %#v"
,
s
)
}
}
func
TestDedupePluralAggregate
(
t
*
testing
.
T
)
{
var
slice
[]
error
=
[]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"123"
)}
var
agg
Aggregate
agg
=
NewAggregate
(
slice
)
if
agg
==
nil
{
t
.
Errorf
(
"expected non-nil"
)
}
if
s
:=
agg
.
Error
();
s
!=
"[abc, 123]"
{
t
.
Errorf
(
"expected '[abc, 123]', got %q"
,
s
)
}
if
s
:=
agg
.
Errors
();
len
(
s
)
!=
3
{
t
.
Errorf
(
"expected three-elements slice, got %#v"
,
s
)
}
}
func
TestFlattenAndDedupeAggregate
(
t
*
testing
.
T
)
{
var
slice
[]
error
=
[]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"abc"
),
NewAggregate
([]
error
{
fmt
.
Errorf
(
"abc"
)})}
var
agg
Aggregate
agg
=
NewAggregate
(
slice
)
if
agg
==
nil
{
t
.
Errorf
(
"expected non-nil"
)
}
if
s
:=
agg
.
Error
();
s
!=
"abc"
{
t
.
Errorf
(
"expected 'abc', got %q"
,
s
)
}
if
s
:=
agg
.
Errors
();
len
(
s
)
!=
3
{
t
.
Errorf
(
"expected three-elements slice, got %#v"
,
s
)
}
}
func
TestFlattenAggregate
(
t
*
testing
.
T
)
{
var
slice
[]
error
=
[]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"abc"
),
NewAggregate
([]
error
{
fmt
.
Errorf
(
"abc"
),
fmt
.
Errorf
(
"def"
),
NewAggregate
([]
error
{
fmt
.
Errorf
(
"def"
),
fmt
.
Errorf
(
"ghi"
)})})}
var
agg
Aggregate
agg
=
NewAggregate
(
slice
)
if
agg
==
nil
{
t
.
Errorf
(
"expected non-nil"
)
}
if
s
:=
agg
.
Error
();
s
!=
"[abc, def, ghi]"
{
t
.
Errorf
(
"expected '[abc, def, ghi]', got %q"
,
s
)
}
if
s
:=
agg
.
Errors
();
len
(
s
)
!=
3
{
t
.
Errorf
(
"expected three-elements slice, got %#v"
,
s
)
}
}
func
TestFilterOut
(
t
*
testing
.
T
)
{
func
TestFilterOut
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
err
error
err
error
...
...
staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/webhook.go
View file @
4992402f
...
@@ -19,6 +19,7 @@ package webhook
...
@@ -19,6 +19,7 @@ package webhook
import
(
import
(
"context"
"context"
"errors"
"time"
"time"
authentication
"k8s.io/api/authentication/v1beta1"
authentication
"k8s.io/api/authentication/v1beta1"
...
@@ -120,7 +121,11 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(ctx context.Context, token
...
@@ -120,7 +121,11 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(ctx context.Context, token
r
.
Status
=
result
.
Status
r
.
Status
=
result
.
Status
if
!
r
.
Status
.
Authenticated
{
if
!
r
.
Status
.
Authenticated
{
return
nil
,
false
,
nil
var
err
error
if
len
(
r
.
Status
.
Error
)
!=
0
{
err
=
errors
.
New
(
r
.
Status
.
Error
)
}
return
nil
,
false
,
err
}
}
var
extra
map
[
string
][]
string
var
extra
map
[
string
][]
string
...
...
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