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
cfe2bf10
Commit
cfe2bf10
authored
Sep 01, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13426 from feihujiang/aggregateErrorsWhenValidateParams
Aggregate errors when validate kubectl required parameters and labels
parents
a98a0f52
da03746b
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 @
cfe2bf10
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors"
)
)
// LabelOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
// LabelOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
...
@@ -86,12 +87,13 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -86,12 +87,13 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
}
}
func
validateNoOverwrites
(
meta
*
api
.
ObjectMeta
,
labels
map
[
string
]
string
)
error
{
func
validateNoOverwrites
(
meta
*
api
.
ObjectMeta
,
labels
map
[
string
]
string
)
error
{
allErrs
:=
[]
error
{}
for
key
:=
range
labels
{
for
key
:=
range
labels
{
if
value
,
found
:=
meta
.
Labels
[
key
];
found
{
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
)
{
func
parseLabels
(
spec
[]
string
)
(
map
[
string
]
string
,
[]
string
,
error
)
{
...
...
pkg/kubectl/generate.go
View file @
cfe2bf10
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/errors"
)
)
// GeneratorParam is a parameter for a generator
// GeneratorParam is a parameter for a generator
...
@@ -50,15 +51,16 @@ func IsZero(i interface{}) bool {
...
@@ -50,15 +51,16 @@ func IsZero(i interface{}) bool {
// ValidateParams ensures that all required params are present in the params map
// ValidateParams ensures that all required params are present in the params map
func
ValidateParams
(
paramSpec
[]
GeneratorParam
,
params
map
[
string
]
interface
{})
error
{
func
ValidateParams
(
paramSpec
[]
GeneratorParam
,
params
map
[
string
]
interface
{})
error
{
allErrs
:=
[]
error
{}
for
ix
:=
range
paramSpec
{
for
ix
:=
range
paramSpec
{
if
paramSpec
[
ix
]
.
Required
{
if
paramSpec
[
ix
]
.
Required
{
value
,
found
:=
params
[
paramSpec
[
ix
]
.
Name
]
value
,
found
:=
params
[
paramSpec
[
ix
]
.
Name
]
if
!
found
||
IsZero
(
value
)
{
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
// 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