Skip to content

Commit

Permalink
Added support for multi-namespace watch on services and made nodeInfo…
Browse files Browse the repository at this point in the history
…rmer 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 <dobre@adobe.com>
  • Loading branch information
2 people authored and azun committed Jul 31, 2023
1 parent bc61d4d commit 812ba38
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 130 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/docker-image-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: docker-image-push

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
tags:
- 'v*'

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: adobe/external-dns

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
build-args: |
ARCH=amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 1 addition & 8 deletions .github/workflows/release-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
permissions:
contents: write # to push chart release and create a release (helm/chart-releaser-action)

if: github.repository == 'kubernetes-sigs/external-dns'
if: github.repository == 'adobe/external-dns'
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -31,13 +31,6 @@ jobs:
chart_version="$(grep -Po "(?<=^version: ).+" charts/external-dns/Chart.yaml)"
echo "version=${chart_version}" >> $GITHUB_OUTPUT
- name: Get changelog entry
id: changelog_reader
uses: mindsers/changelog-reader-action@b97ce03a10d9bdbb07beb491c76a5a01d78cd3ef
with:
path: charts/external-dns/CHANGELOG.md
version: "v${{ steps.chart_version.outputs.version }}"

- name: Create release notes
run: |
set -euo pipefail
Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,30 @@ release.staging: test

release.prod: test
$(MAKE) build.push/multiarch

# ================= Kind deployment

KIND_CLUSTER="edns"

kind-up:
kind create cluster \
--image kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac \
--name $(KIND_CLUSTER) \
--config zarf/kind/kind-config.yaml
kubectl config set-context --current --namespace=default

kind-down:
kind delete cluster --name $(KIND_CLUSTER)

kind-load:
kind load docker-image "$(IMAGE):$(VERSION)" --name $(KIND_CLUSTER)

kind-apply:
kubectl apply -f zarf/helm/rolebinding.yaml
helm template edns charts/external-dns -f zarf/helm/custom-values.yaml --set image.repository=$(IMAGE) --set image.tag=$(VERSION) | kubectl apply -f -
kubectl apply -f zarf/helm/service.yaml

kind-update: build build.docker kind-load kind-apply

kind-logs:
kubectl logs deployment/edns-external-dns -f
2 changes: 1 addition & 1 deletion charts/external-dns/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: external-dns
description: ExternalDNS synchronizes exposed Kubernetes Services and Ingresses with DNS providers.
type: application
version: 1.13.0
appVersion: 0.13.5
appVersion: 0.13.5-202300727-1700-adobe
keywords:
- kubernetes
- externaldns
Expand Down
2 changes: 1 addition & 1 deletion charts/external-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Before you can install the chart you will need to add the `external-dns` repo to [Helm](https://helm.sh/).

```shell
helm repo add external-dns https://kubernetes-sigs.github.io/external-dns/
helm repo add external-dns https://adobe.github.io/external-dns/
```

After you've installed the repo you can install the chart.
Expand Down
3 changes: 3 additions & 0 deletions charts/external-dns/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ spec:
{{- if .Values.triggerLoopOnEvent }}
- --events
{{- end }}
{{- if .Values.watchNamespaces }}
- --namespace={{ .Values.watchNamespaces | join "," }}
{{- end }}
{{- range .Values.sources }}
- --source={{ . }}
{{- end }}
Expand Down
4 changes: 3 additions & 1 deletion charts/external-dns/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Declare variables to be passed into your templates.

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

provider: aws

watchNamespaces: []

extraArgs: []

secretConfiguration:
Expand Down
48 changes: 25 additions & 23 deletions source/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,34 @@ func legacyEndpointsFromDNSControllerNodePortService(svc *v1.Service, sc *servic
return nil, nil
}

nodes, err := sc.nodeInformer.Lister().List(labels.Everything())
if err != nil {
return nil, err
}
for _, informer := range sc.informers {
nodes, err := informer.nodeInformer.Lister().List(labels.Everything())
if err != nil {
return nil, err
}

var hostnameList []string
if isExternal {
hostnameList = strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
} else {
hostnameList = strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")
}
var hostnameList []string
if isExternal {
hostnameList = strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
} else {
hostnameList = strings.Split(strings.Replace(internalHostnameAnnotation, " ", "", -1), ",")
}

for _, hostname := range hostnameList {
for _, node := range nodes {
_, isNode := node.Labels["node-role.kubernetes.io/node"]
if !isNode {
continue
}
for _, address := range node.Status.Addresses {
recordType := suitableType(address.Address)
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
for _, hostname := range hostnameList {
for _, node := range nodes {
_, isNode := node.Labels["node-role.kubernetes.io/node"]
if !isNode {
continue
}
if isInternal && address.Type == v1.NodeInternalIP {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
for _, address := range node.Status.Addresses {
recordType := suitableType(address.Address)
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well.
if isExternal && (address.Type == v1.NodeExternalIP || (address.Type == v1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA)) {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
}
if isInternal && address.Type == v1.NodeInternalIP {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, recordType, address.Address))
}
}
}
}
Expand Down
Loading

0 comments on commit 812ba38

Please sign in to comment.