plugin/kubernetes: support pods with multiple IPs (#8635)

The Pod object stored only the primary pod IP (status.podIP), causing
PodIndex lookups to fail for IPv6 clients in dual-stack clusters. This
prevented the metadata plugin from populating client-pod-name and
client-namespace.

Replace the PodIP string field with a PodIPs []string slice populated
from status.podIPs, and update podIPIndexFunc to index all IPs.

Signed-off-by: Christian Norbert Menges <christian.norbert.menges@sap.com>
This commit is contained in:
Christian Menges
2026-10-15 10:12:29 +02:00
committed by GitHub
parent 25b51bcbd9
commit 2e2324715b
6 changed files with 32 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"maps"
"slices"
api "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -14,7 +15,7 @@ import (
type Pod struct {
// Don't add new fields to this struct without talking to the CoreDNS maintainers.
Version string
PodIP string
PodIPs []string
Name string
Namespace string
Labels map[string]string
@@ -30,9 +31,13 @@ func ToPod(obj meta.Object) (meta.Object, error) {
if !ok {
return nil, fmt.Errorf("unexpected object %v", obj)
}
podIPs := make([]string, len(apiPod.Status.PodIPs))
for i, pip := range apiPod.Status.PodIPs {
podIPs[i] = pip.IP
}
pod := &Pod{
Version: apiPod.GetResourceVersion(),
PodIP: apiPod.Status.PodIP,
PodIPs: podIPs,
Namespace: apiPod.GetNamespace(),
Name: apiPod.GetName(),
Labels: apiPod.GetLabels(),
@@ -55,7 +60,7 @@ var _ runtime.Object = &Pod{}
func (p *Pod) DeepCopyObject() runtime.Object {
p1 := &Pod{
Version: p.Version,
PodIP: p.PodIP,
PodIPs: slices.Clone(p.PodIPs),
Namespace: p.Namespace,
Name: p.Name,
// maps.Clone returns nil for a nil map, so an unlabelled pod stays unlabelled.