Skip to content

Commit

Permalink
controller: respect named ports of restartable init containers
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Feb 17, 2025
1 parent d4eb19d commit b05bc61
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ func (n *NamedPort) AddNamedPortByPod(pod *v1.Pod) {
ns := pod.Namespace
podName := pod.Name

if pod.Spec.Containers == nil {
restartableInitContainers := make([]v1.Container, 0, len(pod.Spec.InitContainers))
for i := range pod.Spec.InitContainers {
if pod.Spec.InitContainers[i].RestartPolicy != nil &&
*pod.Spec.InitContainers[i].RestartPolicy == v1.ContainerRestartPolicyAlways {
restartableInitContainers = append(restartableInitContainers, pod.Spec.InitContainers[i])
}
}

containers := slices.Concat(restartableInitContainers, pod.Spec.Containers)
if len(containers) == 0 {
return
}

for _, container := range pod.Spec.Containers {
if container.Ports == nil {
for _, container := range containers {
if len(container.Ports) == 0 {
continue
}

Expand Down

0 comments on commit b05bc61

Please sign in to comment.