mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			83 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
/*
 | 
						|
Copyright 2016 The Kubernetes Authors.
 | 
						|
 | 
						|
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"
 | 
						|
	extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
 | 
						|
	"k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake"
 | 
						|
	"k8s.io/kubernetes/pkg/controller"
 | 
						|
	"k8s.io/kubernetes/pkg/controller/informers"
 | 
						|
	"k8s.io/kubernetes/pkg/runtime"
 | 
						|
)
 | 
						|
 | 
						|
func TestScaleDownOldReplicaSets(t *testing.T) {
 | 
						|
	tests := []struct {
 | 
						|
		oldRSSizes []int
 | 
						|
		d          *extensions.Deployment
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			oldRSSizes: []int{3},
 | 
						|
			d:          newDeployment("foo", 3, nil, nil, nil, map[string]string{"foo": "bar"}),
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	for i := range tests {
 | 
						|
		t.Logf("running scenario %d", i)
 | 
						|
		test := tests[i]
 | 
						|
 | 
						|
		var oldRSs []*extensions.ReplicaSet
 | 
						|
		var expected []runtime.Object
 | 
						|
 | 
						|
		for n, size := range test.oldRSSizes {
 | 
						|
			rs := newReplicaSet(test.d, fmt.Sprintf("%s-%d", test.d.Name, n), size)
 | 
						|
			oldRSs = append(oldRSs, rs)
 | 
						|
 | 
						|
			objCopy, err := api.Scheme.Copy(rs)
 | 
						|
			if err != nil {
 | 
						|
				t.Errorf("unexpected error while deep-copying: %v", err)
 | 
						|
				continue
 | 
						|
			}
 | 
						|
			rsCopy := objCopy.(*extensions.ReplicaSet)
 | 
						|
 | 
						|
			zero := int32(0)
 | 
						|
			rsCopy.Spec.Replicas = &zero
 | 
						|
			expected = append(expected, rsCopy)
 | 
						|
 | 
						|
			if *(oldRSs[n].Spec.Replicas) == *(expected[n].(*extensions.ReplicaSet).Spec.Replicas) {
 | 
						|
				t.Errorf("broken test - original and expected RS have the same size")
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		kc := fake.NewSimpleClientset(expected...)
 | 
						|
		informers := informers.NewSharedInformerFactory(kc, nil, controller.NoResyncPeriodFunc())
 | 
						|
		c := NewDeploymentController(informers.Deployments(), informers.ReplicaSets(), informers.Pods(), kc)
 | 
						|
 | 
						|
		c.scaleDownOldReplicaSetsForRecreate(oldRSs, test.d)
 | 
						|
		for j := range oldRSs {
 | 
						|
			rs := oldRSs[j]
 | 
						|
 | 
						|
			if *rs.Spec.Replicas != 0 {
 | 
						|
				t.Errorf("rs %q has non-zero replicas", rs.Name)
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |