Skip to content

Commit

Permalink
feat: pods can have hostPorts without hostNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycuellar committed Mar 11, 2023
1 parent dd61d0f commit 2497395
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 2 additions & 4 deletions docs/tutorials/kops-dns-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ The DNS record mappings try to "do the right thing", but what this means is diff

### Pods

For the external annotation, ExternalDNS will map a HostNetwork=true Pod to the external IPs of the Node.
For the external annotation, ExternalDNS will map a Pod to the external IPs of the Node.

For the internal annotation, ExternalDNS will map a HostNetwork=true Pod to the internal IPs of the Node.

ExternalDNS ignore Pods that are not HostNetwork=true
For the internal annotation, ExternalDNS will map a Pod to the internal IPs of the Node.

Annotations added to Pods will always result in an A record being created.

Expand Down
6 changes: 0 additions & 6 deletions source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"sigs.k8s.io/external-dns/endpoint"

log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
kubeinformers "k8s.io/client-go/informers"
Expand Down Expand Up @@ -84,11 +83,6 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error

domains := make(map[string][]string)
for _, pod := range pods {
if !pod.Spec.HostNetwork {
log.Debugf("skipping pod %s. hostNetwork=false", pod.Name)
continue
}

if domain, ok := pod.Annotations[internalHostnameAnnotationKey]; ok {
if _, ok := domains[domain]; !ok {
domains[domain] = []string{}
Expand Down
10 changes: 6 additions & 4 deletions source/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ func TestPodSource(t *testing.T) {
},
},
{
"pods with hostNetwore=false should be ignored",
"pods with hostNetwore=false should not be ignored",
"",
"",
[]*endpoint.Endpoint{
{DNSName: "a.foo.example.org", Targets: endpoint.Targets{"54.10.11.1"}, RecordType: endpoint.RecordTypeA},
{DNSName: "internal.a.foo.example.org", Targets: endpoint.Targets{"10.0.1.1"}, RecordType: endpoint.RecordTypeA},
{DNSName: "b.foo.example.org", Targets: endpoint.Targets{"54.10.11.2"}, RecordType: endpoint.RecordTypeA},
{DNSName: "internal.b.foo.example.org", Targets: endpoint.Targets{"10.0.1.2"}, RecordType: endpoint.RecordTypeA},
},
false,
[]*corev1.Node{
Expand Down Expand Up @@ -304,16 +306,16 @@ func TestPodSource(t *testing.T) {
Name: "my-pod2",
Namespace: "kube-system",
Annotations: map[string]string{
internalHostnameAnnotationKey: "internal.a.foo.example.org",
hostnameAnnotationKey: "a.foo.example.org",
internalHostnameAnnotationKey: "internal.b.foo.example.org",
hostnameAnnotationKey: "b.foo.example.org",
},
},
Spec: corev1.PodSpec{
HostNetwork: false,
NodeName: "my-node2",
},
Status: corev1.PodStatus{
PodIP: "100.0.1.2",
PodIP: "10.0.1.2",
},
},
},
Expand Down

0 comments on commit 2497395

Please sign in to comment.