Skip to content

Commit 6c47d4e

Browse files
committed
nrt: filter: log correctly sidecar containers
add utilities to recognize sidecar containers, and log them correctly. Signed-off-by: Francesco Romani <[email protected]>
1 parent bf4d1bd commit 6c47d4e

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

pkg/noderesourcetopology/filter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ func singleNUMAContainerLevelHandler(lh logr.Logger, pod *v1.Pod, zones topology
5555
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#understanding-init-containers
5656
// therefore, we don't need to accumulate their resources together
5757
for _, initContainer := range pod.Spec.InitContainers {
58-
// TODO: handle sidecar explicitely (new kind)
59-
clh := lh.WithValues(logging.KeyContainer, initContainer.Name, logging.KeyContainerKind, logging.KindContainerInit)
58+
clh := lh.WithValues(logging.KeyContainer, initContainer.Name, logging.KeyContainerKind, logging.GetInitContainerKind(&initContainer))
6059
clh.V(6).Info("desired resources", stringify.ResourceListToLoggable(initContainer.Resources.Requests)...)
6160

6261
_, match := resourcesAvailableInAnyNUMANodes(clh, nodes, initContainer.Resources.Requests, qos, nodeInfo)
6362
if !match {
6463
// we can't align init container, so definitely we can't align a pod
65-
clh.V(2).Info("cannot align container")
64+
clh.V(2).Info("cannot align init container")
6665
return framework.NewStatus(framework.Unschedulable, "cannot align init container")
6766
}
6867
}

pkg/noderesourcetopology/logging/logging.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"reflect"
2121

2222
corev1 "k8s.io/api/core/v1"
23+
"sigs.k8s.io/scheduler-plugins/pkg/util"
2324
)
2425

2526
// well-known structured log keys
@@ -44,8 +45,9 @@ const (
4445
)
4546

4647
const (
47-
KindContainerInit string = "init"
48-
KindContainerApp string = "app"
48+
KindContainerInit string = "init"
49+
KindContainerSidecar string = "sidecar"
50+
KindContainerApp string = "app"
4951
)
5052

5153
const (
@@ -62,3 +64,10 @@ func PodUID(pod *corev1.Pod) string {
6264
}
6365
return string(pod.GetUID())
6466
}
67+
68+
func GetInitContainerKind(container *corev1.Container) string {
69+
if util.IsSidecarInitContainer(container) {
70+
return KindContainerSidecar
71+
}
72+
return KindContainerInit
73+
}

pkg/util/sidecar.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package util
18+
19+
import (
20+
v1 "k8s.io/api/core/v1"
21+
)
22+
23+
// IsSidecarInitContainer assumes the given container is a pod init container;
24+
// returns true if that container is a sidecar, false otherwise.
25+
func IsSidecarInitContainer(container *v1.Container) bool {
26+
return container.RestartPolicy != nil && *container.RestartPolicy == v1.ContainerRestartPolicyAlways
27+
}
28+
29+
// IsSidecarContainer assumes the given container is a pod init container;
30+
// returns true if the given container is a sidecar, false otherwise.
31+
func IsSidecarContainer(pod *v1.Pod, container *v1.Container) bool {
32+
for _, initContainer := range pod.Spec.InitContainers {
33+
if initContainer.Name == container.Name {
34+
return IsSidecarInitContainer(container)
35+
}
36+
}
37+
return false
38+
}

0 commit comments

Comments
 (0)