Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external DNS endpoint CRD #2762

Merged
merged 6 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions deployments/common/crds/externaldns.nginx.org_dnsendpoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: dnsendpoints.externaldns.nginx.org
spec:
group: externaldns.nginx.org
names:
kind: DNSEndpoint
listKind: DNSEndpointList
plural: dnsendpoints
singular: dnsendpoint
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: DNSEndpoint is the CRD wrapper for Endpoint
type: object
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
type: object
properties:
endpoints:
type: array
items:
type: object
properties:
dnsName:
description: The hostname for the DNS record
type: string
labels:
description: Labels stores labels defined for the Endpoint
type: object
additionalProperties:
type: string
providerSpecific:
description: ProviderSpecific stores provider specific config
type: array
items:
type: object
properties:
name:
description: Name of the property
type: string
value:
description: Value of the property
type: string
recordTTL:
description: TTL for the record
type: integer
format: int64
recordType:
description: RecordType type of record, e.g. CNAME, A, SRV, TXT, MX
type: string
targets:
description: The targets the DNS service points to
type: array
items:
type: string
status:
type: object
properties:
observedGeneration:
description: The generation observed by by the external-dns controller.
type: integer
format: int64
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: dnsendpoints.externaldns.nginx.org
spec:
group: externaldns.nginx.org
names:
kind: DNSEndpoint
listKind: DNSEndpointList
plural: dnsendpoints
singular: dnsendpoint
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: DNSEndpoint is the CRD wrapper for Endpoint
type: object
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
type: object
properties:
endpoints:
type: array
items:
type: object
properties:
dnsName:
description: The hostname for the DNS record
type: string
labels:
description: Labels stores labels defined for the Endpoint
type: object
additionalProperties:
type: string
providerSpecific:
description: ProviderSpecific stores provider specific config
type: array
items:
type: object
properties:
name:
description: Name of the property
type: string
value:
description: Value of the property
type: string
recordTTL:
description: TTL for the record
type: integer
format: int64
recordType:
description: RecordType type of record, e.g. CNAME, A, SRV, TXT, MX
type: string
targets:
description: The targets the DNS service points to
type: array
items:
type: string
status:
type: object
properties:
observedGeneration:
description: The generation observed by by the external-dns controller.
type: integer
format: int64
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
32 changes: 32 additions & 0 deletions examples/custom-resources/external-dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Step 1: Register the external-crd with the k8s api (run from the root of this repo):

```k apply -f deployments/common/crds/externaldns.nginx.org_dnsendpoints.yaml```

Step 2: Deploy external-dns

Update `external-dns-route53.yaml` with your Domain Name and Hosted Zone ID, and apply the file.

```k apply -f external-dns-route53.yaml```

Step 3: Deploy the DNSEndpoint object

Update `dnsendpoint.yaml` with the DNS hostname and the target IPs (the external IPs of the Ingress Controller service), and apply the file.

```k apply -f dnsendpoint.yaml```

Step 4: Check the logs of the external-dns pod, and you'll see something like this:

```
time="2022-05-26T15:04:45Z" level=info msg="Desired change: CREATE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:04:45Z" level=info msg="Desired change: CREATE cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:04:46Z" level=info msg="2 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
time="2022-05-26T15:05:45Z" level=info msg="Applying provider record filter for domains: [example.com. .example.com.]"
time="2022-05-26T15:05:45Z" level=info msg="Desired change: UPSERT cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:05:45Z" level=info msg="Desired change: UPSERT cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:05:46Z" level=info msg="2 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
time="2022-05-26T15:06:45Z" level=info msg="Applying provider record filter for domains: [example.com. .example.com.]"
time="2022-05-26T15:06:45Z" level=info msg="Desired change: UPSERT cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:06:45Z" level=info msg="Desired change: DELETE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:06:45Z" level=info msg="Desired change: CREATE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
time="2022-05-26T15:06:46Z" level=info msg="3 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
```
12 changes: 12 additions & 0 deletions examples/custom-resources/external-dns/dnsendpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: externaldns.nginx.org/v1
kind: DNSEndpoint
metadata:
name: examplednsrecord
spec:
endpoints:
- dnsName: <DNS_NAME>
recordTTL: 180
recordType: A
targets:
- <IP_1>
- <IP_2>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: external-dns
rules:
- apiGroups: [""]
resources: ["services","endpoints","pods"]
verbs: ["get","watch","list"]
- apiGroups: ["extensions","networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get","watch","list"]
- apiGroups: ["externaldns.nginx.org"]
resources: ["dnsendpoints"]
verbs: ["get","watch","list"]
- apiGroups: ["externaldns.nginx.org"]
resources: ["dnsendpoints/status"]
verbs: ["update"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list","watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: external-dns-viewer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: external-dns
subjects:
- kind: ServiceAccount
name: external-dns
namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: external-dns
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: external-dns
template:
metadata:
labels:
app: external-dns
spec:
serviceAccountName: external-dns
containers:
- name: external-dns
image: k8s.gcr.io/external-dns/external-dns:v0.11.0
args:
- --source=service
- --source=ingress
- --source=crd
- --crd-source-apiversion=externaldns.nginx.org/v1
- --crd-source-kind=DNSEndpoint
- --domain-filter=<MY_DOMAIN> # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
- --provider=aws
- --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
- --aws-zone-type=public # only look at public hosted zones (valid values are public, private or no value for both)
- --registry=txt
- --txt-owner-id=<HOSTED_ZONE_ID>
securityContext:
fsGroup: 65534 # For ExternalDNS to be able to read Kubernetes and AWS token files
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/prometheus/client_golang v1.12.2
github.com/spiffe/go-spiffe/v2 v2.1.0
github.com/stretchr/testify v1.7.2
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
google.golang.org/grpc v1.47.0
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
Expand Down Expand Up @@ -99,14 +100,14 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0=
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand All @@ -784,8 +786,9 @@ golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hM
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1045,8 +1048,9 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff h1:VX/uD7MK0AHXGiScH3fsieUQUcpmRERPDYtqZdJnA+Q=
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ fi
# instead of the $GOPATH directly. For normal projects this can be dropped.
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/nginxinc/kubernetes-ingress/pkg/client github.com/nginxinc/kubernetes-ingress/pkg/apis \
"configuration:v1alpha1,v1 dos:v1beta1" \
"configuration:v1alpha1,v1 dos:v1beta1 externaldns:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
6 changes: 6 additions & 0 deletions pkg/apis/externaldns/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package externaldns

const (
// GroupName the name of the group used by kubernetes.
GroupName = "externaldns.nginx.org"
)
5 changes: 5 additions & 0 deletions pkg/apis/externaldns/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package
// +groupName=externaldns.nginx.org

// Package v1 is the v1 version of the API.
package v1
Loading