Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dist/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ controllerManager:
# level: debug
# reboot:
# checkInterval: 5m
# pod:
# podPriorityClassName: ""
# containerResources:
# requests:
# cpu: 10m
# memory: 16Mi
# limits:
# cpu: 100m
# memory: 32Mi
#
# plugins:
# example-plugin:
Expand Down
38 changes: 38 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/knadh/koanf/providers/rawbytes"
"github.com/knadh/koanf/v2"
pluginv1 "github.com/slyngdk/node-drain/api/plugins/proto/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

//go:embed default-config.yaml
Expand All @@ -37,9 +39,45 @@ type Config struct {
Reboot struct {
CheckInterval time.Duration `koanf:"checkInterval"`
}
Pod struct {
PriorityClassName string `koanf:"priorityClassName"`
ContainerResources ContainerResources `koanf:"containerResources"`
} `koanf:"pod"`
ContainerNode bool `koanf:"containerNode"`
}

type ContainerResources struct {
Requests ResourceList `koanf:"requests"`
Limits ResourceList `koanf:"limits"`
}

func (c *ContainerResources) ToResourceRequirement() corev1.ResourceRequirements {
requirements := corev1.ResourceRequirements{
Requests: c.Requests.toKubernetes(),
Limits: c.Limits.toKubernetes(),
}
return requirements
}

type ResourceList struct {
Memory string `koanf:"memory"`
CPU string `koanf:"cpu"`
}

func (c *ResourceList) toKubernetes() corev1.ResourceList {
if c.CPU != "" && c.Memory != "" {
list := corev1.ResourceList{}
if c.CPU != "" {
list[corev1.ResourceCPU] = resource.MustParse(c.CPU)
}
if c.Memory != "" {
list[corev1.ResourceMemory] = resource.MustParse(c.Memory)
}
return list
}
return nil
}

func (c *Config) GetLogger(name string) Logger {
if logger, ok := c.Log.Loggers[name]; ok {
if logger.Level == "" {
Expand Down
8 changes: 8 additions & 0 deletions internal/config/default-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ log:
format: json
reboot:
checkInterval: 12h
pod:
containerResources:
requests:
cpu: 10m
memory: 16Mi
limits:
cpu: 100m
memory: 32Mi
12 changes: 10 additions & 2 deletions internal/utils/reboot-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (r *RebootManager) rebootRequiredPod(nodeName string) *corev1.Pod {
ReadOnly: true,
MountPath: "/host/var/run",
}},
Resources: config.GetConfig().Pod.ContainerResources.ToResourceRequirement(),
}},
RestartPolicy: "Never",
TerminationGracePeriodSeconds: PtrTo(int64(1)),
Expand All @@ -133,6 +134,7 @@ func (r *RebootManager) rebootRequiredPod(nodeName string) *corev1.Pod {
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
}},
PriorityClassName: config.GetConfig().Pod.PriorityClassName,
},
}
}
Expand Down Expand Up @@ -169,7 +171,6 @@ func (r *RebootManager) rebootNodePod(nodeName string) *corev1.Pod {
GenerateName: "reboot-",
Namespace: r.namespace,
Labels: map[string]string{LabelComponent: "reboot"},
Annotations: map[string]string{"container.apparmor.security.beta.kubernetes.io/shell": "unconfined"},
},
Spec: corev1.PodSpec{
Tolerations: []corev1.Toleration{{
Expand All @@ -196,8 +197,15 @@ func (r *RebootManager) rebootNodePod(nodeName string) *corev1.Pod {
Privileged: PtrTo(false),
ReadOnlyRootFilesystem: PtrTo(true),
},
Resources: config.GetConfig().Pod.ContainerResources.ToResourceRequirement(),
}},
RestartPolicy: "Never",
RestartPolicy: "Never",
PriorityClassName: config.GetConfig().Pod.PriorityClassName,
SecurityContext: &corev1.PodSecurityContext{
AppArmorProfile: &corev1.AppArmorProfile{
Type: corev1.AppArmorProfileTypeUnconfined,
},
},
},
}
}
Expand Down
Loading