Skip to content

Commit 99962c0

Browse files
committed
Added support for configuring utillity pods
1 parent c05fc6f commit 99962c0

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

dist/chart/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ controllerManager:
5353
# level: debug
5454
# reboot:
5555
# checkInterval: 5m
56+
# pod:
57+
# podPriorityClassName: ""
58+
# containerResources:
59+
# requests:
60+
# cpu: 10m
61+
# memory: 16Mi
62+
# limits:
63+
# cpu: 100m
64+
# memory: 32Mi
5665
#
5766
# plugins:
5867
# example-plugin:

internal/config/config.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/knadh/koanf/providers/rawbytes"
1717
"github.com/knadh/koanf/v2"
1818
pluginv1 "github.com/slyngdk/node-drain/api/plugins/proto/v1"
19+
corev1 "k8s.io/api/core/v1"
20+
"k8s.io/apimachinery/pkg/api/resource"
1921
)
2022

2123
//go:embed default-config.yaml
@@ -37,9 +39,45 @@ type Config struct {
3739
Reboot struct {
3840
CheckInterval time.Duration `koanf:"checkInterval"`
3941
}
42+
Pod struct {
43+
PriorityClassName string `koanf:"priorityClassName"`
44+
ContainerResources ContainerResources `koanf:"containerResources"`
45+
} `koanf:"pod"`
4046
ContainerNode bool `koanf:"containerNode"`
4147
}
4248

49+
type ContainerResources struct {
50+
Requests ResourceList `koanf:"requests"`
51+
Limits ResourceList `koanf:"limits"`
52+
}
53+
54+
func (c *ContainerResources) ToResourceRequirement() corev1.ResourceRequirements {
55+
requirements := corev1.ResourceRequirements{
56+
Requests: c.Requests.toKubernetes(),
57+
Limits: c.Limits.toKubernetes(),
58+
}
59+
return requirements
60+
}
61+
62+
type ResourceList struct {
63+
Memory string `koanf:"memory"`
64+
CPU string `koanf:"cpu"`
65+
}
66+
67+
func (c *ResourceList) toKubernetes() corev1.ResourceList {
68+
if c.CPU != "" && c.Memory != "" {
69+
list := corev1.ResourceList{}
70+
if c.CPU != "" {
71+
list[corev1.ResourceCPU] = resource.MustParse(c.CPU)
72+
}
73+
if c.Memory != "" {
74+
list[corev1.ResourceMemory] = resource.MustParse(c.Memory)
75+
}
76+
return list
77+
}
78+
return nil
79+
}
80+
4381
func (c *Config) GetLogger(name string) Logger {
4482
if logger, ok := c.Log.Loggers[name]; ok {
4583
if logger.Level == "" {

internal/config/default-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ log:
44
format: json
55
reboot:
66
checkInterval: 12h
7+
pod:
8+
containerResources:
9+
requests:
10+
cpu: 10m
11+
memory: 16Mi
12+
limits:
13+
cpu: 100m
14+
memory: 32Mi

internal/utils/reboot-manager.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func (r *RebootManager) rebootRequiredPod(nodeName string) *corev1.Pod {
115115
ReadOnly: true,
116116
MountPath: "/host/var/run",
117117
}},
118+
Resources: config.GetConfig().Pod.ContainerResources.ToResourceRequirement(),
118119
}},
119120
RestartPolicy: "Never",
120121
TerminationGracePeriodSeconds: PtrTo(int64(1)),
@@ -133,6 +134,7 @@ func (r *RebootManager) rebootRequiredPod(nodeName string) *corev1.Pod {
133134
Operator: corev1.TolerationOpExists,
134135
Effect: corev1.TaintEffectNoSchedule,
135136
}},
137+
PriorityClassName: config.GetConfig().Pod.PriorityClassName,
136138
},
137139
}
138140
}
@@ -169,7 +171,6 @@ func (r *RebootManager) rebootNodePod(nodeName string) *corev1.Pod {
169171
GenerateName: "reboot-",
170172
Namespace: r.namespace,
171173
Labels: map[string]string{LabelComponent: "reboot"},
172-
Annotations: map[string]string{"container.apparmor.security.beta.kubernetes.io/shell": "unconfined"},
173174
},
174175
Spec: corev1.PodSpec{
175176
Tolerations: []corev1.Toleration{{
@@ -196,8 +197,15 @@ func (r *RebootManager) rebootNodePod(nodeName string) *corev1.Pod {
196197
Privileged: PtrTo(false),
197198
ReadOnlyRootFilesystem: PtrTo(true),
198199
},
200+
Resources: config.GetConfig().Pod.ContainerResources.ToResourceRequirement(),
199201
}},
200-
RestartPolicy: "Never",
202+
RestartPolicy: "Never",
203+
PriorityClassName: config.GetConfig().Pod.PriorityClassName,
204+
SecurityContext: &corev1.PodSecurityContext{
205+
AppArmorProfile: &corev1.AppArmorProfile{
206+
Type: corev1.AppArmorProfileTypeUnconfined,
207+
},
208+
},
201209
},
202210
}
203211
}

0 commit comments

Comments
 (0)