-
Notifications
You must be signed in to change notification settings - Fork 317
/
resources.go
45 lines (39 loc) · 1.07 KB
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package config
import (
corev1 "k8s.io/api/core/v1"
)
type ResourcesSpec map[string]corev1.ResourceRequirements
func (s ResourcesSpec) ApplyTo(podSpec *corev1.PodSpec) {
for i, c := range podSpec.InitContainers {
if res, ok := s[c.Name]; ok {
podSpec.InitContainers[i].Resources = res
}
}
for i, c := range podSpec.Containers {
if res, ok := s[c.Name]; ok {
podSpec.Containers[i].Resources = res
}
}
}
func (s ResourcesSpec) ApplyRequestsOverrideTo(podSpec *corev1.PodSpec) {
for i, c := range podSpec.InitContainers {
if res, ok := s[c.Name]; ok {
for name, value := range res.Requests {
podSpec.InitContainers[i].Resources.Requests[name] = value
}
}
}
for i, c := range podSpec.Containers {
if res, ok := s[c.Name]; ok {
for name, value := range res.Requests {
podSpec.Containers[i].Resources.Requests[name] = value
}
}
}
}
type ResourceOverrides map[string]ResourcesSpec
func (o ResourceOverrides) ApplyRequestsTo(name string, podSpec *corev1.PodSpec) {
if spec, exists := o[name]; exists {
spec.ApplyRequestsOverrideTo(podSpec)
}
}