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
9bfa63db
Unverified
Commit
9bfa63db
authored
Sep 10, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unwrap aggregates of size 1 when writing errors
Also, only use aggregate in get when we actually are dealing with multiple errors.
parent
19a2a103
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
15 deletions
+35
-15
get.go
pkg/kubectl/cmd/get.go
+16
-15
helpers.go
pkg/kubectl/cmd/util/helpers.go
+5
-0
errors.go
pkg/util/errors/errors.go
+14
-0
No files found.
pkg/kubectl/cmd/get.go
View file @
9bfa63db
...
@@ -301,22 +301,23 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
...
@@ -301,22 +301,23 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
return
err
return
err
}
}
allErrs
:=
[]
error
{}
// the outermost object will be converted to the output-version, but inner
// objects can use their mappings
version
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
if
err
!=
nil
{
return
err
}
var
errs
[]
error
singular
:=
false
singular
:=
false
infos
,
err
:=
r
.
IntoSingular
(
&
singular
)
.
Infos
()
infos
,
err
:=
r
.
IntoSingular
(
&
singular
)
.
Infos
()
if
err
!=
nil
{
if
err
!=
nil
{
if
singular
{
if
singular
{
return
err
return
err
}
}
allErrs
=
append
(
allE
rrs
,
err
)
errs
=
append
(
e
rrs
,
err
)
}
}
// the outermost object will be converted to the output-version, but inner
// objects can use their mappings
version
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
if
err
!=
nil
{
return
err
}
res
:=
""
res
:=
""
if
len
(
infos
)
>
0
{
if
len
(
infos
)
>
0
{
res
=
infos
[
0
]
.
ResourceMapping
()
.
Resource
res
=
infos
[
0
]
.
ResourceMapping
()
.
Resource
...
@@ -329,20 +330,20 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
...
@@ -329,20 +330,20 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
isList
:=
meta
.
IsListType
(
obj
)
isList
:=
meta
.
IsListType
(
obj
)
if
isList
{
if
isList
{
filteredResourceCount
,
items
,
err
s
:=
cmdutil
.
FilterResourceList
(
obj
,
filterFuncs
,
filterOpts
)
filteredResourceCount
,
items
,
err
:=
cmdutil
.
FilterResourceList
(
obj
,
filterFuncs
,
filterOpts
)
if
err
s
!=
nil
{
if
err
!=
nil
{
return
err
s
return
err
}
}
filteredObj
,
err
:=
cmdutil
.
ObjectListToVersionedObject
(
items
,
version
)
filteredObj
,
err
:=
cmdutil
.
ObjectListToVersionedObject
(
items
,
version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
filteredObj
,
out
);
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
filteredObj
,
out
);
err
!=
nil
{
allErrs
=
append
(
allE
rrs
,
err
)
errs
=
append
(
e
rrs
,
err
)
}
}
cmdutil
.
PrintFilterCount
(
filteredResourceCount
,
res
,
errOut
,
filterOpts
)
cmdutil
.
PrintFilterCount
(
filteredResourceCount
,
res
,
errOut
,
filterOpts
)
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
Reduce
(
utilerrors
.
Flatten
(
utilerrors
.
NewAggregate
(
errs
))
)
}
}
filteredResourceCount
:=
0
filteredResourceCount
:=
0
...
@@ -350,14 +351,14 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
...
@@ -350,14 +351,14 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"Unable to filter resource: %v"
,
err
)
glog
.
V
(
2
)
.
Infof
(
"Unable to filter resource: %v"
,
err
)
}
else
if
err
:=
printer
.
PrintObj
(
obj
,
out
);
err
!=
nil
{
}
else
if
err
:=
printer
.
PrintObj
(
obj
,
out
);
err
!=
nil
{
allErrs
=
append
(
allE
rrs
,
err
)
errs
=
append
(
e
rrs
,
err
)
}
}
}
else
if
isFiltered
{
}
else
if
isFiltered
{
filteredResourceCount
++
filteredResourceCount
++
}
}
cmdutil
.
PrintFilterCount
(
filteredResourceCount
,
res
,
errOut
,
filterOpts
)
cmdutil
.
PrintFilterCount
(
filteredResourceCount
,
res
,
errOut
,
filterOpts
)
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
Reduce
(
utilerrors
.
Flatten
(
utilerrors
.
NewAggregate
(
errs
))
)
}
}
allErrs
:=
[]
error
{}
allErrs
:=
[]
error
{}
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
9bfa63db
...
@@ -122,6 +122,11 @@ func checkErrWithPrefix(prefix string, err error) {
...
@@ -122,6 +122,11 @@ func checkErrWithPrefix(prefix string, err error) {
// checkErr formats a given error as a string and calls the passed handleErr
// checkErr formats a given error as a string and calls the passed handleErr
// func with that string and an kubectl exit code.
// func with that string and an kubectl exit code.
func
checkErr
(
prefix
string
,
err
error
,
handleErr
func
(
string
,
int
))
{
func
checkErr
(
prefix
string
,
err
error
,
handleErr
func
(
string
,
int
))
{
// unwrap aggregates of 1
if
agg
,
ok
:=
err
.
(
utilerrors
.
Aggregate
);
ok
&&
len
(
agg
.
Errors
())
==
1
{
err
=
agg
.
Errors
()[
0
]
}
switch
{
switch
{
case
err
==
nil
:
case
err
==
nil
:
return
return
...
...
pkg/util/errors/errors.go
View file @
9bfa63db
...
@@ -147,6 +147,20 @@ func Flatten(agg Aggregate) Aggregate {
...
@@ -147,6 +147,20 @@ func Flatten(agg Aggregate) Aggregate {
return
NewAggregate
(
result
)
return
NewAggregate
(
result
)
}
}
// Reduce will return err or, if err is an Aggregate and only has one item,
// the first item in the aggregate.
func
Reduce
(
err
error
)
error
{
if
agg
,
ok
:=
err
.
(
Aggregate
);
ok
&&
err
!=
nil
{
switch
len
(
agg
.
Errors
())
{
case
1
:
return
agg
.
Errors
()[
0
]
case
0
:
return
nil
}
}
return
err
}
// AggregateGoroutines runs the provided functions in parallel, stuffing all
// AggregateGoroutines runs the provided functions in parallel, stuffing all
// non-nil errors into the returned Aggregate.
// non-nil errors into the returned Aggregate.
// Returns nil if all the functions complete successfully.
// Returns nil if all the functions complete successfully.
...
...
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