Skip to content

Commit 94472f5

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 7dd84a5 commit 94472f5

File tree

12 files changed

+358
-119
lines changed

12 files changed

+358
-119
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
permissions:
1515
contents: write # to push chart release and create a release (helm/chart-releaser-action)
1616

17-
if: github.repository == 'kubernetes-sigs/external-dns'
17+
if: github.repository == 'adobe/external-dns'
1818
runs-on: ubuntu-latest
1919
defaults:
2020
run:

Makefile

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

146146
release.prod:
147147
$(MAKE) build.push/multiarch
148+
149+
# ================= Kind deployment
150+
151+
KIND_CLUSTER="edns"
152+
153+
kind-up:
154+
kind create cluster \
155+
--image kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac \
156+
--name $(KIND_CLUSTER) \
157+
--config zarf/kind/kind-config.yaml
158+
kubectl config set-context --current --namespace=default
159+
160+
kind-down:
161+
kind delete cluster --name $(KIND_CLUSTER)
162+
163+
kind-load:
164+
kind load docker-image "$(IMAGE):$(VERSION)" --name $(KIND_CLUSTER)
165+
166+
kind-apply:
167+
kubectl apply -f zarf/helm/rolebinding.yaml
168+
helm template edns charts/external-dns -f zarf/helm/custom-values.yaml --set image.repository=$(IMAGE) --set image.tag=$(VERSION) | kubectl apply -f -
169+
kubectl apply -f zarf/helm/service.yaml
170+
171+
kind-update: build build.docker kind-load kind-apply
172+
173+
kind-logs:
174+
kubectl logs deployment/edns-external-dns -f

charts/external-dns/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The following table lists the configurable parameters of the _ExternalDNS_ chart
6969
| `txtPrefix` | Prefix to create a TXT record with a name following the pattern `prefix.<CNAME record>`. | `""` |
7070
| `domainFilters` | Limit possible target zones by domain suffixes. | `[]` |
7171
| `provider` | DNS provider where the DNS records will be created, for the available providers and how to configure them see the [README](https://github.com/kubernetes-sigs/external-dns#deploying-to-a-cluster) (this can be templated). | `aws` |
72+
| `watchNamespaces` | List of namespaces to be observed for new DNS entries. | `[]` |
7273
| `extraArgs` | Extra arguments to pass to the _external-dns_ container, these are needed for provider specific arguments (these can be templated). | `[]` |
7374
| `deploymentStrategy` | .spec.strategy of the external-dns Deployment. Defaults to 'Recreate' since multiple external-dns pods may conflict with each other. | `{type: Recreate}` |
7475
| `secretConfiguration.enabled` | Enable additional secret configuration. | `false` |

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
@@ -126,6 +126,8 @@ domainFilters: []
126126

127127
provider: aws
128128

129+
watchNamespaces: []
130+
129131
extraArgs: []
130132

131133
secretConfiguration:

source/compatibility.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,32 @@ 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-
if address.Type == v1.NodeExternalIP && isExternal {
161-
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, endpoint.RecordTypeA, 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
162159
}
163-
if address.Type == v1.NodeInternalIP && isInternal {
164-
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, endpoint.RecordTypeA, address.Address))
160+
for _, address := range node.Status.Addresses {
161+
if address.Type == v1.NodeExternalIP && isExternal {
162+
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, endpoint.RecordTypeA, address.Address))
163+
}
164+
if address.Type == v1.NodeInternalIP && isInternal {
165+
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, endpoint.RecordTypeA, address.Address))
166+
}
165167
}
166168
}
167169
}

0 commit comments

Comments
 (0)