Skip to content

Commit 4ef419f

Browse files
runtime/kubernetes: Only add capabilities stanza when there is something to add.
We see churn in mimir deployments: cabilities message is being added and removed all the time. This shouldn't be happening logically, but we are making this fix to prevent it anyway before diving deeper.
1 parent 38cefd3 commit 4ef419f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

internal/runtime/kubernetes/securitycontext.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ func makeSecurityContext(opts runtime.ContainerRunOpts, containerName string, de
5454
WithRunAsNonRoot(false)
5555
}
5656

57-
var caps []k8sv1.Capability
58-
for _, cap := range opts.Capabilities {
59-
caps = append(caps, k8sv1.Capability(cap))
57+
if len(opts.Capabilities) > 0 {
58+
var caps []k8sv1.Capability
59+
for _, cap := range opts.Capabilities {
60+
caps = append(caps, k8sv1.Capability(cap))
61+
}
62+
secCtx = secCtx.WithCapabilities(&applycorev1.CapabilitiesApplyConfiguration{
63+
Add: caps,
64+
})
6065
}
61-
secCtx = secCtx.WithCapabilities(&applycorev1.CapabilitiesApplyConfiguration{
62-
Add: caps,
63-
})
6466

6567
if opts.ReadOnlyFilesystem {
6668
secCtx = secCtx.WithReadOnlyRootFilesystem(true)

0 commit comments

Comments
 (0)