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
da03746b
Commit
da03746b
authored
Sep 01, 2015
by
feihujiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Aggregate errors when validate kubectl required parameters
parent
2f9652c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
label.go
pkg/kubectl/cmd/label.go
+4
-2
generate.go
pkg/kubectl/generate.go
+4
-2
No files found.
pkg/kubectl/cmd/label.go
View file @
da03746b
...
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors"
)
const
(
...
...
@@ -78,12 +79,13 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
}
func
validateNoOverwrites
(
meta
*
api
.
ObjectMeta
,
labels
map
[
string
]
string
)
error
{
allErrs
:=
[]
error
{}
for
key
:=
range
labels
{
if
value
,
found
:=
meta
.
Labels
[
key
];
found
{
return
fmt
.
Errorf
(
"'%s' already has a value (%s), and --overwrite is false"
,
key
,
value
)
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"'%s' already has a value (%s), and --overwrite is false"
,
key
,
value
)
)
}
}
return
nil
return
errors
.
NewAggregate
(
allErrs
)
}
func
parseLabels
(
spec
[]
string
)
(
map
[
string
]
string
,
[]
string
,
error
)
{
...
...
pkg/kubectl/generate.go
View file @
da03746b
...
...
@@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/errors"
)
// GeneratorParam is a parameter for a generator
...
...
@@ -50,15 +51,16 @@ func IsZero(i interface{}) bool {
// ValidateParams ensures that all required params are present in the params map
func
ValidateParams
(
paramSpec
[]
GeneratorParam
,
params
map
[
string
]
interface
{})
error
{
allErrs
:=
[]
error
{}
for
ix
:=
range
paramSpec
{
if
paramSpec
[
ix
]
.
Required
{
value
,
found
:=
params
[
paramSpec
[
ix
]
.
Name
]
if
!
found
||
IsZero
(
value
)
{
return
fmt
.
Errorf
(
"Parameter: %s is required"
,
paramSpec
[
ix
]
.
Name
)
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"Parameter: %s is required"
,
paramSpec
[
ix
]
.
Name
)
)
}
}
}
return
nil
return
errors
.
NewAggregate
(
allErrs
)
}
// MakeParams is a utility that creates generator parameters from a command line
...
...
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