Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
fix: Don't remove memoryLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
bjw-s committed Jul 27, 2023
1 parent 3eff373 commit ce9c1c8
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/pod_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,28 @@ func (m *podMutator) Default(ctx context.Context, obj runtime.Object) error {
}

for _, container := range pod.Spec.InitContainers {
if removeContainerLimits(&container, corev1.ResourceCPU) {
log.Info("Removed resource limit", "pod", pod.ObjectMeta, "container", container.Name, "limit", corev1.ResourceCPU)
}
removeContainerLimits(&container, corev1.ResourceCPU, pod)
}

for _, container := range pod.Spec.Containers {
if removeContainerLimits(&container, corev1.ResourceCPU) {
log.Info("Removed resource limit", "pod", pod.ObjectMeta, "container", container.Name, "limit", corev1.ResourceCPU)
}

if removeContainerLimits(&container, corev1.ResourceMemory) {
log.Info("Removed resource limit",
"namespace", pod.Namespace,
"pod", getPodName(pod),
"container", container.Name,
"limit", corev1.ResourceMemory,
)
}
removeContainerLimits(&container, corev1.ResourceCPU, pod)
}
return nil
}

func removeContainerLimits(container *corev1.Container, limitType corev1.ResourceName) bool {
func removeContainerLimits(container *corev1.Container, limitType corev1.ResourceName, pod *corev1.Pod) {
log := logf.Log
limits := container.Resources.Limits
_, cpuLimitExists := limits[limitType]
if cpuLimitExists {
delete(limits, limitType)
return true
log.Info("Removed resource limit",
"namespace", pod.Namespace,
"pod", getPodName(pod),
"container", container.Name,
"limit", limitType,
)
}
return false
}

func getPodName(pod *corev1.Pod) string {
Expand Down

0 comments on commit ce9c1c8

Please sign in to comment.