Skip to content

Commit

Permalink
fixup! VPA: hack unit tests to account for in-place
Browse files Browse the repository at this point in the history
  • Loading branch information
jkyros committed Nov 20, 2024
1 parent 75aa467 commit 6d16d41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions vertical-pod-autoscaler/pkg/updater/logic/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (u *updater) RunOnce(ctx context.Context) {
continue
}
} else {
klog.Infof("Not falling back to eviction, probably because we don't have a recommendation yet?")
continue
}

Expand Down
14 changes: 12 additions & 2 deletions vertical-pod-autoscaler/pkg/updater/logic/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"

corev1 "k8s.io/api/core/v1"
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
controllerfetcher "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/controller_fetcher"
target_mock "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/mock"
Expand Down Expand Up @@ -177,12 +178,16 @@ func testRunOnceBase(
Name: rc.Name,
APIVersion: rc.APIVersion,
}
// TOD0(jkyros): I added the recommendationProvided condition here because in-place needs to wait for a
// recommendation to scale, causing this test to fail (because in-place checks before eviction, and in-place will
// wait to scale -- and not fall back to eviction -- until the VPA has made a recommendation)
vpaObj := test.VerticalPodAutoscaler().
WithContainer(containerName).
WithTarget("2", "200M").
WithMinAllowed(containerName, "1", "100M").
WithMaxAllowed(containerName, "3", "1G").
WithTargetRef(targetRef).Get()
WithTargetRef(targetRef).
AppendCondition(vpa_types.RecommendationProvided, corev1.ConditionTrue, "reason", "msg", time.Unix(0, 0)).Get()

vpaObj.Spec.UpdatePolicy = &vpa_types.PodUpdatePolicy{UpdateMode: &updateMode}
vpaLister.On("List").Return([]*vpa_types.VerticalPodAutoscaler{vpaObj}, nil).Once()
Expand Down Expand Up @@ -314,13 +319,18 @@ func TestRunOnceIgnoreNamespaceMatchingPods(t *testing.T) {
Name: rc.Name,
APIVersion: rc.APIVersion,
}

// TOD0(jkyros): I added the recommendationProvided condition here because in-place needs to wait for a
// recommendation to scale, causing this test to fail (because in-place checks before eviction, and in-place will
// wait to scale -- and not fall back to eviction -- until the VPA has made a recommendation)
vpaObj := test.VerticalPodAutoscaler().
WithNamespace("default").
WithContainer(containerName).
WithTarget("2", "200M").
WithMinAllowed(containerName, "1", "100M").
WithMaxAllowed(containerName, "3", "1G").
WithTargetRef(targetRef).Get()
WithTargetRef(targetRef).
AppendCondition(vpa_types.RecommendationProvided, corev1.ConditionTrue, "reason", "msg", time.Unix(0, 0)).Get()

vpaLister.On("List").Return([]*vpa_types.VerticalPodAutoscaler{vpaObj}, nil).Once()

Expand Down

0 comments on commit 6d16d41

Please sign in to comment.