Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 080f788

Browse files
authored
Merge pull request #554 from mumoshu/deprecate-external-dns-name-create-record-set-hosted-zone-id
Deprecate externalDNSName/createRecordSet/hostedZoneId
2 parents 71ca20c + 40fdf69 commit 080f788

File tree

8 files changed

+115
-73
lines changed

8 files changed

+115
-73
lines changed

Documentation/kubernetes-on-aws-render.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,28 @@ useCalico: true
251251

252252
`kube-aws` can optionally create an ALIAS record for the controller's ELB in an existing Route53 hosted zone.
253253

254-
Edit the `cluster.yaml` file:
254+
Just run `kube-aws init` with the flag `--hosted-zone-id` to specify the id of the hosted zone in which the record is created.
255+
256+
If you've run `kube-aws init` without the flag, edit the `cluster.yaml` file to add `loadBalancer.hostedZone.id` under the first item of `apiEndpoints`:
255257

256258
```yaml
257-
externalDNSName: kubernetes.staging.example.com
258-
createRecordSet: true
259-
hostedZoneId: A12B3CDE4FG5HI
259+
apiEndpoints:
260+
- name: default
261+
dNSName: kubernetes.staging.example.com
262+
loadBalancer:
263+
hostedZone:
264+
id: A12B3CDE4FG5HI
265+
260266
# DEPRECATED: use hostedZoneId instead
261267
#hostedZone: staging.example.com
268+
269+
# DEPRECATED: use loadBalancer.hostedZone.id instead
270+
#hostedZoneId: A12B3CDE4FG5HI
271+
272+
# DEPRECATED: use loadBalancer.createRecordSet instead
273+
# This is even implied to be true when loadBalancer.hostedZone.id is specified
274+
#createRecordSet: true
275+
262276
```
263277

264278
If `createRecordSet` is not set to true, the deployer will be responsible for making externalDNSName routable to the the ELB managing the controller nodes after the cluster is created.

