mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Wait for clean old RSs statuses in the middle of Recreate rollouts
This commit is contained in:
		@@ -21,8 +21,10 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/types"
 | 
			
		||||
	"k8s.io/client-go/tools/record"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/v1"
 | 
			
		||||
	extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake"
 | 
			
		||||
	informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions"
 | 
			
		||||
@@ -82,3 +84,62 @@ func TestScaleDownOldReplicaSets(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestOldPodsRunning(t *testing.T) {
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		name string
 | 
			
		||||
 | 
			
		||||
		newRS  *extensions.ReplicaSet
 | 
			
		||||
		oldRSs []*extensions.ReplicaSet
 | 
			
		||||
		podMap map[types.UID]*v1.PodList
 | 
			
		||||
 | 
			
		||||
		expected bool
 | 
			
		||||
	}{
 | 
			
		||||
		{
 | 
			
		||||
			name:     "no old RSs",
 | 
			
		||||
			expected: false,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:     "old RSs with running pods",
 | 
			
		||||
			oldRSs:   []*extensions.ReplicaSet{rsWithUID("some-uid"), rsWithUID("other-uid")},
 | 
			
		||||
			podMap:   podMapWithUIDs([]string{"some-uid", "other-uid"}),
 | 
			
		||||
			expected: true,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:     "old RSs without pods but with non-zero status replicas",
 | 
			
		||||
			oldRSs:   []*extensions.ReplicaSet{newRSWithStatus("rs-blabla", 0, 1, nil)},
 | 
			
		||||
			expected: true,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:     "old RSs without pods or non-zero status replicas",
 | 
			
		||||
			oldRSs:   []*extensions.ReplicaSet{newRSWithStatus("rs-blabla", 0, 0, nil)},
 | 
			
		||||
			expected: false,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, test := range tests {
 | 
			
		||||
		if expected, got := test.expected, oldPodsRunning(test.newRS, test.oldRSs, test.podMap); expected != got {
 | 
			
		||||
			t.Errorf("%s: expected %t, got %t", test.name, expected, got)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func rsWithUID(uid string) *extensions.ReplicaSet {
 | 
			
		||||
	d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
 | 
			
		||||
	rs := newReplicaSet(d, fmt.Sprintf("foo-%s", uid), 0)
 | 
			
		||||
	rs.UID = types.UID(uid)
 | 
			
		||||
	return rs
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func podMapWithUIDs(uids []string) map[types.UID]*v1.PodList {
 | 
			
		||||
	podMap := make(map[types.UID]*v1.PodList)
 | 
			
		||||
	for _, uid := range uids {
 | 
			
		||||
		podMap[types.UID(uid)] = &v1.PodList{
 | 
			
		||||
			Items: []v1.Pod{
 | 
			
		||||
				{ /* supposedly a pod */ },
 | 
			
		||||
				{ /* supposedly another pod pod */ },
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return podMap
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user