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
c9bd9e9c
Commit
c9bd9e9c
authored
Feb 29, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22223 from nikhiljindal/deploymente2eFlake
Auto commit by PR queue bot
parents
a608cc94
2019d18e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
96 deletions
+116
-96
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+1
-1
deployment_controller_test.go
pkg/controller/deployment/deployment_controller_test.go
+115
-95
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
c9bd9e9c
...
...
@@ -992,7 +992,7 @@ func (dc *DeploymentController) cleanupOldReplicaSets(oldRSs []*extensions.Repli
for
i
:=
0
;
i
<
diff
;
i
++
{
rs
:=
oldRSs
[
i
]
// Avoid delete replica set with non-zero replica counts
if
rs
.
Spec
.
Replicas
!=
0
||
rs
.
Generation
>
rs
.
Status
.
ObservedGeneration
{
if
rs
.
S
tatus
.
Replicas
!=
0
||
rs
.
S
pec
.
Replicas
!=
0
||
rs
.
Generation
>
rs
.
Status
.
ObservedGeneration
{
continue
}
if
err
:=
dc
.
client
.
Extensions
()
.
ReplicaSets
(
rs
.
Namespace
)
.
Delete
(
rs
.
Name
,
nil
);
err
!=
nil
&&
!
errors
.
IsNotFound
(
err
)
{
...
...
pkg/controller/deployment/deployment_controller_test.go
View file @
c9bd9e9c
...
...
@@ -34,6 +34,102 @@ import (
"k8s.io/kubernetes/pkg/util/intstr"
)
func
rs
(
name
string
,
replicas
int
,
selector
map
[
string
]
string
)
*
exp
.
ReplicaSet
{
return
&
exp
.
ReplicaSet
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
exp
.
ReplicaSetSpec
{
Replicas
:
replicas
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
selector
},
Template
:
&
api
.
PodTemplateSpec
{},
},
}
}
func
newRSWithStatus
(
name
string
,
specReplicas
,
statusReplicas
int
,
selector
map
[
string
]
string
)
*
exp
.
ReplicaSet
{
rs
:=
rs
(
name
,
specReplicas
,
selector
)
rs
.
Status
=
exp
.
ReplicaSetStatus
{
Replicas
:
statusReplicas
,
}
return
rs
}
func
deployment
(
name
string
,
replicas
int
,
maxSurge
,
maxUnavailable
intstr
.
IntOrString
)
exp
.
Deployment
{
return
exp
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
exp
.
DeploymentSpec
{
Replicas
:
replicas
,
Strategy
:
exp
.
DeploymentStrategy
{
Type
:
exp
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
exp
.
RollingUpdateDeployment
{
MaxSurge
:
maxSurge
,
MaxUnavailable
:
maxUnavailable
,
},
},
},
}
}
var
alwaysReady
=
func
()
bool
{
return
true
}
func
newDeployment
(
replicas
int
,
revisionHistoryLimit
*
int
)
*
exp
.
Deployment
{
d
:=
exp
.
Deployment
{
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
testapi
.
Default
.
GroupVersion
()
.
String
()},
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
util
.
NewUUID
(),
Name
:
"foobar"
,
Namespace
:
api
.
NamespaceDefault
,
ResourceVersion
:
"18"
,
},
Spec
:
exp
.
DeploymentSpec
{
Strategy
:
exp
.
DeploymentStrategy
{
Type
:
exp
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
exp
.
RollingUpdateDeployment
{},
},
Replicas
:
replicas
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
Template
:
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
},
},
RevisionHistoryLimit
:
revisionHistoryLimit
,
},
}
return
&
d
}
func
newReplicaSet
(
d
*
exp
.
Deployment
,
name
string
,
replicas
int
)
*
exp
.
ReplicaSet
{
return
&
exp
.
ReplicaSet
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
exp
.
ReplicaSetSpec
{
Replicas
:
replicas
,
Template
:
&
d
.
Spec
.
Template
,
},
}
}
func
newListOptions
()
api
.
ListOptions
{
return
api
.
ListOptions
{}
}
func
TestDeploymentController_reconcileNewReplicaSet
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
deploymentReplicas
int
...
...
@@ -510,25 +606,37 @@ func TestDeploymentController_cleanupOldReplicaSets(t *testing.T) {
}{
{
oldRSs
:
[]
*
exp
.
ReplicaSet
{
rs
(
"foo-1"
,
0
,
selector
),
rs
(
"foo-2"
,
0
,
selector
),
rs
(
"foo-3"
,
0
,
selector
),
newRSWithStatus
(
"foo-1"
,
0
,
0
,
selector
),
newRSWithStatus
(
"foo-2"
,
0
,
0
,
selector
),
newRSWithStatus
(
"foo-3"
,
0
,
0
,
selector
),
},
revisionHistoryLimit
:
1
,
expectedDeletions
:
2
,
},
{
// Only delete the replica set with Spec.Replicas = Status.Replicas = 0.
oldRSs
:
[]
*
exp
.
ReplicaSet
{
rs
(
"foo-1"
,
0
,
selector
),
rs
(
"foo-2"
,
0
,
selector
),
newRSWithStatus
(
"foo-1"
,
0
,
0
,
selector
),
newRSWithStatus
(
"foo-2"
,
0
,
1
,
selector
),
newRSWithStatus
(
"foo-3"
,
1
,
0
,
selector
),
newRSWithStatus
(
"foo-4"
,
1
,
1
,
selector
),
},
revisionHistoryLimit
:
0
,
expectedDeletions
:
1
,
},
{
oldRSs
:
[]
*
exp
.
ReplicaSet
{
newRSWithStatus
(
"foo-1"
,
0
,
0
,
selector
),
newRSWithStatus
(
"foo-2"
,
0
,
0
,
selector
),
},
revisionHistoryLimit
:
0
,
expectedDeletions
:
2
,
},
{
oldRSs
:
[]
*
exp
.
ReplicaSet
{
rs
(
"foo-1"
,
1
,
selector
),
rs
(
"foo-2"
,
1
,
selector
),
newRSWithStatus
(
"foo-1"
,
1
,
1
,
selector
),
newRSWithStatus
(
"foo-2"
,
1
,
1
,
selector
),
},
revisionHistoryLimit
:
0
,
expectedDeletions
:
0
,
...
...
@@ -562,76 +670,6 @@ func TestDeploymentController_cleanupOldReplicaSets(t *testing.T) {
}
}
func
rs
(
name
string
,
replicas
int
,
selector
map
[
string
]
string
)
*
exp
.
ReplicaSet
{
return
&
exp
.
ReplicaSet
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
exp
.
ReplicaSetSpec
{
Replicas
:
replicas
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
selector
},
Template
:
&
api
.
PodTemplateSpec
{},
},
}
}
func
deployment
(
name
string
,
replicas
int
,
maxSurge
,
maxUnavailable
intstr
.
IntOrString
)
exp
.
Deployment
{
return
exp
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
exp
.
DeploymentSpec
{
Replicas
:
replicas
,
Strategy
:
exp
.
DeploymentStrategy
{
Type
:
exp
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
exp
.
RollingUpdateDeployment
{
MaxSurge
:
maxSurge
,
MaxUnavailable
:
maxUnavailable
,
},
},
},
}
}
var
alwaysReady
=
func
()
bool
{
return
true
}
func
newDeployment
(
replicas
int
,
revisionHistoryLimit
*
int
)
*
exp
.
Deployment
{
d
:=
exp
.
Deployment
{
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
testapi
.
Default
.
GroupVersion
()
.
String
()},
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
util
.
NewUUID
(),
Name
:
"foobar"
,
Namespace
:
api
.
NamespaceDefault
,
ResourceVersion
:
"18"
,
},
Spec
:
exp
.
DeploymentSpec
{
Strategy
:
exp
.
DeploymentStrategy
{
Type
:
exp
.
RollingUpdateDeploymentStrategyType
,
RollingUpdate
:
&
exp
.
RollingUpdateDeployment
{},
},
Replicas
:
replicas
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"foo"
:
"bar"
}},
Template
:
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"foo"
,
"type"
:
"production"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Image
:
"foo/bar"
,
},
},
},
},
RevisionHistoryLimit
:
revisionHistoryLimit
,
},
}
return
&
d
}
func
getKey
(
d
*
exp
.
Deployment
,
t
*
testing
.
T
)
string
{
if
key
,
err
:=
controller
.
KeyFunc
(
d
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error getting key for deployment %v: %v"
,
d
.
Name
,
err
)
...
...
@@ -641,24 +679,6 @@ func getKey(d *exp.Deployment, t *testing.T) string {
}
}
func
newReplicaSet
(
d
*
exp
.
Deployment
,
name
string
,
replicas
int
)
*
exp
.
ReplicaSet
{
return
&
exp
.
ReplicaSet
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
exp
.
ReplicaSetSpec
{
Replicas
:
replicas
,
Template
:
&
d
.
Spec
.
Template
,
},
}
}
func
newListOptions
()
api
.
ListOptions
{
return
api
.
ListOptions
{}
}
type
fixture
struct
{
t
*
testing
.
T
...
...
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