Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
18 changes: 15 additions & 3 deletions source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func (ps *podSource) addPodEndpointsToEndpointMap(endpointMap map[endpoint.Endpo
func (ps *podSource) addInternalHostnameAnnotationEndpoints(endpointMap map[endpoint.EndpointKey][]string, pod *v1.Pod, targets []string) {
if domainAnnotation, ok := pod.Annotations[annotations.InternalHostnameKey]; ok {
domainList := annotations.SplitHostnameAnnotation(domainAnnotation)
if len(targets) == 0 && pod.Status.PodIP == "" {
log.Debugf("skipping pod %q. PodIP is empty with phase %q", pod.Name, pod.Status.Phase)
return
}
for _, domain := range domainList {
if len(targets) == 0 {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
Expand All @@ -210,8 +214,12 @@ func (ps *podSource) addKopsDNSControllerEndpoints(endpointMap map[endpoint.Endp
if ps.compatibility == "kops-dns-controller" {
if domainAnnotation, ok := pod.Annotations[kopsDNSControllerInternalHostnameAnnotationKey]; ok {
domainList := annotations.SplitHostnameAnnotation(domainAnnotation)
for _, domain := range domainList {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
if pod.Status.PodIP == "" {
log.Debugf("skipping pod %q. PodIP is empty with phase %q", pod.Name, pod.Status.Phase)
Comment thread
isumitsolanki marked this conversation as resolved.
Outdated
} else {
for _, domain := range domainList {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
}
}
}

Expand All @@ -226,7 +234,11 @@ func (ps *podSource) addPodSourceDomainEndpoints(endpointMap map[endpoint.Endpoi
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 pod.Status.PodIP == "" {
log.Debugf("skipping pod %q. PodIP is empty with phase %q", pod.Name, pod.Status.Phase)
Comment thread
isumitsolanki marked this conversation as resolved.
Outdated
} else {
addToEndpointMap(endpointMap, pod, domain, endpoint.SuitableType(pod.Status.PodIP), pod.Status.PodIP)
}
}
addTargetsToEndpointMap(endpointMap, pod, targets, domain)
Comment thread
isumitsolanki marked this conversation as resolved.
Outdated
}
Expand Down
77 changes: 77 additions & 0 deletions source/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,83 @@ func TestPodSource(t *testing.T) {
},
},
},
{
Comment thread
isumitsolanki marked this conversation as resolved.
"pending pod with empty PodIP and internal-hostname annotation should not create CNAME",
"",
"",
false,
"",
[]*endpoint.Endpoint{},
false,
nil,
[]*corev1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "pending-pod",
Namespace: "kube-system",
Annotations: map[string]string{
annotations.InternalHostnameKey: "foo.example.com",
},
},
Spec: corev1.PodSpec{
HostNetwork: false,
},
Status: corev1.PodStatus{
Phase: corev1.PodPending,
PodIP: "",
},
},
},
},
{
"pending pod with empty PodIP and pod-source-domain should not create CNAME",
"",
"",
false,
"example.org",
[]*endpoint.Endpoint{},
false,
nil,
[]*corev1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "pending-pod",
Namespace: "kube-system",
},
Spec: corev1.PodSpec{HostNetwork: false},
Status: corev1.PodStatus{
Phase: corev1.PodPending,
PodIP: "",
},
},
},
},
{
"pending pod with empty PodIP and kops-dns-controller annotation should not create CNAME",
"",
"kops-dns-controller",
false,
"",
[]*endpoint.Endpoint{},
false,
nil,
[]*corev1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "pending-pod",
Namespace: "kube-system",
Annotations: map[string]string{
kopsDNSControllerInternalHostnameAnnotationKey: "foo.example.com",
},
},
Spec: corev1.PodSpec{HostNetwork: false},
Status: corev1.PodStatus{
Phase: corev1.PodPending,
PodIP: "",
},
},
},
},
} {
t.Run(tc.title, func(t *testing.T) {
kubernetes := fake.NewClientset()
Expand Down
Loading