mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	Fix expectations in deployment controller test
Since fake clientset now correctly tracks objects created by deployment controller, it triggers different controller behavior: controller only creates replica set once and updates deployment once.
This commit is contained in:
		| @@ -44,6 +44,7 @@ func rs(name string, replicas int, selector map[string]string, timestamp unversi | |||||||
| 		ObjectMeta: api.ObjectMeta{ | 		ObjectMeta: api.ObjectMeta{ | ||||||
| 			Name:              name, | 			Name:              name, | ||||||
| 			CreationTimestamp: timestamp, | 			CreationTimestamp: timestamp, | ||||||
|  | 			Namespace:         api.NamespaceDefault, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: exp.ReplicaSetSpec{ | 		Spec: exp.ReplicaSetSpec{ | ||||||
| 			Replicas: int32(replicas), | 			Replicas: int32(replicas), | ||||||
| @@ -64,7 +65,8 @@ func newRSWithStatus(name string, specReplicas, statusReplicas int, selector map | |||||||
| func deployment(name string, replicas int, maxSurge, maxUnavailable intstr.IntOrString, selector map[string]string) exp.Deployment { | func deployment(name string, replicas int, maxSurge, maxUnavailable intstr.IntOrString, selector map[string]string) exp.Deployment { | ||||||
| 	return exp.Deployment{ | 	return exp.Deployment{ | ||||||
| 		ObjectMeta: api.ObjectMeta{ | 		ObjectMeta: api.ObjectMeta{ | ||||||
| 			Name: name, | 			Name:      name, | ||||||
|  | 			Namespace: api.NamespaceDefault, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: exp.DeploymentSpec{ | 		Spec: exp.DeploymentSpec{ | ||||||
| 			Replicas: int32(replicas), | 			Replicas: int32(replicas), | ||||||
| @@ -142,10 +144,6 @@ func newReplicaSet(d *exp.Deployment, name string, replicas int) *exp.ReplicaSet | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func newListOptions() api.ListOptions { |  | ||||||
| 	return api.ListOptions{} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // TestScale tests proportional scaling of deployments. Note that fenceposts for | // TestScale tests proportional scaling of deployments. Note that fenceposts for | ||||||
| // rolling out (maxUnavailable, maxSurge) have no meaning for simple scaling other | // rolling out (maxUnavailable, maxSurge) have no meaning for simple scaling other | ||||||
| // than recording maxSurge as part of the max-replicas annotation that is taken | // than recording maxSurge as part of the max-replicas annotation that is taken | ||||||
| @@ -966,22 +964,25 @@ type fixture struct { | |||||||
| 	// Actions expected to happen on the client. Objects from here are also | 	// Actions expected to happen on the client. Objects from here are also | ||||||
| 	// preloaded into NewSimpleFake. | 	// preloaded into NewSimpleFake. | ||||||
| 	actions []core.Action | 	actions []core.Action | ||||||
| 	objects *api.List | 	objects []runtime.Object | ||||||
| } | } | ||||||
|  |  | ||||||
| func (f *fixture) expectUpdateDeploymentAction(d *exp.Deployment) { | func (f *fixture) expectUpdateDeploymentAction(d *exp.Deployment) { | ||||||
| 	f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "deployments"}, d.Namespace, d)) | 	f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "deployments"}, d.Namespace, d)) | ||||||
| 	f.objects.Items = append(f.objects.Items, d) | } | ||||||
|  |  | ||||||
|  | func (f *fixture) expectUpdateDeploymentStatusAction(d *exp.Deployment) { | ||||||
|  | 	action := core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "deployments"}, d.Namespace, d) | ||||||
|  | 	action.Subresource = "status" | ||||||
|  | 	f.actions = append(f.actions, action) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (f *fixture) expectCreateRSAction(rs *exp.ReplicaSet) { | func (f *fixture) expectCreateRSAction(rs *exp.ReplicaSet) { | ||||||
| 	f.actions = append(f.actions, core.NewCreateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs)) | 	f.actions = append(f.actions, core.NewCreateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs)) | ||||||
| 	f.objects.Items = append(f.objects.Items, rs) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (f *fixture) expectUpdateRSAction(rs *exp.ReplicaSet) { | func (f *fixture) expectUpdateRSAction(rs *exp.ReplicaSet) { | ||||||
| 	f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs)) | 	f.actions = append(f.actions, core.NewUpdateAction(unversioned.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs)) | ||||||
| 	f.objects.Items = append(f.objects.Items, rs) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (f *fixture) expectListPodAction(namespace string, opt api.ListOptions) { | func (f *fixture) expectListPodAction(namespace string, opt api.ListOptions) { | ||||||
| @@ -991,12 +992,12 @@ func (f *fixture) expectListPodAction(namespace string, opt api.ListOptions) { | |||||||
| func newFixture(t *testing.T) *fixture { | func newFixture(t *testing.T) *fixture { | ||||||
| 	f := &fixture{} | 	f := &fixture{} | ||||||
| 	f.t = t | 	f.t = t | ||||||
| 	f.objects = &api.List{} | 	f.objects = []runtime.Object{} | ||||||
| 	return f | 	return f | ||||||
| } | } | ||||||
|  |  | ||||||
| func (f *fixture) run(deploymentName string) { | func (f *fixture) run(deploymentName string) { | ||||||
| 	f.client = fake.NewSimpleClientset(f.objects) | 	f.client = fake.NewSimpleClientset(f.objects...) | ||||||
| 	c := NewDeploymentController(f.client, controller.NoResyncPeriodFunc) | 	c := NewDeploymentController(f.client, controller.NoResyncPeriodFunc) | ||||||
| 	c.eventRecorder = &record.FakeRecorder{} | 	c.eventRecorder = &record.FakeRecorder{} | ||||||
| 	c.rsStoreSynced = alwaysReady | 	c.rsStoreSynced = alwaysReady | ||||||
| @@ -1040,16 +1041,13 @@ func TestSyncDeploymentCreatesReplicaSet(t *testing.T) { | |||||||
|  |  | ||||||
| 	d := newDeployment(1, nil) | 	d := newDeployment(1, nil) | ||||||
| 	f.dStore = append(f.dStore, d) | 	f.dStore = append(f.dStore, d) | ||||||
|  | 	f.objects = append(f.objects, d) | ||||||
|  |  | ||||||
| 	// expect that one ReplicaSet with zero replicas is created | 	rs := newReplicaSet(d, "deploymentrs-4186632231", 1) | ||||||
| 	// then is updated to 1 replica |  | ||||||
| 	rs := newReplicaSet(d, "deploymentrs-4186632231", 0) |  | ||||||
| 	updatedRS := newReplicaSet(d, "deploymentrs-4186632231", 1) |  | ||||||
|  |  | ||||||
| 	f.expectCreateRSAction(rs) | 	f.expectCreateRSAction(rs) | ||||||
| 	f.expectUpdateDeploymentAction(d) | 	f.expectUpdateDeploymentAction(d) | ||||||
| 	f.expectUpdateRSAction(updatedRS) | 	f.expectUpdateDeploymentStatusAction(d) | ||||||
| 	f.expectUpdateDeploymentAction(d) |  | ||||||
|  |  | ||||||
| 	f.run(getKey(d, t)) | 	f.run(getKey(d, t)) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user