Skip to content

Commit

Permalink
add docker build to external dns & use webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Jansen <[email protected]>
  • Loading branch information
farodin91 committed Sep 25, 2023
1 parent 06748d0 commit c7569f4
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 220 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
- package-ecosystem: docker
directory: /
schedule:
interval: daily
45 changes: 45 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: main

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types:
- published

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/gdatasoftwareag/external-dns-coredns-plugin
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${VERSION}-${GITHUB_SHA::8}"
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Login to Github Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub Packages
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-buster as builder
FROM golang:1.20-buster as builder

COPY . /code/external-dns-coredns-plugin
WORKDIR /code/external-dns-coredns-plugin
Expand All @@ -10,3 +10,9 @@ COPY --from=builder /code/external-dns-coredns-plugin/external-dns-coredns-plugi

# replace with your desire device count
CMD ["external-dns-coredns-plugin"]

LABEL org.opencontainers.image.title="ExternalDNS CoreDNS plugin Docker Image" \
org.opencontainers.image.description="external-dns-coredns-plugin" \
org.opencontainers.image.url="https://github.com/GDATASoftwareAG/external-dns-coredns-plugin" \
org.opencontainers.image.source="https://github.com/GDATASoftwareAG/external-dns-coredns-plugin" \
org.opencontainers.image.license="MIT"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# ExternalDNS Plugin CoreDNS Provider
# ExternalDNS Plugin CoreDNS Webhook


## Pre-filtering CoreDNS services based on ownerIDs

If your are running external-dns in multi cluster, you can use `--coredns-pre-filter-external-owned-records` and `--txt-owner-id` to ignore external created services, for example from a different external-dns.
If you are running external-dns in multi cluster, you can use `--coredns-pre-filter-external-owned-records` and
`--txt-owner-id` to ignore external created services, for example from a different external-dns.

## Custom attributes

Expand Down
4 changes: 2 additions & 2 deletions coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (p coreDNSProvider) Records(_ context.Context) ([]*endpoint.Endpoint, error
}
for _, service := range services {
if p.preFilterExternalOwnedRecords && service.Text != "" {
if labels, err := endpoint.NewLabelsFromString(service.Text); err == nil && labels != nil {
if labels, err := endpoint.NewLabelsFromStringPlain(service.Text); err == nil && labels != nil {
if owner, exists := labels[endpoint.OwnerLabelKey]; exists && owner != p.ownerID {
log.Debugf(`Skipping coredns service %v because owner id does not match, found: "%s", required: "%s"`, service, owner, p.ownerID)
continue
Expand Down Expand Up @@ -379,7 +379,7 @@ func (p coreDNSProvider) ApplyChanges(_ context.Context, changes *plan.Changes)

group := ""
if prop, ok := ep.GetProviderSpecificProperty(providerSpecificGroup); ok {
group = prop.Value
group = prop
}
service := Service{
Host: target,
Expand Down
4 changes: 2 additions & 2 deletions coredns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ func TestRecordsAWithGroupServiceTranslation(t *testing.T) {
endpoints, _ := coredns.Records(context.Background())
if prop, ok := endpoints[0].GetProviderSpecificProperty(providerSpecificGroup); !ok {
t.Error("go no Group name")
} else if prop.Value != "test1" {
t.Errorf("got unexpected Group name: %s != %s", prop.Value, "test1")
} else if prop != "test1" {
t.Errorf("got unexpected Group name: %s != %s", prop, "test1")
}
}

Expand Down
66 changes: 39 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
module github.com/GDATASoftwareAG/external-dns-coredns-plugin
module github.com/GDATASoftwareAG/external-dns-coredns-webhook

go 1.19
go 1.20

require (
github.com/alecthomas/kingpin v2.2.5+incompatible
github.com/sirupsen/logrus v1.9.0
go.etcd.io/etcd/client/v3 v3.5.7
sigs.k8s.io/external-dns v0.13.2
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/sirupsen/logrus v1.9.3
go.etcd.io/etcd/client/v3 v3.5.9
sigs.k8s.io/external-dns v0.13.6
)

replace sigs.k8s.io/external-dns => sigs.k8s.io/external-dns v0.13.7-0.20230925081458-8251b6dd8534

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aws/aws-sdk-go v1.44.136 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aws/aws-sdk-go v1.44.311 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.43.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.9 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect
google.golang.org/grpc v1.56.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apimachinery v0.26.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apimachinery v0.27.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Loading

0 comments on commit c7569f4

Please sign in to comment.