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
32ababbe
Commit
32ababbe
authored
Jul 29, 2016
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error out when any RS has more available pods then its spec replicas
parent
f0fa9e58
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
rolling_test.go
pkg/controller/deployment/rolling_test.go
+7
-1
deployment_util.go
pkg/controller/deployment/util/deployment_util.go
+12
-5
No files found.
pkg/controller/deployment/rolling_test.go
View file @
32ababbe
...
@@ -390,6 +390,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -390,6 +390,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas
int
oldReplicas
int
scaleExpected
bool
scaleExpected
bool
expectedOldReplicas
int
expectedOldReplicas
int
errorExpected
bool
}{
}{
{
{
deploymentReplicas
:
10
,
deploymentReplicas
:
10
,
...
@@ -398,6 +399,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -398,6 +399,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas
:
10
,
oldReplicas
:
10
,
scaleExpected
:
true
,
scaleExpected
:
true
,
expectedOldReplicas
:
9
,
expectedOldReplicas
:
9
,
errorExpected
:
false
,
},
},
{
{
deploymentReplicas
:
10
,
deploymentReplicas
:
10
,
...
@@ -406,6 +408,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -406,6 +408,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas
:
10
,
oldReplicas
:
10
,
scaleExpected
:
true
,
scaleExpected
:
true
,
expectedOldReplicas
:
8
,
expectedOldReplicas
:
8
,
errorExpected
:
false
,
},
},
{
{
deploymentReplicas
:
10
,
deploymentReplicas
:
10
,
...
@@ -413,6 +416,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -413,6 +416,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
readyPods
:
8
,
readyPods
:
8
,
oldReplicas
:
10
,
oldReplicas
:
10
,
scaleExpected
:
false
,
scaleExpected
:
false
,
errorExpected
:
false
,
},
},
{
{
deploymentReplicas
:
10
,
deploymentReplicas
:
10
,
...
@@ -420,6 +424,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -420,6 +424,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
readyPods
:
10
,
readyPods
:
10
,
oldReplicas
:
0
,
oldReplicas
:
0
,
scaleExpected
:
false
,
scaleExpected
:
false
,
errorExpected
:
true
,
},
},
{
{
deploymentReplicas
:
10
,
deploymentReplicas
:
10
,
...
@@ -427,6 +432,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -427,6 +432,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
readyPods
:
1
,
readyPods
:
1
,
oldReplicas
:
10
,
oldReplicas
:
10
,
scaleExpected
:
false
,
scaleExpected
:
false
,
errorExpected
:
false
,
},
},
}
}
...
@@ -466,7 +472,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
...
@@ -466,7 +472,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
eventRecorder
:
&
record
.
FakeRecorder
{},
eventRecorder
:
&
record
.
FakeRecorder
{},
}
}
scaled
,
err
:=
controller
.
scaleDownOldReplicaSetsForRollingUpdate
(
allRSs
,
oldRSs
,
&
deployment
)
scaled
,
err
:=
controller
.
scaleDownOldReplicaSetsForRollingUpdate
(
allRSs
,
oldRSs
,
&
deployment
)
if
err
!=
nil
{
if
!
test
.
errorExpected
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
continue
continue
}
}
...
...
pkg/controller/deployment/util/deployment_util.go
View file @
32ababbe
...
@@ -585,7 +585,7 @@ func GetAvailablePodsForReplicaSets(c clientset.Interface, deployment *extension
...
@@ -585,7 +585,7 @@ func GetAvailablePodsForReplicaSets(c clientset.Interface, deployment *extension
// CountAvailablePodsForReplicaSets returns the number of available pods corresponding to the given pod list and replica sets.
// CountAvailablePodsForReplicaSets returns the number of available pods corresponding to the given pod list and replica sets.
// Note that the input pod list should be the pods targeted by the deployment of input replica sets.
// Note that the input pod list should be the pods targeted by the deployment of input replica sets.
func
CountAvailablePodsForReplicaSets
(
podList
*
api
.
PodList
,
rss
[]
*
extensions
.
ReplicaSet
,
minReadySeconds
int32
)
(
int32
,
error
)
{
func
CountAvailablePodsForReplicaSets
(
podList
*
api
.
PodList
,
rss
[]
*
extensions
.
ReplicaSet
,
minReadySeconds
int32
)
(
int32
,
error
)
{
rsPods
,
err
:=
filterPodsMatchingReplicaSets
(
rss
,
podList
)
rsPods
,
err
:=
filterPodsMatchingReplicaSets
(
rss
,
podList
,
minReadySeconds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -638,8 +638,8 @@ func IsPodAvailable(pod *api.Pod, minReadySeconds int32, now time.Time) bool {
...
@@ -638,8 +638,8 @@ func IsPodAvailable(pod *api.Pod, minReadySeconds int32, now time.Time) bool {
}
}
// filterPodsMatchingReplicaSets filters the given pod list and only return the ones targeted by the input replicasets
// filterPodsMatchingReplicaSets filters the given pod list and only return the ones targeted by the input replicasets
func
filterPodsMatchingReplicaSets
(
replicaSets
[]
*
extensions
.
ReplicaSet
,
podList
*
api
.
PodList
)
([]
api
.
Pod
,
error
)
{
func
filterPodsMatchingReplicaSets
(
replicaSets
[]
*
extensions
.
ReplicaSet
,
podList
*
api
.
PodList
,
minReadySeconds
int32
)
([]
api
.
Pod
,
error
)
{
rs
Pods
:=
[]
api
.
Pod
{}
allRS
Pods
:=
[]
api
.
Pod
{}
for
_
,
rs
:=
range
replicaSets
{
for
_
,
rs
:=
range
replicaSets
{
matchingFunc
,
err
:=
rsutil
.
MatchingPodsFunc
(
rs
)
matchingFunc
,
err
:=
rsutil
.
MatchingPodsFunc
(
rs
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -648,9 +648,16 @@ func filterPodsMatchingReplicaSets(replicaSets []*extensions.ReplicaSet, podList
...
@@ -648,9 +648,16 @@ func filterPodsMatchingReplicaSets(replicaSets []*extensions.ReplicaSet, podList
if
matchingFunc
==
nil
{
if
matchingFunc
==
nil
{
continue
continue
}
}
rsPods
=
append
(
rsPods
,
podutil
.
Filter
(
podList
,
matchingFunc
)
...
)
rsPods
:=
podutil
.
Filter
(
podList
,
matchingFunc
)
avaPodsCount
:=
countAvailablePods
(
rsPods
,
minReadySeconds
)
if
avaPodsCount
>
rs
.
Spec
.
Replicas
{
msg
:=
fmt
.
Sprintf
(
"Found %s/%s with %d available pods, more than its spec replicas %d"
,
rs
.
Namespace
,
rs
.
Name
,
avaPodsCount
,
rs
.
Spec
.
Replicas
)
glog
.
Errorf
(
"ERROR: %s"
,
msg
)
return
nil
,
fmt
.
Errorf
(
msg
)
}
}
return
rsPods
,
nil
allRSPods
=
append
(
allRSPods
,
podutil
.
Filter
(
podList
,
matchingFunc
)
...
)
}
return
allRSPods
,
nil
}
}
// Revision returns the revision number of the input replica set
// Revision returns the revision number of the input replica set
...
...
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