Skip to content

Commit

Permalink
Webhook reflects container resize policy (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikouaj authored Dec 6, 2023
1 parent c30951b commit 9e27322
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 169 deletions.
14 changes: 14 additions & 0 deletions internal/webhook/podcpuboost_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (h *podCPUBoostHandler) boostContainerResources(b boost.StartupCPUBoost, po
"CPURequests", container.Resources.Requests.Cpu().String(),
"CPULimits", container.Resources.Limits.Cpu().String(),
)
if resizeRequiresRestart(container, corev1.ResourceCPU) {
log.Info("skipping container due to restart policy")
continue
}
updateBoostAnnotation(annotation, container.Name, container.Resources)
resources := policy.NewResources(&container)
log = log.WithValues(
Expand Down Expand Up @@ -108,3 +112,13 @@ func updateBoostAnnotation(annot *bpod.BoostPodAnnotation, containerName string,
annot.InitCPULimits[containerName] = cpuLimits.String()
}
}

func resizeRequiresRestart(c corev1.Container, r corev1.ResourceName) bool {
for _, p := range c.ResizePolicy {
if p.ResourceName != r {
continue
}
return p.RestartPolicy == corev1.RestartContainer
}
return false
}
16 changes: 16 additions & 0 deletions internal/webhook/podcpuboost_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ var _ = Describe("Pod CPU Boost Webhook", func() {
Expect(response.Patches).To(HaveLen(3))
})
})
When("container has restart container resize policy", func() {
BeforeEach(func() {
pod.Spec.Containers[0].ResizePolicy = []corev1.ContainerResizePolicy{
{
ResourceName: corev1.ResourceCPU,
RestartPolicy: corev1.RestartContainer,
},
}
})
It("allows the admission", func() {
Expect(response.Allowed).To(BeTrue())
})
It("returns admission with zero patches", func() {
Expect(response.Patches).To(HaveLen(0))
})
})
})
When("there is a policy for two containers", func() {
var (
Expand Down
169 changes: 0 additions & 169 deletions internal/webhook/podcpuboost_webhook_test.go.old

This file was deleted.

0 comments on commit 9e27322

Please sign in to comment.