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

v0.14.x: Remove the control-plane stacks dependence on cross stack references #1755

Merged
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
12 changes: 9 additions & 3 deletions builtin/files/stack-templates/control-plane.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
"Type": "String",
"Description": "The name of an etcd stack used to import values into this stack"
}
{{if .CloudWatchLogging.Enabled}},
{{range $index, $etcdInstance := $.EtcdNodes }},
"{{$etcdInstance.LogicalName}}FQDN": {
"Type": "String",
"Description": "The FQDN for etcd node {{$index}}"
}
{{- end}}
{{if .CloudWatchLogging.Enabled }},
"CloudWatchLogGroupARN": {
"Type": "String",
"Description": "CloudWatch LogGroup to send journald logs to"
}
{{end}}
{{- end}}
},
"Resources": {
"{{.Controller.LogicalName}}": {
Expand Down Expand Up @@ -156,7 +162,7 @@
"ETCD_ENDPOINTS='",
{{range $index, $etcdInstance := $.EtcdNodes}}
{{if $index}}",", {{end}} "https://",
{{$etcdInstance.ImportedAdvertisedFQDNRef}}, ":2379",
{ "Ref" : "{{$etcdInstance.LogicalName}}FQDN" }, ":2379",
{{end}}
"'\n"
]]}
Expand Down
11 changes: 8 additions & 3 deletions builtin/files/stack-templates/etcd.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@
,
{{quote $n}}: {{toJSON $r}}
{{end}}

},
"Outputs": {
{{range $index, $etcdInstance := $.EtcdNodes}}
Expand All @@ -609,9 +608,15 @@
"Description": "The name of this stack which is used by node pool stacks to import outputs from this stack",
"Value": { "Ref": "AWS::StackName" }
}
{{range $n, $r := .ExtraCfnOutputs}}
{{range $index, $etcdInstance := $.EtcdNodes }},
"{{$etcdInstance.LogicalName}}FQDN": {
"Description": "The FQDN for etcd node {{$index}}",
"Value": {{$etcdInstance.AdvertisedFQDN}}
}
{{- end}}
{{range $n, $r := .ExtraCfnOutputs -}}
,
{{quote $n}}: {{toJSON $r}}
{{end}}
{{- end}}
}
}
7 changes: 5 additions & 2 deletions builtin/files/stack-templates/root.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
"Parameters": {
"EtcdStackName": {"Fn::GetAtt" : [ "{{$.Etcd.Name}}" , "Outputs.StackName" ]},
"NetworkStackName": {"Fn::GetAtt" : [ "{{$.Network.Name}}" , "Outputs.StackName" ]}
{{if .CloudWatchLogging.Enabled}}
{{range $index, $etcdInstance := $.EtcdNodes -}}
,
"{{$etcdInstance.LogicalName}}FQDN": {"Fn::GetAtt" : [ "{{$.Etcd.Name}}" , "Outputs.{{$etcdInstance.LogicalName}}FQDN" ]}
{{- end}}
{{if .CloudWatchLogging.Enabled}},
"CloudWatchLogGroupARN": { "Fn::GetAtt": [ "CloudWatchLogGroup", "Arn" ] }
{{ end }}
{{- end }}
},
"Tags" : [
{
Expand Down
4 changes: 4 additions & 0 deletions core/root/template_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (p TemplateParams) KubeDnsMasq() api.KubeDns {
return p.cluster.controlPlaneStack.Config.KubeDns
}

func (p TemplateParams) EtcdNodes() []model.EtcdNode {
return p.cluster.Cfg.EtcdNodes
}

func newTemplateParams(c *Cluster) TemplateParams {
return TemplateParams{
cluster: *c,
Expand Down
23 changes: 4 additions & 19 deletions pkg/model/etcd_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"

"github.com/kubernetes-incubator/kube-aws/pkg/api"
)

Expand Down Expand Up @@ -57,13 +58,6 @@ func (i EtcdNode) privateDNSNameRef() string {
return fmt.Sprintf(`"%s"`, i.customPrivateDNSName())
}

func (i EtcdNode) importedPrivateDNSNameRef() string {
if i.cluster.EC2InternalDomainUsed() {
return i.defaultPrivateDNSNameRefFromIPRef(fmt.Sprintf(`{ "Fn::ImportValue": {"Fn::Sub" : "${EtcdStackName}-%s"} }`, i.NetworkInterfacePrivateIPLogicalName()))
}
return fmt.Sprintf(`"%s"`, i.customPrivateDNSName())
}

func (i EtcdNode) defaultPrivateDNSNameRefFromIPRef(ipRef string) string {
hostnameRef := fmt.Sprintf(`
{ "Fn::Join" : [ "-",
Expand All @@ -88,15 +82,6 @@ func (i EtcdNode) defaultPublicDNSNameRef() (string, error) {
return i.defaultPublicDNSNameRefFromIPRef(eipRef), nil
}

func (i EtcdNode) importedDefaultPublicDNSNameRef() (string, error) {
eipLogicalName, err := i.EIPLogicalName()
if err != nil {
return "", fmt.Errorf("failed to determine an ec2 default public dns name: %v", err)
}
eipRef := fmt.Sprintf(`{ "Fn::ImportValue": {"Fn::Sub" : "${EtcdStackName}-%s"} }`, eipLogicalName)
return i.defaultPublicDNSNameRefFromIPRef(eipRef), nil
}

func (i EtcdNode) defaultPublicDNSNameRefFromIPRef(ipRef string) string {
return fmt.Sprintf(`{ "Fn::Join" : [ ".", [
{ "Fn::Join" : [ "-", [
Expand All @@ -114,11 +99,11 @@ func (i EtcdNode) AdvertisedFQDNRef() (string, error) {
return i.defaultPublicDNSNameRef()
}

func (i EtcdNode) ImportedAdvertisedFQDNRef() (string, error) {
func (i EtcdNode) AdvertisedFQDN() (string, error) {
if i.cluster.NodeShouldHaveSecondaryENI() {
return i.importedPrivateDNSNameRef(), nil
return i.privateDNSNameRef(), nil
}
return i.importedDefaultPublicDNSNameRef()
return i.defaultPublicDNSNameRef()
}

func (i EtcdNode) SubnetRef() string {
Expand Down