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

Commit

Permalink
Remove the control-plane stacks dependence on cross stack references,…
Browse files Browse the repository at this point in the history
… this prevents us from ever removing or changing these values. The best practice way is to pass variables as parameters between nested stacks (via the root stack). We have to remove the dependencies before we can remove the exports, so they are still exported from the etcd stack alongside our new parameters which are used in the updated control-plane stack.
  • Loading branch information
davidmccormick committed Oct 15, 2019
1 parent ef033d5 commit 3006c09
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
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}}
}
}
10 changes: 6 additions & 4 deletions builtin/files/stack-templates/root.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
"Properties" : {
"Parameters": {
"EtcdStackName": {"Fn::GetAtt" : [ "{{$.Etcd.Name}}" , "Outputs.StackName" ]},
"NetworkStackName": {"Fn::GetAtt" : [ "{{$.Network.Name}}" , "Outputs.StackName" ]}
{{if .CloudWatchLogging.Enabled}}
,
"NetworkStackName": {"Fn::GetAtt" : [ "{{$.Network.Name}}" , "Outputs.StackName" ]},
{{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

0 comments on commit 3006c09

Please sign in to comment.