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
3ee1c587
Commit
3ee1c587
authored
Oct 19, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15773 from mqliang/BE1-ErrMsg
Auto commit by PR queue bot
parents
56093b77
b6f19b14
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
38 deletions
+50
-38
validation.go
pkg/apis/extensions/validation/validation.go
+1
-1
validation_test.go
pkg/apis/extensions/validation/validation_test.go
+49
-37
No files found.
pkg/apis/extensions/validation/validation.go
View file @
3ee1c587
...
...
@@ -63,7 +63,7 @@ func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAuto
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"maxReplicas"
,
autoscaler
.
MaxReplicas
,
`must be bigger or equal to minReplicas`
))
}
if
autoscaler
.
CPUUtilization
!=
nil
&&
autoscaler
.
CPUUtilization
.
TargetPercentage
<
1
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"cpuUtilization.targetPercentage"
,
autoscaler
.
CPUUtilization
.
TargetPercentage
,
isNegativeErrorMsg
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"cpuUtilization.targetPercentage"
,
autoscaler
.
CPUUtilization
.
TargetPercentage
,
`must be bigger or equal to 1`
))
}
return
allErrs
}
...
...
pkg/apis/extensions/validation/validation_test.go
View file @
3ee1c587
...
...
@@ -63,55 +63,67 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
}
}
errorCases
:=
map
[
string
]
extensions
.
HorizontalPodAutoscaler
{
"must be bigger or equal to 1"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
errorCases
:=
[]
struct
{
horizontalPodAutoscaler
extensions
.
HorizontalPodAutoscaler
msg
string
}{
{
horizontalPodAutoscaler
:
extensions
.
HorizontalPodAutoscaler
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
},
MinReplicas
:
newInt
(
-
1
),
MaxReplicas
:
5
,
},
MinReplicas
:
newInt
(
-
1
),
MaxReplicas
:
5
,
},
msg
:
"must be bigger or equal to 1"
,
},
"must be bigger or equal to minReplicas"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
{
horizontalPodAutoscaler
:
extensions
.
HorizontalPodAutoscaler
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
},
MinReplicas
:
newInt
(
7
),
MaxReplicas
:
5
,
},
MinReplicas
:
newInt
(
7
),
MaxReplicas
:
5
,
},
msg
:
"must be bigger or equal to minReplicas"
,
},
"must be non-negative"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
{
horizontalPodAutoscaler
:
extensions
.
HorizontalPodAutoscaler
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myautoscaler"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
extensions
.
HorizontalPodAutoscalerSpec
{
ScaleRef
:
extensions
.
SubresourceReference
{
Subresource
:
"scale"
,
},
MinReplicas
:
newInt
(
1
),
MaxReplicas
:
5
,
CPUUtilization
:
&
extensions
.
CPUTargetUtilization
{
TargetPercentage
:
-
70
},
},
MinReplicas
:
newInt
(
1
),
MaxReplicas
:
5
,
CPUUtilization
:
&
extensions
.
CPUTargetUtilization
{
TargetPercentage
:
-
70
},
},
msg
:
"must be bigger or equal to 1"
,
},
}
for
k
,
v
:=
range
errorCases
{
errs
:=
ValidateHorizontalPodAutoscaler
(
&
v
)
for
_
,
c
:=
range
errorCases
{
errs
:=
ValidateHorizontalPodAutoscaler
(
&
c
.
horizontalPodAutoscaler
)
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %s"
,
k
)
}
else
if
!
strings
.
Contains
(
errs
[
0
]
.
Error
(),
k
)
{
t
.
Errorf
(
"unexpected error: %v, expected: %s"
,
errs
[
0
],
k
)
t
.
Errorf
(
"expected failure for %s"
,
c
.
msg
)
}
else
if
!
strings
.
Contains
(
errs
[
0
]
.
Error
(),
c
.
msg
)
{
t
.
Errorf
(
"unexpected error: %v, expected: %s"
,
errs
[
0
],
c
.
msg
)
}
}
}
...
...
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