10BC0 Add external DNS endpoint CRD (#2762) · nginx/kubernetes-ingress@e0590e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0590e5

Browse files
jjngxciarams87
andauthored
Add external DNS endpoint CRD (#2762)
* Add external DNS endpoint CRD * Make Go linter happy * Update examples/custom-resources/external-dns/README.md Co-authored-by: Ciara Stacke <18287516+ciarams87@users.noreply.github.com> * Add output of update-codegen * Allow IPv6 addresses and AAAA records Co-authored-by: Ciara Stacke <18287516+ciarams87@users.noreply.github.com> Co-authored-by: Ciara Stacke <c.stacke@f5.com>
1 parent f27f7db commit e0590e5

34 files changed

+1776
-9
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.8.0
6+
creationTimestamp: null
7+
name: dnsendpoints.externaldns.nginx.org
8+
spec:
9+
group: externaldns.nginx.org
10+
names:
11+
kind: DNSEndpoint
12+
listKind: DNSEndpointList
13+
plural: dnsendpoints
14+
singular: dnsendpoint
15+
scope: Namespaced
16+
versions:
17+
- name: v1
18+
schema:
19+
openAPIV3Schema:
20+
description: DNSEndpoint is the CRD wrapper for Endpoint
21+
type: object
22+
properties:
23+
apiVersion:
24+
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'
25+
type: string
26+
kind:
27+
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'
28+
type: string
29+
metadata:
30+
type: object
31+
spec:
32+
type: object
33+
properties:
34+
endpoints:
35+
type: array
36+
items:
37+
type: object
38+
properties:
39+
dnsName:
40+
description: The hostname for the DNS record
41+
type: string
42+
labels:
43+
description: Labels stores labels defined for the Endpoint
44+
type: object
45+
additionalProperties:
46+
type: string
47+
providerSpecific:
48+
description: ProviderSpecific stores provider specific config
49+
type: array
50+
items:
51+
type: object
52+
properties:
53+
name:
54+
description: Name of the property
55+
type: string
56+
value:
57+
description: Value of the property
58+
type: string
59+
recordTTL:
60+
description: TTL for the record
61+
type: integer
62+
format: int64
63+
recordType:
64+
description: RecordType type of record, e.g. CNAME, A, SRV, TXT, MX
65+
type: string
66+
targets:
67+
description: The targets the DNS service points to
68+
type: array
69+
items:
70+
type: string
71+
status:
72+
type: object
73+
properties:
74+
observedGeneration:
75+
description: The generation observed by by the external-dns controller.
76+
type: integer
77+
format: int64
78+
served: true
79+
storage: true
80+
subresources:
81+
status: {}
82+
status:
83+
acceptedNames:
84+
kind: ""
85+
plural: ""
86+
conditions: []
87+
storedVersions: []
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.8.0
6+
creationTimestamp: null
7+
name: dnsendpoints.externaldns.nginx.org
8+
spec:
9+
group: externaldns.nginx.org
10+
names:
11+
kind: DNSEndpoint
12+
listKind: DNSEndpointList
13+
plural: dnsendpoints
14+
singular: dnsendpoint
15+
scope: Namespaced
16+
versions:
17+
- name: v1
18+
schema:
19+
openAPIV3Schema:
20+
description: DNSEndpoint is the CRD wrapper for Endpoint
21+
type: object
22+
properties:
23+
apiVersion:
24+
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'
25+
type: string
26+
kind:
27+
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'
28+
type: string
29+
metadata:
30+
type: object
31+
spec:
32+
type: object
33+
properties:
34+
endpoints:
35+
type: array
36+
items:
37+
type: object
38+
properties:
39+
dnsName:
40+
description: The hostname for the DNS record
41+
type: string
42+
labels:
43+
description: Labels stores labels defined for the Endpoint
44+
type: object
45+
additionalProperties:
46+
type: string
47+
providerSpecific:
48+
description: ProviderSpecific stores provider specific config
49+
type: array
50+
items:
51+
type: object
52+
properties:
53+
name:
54+
description: Name of the property
55+
type: string
56+
value:
57+
description: Value of the property
58+
type: string
59+
recordTTL:
60+
description: TTL for the record
61+
type: integer
62+
format: int64
63+
recordType:
64+
description: RecordType type of record, e.g. CNAME, A, SRV, TXT, MX
65+
type: string
66+
targets:
67+
description: The targets the DNS service points to
68+
type: array
69+
items:
70+
type: string
71+
status:
72+
type: object
73+
properties:
74+
observedGeneration:
75+
description: The generation observed by by the external-dns controller.
76+
type: integer
77+
format: int64
78+
served: true
79+
storage: true
80+
subresources:
81+
status: {}
82+
status:
83+
acceptedNames:
84+
kind: ""
85+
plural: ""
86+
conditions: []
87+
storedVersions: []
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Step 1: Register the external-crd with the k8s api (run from the root of this repo):
2+
3+
```k apply -f deployments/common/crds/externaldns.nginx.org_dnsendpoints.yaml```
4+
5+
Step 2: Deploy external-dns
6+
7+
Update `external-dns-route53.yaml` with your Domain Name and Hosted Zone ID, and apply the file.
8+
9+
```k apply -f external-dns-route53.yaml```
10+
11+
Step 3: Deploy the DNSEndpoint object
12+
13+
Update `dnsendpoint.yaml` with the DNS hostname and the target IPs (the external IPs of the Ingress Controller service), and apply the file.
14+
15+
```k apply -f dnsendpoint.yaml```
16+
17+
Step 4: Check the logs of the external-dns pod, and you'll see something like this:
18+
19+
```
20+
time="2022-05-26T15:04:45Z" level=info msg="Desired change: CREATE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
21+
time="2022-05-26T15:04:45Z" level=info msg="Desired change: CREATE cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
22+
time="2022-05-26T15:04:46Z" level=info msg="2 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
23+
time="2022-05-26T15:05:45Z" level=info msg="Applying provider record filter for domains: [example.com. .example.com.]"
24+
time="2022-05-26T15:05:45Z" level=info msg="Desired change: UPSERT cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
25+
time="2022-05-26T15:05:45Z" level=info msg="Desired change: UPSERT cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
26+
time="2022-05-26T15:05:46Z" level=info msg="2 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
27+
time="2022-05-26T15:06:45Z" level=info msg="Applying provider record filter for domains: [example.com. .example.com.]"
28+
time="2022-05-26T15:06:45Z" level=info msg="Desired change: UPSERT cafe.example.com TXT [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
29+
time="2022-05-26T15:06:45Z" level=info msg="Desired change: DELETE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
30+
time="2022-05-26T15:06:45Z" level=info msg="Desired change: CREATE cafe.example.com A [Id: /hostedzone/Z04ABCDEFGHIJKLMNO]"
31+
time="2022-05-26T15:06:46Z" level=info msg="3 record(s) in zone example.com. [Id: /hostedzone/Z04ABCDEFGHIJKLMNO] were successfully updated"
32+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: externaldns.nginx.org/v1
2+
kind: DNSEndpoint
3+
metadata:
4+
name: examplednsrecord
5+
spec:
6+
endpoints:
7+
- dnsName: <DNS_NAME>
8+
recordTTL: 180
9+
recordType: A
10+
targets:
11+
- <IP_1>
12+
- <IP_2>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: external-dns
5+
rules:
6+
- apiGroups: [""]
7+
resources: ["services","endpoints","pods"]
8+
verbs: ["get","watch","list"]
9+
- apiGroups: ["extensions","networking.k8s.io"]
10+
resources: ["ingresses"]
11+
verbs: ["get","watch","list"]
12+
- apiGroups: ["externaldns.nginx.org"]
13+
resources: ["dnsendpoints"]
14+
verbs: ["get","watch","list"]
15+
- apiGroups: ["externaldns.nginx.org"]
16+
resources: ["dnsendpoints/status"]
17+
verbs: ["update"]
18+
- apiGroups: [""]
19+
resources: ["nodes"]
20+
verbs: ["list","watch"]
21+
---
22+
apiVersion: rbac.authorization.k8s.io/v1
23+
kind: ClusterRoleBinding
24+
metadata:
25+
name: external-dns-viewer
26+
roleRef:
27+
apiGroup: rbac.authorization.k8s.io
28+
kind: ClusterRole
29+
name: external-dns
30+
subjects:
31+
- kind: ServiceAccount
32+
name: external-dns
33+
namespace: default
34+
---
35+
apiVersion: apps/v1
36+
kind: Deployment
37+
metadata:
38+
name: external-dns
39+
spec:
40+
strategy:
41+
type: Recreate
42+
selector:
43+
matchLabels:
44+
app: external-dns
45+
template:
46+
metadata:
47+
labels:
48+
app: external-dns
49+
spec:
50+
serviceAccountName: external-dns
51+
containers:
52+
- name: external-dns
53+
image: k8s.gcr.io/external-dns/external-dns:v0.11.0
54+
args:
55+
- --source=service
56+
- --source=ingress
57+
- --source=crd
58+
- --crd-source-apiversion=externaldns.nginx.org/v1
59+
- --crd-source-kind=DNSEndpoint
60+
- --domain-filter=<MY_DOMAIN> # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
61+
- --provider=aws
62+
- --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
63+
- --aws-zone-type=public # only look at public hosted zones (valid values are public, private or no value for both)
64+
- --registry=txt
65+
- --txt-owner-id=<HOSTED_ZONE_ID>
66+
securityContext:
67+
fsGroup: 65534 # For ExternalDNS to be able to read Kubernetes and AWS token files

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/prometheus/client_golang v1.12.2
1616
github.com/spiffe/go-spiffe/v2 v2.1.0
1717
github.com/stretchr/testify v1.7.2
18+
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
1819
google.golang.org/grpc v1.47.0
1920
k8s.io/api v0.23.6
2021
k8s.io/apimachinery v0.23.6
@@ -99,14 +100,14 @@ require (
99100
go.uber.org/multierr v1.6.0 // indirect
100101
go.uber.org/zap v1.19.1 // indirect
101102
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
102-
golang.org/x/mod v0.5.0 // indirect
103+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
103104
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
104105
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
105106
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
106107
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
107108
golang.org/x/text v0.3.7 // indirect
108109
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
109-
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff // indirect
110+
golang.org/x/tools v0.1.10 // indirect
110111
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
111112
google.golang.org/appengine v1.6.7 // indirect
112113
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
758758
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
759759
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
760760
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
761+
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0=
762+
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
761763
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
762764
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
763765
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -784,8 +786,9 @@ golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hM
784786
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
785787
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
786788
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
787-
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
788789
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
790+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
791+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
789792
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
790793
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
791794
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1045,8 +1048,9 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
10451048
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
10461049
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
10471050
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
1048-
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff h1:VX/uD7MK0AHXGiScH3fsieUQUcpmRERPDYtqZdJnA+Q=
10491051
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
1052+
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
1053+
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
10501054
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10511055
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10521056
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

hack/update-codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ fi
3333
# instead of the $GOPATH directly. For normal projects this can be dropped.
3434
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
3535
github.com/nginxinc/kubernetes-ingress/pkg/client github.com/nginxinc/kubernetes-ingress/pkg/apis \
36-
"configuration:v1alpha1,v1 dos:v1beta1" \
36+
"configuration:v1alpha1,v1 dos:v1beta1 externaldns:v1" \
3737
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \
3838
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt

pkg/apis/externaldns/register.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package externaldns
2+
3+
const (
4+
// GroupName the name of the group used by kubernetes.
5+
GroupName = "externaldns.nginx.org"
6+
)

pkg/apis/externaldns/v1/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// +k8s:deepcopy-gen=package
2+
// +groupName=externaldns.nginx.org
3+
4+
// Package v1 is the v1 version of the API.
5+
package v1

0 commit comments

Comments
 (0)
0