Skip to content

Commit 8744043

Browse files
committed
updated history init for prometheus to take container types into account
1 parent 0b1fcc5 commit 8744043

File tree

8 files changed

+305
-159
lines changed

8 files changed

+305
-159
lines changed

vertical-pod-autoscaler/docs/flags.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ This document is auto-generated from the flag definitions in the VPA admission-c
1414
| `address` | string | ":8944" | The address to expose Prometheus metrics. |
1515
| `alsologtostderr` | | | log to standard error as well as files (no effect when -logtostderr=true) |
1616
| `client-ca-file` | string | "/etc/tls-certs/caCert.pem" | Path to CA PEM file. |
17-
<<<<<<< HEAD
18-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
19-
=======
20-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false) |
21-
>>>>>>> a4748ee23 (adding feature flag `NativeSidecar`)
17+
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
2218
| `ignored-vpa-object-namespaces` | string | | A comma-separated list of namespaces to ignore when searching for VPA objects. Leave empty to avoid ignoring any namespaces. These namespaces will not be cleaned by the garbage collector. |
2319
| `kube-api-burst` | float | 100 | QPS burst limit when making requests to Kubernetes apiserver |
2420
| `kube-api-qps` | float | 50 | QPS limit when making requests to Kubernetes apiserver |
@@ -72,11 +68,7 @@ This document is auto-generated from the flag definitions in the VPA recommender
7268
| `cpu-integer-post-processor-enabled` | | | Enable the cpu-integer recommendation post processor. The post processor will round up CPU recommendations to a whole CPU for pods which were opted in by setting an appropriate label on VPA object (experimental) |
7369
| `external-metrics-cpu-metric` | string | | ALPHA. Metric to use with external metrics provider for CPU usage. |
7470
| `external-metrics-memory-metric` | string | | ALPHA. Metric to use with external metrics provider for memory usage. |
75-
<<<<<<< HEAD
76-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
77-
=======
78-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false) |
79-
>>>>>>> a4748ee23 (adding feature flag `NativeSidecar`)
71+
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
8072
| `history-length` | string | "8d" | How much time back prometheus have to be queried to get historical metrics |
8173
| `history-resolution` | string | "1h" | Resolution at which Prometheus is queried for historical metrics |
8274
| `humanize-memory` | | | DEPRECATED: Convert memory values in recommendations to the highest appropriate SI unit with up to 2 decimal places for better readability. This flag is deprecated and will be removed in a future version. Use --round-memory-bytes instead. |
@@ -152,11 +144,7 @@ This document is auto-generated from the flag definitions in the VPA updater cod
152144
| `eviction-rate-burst` | int | 1 | Burst of pods that can be evicted. |
153145
| `eviction-rate-limit` | float | | Number of pods that can be evicted per seconds. A rate limit set to 0 or -1 will disable<br>the rate limiter. (default -1) |
154146
| `eviction-tolerance` | float | 0.5 | Fraction of replica count that can be evicted for update, if more than one pod can be evicted. |
155-
<<<<<<< HEAD
156-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
157-
=======
158-
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false) |
159-
>>>>>>> a4748ee23 (adding feature flag `NativeSidecar`)
147+
| `feature-gates` | mapStringBool | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:<br>AllAlpha=true\|false (ALPHA - default=false)<br>AllBeta=true\|false (BETA - default=false)<br>InPlaceOrRecreate=true\|false (BETA - default=true)<br>NativeSidecar=true\|false (ALPHA - default=false)<br>PerVPAConfig=true\|false (ALPHA - default=false) |
160148
| `ignored-vpa-object-namespaces` | string | | A comma-separated list of namespaces to ignore when searching for VPA objects. Leave empty to avoid ignoring any namespaces. These namespaces will not be cleaned by the garbage collector. |
161149
| `in-recommendation-bounds-eviction-lifetime-threshold` | | 12h0m0s | duration Pods that live for at least that long can be evicted even if their request is within the [MinRecommended...MaxRecommended] range |
162150
| `kube-api-burst` | float | 100 | QPS burst limit when making requests to Kubernetes apiserver |

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch/resource_updates_test.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,44 @@ func addResourceLimitPatch(index int, res, amount string) resource_admission.Pat
8989
}
9090
}
9191

