2015-10-05 21:28:46 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package deployment
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-21 07:06:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-10-09 22:04:41 +00:00
|
|
|
exp "k8s.io/kubernetes/pkg/apis/extensions"
|
2016-02-16 22:16:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
2015-10-05 21:28:46 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/record"
|
2016-01-15 05:00:58 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/testing/core"
|
2015-09-21 07:06:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller"
|
2015-10-05 21:28:46 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-09-21 07:06:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util"
|
2015-11-10 06:28:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/intstr"
|
2015-10-05 21:28:46 +00:00
|
|
|
)
|
|
|
|
|
2016-02-29 23:15:55 +00:00
|
|
|
func rs(name string, replicas int, selector map[string]string) *exp.ReplicaSet {
|
|
|
|
return &exp.ReplicaSet{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: exp.ReplicaSetSpec{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(replicas),
|
2016-02-29 23:15:55 +00:00
|
|
|
Selector: &unversioned.LabelSelector{MatchLabels: selector},
|
2016-03-09 21:11:13 +00:00
|
|
|
Template: api.PodTemplateSpec{},
|
2016-02-29 23:15:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRSWithStatus(name string, specReplicas, statusReplicas int, selector map[string]string) *exp.ReplicaSet {
|
|
|
|
rs := rs(name, specReplicas, selector)
|
|
|
|
rs.Status = exp.ReplicaSetStatus{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(statusReplicas),
|
2016-02-29 23:15:55 +00:00
|
|
|
}
|
|
|
|
return rs
|
|
|
|
}
|
|
|
|
|
2016-06-07 23:58:18 +00:00
|
|
|
func deployment(name string, replicas int, maxSurge, maxUnavailable intstr.IntOrString, selector map[string]string) exp.Deployment {
|
2016-02-29 23:15:55 +00:00
|
|
|
return exp.Deployment{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: exp.DeploymentSpec{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(replicas),
|
2016-06-07 23:58:18 +00:00
|
|
|
Selector: &unversioned.LabelSelector{MatchLabels: selector},
|
2016-02-29 23:15:55 +00:00
|
|
|
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 {
|
2016-04-27 04:35:14 +00:00
|
|
|
var v *int32
|
|
|
|
if revisionHistoryLimit != nil {
|
|
|
|
v = new(int32)
|
|
|
|
*v = int32(*revisionHistoryLimit)
|
|
|
|
}
|
2016-02-29 23:15:55 +00:00
|
|
|
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{},
|
|
|
|
},
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(replicas),
|
2016-02-29 23:15:55 +00:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-27 04:35:14 +00:00
|
|
|
RevisionHistoryLimit: v,
|
2016-02-29 23:15:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(replicas),
|
2016-03-09 21:11:13 +00:00
|
|
|
Template: d.Spec.Template,
|
2016-02-29 23:15:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListOptions() api.ListOptions {
|
|
|
|
return api.ListOptions{}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
|
2015-10-05 21:28:46 +00:00
|
|
|
tests := []struct {
|
|
|
|
deploymentReplicas int
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge intstr.IntOrString
|
2015-10-05 21:28:46 +00:00
|
|
|
oldReplicas int
|
|
|
|
newReplicas int
|
|
|
|
scaleExpected bool
|
|
|
|
expectedNewReplicas int
|
|
|
|
}{
|
|
|
|
{
|
2015-10-07 20:13:18 +00:00
|
|
|
// Should not scale up.
|
2015-10-05 21:28:46 +00:00
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge: intstr.FromInt(0),
|
2015-10-05 21:28:46 +00:00
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
|
|
|
scaleExpected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedNewReplicas: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
oldReplicas: 5,
|
|
|
|
newReplicas: 0,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedNewReplicas: 7,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 2,
|
|
|
|
scaleExpected: false,
|
|
|
|
},
|
2015-10-07 20:13:18 +00:00
|
|
|
{
|
|
|
|
// Should scale down.
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge: intstr.FromInt(2),
|
2015-10-07 20:13:18 +00:00
|
|
|
oldReplicas: 2,
|
|
|
|
newReplicas: 11,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedNewReplicas: 10,
|
|
|
|
},
|
2015-10-05 21:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Logf("executing scenario %d", i)
|
2016-01-20 00:40:18 +00:00
|
|
|
newRS := rs("foo-v2", test.newReplicas, nil)
|
|
|
|
oldRS := rs("foo-v2", test.oldReplicas, nil)
|
2016-02-06 02:43:02 +00:00
|
|
|
allRSs := []*exp.ReplicaSet{newRS, oldRS}
|
2016-06-07 23:58:18 +00:00
|
|
|
deployment := deployment("foo", test.deploymentReplicas, test.maxSurge, intstr.FromInt(0), nil)
|
2016-01-15 05:00:58 +00:00
|
|
|
fake := fake.Clientset{}
|
2015-10-05 21:28:46 +00:00
|
|
|
controller := &DeploymentController{
|
2016-02-28 02:13:32 +00:00
|
|
|
client: &fake,
|
|
|
|
eventRecorder: &record.FakeRecorder{},
|
2015-10-05 21:28:46 +00:00
|
|
|
}
|
2016-02-28 02:13:32 +00:00
|
|
|
scaled, err := controller.reconcileNewReplicaSet(allRSs, newRS, &deployment)
|
2015-10-05 21:28:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !test.scaleExpected {
|
|
|
|
if scaled || len(fake.Actions()) > 0 {
|
|
|
|
t.Errorf("unexpected scaling: %v", fake.Actions())
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if test.scaleExpected && !scaled {
|
|
|
|
t.Errorf("expected scaling to occur")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(fake.Actions()) != 1 {
|
|
|
|
t.Errorf("expected 1 action during scale, got: %v", fake.Actions())
|
|
|
|
continue
|
|
|
|
}
|
2016-04-13 22:33:15 +00:00
|
|
|
updated := fake.Actions()[0].(core.UpdateAction).GetObject().(*exp.ReplicaSet)
|
2016-04-27 04:35:14 +00:00
|
|
|
if e, a := test.expectedNewReplicas, int(updated.Spec.Replicas); e != a {
|
2015-10-05 21:28:46 +00:00
|
|
|
t.Errorf("expected update to %d replicas, got %d", e, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
|
2016-01-30 07:09:26 +00:00
|
|
|
tests := []struct {
|
|
|
|
deploymentReplicas int
|
|
|
|
maxUnavailable intstr.IntOrString
|
|
|
|
oldReplicas int
|
|
|
|
newReplicas int
|
2016-01-20 00:40:18 +00:00
|
|
|
readyPodsFromOldRS int
|
|
|
|
readyPodsFromNewRS int
|
2016-01-30 07:09:26 +00:00
|
|
|
scaleExpected bool
|
|
|
|
expectedOldReplicas int
|
|
|
|
}{
|
|
|
|
{
|
2016-03-07 10:18:58 +00:00
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(0),
|
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
|
|
|
readyPodsFromOldRS: 10,
|
|
|
|
readyPodsFromNewRS: 0,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 9,
|
2016-01-30 07:09:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(2),
|
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
2016-01-20 00:40:18 +00:00
|
|
|
readyPodsFromOldRS: 10,
|
|
|
|
readyPodsFromNewRS: 0,
|
2016-01-30 07:09:26 +00:00
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 8,
|
|
|
|
},
|
2016-01-20 00:40:18 +00:00
|
|
|
{ // expect unhealthy replicas from old replica sets been cleaned up
|
2016-01-30 07:09:26 +00:00
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(2),
|
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
2016-01-20 00:40:18 +00:00
|
|
|
readyPodsFromOldRS: 8,
|
|
|
|
readyPodsFromNewRS: 0,
|
2016-01-30 07:09:26 +00:00
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 8,
|
|
|
|
},
|
2016-01-20 00:40:18 +00:00
|
|
|
{ // expect 1 unhealthy replica from old replica sets been cleaned up, and 1 ready pod been scaled down
|
2016-01-30 07:09:26 +00:00
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(2),
|
|
|
|
oldReplicas: 10,
|
|
|
|
newReplicas: 0,
|
2016-01-20 00:40:18 +00:00
|
|
|
readyPodsFromOldRS: 9,
|
|
|
|
readyPodsFromNewRS: 0,
|
2016-01-30 07:09:26 +00:00
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 8,
|
|
|
|
},
|
2016-01-20 00:40:18 +00:00
|
|
|
{ // the unavailable pods from the newRS would not make us scale down old RSs in a further step
|
2016-01-30 07:09:26 +00:00
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(2),
|
|
|
|
oldReplicas: 8,
|
|
|
|
newReplicas: 2,
|
2016-01-20 00:40:18 +00:00
|
|
|
readyPodsFromOldRS: 8,
|
|
|
|
readyPodsFromNewRS: 0,
|
2016-01-30 07:09:26 +00:00
|
|
|
scaleExpected: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Logf("executing scenario %d", i)
|
|
|
|
|
|
|
|
newSelector := map[string]string{"foo": "new"}
|
|
|
|
oldSelector := map[string]string{"foo": "old"}
|
2016-01-20 00:40:18 +00:00
|
|
|
newRS := rs("foo-new", test.newReplicas, newSelector)
|
|
|
|
oldRS := rs("foo-old", test.oldReplicas, oldSelector)
|
|
|
|
oldRSs := []*exp.ReplicaSet{oldRS}
|
|
|
|
allRSs := []*exp.ReplicaSet{oldRS, newRS}
|
2016-01-30 07:09:26 +00:00
|
|
|
|
2016-06-07 23:58:18 +00:00
|
|
|
deployment := deployment("foo", test.deploymentReplicas, intstr.FromInt(0), test.maxUnavailable, newSelector)
|
2016-01-30 07:09:26 +00:00
|
|
|
fakeClientset := fake.Clientset{}
|
|
|
|
fakeClientset.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
switch action.(type) {
|
|
|
|
case core.ListAction:
|
|
|
|
podList := &api.PodList{}
|
2016-01-20 00:40:18 +00:00
|
|
|
for podIndex := 0; podIndex < test.readyPodsFromOldRS; podIndex++ {
|
2016-01-30 07:09:26 +00:00
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-oldReadyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
Labels: oldSelector,
|
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-01-20 00:40:18 +00:00
|
|
|
for podIndex := 0; podIndex < test.oldReplicas-test.readyPodsFromOldRS; podIndex++ {
|
2016-01-30 07:09:26 +00:00
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-oldUnhealthyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
Labels: oldSelector,
|
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionFalse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-01-20 00:40:18 +00:00
|
|
|
for podIndex := 0; podIndex < test.readyPodsFromNewRS; podIndex++ {
|
2016-01-30 07:09:26 +00:00
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-newReadyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
Labels: newSelector,
|
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-01-20 00:40:18 +00:00
|
|
|
for podIndex := 0; podIndex < test.oldReplicas-test.readyPodsFromOldRS; podIndex++ {
|
2016-01-30 07:09:26 +00:00
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-newUnhealthyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
Labels: newSelector,
|
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionFalse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return true, podList, nil
|
|
|
|
}
|
|
|
|
return false, nil, nil
|
|
|
|
})
|
|
|
|
controller := &DeploymentController{
|
2016-02-28 02:13:32 +00:00
|
|
|
client: &fakeClientset,
|
|
|
|
eventRecorder: &record.FakeRecorder{},
|
2016-01-30 07:09:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-28 02:13:32 +00:00
|
|
|
scaled, err := controller.reconcileOldReplicaSets(allRSs, oldRSs, newRS, &deployment)
|
2016-01-30 07:09:26 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !test.scaleExpected && scaled {
|
|
|
|
t.Errorf("unexpected scaling: %v", fakeClientset.Actions())
|
|
|
|
}
|
|
|
|
if test.scaleExpected && !scaled {
|
|
|
|
t.Errorf("expected scaling to occur")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeploymentController_cleanupUnhealthyReplicas(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
oldReplicas int
|
|
|
|
readyPods int
|
|
|
|
unHealthyPods int
|
|
|
|
maxCleanupCount int
|
|
|
|
cleanupCountExpected int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
oldReplicas: 10,
|
|
|
|
readyPods: 8,
|
|
|
|
unHealthyPods: 2,
|
|
|
|
maxCleanupCount: 1,
|
|
|
|
cleanupCountExpected: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
oldReplicas: 10,
|
|
|
|
readyPods: 8,
|
|
|
|
unHealthyPods: 2,
|
|
|
|
maxCleanupCount: 3,
|
|
|
|
cleanupCountExpected: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
oldReplicas: 10,
|
|
|
|
readyPods: 8,
|
|
|
|
unHealthyPods: 2,
|
|
|
|
maxCleanupCount: 0,
|
|
|
|
cleanupCountExpected: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
oldReplicas: 10,
|
|
|
|
readyPods: 10,
|
|
|
|
unHealthyPods: 0,
|
|
|
|
maxCleanupCount: 3,
|
|
|
|
cleanupCountExpected: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Logf("executing scenario %d", i)
|
2016-01-20 00:40:18 +00:00
|
|
|
oldRS := rs("foo-v2", test.oldReplicas, nil)
|
|
|
|
oldRSs := []*exp.ReplicaSet{oldRS}
|
2016-06-07 23:58:18 +00:00
|
|
|
deployment := deployment("foo", 10, intstr.FromInt(2), intstr.FromInt(2), nil)
|
2016-01-30 07:09:26 +00:00
|
|
|
fakeClientset := fake.Clientset{}
|
|
|
|
fakeClientset.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
switch action.(type) {
|
|
|
|
case core.ListAction:
|
|
|
|
podList := &api.PodList{}
|
|
|
|
for podIndex := 0; podIndex < test.readyPods; podIndex++ {
|
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-readyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for podIndex := 0; podIndex < test.unHealthyPods; podIndex++ {
|
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-unHealthyPod-%d", oldRS.Name, podIndex),
|
2016-01-30 07:09:26 +00:00
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionFalse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return true, podList, nil
|
|
|
|
}
|
|
|
|
return false, nil, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
controller := &DeploymentController{
|
2016-02-28 02:13:32 +00:00
|
|
|
client: &fakeClientset,
|
|
|
|
eventRecorder: &record.FakeRecorder{},
|
2016-01-30 07:09:26 +00:00
|
|
|
}
|
2016-04-27 04:35:14 +00:00
|
|
|
_, cleanupCount, err := controller.cleanupUnhealthyReplicas(oldRSs, &deployment, int32(test.maxCleanupCount))
|
2016-01-30 07:09:26 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
2016-04-27 04:35:14 +00:00
|
|
|
if int(cleanupCount) != test.cleanupCountExpected {
|
2016-01-30 07:09:26 +00:00
|
|
|
t.Errorf("expected %v unhealthy replicas been cleaned up, got %v", test.cleanupCountExpected, cleanupCount)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing.T) {
|
2015-10-05 21:28:46 +00:00
|
|
|
tests := []struct {
|
|
|
|
deploymentReplicas int
|
2015-11-10 06:28:45 +00:00
|
|
|
maxUnavailable intstr.IntOrString
|
2015-10-05 21:28:46 +00:00
|
|
|
readyPods int
|
|
|
|
oldReplicas int
|
|
|
|
scaleExpected bool
|
|
|
|
expectedOldReplicas int
|
|
|
|
}{
|
|
|
|
{
|
2016-03-07 10:18:58 +00:00
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(0),
|
|
|
|
readyPods: 10,
|
|
|
|
oldReplicas: 10,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 9,
|
2015-10-05 21:28:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxUnavailable: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
readyPods: 10,
|
|
|
|
oldReplicas: 10,
|
|
|
|
scaleExpected: true,
|
|
|
|
expectedOldReplicas: 8,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxUnavailable: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
readyPods: 8,
|
|
|
|
oldReplicas: 10,
|
|
|
|
scaleExpected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
2015-11-10 06:28:45 +00:00
|
|
|
maxUnavailable: intstr.FromInt(2),
|
2015-10-05 21:28:46 +00:00
|
|
|
readyPods: 10,
|
|
|
|
oldReplicas: 0,
|
|
|
|
scaleExpected: false,
|
|
|
|
},
|
2016-03-10 23:06:38 +00:00
|
|
|
{
|
|
|
|
deploymentReplicas: 10,
|
|
|
|
maxUnavailable: intstr.FromInt(2),
|
|
|
|
readyPods: 1,
|
|
|
|
oldReplicas: 10,
|
|
|
|
scaleExpected: false,
|
|
|
|
},
|
2015-10-05 21:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Logf("executing scenario %d", i)
|
2016-01-20 00:40:18 +00:00
|
|
|
oldRS := rs("foo-v2", test.oldReplicas, nil)
|
2016-02-06 02:43:02 +00:00
|
|
|
allRSs := []*exp.ReplicaSet{oldRS}
|
|
|
|
oldRSs := []*exp.ReplicaSet{oldRS}
|
2016-06-07 23:58:18 +00:00
|
|
|
deployment := deployment("foo", test.deploymentReplicas, intstr.FromInt(0), test.maxUnavailable, map[string]string{"foo": "bar"})
|
2016-01-15 05:00:58 +00:00
|
|
|
fakeClientset := fake.Clientset{}
|
|
|
|
fakeClientset.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
2015-10-05 21:28:46 +00:00
|
|
|
switch action.(type) {
|
2016-01-15 05:00:58 +00:00
|
|
|
case core.ListAction:
|
2015-10-05 21:28:46 +00:00
|
|
|
podList := &api.PodList{}
|
|
|
|
for podIndex := 0; podIndex < test.readyPods; podIndex++ {
|
|
|
|
podList.Items = append(podList.Items, api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2016-01-20 00:40:18 +00:00
|
|
|
Name: fmt.Sprintf("%s-pod-%d", oldRS.Name, podIndex),
|
|
|
|
Labels: map[string]string{"foo": "bar"},
|
2015-10-05 21:28:46 +00:00
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
Conditions: []api.PodCondition{
|
|
|
|
{
|
|
|
|
Type: api.PodReady,
|
|
|
|
Status: api.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return true, podList, nil
|
|
|
|
}
|
|
|
|
return false, nil, nil
|
|
|
|
})
|
|
|
|
controller := &DeploymentController{
|
2016-02-28 02:13:32 +00:00
|
|
|
client: &fakeClientset,
|
|
|
|
eventRecorder: &record.FakeRecorder{},
|
2015-10-05 21:28:46 +00:00
|
|
|
}
|
2016-02-28 02:13:32 +00:00
|
|
|
scaled, err := controller.scaleDownOldReplicaSetsForRollingUpdate(allRSs, oldRSs, &deployment)
|
2015-10-05 21:28:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !test.scaleExpected {
|
2016-01-30 07:09:26 +00:00
|
|
|
if scaled != 0 {
|
2016-01-15 05:00:58 +00:00
|
|
|
t.Errorf("unexpected scaling: %v", fakeClientset.Actions())
|
2015-10-05 21:28:46 +00:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2016-01-30 07:09:26 +00:00
|
|
|
if test.scaleExpected && scaled == 0 {
|
2016-01-15 05:00:58 +00:00
|
|
|
t.Errorf("expected scaling to occur; actions: %v", fakeClientset.Actions())
|
2015-10-05 21:28:46 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
// There are both list and update actions logged, so extract the update
|
|
|
|
// action for verification.
|
2016-04-13 22:33:15 +00:00
|
|
|
var updateAction core.UpdateAction
|
2016-01-15 05:00:58 +00:00
|
|
|
for _, action := range fakeClientset.Actions() {
|
2015-10-05 21:28:46 +00:00
|
|
|
switch a := action.(type) {
|
2016-04-13 22:33:15 +00:00
|
|
|
case core.UpdateAction:
|
2015-10-05 21:28:46 +00:00
|
|
|
if updateAction != nil {
|
|
|
|
t.Errorf("expected only 1 update action; had %v and found %v", updateAction, a)
|
|
|
|
} else {
|
|
|
|
updateAction = a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if updateAction == nil {
|
|
|
|
t.Errorf("expected an update action")
|
|
|
|
continue
|
|
|
|
}
|
2016-01-20 00:40:18 +00:00
|
|
|
updated := updateAction.GetObject().(*exp.ReplicaSet)
|
2016-04-27 04:35:14 +00:00
|
|
|
if e, a := test.expectedOldReplicas, int(updated.Spec.Replicas); e != a {
|
2015-10-05 21:28:46 +00:00
|
|
|
t.Errorf("expected update to %d replicas, got %d", e, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
func TestDeploymentController_cleanupOldReplicaSets(t *testing.T) {
|
2016-01-28 06:13:07 +00:00
|
|
|
selector := map[string]string{"foo": "bar"}
|
|
|
|
|
|
|
|
tests := []struct {
|
2016-02-06 02:43:02 +00:00
|
|
|
oldRSs []*exp.ReplicaSet
|
2016-01-28 06:13:07 +00:00
|
|
|
revisionHistoryLimit int
|
|
|
|
expectedDeletions int
|
|
|
|
}{
|
|
|
|
{
|
2016-02-06 02:43:02 +00:00
|
|
|
oldRSs: []*exp.ReplicaSet{
|
2016-02-29 23:15:55 +00:00
|
|
|
newRSWithStatus("foo-1", 0, 0, selector),
|
|
|
|
newRSWithStatus("foo-2", 0, 0, selector),
|
|
|
|
newRSWithStatus("foo-3", 0, 0, selector),
|
2016-01-28 06:13:07 +00:00
|
|
|
},
|
|
|
|
revisionHistoryLimit: 1,
|
|
|
|
expectedDeletions: 2,
|
|
|
|
},
|
|
|
|
{
|
2016-02-29 23:15:55 +00:00
|
|
|
// Only delete the replica set with Spec.Replicas = Status.Replicas = 0.
|
2016-02-06 02:43:02 +00:00
|
|
|
oldRSs: []*exp.ReplicaSet{
|
2016-02-29 23:15:55 +00:00
|
|
|
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),
|
2016-01-28 06:13:07 +00:00
|
|
|
},
|
|
|
|
revisionHistoryLimit: 0,
|
|
|
|
expectedDeletions: 2,
|
|
|
|
},
|
|
|
|
{
|
2016-02-06 02:43:02 +00:00
|
|
|
oldRSs: []*exp.ReplicaSet{
|
2016-02-29 23:15:55 +00:00
|
|
|
newRSWithStatus("foo-1", 1, 1, selector),
|
|
|
|
newRSWithStatus("foo-2", 1, 1, selector),
|
2016-01-28 06:13:07 +00:00
|
|
|
},
|
|
|
|
revisionHistoryLimit: 0,
|
|
|
|
expectedDeletions: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2016-01-15 05:00:58 +00:00
|
|
|
fake := &fake.Clientset{}
|
2016-01-28 06:13:07 +00:00
|
|
|
controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
|
|
|
|
|
|
|
|
controller.eventRecorder = &record.FakeRecorder{}
|
2016-01-20 00:40:18 +00:00
|
|
|
controller.rsStoreSynced = alwaysReady
|
2016-01-28 06:13:07 +00:00
|
|
|
controller.podStoreSynced = alwaysReady
|
2016-01-20 00:40:18 +00:00
|
|
|
for _, rs := range test.oldRSs {
|
|
|
|
controller.rsStore.Add(rs)
|
2016-01-28 06:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d := newDeployment(1, &tests[i].revisionHistoryLimit)
|
2016-02-28 02:13:32 +00:00
|
|
|
controller.cleanupOldReplicaSets(test.oldRSs, d)
|
2016-01-28 06:13:07 +00:00
|
|
|
|
|
|
|
gotDeletions := 0
|
|
|
|
for _, action := range fake.Actions() {
|
|
|
|
if "delete" == action.GetVerb() {
|
|
|
|
gotDeletions++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if gotDeletions != test.expectedDeletions {
|
2016-01-20 00:40:18 +00:00
|
|
|
t.Errorf("expect %v old replica sets been deleted, but got %v", test.expectedDeletions, gotDeletions)
|
2016-01-28 06:13:07 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 07:06:45 +00:00
|
|
|
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)
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fixture struct {
|
|
|
|
t *testing.T
|
|
|
|
|
2016-01-15 05:00:58 +00:00
|
|
|
client *fake.Clientset
|
2015-09-21 07:06:45 +00:00
|
|
|
// Objects to put in the store.
|
|
|
|
dStore []*exp.Deployment
|
2016-01-20 00:40:18 +00:00
|
|
|
rsStore []*exp.ReplicaSet
|
2015-09-21 07:06:45 +00:00
|
|
|
podStore []*api.Pod
|
|
|
|
|
|
|
|
// Actions expected to happen on the client. Objects from here are also
|
|
|
|
// preloaded into NewSimpleFake.
|
2016-01-15 05:00:58 +00:00
|
|
|
actions []core.Action
|
2015-09-21 07:06:45 +00:00
|
|
|
objects *api.List
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fixture) expectUpdateDeploymentAction(d *exp.Deployment) {
|
2016-04-13 22:33:15 +00:00
|
|
|
f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "deployments"}, d.Namespace, d))
|
2015-09-21 07:06:45 +00:00
|
|
|
f.objects.Items = append(f.objects.Items, d)
|
|
|
|
}
|
|
|
|
|
2016-02-06 02:43:02 +00:00
|
|
|
func (f *fixture) expectCreateRSAction(rs *exp.ReplicaSet) {
|
2016-04-13 22:33:15 +00:00
|
|
|
f.actions = append(f.actions, core.NewCreateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs))
|
2016-01-20 00:40:18 +00:00
|
|
|
f.objects.Items = append(f.objects.Items, rs)
|
2015-09-21 07:06:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 02:43:02 +00:00
|
|
|
func (f *fixture) expectUpdateRSAction(rs *exp.ReplicaSet) {
|
2016-04-13 22:33:15 +00:00
|
|
|
f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs))
|
2016-01-20 00:40:18 +00:00
|
|
|
f.objects.Items = append(f.objects.Items, rs)
|
2015-09-21 07:06:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 23:58:52 +00:00
|
|
|
func (f *fixture) expectListPodAction(namespace string, opt api.ListOptions) {
|
2016-04-13 22:33:15 +00:00
|
|
|
f.actions = append(f.actions, core.NewListAction(unversioned.GroupVersionResource{Resource: "pods"}, namespace, opt))
|
2016-01-08 23:58:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 07:06:45 +00:00
|
|
|
func newFixture(t *testing.T) *fixture {
|
|
|
|
f := &fixture{}
|
|
|
|
f.t = t
|
|
|
|
f.objects = &api.List{}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fixture) run(deploymentName string) {
|
2016-01-15 05:00:58 +00:00
|
|
|
f.client = fake.NewSimpleClientset(f.objects)
|
2015-11-18 23:12:11 +00:00
|
|
|
c := NewDeploymentController(f.client, controller.NoResyncPeriodFunc)
|
2015-12-22 22:28:44 +00:00
|
|
|
c.eventRecorder = &record.FakeRecorder{}
|
2016-01-20 00:40:18 +00:00
|
|
|
c.rsStoreSynced = alwaysReady
|
2015-09-21 07:06:45 +00:00
|
|
|
c.podStoreSynced = alwaysReady
|
|
|
|
for _, d := range f.dStore {
|
|
|
|
c.dStore.Store.Add(d)
|
|
|
|
}
|
2016-01-20 00:40:18 +00:00
|
|
|
for _, rs := range f.rsStore {
|
|
|
|
c.rsStore.Store.Add(rs)
|
2015-09-21 07:06:45 +00:00
|
|
|
}
|
|
|
|
for _, pod := range f.podStore {
|
2016-04-07 12:15:21 +00:00
|
|
|
c.podStore.Indexer.Add(pod)
|
2015-09-21 07:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := c.syncDeployment(deploymentName)
|
|
|
|
if err != nil {
|
|
|
|
f.t.Errorf("error syncing deployment: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actions := f.client.Actions()
|
|
|
|
for i, action := range actions {
|
|
|
|
if len(f.actions) < i+1 {
|
|
|
|
f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:])
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedAction := f.actions[i]
|
2016-04-13 22:33:15 +00:00
|
|
|
if !expectedAction.Matches(action.GetVerb(), action.GetResource().Resource) {
|
2015-09-21 07:06:45 +00:00
|
|
|
f.t.Errorf("Expected\n\t%#v\ngot\n\t%#v", expectedAction, action)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(f.actions) > len(actions) {
|
|
|
|
f.t.Errorf("%d additional expected actions:%+v", len(f.actions)-len(actions), f.actions[len(actions):])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
func TestSyncDeploymentCreatesReplicaSet(t *testing.T) {
|
2015-09-21 07:06:45 +00:00
|
|
|
f := newFixture(t)
|
|
|
|
|
2016-01-28 06:13:07 +00:00
|
|
|
d := newDeployment(1, nil)
|
2015-09-21 07:06:45 +00:00
|
|
|
f.dStore = append(f.dStore, d)
|
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
// expect that one ReplicaSet with zero replicas is created
|
2015-09-21 07:06:45 +00:00
|
|
|
// then is updated to 1 replica
|
2016-01-20 00:40:18 +00:00
|
|
|
rs := newReplicaSet(d, "deploymentrs-4186632231", 0)
|
|
|
|
updatedRS := newReplicaSet(d, "deploymentrs-4186632231", 1)
|
2015-09-21 07:06:45 +00:00
|
|
|
|
2016-01-20 00:40:18 +00:00
|
|
|
f.expectCreateRSAction(rs)
|
2016-01-13 01:52:18 +00:00
|
|
|
f.expectUpdateDeploymentAction(d)
|
2016-01-20 00:40:18 +00:00
|
|
|
f.expectUpdateRSAction(updatedRS)
|
2015-09-21 07:06:45 +00:00
|
|
|
f.expectUpdateDeploymentAction(d)
|
|
|
|
|
|
|
|
f.run(getKey(d, t))
|
|
|
|
}
|
2016-03-25 07:40:12 +00:00
|
|
|
|
|
|
|
// issue: https://github.com/kubernetes/kubernetes/issues/23218
|
|
|
|
func TestDeploymentController_dontSyncDeploymentsWithEmptyPodSelector(t *testing.T) {
|
|
|
|
fake := &fake.Clientset{}
|
|
|
|
controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
|
|
|
|
|
|
|
|
controller.eventRecorder = &record.FakeRecorder{}
|
|
|
|
controller.rsStoreSynced = alwaysReady
|
|
|
|
controller.podStoreSynced = alwaysReady
|
|
|
|
|
|
|
|
d := newDeployment(1, nil)
|
|
|
|
empty := unversioned.LabelSelector{}
|
|
|
|
d.Spec.Selector = &empty
|
|
|
|
controller.dStore.Store.Add(d)
|
|
|
|
// We expect the deployment controller to not take action here since it's configuration
|
|
|
|
// is invalid, even though no replicasets exist that match it's selector.
|
|
|
|
controller.syncDeployment(fmt.Sprintf("%s/%s", d.ObjectMeta.Namespace, d.ObjectMeta.Name))
|
|
|
|
if len(fake.Actions()) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, action := range fake.Actions() {
|
|
|
|
t.Logf("unexpected action: %#v", action)
|
|
|
|
}
|
|
|
|
t.Errorf("expected deployment controller to not take action")
|
|
|
|
}
|