Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/sources/pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

The pod source creates DNS entries based on `Pod` resources.

## Pod phase

Records derived from pod annotations (for example hostname, internal hostname, `--pod-source-domain`, and compatibility annotations) are only generated when the pod `status.phase` is `Running`.
Pods that have not started or have terminated do not contribute annotation-based endpoints, including when they carry explicit target annotations.

FQDN template expansion (`--fqdn-template`) is combined separately and still evaluates templates using the pod object as seen in the informer cache.

## Pods not running with host networking

By default, the pod source will consider the pods that aren't running with host networking enabled. You can override this behavior by using the `--ignore-non-host-network-pods` option to ignore non host networking pods.
Expand Down
16 changes: 11 additions & 5 deletions source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (ps *podSource) addPodEndpointsToEndpointMap(endpointMap map[endpoint.Endpo
log.Debugf("skipping pod %s. hostNetwork=false", pod.Name)
return
}
if pod.Status.Phase != v1.PodRunning {
log.Debugf("skipping pod %q. phase is %q", pod.Name, pod.Status.Phase)
return
}

targets := annotations.TargetsFromTargetAnnotation(pod.Annotations)

Expand Down Expand Up @@ -224,11 +228,13 @@ func (ps *podSource) addKopsDNSControllerEndpoints(endpointMap map[endpoint.Endp
}

func (ps *podSource) addPodSourceDomainEndpoints(endpointMap map[endpoint.EndpointKey][]string, pod *v1.Pod, targets []string) {
if ps.podSourceDomain != "" {
domain := pod.Name + "." + ps.podSourceDomain
if len(targets) == 0 {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
}
if ps.podSourceDomain == "" {
return
}
domain := pod.Name + "." + ps.podSourceDomain
if len(targets) == 0 {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
} else {
addTargetsToEndpointMap(endpointMap, pod, targets, domain)
}
}
Expand Down
13 changes: 13 additions & 0 deletions source/pod_fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
Namespace: "default",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
NodeName: "node-1.internal",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand Down Expand Up @@ -111,6 +113,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
Namespace: "default",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -123,6 +126,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
Namespace: "kube-system",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.102",
PodIPs: []v1.PodIP{
{IP: "100.67.94.102"},
Expand All @@ -145,6 +149,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
Namespace: "default",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -171,6 +176,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -195,6 +201,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -219,6 +226,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -234,6 +242,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.102",
PodIPs: []v1.PodIP{
{IP: "100.67.94.102"},
Expand All @@ -259,6 +268,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand All @@ -274,6 +284,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.102",
PodIPs: []v1.PodIP{
{IP: "100.67.94.102"},
Expand All @@ -296,6 +307,7 @@ func TestPodSourceFqdnTemplatingExamples(t *testing.T) {
Namespace: "kube-system",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand Down Expand Up @@ -436,6 +448,7 @@ func TestPodSourceFqdnTemplatingExamples_Failed(t *testing.T) {
Namespace: "kube-system",
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
PodIP: "100.67.94.101",
PodIPs: []v1.PodIP{
{IP: "100.67.94.101"},
Expand Down
Loading
Loading