92+
func addInitResourcesPatch(idx int) resource_admission.PatchRecord {
93+
return resource_admission.PatchRecord{
94+
Op: "add",
95+
Path: fmt.Sprintf("/spec/initContainers/%d/resources", idx),
96+
Value: core.ResourceRequirements{},
97+
}
98+
}
99+
100+
func addInitRequestsPatch(idx int) resource_admission.PatchRecord {
101+
return resource_admission.PatchRecord{
102+
Op: "add",
103+
Path: fmt.Sprintf("/spec/initContainers/%d/resources/requests", idx),
104+
Value: core.ResourceList{},
105+
}
106+
}
107+
108+
func addInitResourceRequestPatch(index int, res, amount string) resource_admission.PatchRecord {
109+
return resource_admission.PatchRecord{
110+
Op: "add",
111+
Path: fmt.Sprintf("/spec/initContainers/%d/resources/requests/%s", index, res),
112+
Value: resource.MustParse(amount),
113+
}
114+
}
115+
116+
func addInitAnnotationRequest(updateResources [][]string, kind string) resource_admission.PatchRecord {
117+
requests := make([]string, 0)
118+
for idx, podResources := range updateResources {
119+
podRequests := make([]string, 0)
120+
for _, resource := range podResources {
121+
podRequests = append(podRequests, resource+" "+kind)
122+
}
123+
requests = append(requests, fmt.Sprintf("init-sidecar %d: %s", idx, strings.Join(podRequests, ", ")))
124+
}
125+
126+
vpaUpdates := fmt.Sprintf("Pod resources updated by name: %s", strings.Join(requests, "; "))
127+
return GetAddAnnotationPatch(ResourceUpdatesAnnotation, vpaUpdates)
128+
}
129+
92130
func addAnnotationRequest(updateResources [][]string, kind string) resource_admission.PatchRecord {
93131
requests := make([]string, 0)
94132
for idx, podResources := range updateResources {
@@ -138,6 +176,29 @@ func TestCalculatePatches_ResourceUpdates(t *testing.T) {
138176
addAnnotationRequest([][]string{{cpu}}, request),
139177
},
140178
},
179+
{
180+
name: "new init cpu recommendation",
181+
pod: &core.Pod{
182+
Spec: core.PodSpec{
183+
InitContainers: []core.Container{{}},
184+
},
185+
},
186+
namespace: "default",
187+
initResources: []vpa_api_util.ContainerResources{
188+
{
189+
Requests: core.ResourceList{
190+
cpu: resource.MustParse("1"),
191+
},
192+
},
193+
},
194+
recommendAnnotations: vpa_api_util.ContainerToAnnotationsMap{},
195+
expectPatches: []resource_admission.PatchRecord{
196+
addInitResourcesPatch(0),
197+
addInitRequestsPatch(0),
198+
addInitResourceRequestPatch(0, cpu, "1"),
199+
addInitAnnotationRequest([][]string{{cpu}}, request),
200+
},
201+
},
141202
{
142203
name: "replacement cpu recommendation",
143204
pod: &core.Pod{
@@ -294,7 +355,6 @@ func TestCalculatePatches_ResourceUpdates(t *testing.T) {
294355
}
295356
for _, tc := range tests {
296357
t.Run(tc.name, func(t *testing.T) {
297-
// TODO @jklaw tests
298358
frp := fakeRecommendationProvider{tc.initResources, tc.recommendResources, tc.recommendAnnotations, tc.recommendError}
299359
c := NewResourceUpdatesCalculator(&frp)
300360
patches, err := c.CalculatePatches(tc.pod, test.VerticalPodAutoscaler().WithContainer("test").WithName("name").Get())
@@ -337,7 +397,6 @@ func TestGetPatches_TwoReplacementResources(t *testing.T) {
337397
},
338398
}
339399
recommendAnnotations := vpa_api_util.ContainerToAnnotationsMap{}
340-
// TODO @jklaw tests
341400
frp := fakeRecommendationProvider{nil, recommendResources, recommendAnnotations, nil}
342401
c := NewResourceUpdatesCalculator(&frp)
343402
patches, err := c.CalculatePatches(pod, test.VerticalPodAutoscaler().WithName("name").WithContainer("test").Get())

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/recommendation/recommendation_provider_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func TestUpdateResourceRequests(t *testing.T) {
7373
initialized := test.Pod().WithName("test_initialized").
7474
AddContainer(initializedContainer).WithLabels(labels).Get()
7575

76+
initializedWithInit := test.Pod().WithName("test_initialized").
77+
AddContainer(initializedContainer).WithLabels(labels).
78+
AddInitContainer(initializedContainer).WithLabels(labels).Get()
79+
7680
limitsMatchRequestsContainer := test.Container().WithName(containerName).
7781
WithCPURequest(resource.MustParse("2")).WithCPULimit(resource.MustParse("2")).
7882
WithMemRequest(resource.MustParse("200Mi")).WithMemLimit(resource.MustParse("200Mi")).Get()
@@ -163,6 +167,14 @@ func TestUpdateResourceRequests(t *testing.T) {
163167
expectedMem: resource.MustParse("200Mi"),
164168
expectedCPU: resource.MustParse("2"),
165169
},
170+
{
171+
name: "pod with init container",
172+
pod: initializedWithInit,
173+
vpa: vpa,
174+
expectedAction: true,
175+
expectedMem: resource.MustParse("200Mi"),
176+
expectedCPU: resource.MustParse("2"),
177+
},
166178
{
167179
name: "high memory",
168180
pod: initialized,
@@ -302,15 +314,22 @@ func TestUpdateResourceRequests(t *testing.T) {
302314
},
303315
}
304316

305-
// TODO @jklaw90 update tests
306-
_, resources, annotations, err := recommendationProvider.GetContainersResourcesForPod(tc.pod, tc.vpa)
317+
initResources, resources, annotations, err := recommendationProvider.GetContainersResourcesForPod(tc.pod, tc.vpa)
307318

308319
if tc.expectedAction {
309320
assert.Nil(t, err)
310321
if !assert.Equal(t, len(resources), 1) {
311322
return
312323
}
313324

325+
assert.Equal(t, len(tc.pod.Spec.InitContainers), len(initResources), "init containers resources length mismatch")
326+
if len(tc.pod.Spec.InitContainers) > 0 {
327+
cpuRequestInit := initResources[0].Requests[apiv1.ResourceCPU]
328+
assert.Equal(t, tc.expectedCPU.Value(), cpuRequestInit.Value(), "init cpu request doesn't match")
329+
memoryRequestInit := initResources[0].Requests[apiv1.ResourceMemory]
330+
assert.Equal(t, tc.expectedMem.Value(), memoryRequestInit.Value(), "init memory request doesn't match")
331+
}
332+
314333
assert.NotContains(t, resources, "", "expected empty resource to be removed")
315334

316335
cpuRequest := resources[0].Requests[apiv1.ResourceCPU]

vertical-pod-autoscaler/pkg/features/features.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ const (
5858
// same cluster.
5959
PerVPAConfig featuregate.Feature = "PerVPAConfig"
6060

61-
6261
// alpha: v1.5.0
6362
// components: admission-controller, recommender, updater
64-
63+
6564
// NativeSidecar enables support for native sidecars in VPA
6665
NativeSidecar featuregate.Feature = "NativeSidecar"
6766
)

0 commit comments

Comments
 (0)