VPA code adjusted to work woth new version of dependencies
- with modified eviction algorithm as most significant change
This commit is contained in:
parent
9a7b352182
commit
69db09e907
|
|
@ -31,10 +31,9 @@ import (
|
|||
"k8s.io/apimachinery/pkg/labels"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
kubeclient "k8s.io/client-go/kubernetes"
|
||||
admissionregistrationv1alpha1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1alpha1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
kubeclient "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
admissionregistrationv1alpha1 "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/admissionregistration/v1alpha1"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
|
@ -156,11 +155,7 @@ func (initializer *initializer) doUpdatePod(pod *v1.Pod) error {
|
|||
}
|
||||
|
||||
func markAsFailed(pod *v1.Pod) (*v1.Pod, error) {
|
||||
failedPodCopy, err := api.Scheme.Copy(pod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
failedPod := failedPodCopy.(*v1.Pod)
|
||||
failedPod := pod.DeepCopy()
|
||||
markInitializationFailure(failedPod)
|
||||
return failedPod, nil
|
||||
}
|
||||
|
|
@ -170,11 +165,7 @@ func markAsFailed(pod *v1.Pod) (*v1.Pod, error) {
|
|||
func (initializer *initializer) initializePod(pod *v1.Pod) (*v1.Pod, error) {
|
||||
glog.V(2).Infof("updating requirements for pod %v.", pod.Name)
|
||||
|
||||
updatedPodCopy, err := api.Scheme.Copy(pod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedPod := updatedPodCopy.(*v1.Pod)
|
||||
updatedPod := pod.DeepCopy()
|
||||
markInitializationSuccess(updatedPod)
|
||||
|
||||
vpaConfig := initializer.getMatchingVPA(pod)
|
||||
|
|
@ -360,12 +351,9 @@ func newConfiguration() *v1alpha1.InitializerConfiguration {
|
|||
APIVersions: []string{"*"},
|
||||
Resources: []string{"pods"},
|
||||
}
|
||||
// If initializer fails, allow for pod creation.
|
||||
failPolicy := v1alpha1.Ignore
|
||||
vpaInitializer := v1alpha1.Initializer{
|
||||
Name: VPAInitializerName,
|
||||
Rules: []v1alpha1.Rule{allPodsRule},
|
||||
FailurePolicy: &failPolicy,
|
||||
Name: VPAInitializerName,
|
||||
Rules: []v1alpha1.Rule{allPodsRule},
|
||||
}
|
||||
configuration := &v1alpha1.InitializerConfiguration{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import (
|
|||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
|
@ -48,14 +48,14 @@ func TestUpdateResourceRequests(t *testing.T) {
|
|||
recommender := &test.RecommenderMock{}
|
||||
rec := test.Recommendation(containerName, "2", "200M")
|
||||
|
||||
uninitialized := test.BuildTestPod("test_uninitialized", containerName, "1", "100M", nil)
|
||||
uninitialized := test.BuildTestPod("test_uninitialized", containerName, "1", "100M", nil, nil)
|
||||
uninitialized.ObjectMeta.Labels = labels
|
||||
uninitialized.ObjectMeta.Initializers = &metav1.Initializers{
|
||||
Pending: []metav1.Initializer{{Name: VPAInitializerName}},
|
||||
}
|
||||
recommender.On("Get", &uninitialized.Spec).Return(rec, nil)
|
||||
|
||||
initialized := test.BuildTestPod("test_initialized", containerName, "1", "100M", nil)
|
||||
initialized := test.BuildTestPod("test_initialized", containerName, "1", "100M", nil, nil)
|
||||
initialized.ObjectMeta.Labels = labels
|
||||
recommender.On("Get", &initialized.Spec).Return(rec, nil)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import (
|
|||
|
||||
"github.com/golang/glog"
|
||||
kube_flag "k8s.io/apiserver/pkg/util/flag"
|
||||
kube_client "k8s.io/client-go/kubernetes"
|
||||
kube_restclient "k8s.io/client-go/rest"
|
||||
kube_client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -17,17 +17,17 @@ limitations under the License.
|
|||
package placeholder
|
||||
|
||||
import (
|
||||
metrics "k8s.io/metrics/pkg/apis/metrics/v1alpha1"
|
||||
resourceclient "k8s.io/metrics/pkg/client/clientset_generated/clientset/typed/metrics/v1alpha1"
|
||||
"k8s.io/metrics/pkg/client/clientset_generated/clientset/fake"
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
metrics "k8s.io/metrics/pkg/apis/metrics/v1alpha1"
|
||||
"k8s.io/metrics/pkg/client/clientset_generated/clientset/fake"
|
||||
resourceclient "k8s.io/metrics/pkg/client/clientset_generated/clientset/typed/metrics/v1alpha1"
|
||||
)
|
||||
|
||||
var (
|
||||
_ = metrics.NodeMetrics{}
|
||||
_ = &fake.Clientset{}
|
||||
)
|
||||
|
||||
func Nothing(config *rest.Config) {
|
||||
_ = resourceclient.NewForConfigOrDie(config)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import (
|
|||
func TestGetWithCache(t *testing.T) {
|
||||
apiMock := &test.RecommenderAPIMock{}
|
||||
rec := test.Recommendation("test", "", "")
|
||||
pod := test.BuildTestPod("test", "", "", "", nil)
|
||||
pod := test.BuildTestPod("test", "", "", "", nil, nil)
|
||||
apiMock.On("GetRecommendation", &pod.Spec).Return(rec, nil)
|
||||
recommender := NewCachingRecommender(10*time.Second, apiMock)
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ func TestGetWithCache(t *testing.T) {
|
|||
func TestGetCacheExpired(t *testing.T) {
|
||||
apiMock := &test.RecommenderAPIMock{}
|
||||
rec := test.Recommendation("test", "", "")
|
||||
pod := test.BuildTestPod("test", "", "", "", nil)
|
||||
pod := test.BuildTestPod("test", "", "", "", nil, nil)
|
||||
apiMock.On("GetRecommendation", &pod.Spec).Return(rec, nil)
|
||||
recommender := NewCachingRecommender(time.Second, apiMock)
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ func TestGetCacheExpired(t *testing.T) {
|
|||
|
||||
func TestNoRec(t *testing.T) {
|
||||
apiMock := &test.RecommenderAPIMock{}
|
||||
pod := test.BuildTestPod("test", "", "", "", nil)
|
||||
pod := test.BuildTestPod("test", "", "", "", nil, nil)
|
||||
apiMock.On("GetRecommendation", &pod.Spec).Return(nil, nil)
|
||||
recommender := NewCachingRecommender(time.Second, apiMock)
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ func TestNoRec(t *testing.T) {
|
|||
|
||||
func TestError(t *testing.T) {
|
||||
apiMock := &test.RecommenderAPIMock{}
|
||||
pod := test.BuildTestPod("test", "", "", "", nil)
|
||||
pod := test.BuildTestPod("test", "", "", "", nil, nil)
|
||||
err := fmt.Errorf("Expected Fail")
|
||||
apiMock.On("GetRecommendation", &pod.Spec).Return(nil, err)
|
||||
recommender := NewCachingRecommender(time.Second, apiMock)
|
||||
|
|
|
|||
|
|
@ -24,16 +24,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/autoscaler/vertical-pod-autoscaler/apimock"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
refv1 "k8s.io/kubernetes/pkg/api/v1/ref"
|
||||
v1 "k8s.io/kubernetes/pkg/client/listers/core/v1"
|
||||
v1 "k8s.io/client-go/listers/core/v1"
|
||||
)
|
||||
|
||||
// BuildTestPod creates a pod with specified resources.
|
||||
func BuildTestPod(name, containerName, cpu, mem string, creator runtime.Object) *apiv1.Pod {
|
||||
func BuildTestPod(name, containerName, cpu, mem string, creatorObjectMeta *metav1.ObjectMeta, creatorTypeMeta *metav1.TypeMeta) *apiv1.Pod {
|
||||
pod := &apiv1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "default",
|
||||
|
|
@ -45,8 +41,17 @@ func BuildTestPod(name, containerName, cpu, mem string, creator runtime.Object)
|
|||
},
|
||||
}
|
||||
|
||||
if creator != nil {
|
||||
pod.ObjectMeta.Annotations = map[string]string{apiv1.CreatedByAnnotation: RefJSON(creator)}
|
||||
if creatorObjectMeta != nil && creatorTypeMeta != nil {
|
||||
isController := true
|
||||
pod.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
|
||||
{
|
||||
UID: creatorObjectMeta.UID,
|
||||
Name: creatorObjectMeta.Name,
|
||||
APIVersion: creatorObjectMeta.ResourceVersion,
|
||||
Kind: creatorTypeMeta.Kind,
|
||||
Controller: &isController,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if len(cpu) > 0 {
|
||||
|
|
@ -115,18 +120,6 @@ func BuildTestVerticalPodAutoscaler(containerName, minCpu, maxCpu, minMemory, ma
|
|||
|
||||
}
|
||||
|
||||
// RefJSON builds string reference to
|
||||
func RefJSON(o runtime.Object) string {
|
||||
ref, err := refv1.GetReference(api.Scheme, o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
codec := testapi.Default.Codec()
|
||||
json := runtime.EncodeOrDie(codec, &apiv1.SerializedReference{Reference: *ref})
|
||||
return string(json)
|
||||
}
|
||||
|
||||
// Recommendation creates Recommendation with specified container name and resources
|
||||
func Recommendation(containerName, cpu, mem string) *apimock.Recommendation {
|
||||
result := &apimock.Recommendation{Containers: []apimock.ContainerRecommendation{
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ import (
|
|||
apiv1 "k8s.io/api/core/v1"
|
||||
policyv1 "k8s.io/api/policy/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
kube_client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
kube_client "k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
// PodsEvictionRestriction controls pods evictions. It ensures that we will not evict too
|
||||
|
|
@ -168,16 +166,16 @@ func (f *podsEvictionRestrictionFactoryImpl) NewPodsEvictionRestriction(pods []*
|
|||
}
|
||||
|
||||
func getPodReplicaCreator(pod *apiv1.Pod) (*podReplicaCreator, error) {
|
||||
creator, err := creatorRef(pod)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to obtain pod creator reference: %v", err)
|
||||
}
|
||||
creator := managingControllerRef(pod)
|
||||
if creator == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return &podReplicaCreator{Namespace: creator.Reference.Namespace,
|
||||
Name: creator.Reference.Name,
|
||||
Kind: creator.Reference.Kind}, nil
|
||||
podReplicaCreator := &podReplicaCreator{
|
||||
Namespace: pod.Namespace,
|
||||
Name: creator.Name,
|
||||
Kind: creator.Kind,
|
||||
}
|
||||
return podReplicaCreator, nil
|
||||
}
|
||||
|
||||
func getPodID(pod *apiv1.Pod) string {
|
||||
|
|
@ -225,15 +223,13 @@ func getReplicaCount(creator podReplicaCreator, client kube_client.Interface) (i
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
// creatorRef returns the kind of the creator reference of the pod.
|
||||
func creatorRef(pod *apiv1.Pod) (*apiv1.SerializedReference, error) {
|
||||
creatorRef, found := pod.ObjectMeta.Annotations[apiv1.CreatedByAnnotation]
|
||||
if !found {
|
||||
return nil, nil
|
||||
func managingControllerRef(pod *apiv1.Pod) *metav1.OwnerReference {
|
||||
var managingController metav1.OwnerReference
|
||||
for _, ownerReference := range pod.ObjectMeta.GetOwnerReferences() {
|
||||
if *ownerReference.Controller {
|
||||
managingController = ownerReference
|
||||
break
|
||||
}
|
||||
}
|
||||
var sr apiv1.SerializedReference
|
||||
if err := runtime.DecodeInto(api.Codecs.UniversalDecoder(), []byte(creatorRef), &sr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sr, nil
|
||||
return &managingController
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/autoscaler/vertical-pod-autoscaler/test"
|
||||
kube_client "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
kube_client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake"
|
||||
)
|
||||
|
||||
func TestEvictReplicatedByController(t *testing.T) {
|
||||
|
|
@ -44,6 +44,9 @@ func TestEvictReplicatedByController(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: testapi.Default.SelfLink("replicationcontrollers", "rc"),
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicationController",
|
||||
},
|
||||
Spec: apiv1.ReplicationControllerSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -51,7 +54,7 @@ func TestEvictReplicatedByController(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc.ObjectMeta, &rc.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(&rc, nil, nil, nil, pods), 2, 0.5).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -80,6 +83,9 @@ func TestEvictReplicatedByReplicaSet(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: testapi.Default.SelfLink("replicasets", "rs"),
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -87,7 +93,7 @@ func TestEvictReplicatedByReplicaSet(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rs)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rs.ObjectMeta, &rs.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(nil, &rs, nil, nil, pods), 2, 0.5).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -116,6 +122,9 @@ func TestEvictReplicatedByStatefulSet(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: "/apiv1s/extensions/v1beta1/namespaces/default/statefulsets/ss",
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "StatefulSet",
|
||||
},
|
||||
Spec: appsv1beta1.StatefulSetSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -123,7 +132,7 @@ func TestEvictReplicatedByStatefulSet(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &ss)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &ss.ObjectMeta, &ss.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(nil, nil, &ss, nil, pods), 2, 0.5).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -149,13 +158,16 @@ func TestEvictReplicatedByJob(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: "/apiv1s/extensions/v1beta1/namespaces/default/jobs/job",
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Job",
|
||||
},
|
||||
}
|
||||
|
||||
livePods := 5
|
||||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &job)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &job.ObjectMeta, &job.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(nil, nil, nil, &job, pods), 2, 0.5).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -184,6 +196,9 @@ func TestEvictTooFewReplicas(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: testapi.Default.SelfLink("replicationcontrollers", "rc"),
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicationController",
|
||||
},
|
||||
Spec: apiv1.ReplicationControllerSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -191,7 +206,7 @@ func TestEvictTooFewReplicas(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc.ObjectMeta, &rc.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(&rc, nil, nil, nil, pods), 10, 0.5).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -217,6 +232,9 @@ func TestEvictionTolerance(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: testapi.Default.SelfLink("replicationcontrollers", "rc"),
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicationController",
|
||||
},
|
||||
Spec: apiv1.ReplicationControllerSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -224,7 +242,7 @@ func TestEvictionTolerance(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc.ObjectMeta, &rc.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(&rc, nil, nil, nil, pods), 2, tolerance).NewPodsEvictionRestriction(pods)
|
||||
|
|
@ -254,6 +272,9 @@ func TestEvictAtLeastOne(t *testing.T) {
|
|||
Namespace: "default",
|
||||
SelfLink: testapi.Default.SelfLink("replicationcontrollers", "rc"),
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicationController",
|
||||
},
|
||||
Spec: apiv1.ReplicationControllerSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
|
|
@ -261,7 +282,7 @@ func TestEvictAtLeastOne(t *testing.T) {
|
|||
|
||||
pods := make([]*apiv1.Pod, livePods)
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), "", "", "", &rc.ObjectMeta, &rc.TypeMeta)
|
||||
}
|
||||
|
||||
eviction := NewPodsEvictionRestrictionFactory(fakeClient(&rc, nil, nil, nil, pods), 2, tolerance).NewPodsEvictionRestriction(pods)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import (
|
|||
"flag"
|
||||
"github.com/golang/glog"
|
||||
kube_flag "k8s.io/apiserver/pkg/util/flag"
|
||||
kube_client "k8s.io/client-go/kubernetes"
|
||||
kube_restclient "k8s.io/client-go/rest"
|
||||
kube_client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ const (
|
|||
func TestSortPriority(t *testing.T) {
|
||||
calculator := NewUpdatePriorityCalculator(nil, nil)
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "2", "", nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "4", "", nil)
|
||||
pod3 := test.BuildTestPod("POD3", containerName, "1", "", nil)
|
||||
pod4 := test.BuildTestPod("POD4", containerName, "3", "", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "2", "", nil, nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "4", "", nil, nil)
|
||||
pod3 := test.BuildTestPod("POD3", containerName, "1", "", nil, nil)
|
||||
pod4 := test.BuildTestPod("POD4", containerName, "3", "", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "10", "")
|
||||
|
||||
|
|
@ -54,8 +54,8 @@ func TestSortPriority(t *testing.T) {
|
|||
func TestSortPriorityMultiResource(t *testing.T) {
|
||||
calculator := NewUpdatePriorityCalculator(nil, nil)
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "60M", nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "3", "90M", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "60M", nil, nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "3", "90M", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "6", "100M")
|
||||
|
||||
|
|
@ -69,9 +69,9 @@ func TestSortPriorityMultiResource(t *testing.T) {
|
|||
func TestSortPriorityMultiContainers(t *testing.T) {
|
||||
containerName2 := "container2"
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "3", "10M", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "3", "10M", nil, nil)
|
||||
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "4", "10M", nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "4", "10M", nil, nil)
|
||||
container2 := test.BuildTestContainer(containerName2, "3", "20M")
|
||||
pod2.Spec.Containers = append(pod1.Spec.Containers, container2)
|
||||
|
||||
|
|
@ -94,8 +94,8 @@ func TestSortPriorityMultiContainers(t *testing.T) {
|
|||
func TestSortPriorityResorucesDecrease(t *testing.T) {
|
||||
calculator := NewUpdatePriorityCalculator(nil, nil)
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "10", "", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil, nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "10", "", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "5", "")
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ func TestSortPriorityResorucesDecrease(t *testing.T) {
|
|||
func TestUpdateNotRequired(t *testing.T) {
|
||||
calculator := NewUpdatePriorityCalculator(nil, nil)
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "4", "")
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ func TestUsePolicy(t *testing.T) {
|
|||
calculator := NewUpdatePriorityCalculator(
|
||||
test.BuildTestPolicy(containerName, "1", "4", "10M", "100M"), nil)
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "10M", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "10M", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "5", "5M")
|
||||
|
||||
|
|
@ -136,8 +136,8 @@ func TestUsePolicy(t *testing.T) {
|
|||
func TestChangeTooSmall(t *testing.T) {
|
||||
calculator := NewUpdatePriorityCalculator(nil, &UpdateConfig{0.5})
|
||||
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "1", "", nil)
|
||||
pod1 := test.BuildTestPod("POD1", containerName, "4", "", nil, nil)
|
||||
pod2 := test.BuildTestPod("POD2", containerName, "1", "", nil, nil)
|
||||
|
||||
recommendation := test.Recommendation(containerName, "5", "")
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ import (
|
|||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
kube_client "k8s.io/client-go/kubernetes"
|
||||
v1lister "k8s.io/client-go/listers/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
kube_client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
v1lister "k8s.io/kubernetes/pkg/client/listers/core/v1"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
|
@ -163,7 +163,8 @@ func newPodLister(kubeClient kube_client.Interface) v1lister.PodLister {
|
|||
store := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
podLister := v1lister.NewPodLister(store)
|
||||
podReflector := cache.NewReflector(podListWatch, &apiv1.Pod{}, store, time.Hour)
|
||||
podReflector.Run()
|
||||
stopCh := make(chan struct{})
|
||||
podReflector.Run(stopCh)
|
||||
|
||||
return podLister
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func TestRunOnce(t *testing.T) {
|
|||
rec := test.Recommendation(containerName, "2", "200M")
|
||||
|
||||
for i := range pods {
|
||||
pods[i] = test.BuildTestPod("test"+string(i), containerName, "1", "100M", &rc)
|
||||
pods[i] = test.BuildTestPod("test"+string(i), containerName, "1", "100M", &rc.ObjectMeta, &rc.TypeMeta)
|
||||
pods[i].Spec.NodeSelector = labels
|
||||
eviction.On("CanEvict", pods[i]).Return(true)
|
||||
eviction.On("Evict", pods[i]).Return(nil)
|
||||
|
|
|
|||
Loading…
Reference in New Issue