cmd/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func init() {
2424
RootCmd.AddCommand(cmdInit)
2525
cmdInit.Flags().StringVar(&initOpts.ClusterName, "cluster-name", "", "The name of this cluster. This will be the name of the cloudformation stack")
2626
cmdInit.Flags().StringVar(&initOpts.ExternalDNSName, "external-dns-name", "", "The hostname that will route to the api server")
27+
cmdInit.Flags().StringVar(&initOpts.HostedZoneID, "hosted-zone-id", "", "The hosted zone in which a Route53 record set for a k8s API endpoint is created")
2728
cmdInit.Flags().StringVar(&initOpts.Region.Name, "region", "", "The AWS region to deploy to")
2829
cmdInit.Flags().StringVar(&initOpts.AvailabilityZone, "availability-zone", "", "The AWS availability-zone to deploy to")
2930
cmdInit.Flags().StringVar(&initOpts.KeyName, "key-name", "", "The AWS key-pair for ssh access to nodes")

core/controlplane/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,8 @@ func (c DeploymentSettings) Valid() (*DeploymentValidationResult, error) {
13901390
}
13911391

13921392
for i, a := range instanceCIDRs {
1393-
for j, b := range instanceCIDRs[i+1:] {
1393+
for j := i + 1; j < len(instanceCIDRs); j++ {
1394+
b := instanceCIDRs[j]
13941395
if netutil.CidrOverlap(a, b) {
13951396
return nil, fmt.Errorf("CIDR of subnet %d (%s) overlaps with CIDR of subnet %d (%s)", i, a, j, b)
13961397
}

core/controlplane/config/stack_config_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import (
77
)
88

99
func TestRenderStackTemplate(t *testing.T) {
10-
clusterConfig := newDefaultClusterWithDeps(&dummyEncryptService{})
10+
cluster := newDefaultClusterWithDeps(&dummyEncryptService{})
1111

12-
clusterConfig.Region = model.RegionForName("us-west-1")
13-
clusterConfig.Subnets = []model.Subnet{
14-
model.NewPublicSubnet("us-west-1a", "10.0.1.0/16"),
15-
model.NewPublicSubnet("us-west-1b", "10.0.2.0/16"),
12+
cluster.Region = model.RegionForName("us-west-1")
13+
cluster.Subnets = []model.Subnet{
14+
model.NewPublicSubnet("us-west-1a", "10.0.1.0/24"),
15+
model.NewPublicSubnet("us-west-1b", "10.0.2.0/24"),
16+
}
17+
cluster.ExternalDNSName = "foo.example.com"
18+
cluster.KeyName = "mykey"
19+
cluster.KMSKeyARN = "mykmskey"
20+
if err := cluster.Load(); err != nil {
21+
t.Errorf("load failed: %v\n%+v", err, cluster.Subnets)
22+
t.FailNow()
1623
}
17-
clusterConfig.SetDefaults()
1824

1925
helper.WithDummyCredentials(func(dir string) {
2026
var stackTemplateOptions = StackTemplateOptions{
@@ -24,7 +30,7 @@ func TestRenderStackTemplate(t *testing.T) {
2430
StackTemplateTmplFile: "templates/stack-template.json",
2531
}
2632

27-
stackConfig, err := clusterConfig.StackConfig(stackTemplateOptions)
33+
stackConfig, err := cluster.StackConfig(stackTemplateOptions)
2834
if err != nil {
2935
t.Errorf("failed to generate stack config : %v", err)
3036
}
@@ -45,10 +51,16 @@ func TestValidateUserData(t *testing.T) {
4551

4652
cluster.Region = model.RegionForName("us-west-1")
4753
cluster.Subnets = []model.Subnet{
48-
model.NewPublicSubnet("us-west-1a", "10.0.1.0/16"),
49-
model.NewPublicSubnet("us-west-1b", "10.0.2.0/16"),
54+
model.NewPublicSubnet("us-west-1a", "10.0.1.0/24"),
55+
model.NewPublicSubnet("us-west-1b", "10.0.2.0/24"),
56+
}
57+
cluster.ExternalDNSName = "foo.example.com"
58+
cluster.KeyName = "mykey"
59+
cluster.KMSKeyARN = "mykmskey"
60+
if err := cluster.Load(); err != nil {
61+
t.Errorf("load failed: %v", err)
62+
t.FailNow()
5063
}
51-
cluster.SetDefaults()
5264

5365
helper.WithDummyCredentials(func(dir string) {
5466
var stackTemplateOptions = StackTemplateOptions{

core/controlplane/config/templates/cluster.yaml

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
# name must not conflict with an existing cluster.
44
clusterName: {{.ClusterName}}
55

6-
# DNS name routable to the Kubernetes controller nodes
7-
# from worker nodes and external clients. Configure the options
8-
# below if you'd like kube-aws to create a Route53 record sets/hosted zones
9-
# for you. Otherwise the deployer is responsible for making this name routable
10-
# If you'd like to have 2 or more DNS names, please omit this and use `apiEndpoints` instead
11-
externalDNSName: {{.ExternalDNSName}}
6+
# CAUTION: Deprecated and will be removed in v0.9.7. Please use apiEndpoints[].dnsName instead
7+
#externalDNSName:
128

139
# CoreOS release channel to use. Currently supported options: alpha, beta, stable
1410
# See coreos.com/releases for more information
@@ -18,17 +14,14 @@ externalDNSName: {{.ExternalDNSName}}
1814
# If omitted, the latest AMI for the releaseChannel is used.
1915
#amiId: ""
2016

21-
# Set to true if you want kube-aws to create a Route53 Alias Record pointing to the controller ELB for you.
22-
#createRecordSet: false
17+
# CAUTION: Deprecated and will be removed in v0.9.7. Please use apiEndpoints[].loadBalancer.createRecordSet instead
18+
#createRecordSet:
2319

24-
# TTL in seconds for the Route53 RecordSet created if createRecordSet is set to true.
25-
#recordSetTTL: 300
20+
# CAUTION: Deprecated and will be removed in v0.9.7. Please use apiEndpoints[].loadBalancer.recordSetTTL instead
21+
#recordSetTTL:
2622

27-
# DEPRECATED: use hostedZoneId instead
28-
# The name of the hosted zone to add the externalDNSName to,
29-
# E.g: "google.com". This needs to already exist, kube-aws will not create
30-
# it for you.
31-
#hostedZone: ""
23+
# CAUTION: Deprecated and will be removed in v0.9.7. Please use apiEndpoints[].loadBalancer.hostedZone.id instead
24+
#hostedZoneId:
3225

3326
# The ID of hosted zone to add the externalDNSName to.
3427
# Either specify hostedZoneId or hostedZone, but not both
@@ -47,43 +40,58 @@ externalDNSName: {{.ExternalDNSName}}
4740

4841
# Kubernetes API endpoints with each one has a DNS name and is with/without a managed/unmanaged ELB, Route 53 record set
4942
# CAUTION: `externalDNSName` must be omitted when there are one or more items under `apiEndpoints`
50-
#apiEndpoints:
51-
# # The unique name of this API endpoint used to identify it inside CloudFormation stacks or
52-
# # to be referenced from other parts of cluster.yaml
53-
#- name: template
54-
#
55-
# # DNS name for this endpoint, added to the kube-apiserver TLS cert
56-
# dnsName: dns-name.tld
57-
#
58-
# loadBalancer:
59-
# # Specifies an existing load-balancer used for load-balancing controller nodes and serving this endpoint
60-
# # Setting id requires all the other settings excluding `name` to be omitted because reusing an ELB implies that configuring other resources
61-
# # like a Route 53 record set for the endpoint is now your responsibility!
62-
# # Also, don't forget to add controller.securityGroupIds to include a glue SG to allow your existing ELB to access controller nodes created by kube-aws
63-
# id: existing-elb
64-
#
65-
# # Set to false when you want to disable creation of the record set for this api load balancer
66-
# # Must be omitted when `id` is specified
67-
# createRecordSet: true
68-
#
69-
# # All the subnets assigned to this load-balancer. Specified only when this load balancer is not reused but managed one
70-
# # Must be omitted when `id` is specified
71-
# subnets:
72-
# - name: managedPublic1
73-
#
74-
# # Set to true so that the managed ELB becomes an `internal` one rather than `internet-facing` one
75-
# # When set to true while subnets are omitted, one or more private subnets in the top-level `subnets` must exist
76-
# # Must be omitted when `id` is specified
77-
# private: true
78-
#
79-
# # TTL in seconds for the Route53 RecordSet created if createRecordSet is set to true.
80-
# recordSetTTL: 300
81-
#
82-
# # The Route 53 hosted zone is where the resulting Alias record is created for this endpoint
83-
# # Must be omitted when `id` is specified
84-
# hostedZone:
85-
# id: hostedzone-abc
86-
#
43+
apiEndpoints:
44+
- # The unique name of this API endpoint used to identify it inside CloudFormation stacks or
45+
# to be referenced from other parts of cluster.yaml
46+
name: default
47+
48+
# DNS name for this endpoint, added to the kube-apiserver TLS cert
49+
# It must be somehow routable to the Kubernetes controller nodes
50+
# from worker nodes and external clients. Configure the options
51+
# below if you'd like kube-aws to create a Route53 record sets/hosted zones
52+
# for you. Otherwise the deployer is responsible for making this name routable
53+
dnsName: {{.ExternalDNSName}}
54+
55+
# Configuration for an ELB serving this endpoint
56+
# Omit all the settings when you want kube-aws not to provision an ELB for you
57+
loadBalancer:
58+
# Specifies an existing load-balancer used for load-balancing controller nodes and serving this endpoint
59+
# Setting id requires all the other settings excluding `name` to be omitted because reusing an ELB implies that configuring other resources
60+
# like a Route 53 record set for the endpoint is now your responsibility!
61+
# Also, don't forget to add controller.securityGroupIds to include a glue SG to allow your existing ELB to access controller nodes created by kube-aws
62+
#id: existing-elb
63+
64+
# Set to true when you want kube-aws to create a Route53 ALIAS record set for this API load balancer for you
65+
# Must be omitted when `id` is specified
66+
{{if .HostedZoneID -}}
67+
createRecordSet: true
68+
{{else -}}
69+
createRecordSet: false
70+
{{- end}}
71+
# All the subnets assigned to this load-balancer. Specified only when this load balancer is not reused but managed one
72+
# Must be omitted when `id` is specified
73+
#subnets:
74+
#- name: managedPublic1
75+
76+
# Set to true so that the managed ELB becomes an `internal` one rather than `internet-facing` one
77+
# When set to true while subnets are omitted, one or more private subnets in the top-level `subnets` must exist
78+
# Must be omitted when `id` is specified
79+
#private: false
80+
81+
# TTL in seconds for the Route53 RecordSet created if createRecordSet is set to true.
82+
#recordSetTTL: 300
83+
84+
# The Route 53 hosted zone is where the resulting Alias record is created for this endpoint
85+
# Must be omitted when `id` is specified
86+
{{if .HostedZoneID -}}
87+
hostedZone:
88+
# The ID of hosted zone to add the dnsName to.
89+
id: {{.HostedZoneID}}
90+
{{else -}}
91+
#hostedZone:
92+
# # The ID of hosted zone to add the dnsName to.
93+
# id: ""
94+
{{- end}}
8795
# # Network ranges of sources you'd like Kubernetes API accesses to be allowed from, in CIDR notation. Defaults to ["0.0.0.0/0"] which allows any sources.
8896
# # Explicitly set to an empty array to completely disable it.
8997
# # If you do that, probably you would like to set securityGroupIds to provide this load balancer an existing SG with a Kubernetes API access allowed from specific ranges.

e2e/run

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ init() {
9595
--region ${KUBE_AWS_REGION} \
9696
--availability-zone ${KUBE_AWS_AVAILABILITY_ZONE} \
9797
--key-name ${KUBE_AWS_KEY_NAME} \
98-
--kms-key-arn ${KUBE_AWS_KMS_KEY_ARN}
99-
100-
echo "hostedZoneId: ${KUBE_AWS_HOSTED_ZONE_ID}" >> cluster.yaml
101-
echo 'createRecordSet: true' >> cluster.yaml
98+
--kms-key-arn ${KUBE_AWS_KMS_KEY_ARN} \
99+
--hosted-zone-id ${KUBE_AWS_HOSTED_ZONE_ID}
102100

103101
if [ "${KUBE_AWS_USE_CALICO}" != "" ]; then
104102
echo 'useCalico: true' >> cluster.yaml

model/api_endpoints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
type APIEndpoints []APIEndpoint
88

9-
// DefaultAPIEndpointName returns the default endpoint name used when you've omitted the `name` key in each item of the `apiEndpintsp[]` array
9+
// DefaultAPIEndpointName is the default endpoint name used when you've omitted `apiEndpoints` but not `externalDNSName`
1010
const DefaultAPIEndpointName = "Default"
1111

1212
// NewDefaultAPIEndpoints creates the slice of API endpoints containing only the default one which is with arbitrary DNS name and an ELB

model/derived/api_endpoints.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,13 @@ func (e APIEndpoints) ManagedELBLogicalNames() []string {
114114
// GetDefault returns the default API endpoint identified by its name.
115115
// The name is defined as DefaultAPIEndpointName
116116
func (e APIEndpoints) GetDefault() APIEndpoint {
117-
return e[model.DefaultAPIEndpointName]
117+
if len(e) != 1 {
118+
panic(fmt.Sprintf("[bug] GetDefault invoked with an unexpected number of API endpoints: %d", len(e)))
119+
}
120+
var name string
121+
for n, _ := range e {
122+
name = n
123+
break
124+
}
125+
return e[name]
118126
}

0 commit comments

Comments
 (0)