Skip to content

Commit 812ba38

Browse files
ecojandobrerazvan
authored andcommitted
Added support for multi-namespace watch on services and made nodeInformer optional for service source (#1)
* Make external-dns run in a restricted k8s cluster * Added zarf and updated Makefile * Made service nodeInformer optional * Added support for multinamespace watching * Added dedicated extraArgs parameter for namespaces * Added Github action for docker build and push to ghcr Co-authored-by: Razvan Dobre <[email protected]>
1 parent bc61d4d commit 812ba38

File tree

13 files changed

+361
-130
lines changed

13 files changed

+361
-130
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: docker-image-push
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
on:
8+
push:
9+
tags:
10+
- 'v*'
11+
12+
env:
13+
# Use docker.io for Docker Hub if empty
14+
REGISTRY: ghcr.io
15+
# github.repository as <account>/<repo>
16+
IMAGE_NAME: adobe/external-dns
17+
18+
jobs:
19+
build:
20+
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v2
32+
with:
33+
go-version: 1.17
34+
id: go
35+
36+
# Login against a Docker registry except on PR
37+
# https://github.com/docker/login-action
38+
- name: Log into registry ${{ env.REGISTRY }}
39+
if: github.event_name != 'pull_request'
40+
uses: docker/login-action@v1
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
# Extract metadata (tags, labels) for Docker
47+
# https://github.com/docker/metadata-action
48+
- name: Extract Docker metadata
49+
id: meta
50+
uses: docker/metadata-action@v3
51+
with:
52+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53+
tags: |
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
59+
# Build and push Docker image with Buildx (don't push on PR)
60+
# https://github.com/docker/build-push-action
61+
- name: Build and push Docker image
62+
uses: docker/build-push-action@v2
63+
with:
64+
context: .
65+
build-args: |
66+
ARCH=amd64
67+
push: ${{ github.event_name != 'pull_request' }}
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/release-chart.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
permissions:
1414
contents: write # to push chart release and create a release (helm/chart-releaser-action)
1515

16-
if: github.repository == 'kubernetes-sigs/external-dns'
16+
if: github.repository == 'adobe/external-dns'
1717
runs-on: ubuntu-latest
1818
defaults:
1919
run:
@@ -31,13 +31,6 @@ jobs:
3131
chart_version="$(grep -Po "(?<=^version: ).+" charts/external-dns/Chart.yaml)"
3232
echo "version=${chart_version}" >> $GITHUB_OUTPUT
3333
34-
- name: Get changelog entry
35-
id: changelog_reader
36-
uses: mindsers/changelog-reader-action@b97ce03a10d9bdbb07beb491c76a5a01d78cd3ef
37-
with:
38-
path: charts/external-dns/CHANGELOG.md
39-
version: "v${{ steps.chart_version.outputs.version }}"
40-
4134
- name: Create release notes
4235
run: |
4336
set -euo pipefail

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,30 @@ release.staging: test
176176

177177
release.prod: test
178178
$(MAKE) build.push/multiarch
179+
180+
# ================= Kind deployment
181+
182+
KIND_CLUSTER="edns"
183+
184+
kind-up:
185+
kind create cluster \
186+
--image kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac \
187+
--name $(KIND_CLUSTER) \
188+
--config zarf/kind/kind-config.yaml
189+
kubectl config set-context --current --namespace=default
190+
191+
kind-down:
192+
kind delete cluster --name $(KIND_CLUSTER)
193+
194+
kind-load:
195+
kind load docker-image "$(IMAGE):$(VERSION)" --name $(KIND_CLUSTER)
196+
197+
kind-apply:
198+
kubectl apply -f zarf/helm/rolebinding.yaml
199+
helm template edns charts/external-dns -f zarf/helm/custom-values.yaml --set image.repository=$(IMAGE) --set image.tag=$(VERSION) | kubectl apply -f -
200+
kubectl apply -f zarf/helm/service.yaml
201+
202+
kind-update: build build.docker kind-load kind-apply
203+
204+
kind-logs:
205+
kubectl logs deployment/edns-external-dns -f

charts/external-dns/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: external-dns
33
description: ExternalDNS synchronizes exposed Kubernetes Services and Ingresses with DNS providers.
44
type: application
55
version: 1.13.0
6-
appVersion: 0.13.5
6+
appVersion: 0.13.5-202300727-1700-adobe
77
keywords:
88
- kubernetes
99
- externaldns

charts/external-dns/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Before you can install the chart you will need to add the `external-dns` repo to [Helm](https://helm.sh/).
88

99
```shell
10-
helm repo add external-dns https://kubernetes-sigs.github.io/external-dns/
10+
helm repo add external-dns https://adobe.github.io/external-dns/
1111
```
1212

1313
After you've installed the repo you can install the chart.

charts/external-dns/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
{{- if .Values.triggerLoopOnEvent }}
7474
- --events
7575
{{- end }}
76+
{{- if .Values.watchNamespaces }}
77+
- --namespace={{ .Values.watchNamespaces | join "," }}
78+
{{- end }}
7679
{{- range .Values.sources }}
7780
- --source={{ . }}
7881
{{- end }}

charts/external-dns/values.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Declare variables to be passed into your templates.
44

55
image:
6-
repository: registry.k8s.io/external-dns/external-dns
6+
repository: ghcr.io/adobe/external-dns
77
# Overrides the image tag whose default is v{{ .Chart.AppVersion }}
88
tag: ""
99
pullPolicy: IfNotPresent
@@ -177,6 +177,8 @@ domainFilters: []
177177

178178
provider: aws
179179

180+
watchNamespaces: []
181+
180182
extraArgs: []
181183

182184
secretConfiguration:

source/compatibility.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,34 @@ func legacyEndpointsFromDNSControllerNodePortService(svc *v1.Service, sc *servic
138138
return nil, nil
139139
}
140140

141-
nodes, err := sc.nodeInformer.Lister().List(labels.Everything())
142-
if err != nil {
143-
return nil, err
144-
}
141+
for _, informer := range sc.informers {
142+
nodes, err := informer.nodeInformer.Lister().List(labels.Everything())
143+
if err != nil {
144+
return nil, err
145+
}
145146

146-
var hostnameList []string
147-
if isExternal {
148-
hostnameList = strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
149-
} else {
150-
hostnameList = strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")
151-
}
147+
var hostnameList []string
148+
if isExternal {
149+
hostnameList = strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
150+
} else {
151+
hostnameList = strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")
152+
}
152153

153-
for _, hostname := range hostnameList {
154-
for _, node := range nodes {
155-
_, isNode := node.Labels["node-role.kubernetes.io/node"]
156-
if !isNode {
157-
continue
158-
}
159-
for _, address := range node.Status.Addresses {
160-
recordType := suitableType(address.Address)
161-
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
162-
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
163-
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
154+
for _, hostname := range hostnameList {
155+
for _, node := range nodes {
156+
_, isNode := node.Labels["node-role.kubernetes.io/node"]
157+
if !isNode {
158+
continue
164159
}
165-
if isInternal && address.Type == v1.NodeInternalIP {
166-
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
160+
for _, address := range node.Status.Addresses {
161+
recordType := suitableType(address.Address)
162+
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
163+
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
164+
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
165+
}
166+
if isInternal && address.Type == v1.NodeInternalIP {
167+
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
168+
}
167169
}
168170
}
169171
}

0 commit comments

Comments
 (0)