From f53f2a840653e45f2a9efb1ee8c17ac33596c258 Mon Sep 17 00:00:00 2001 From: David McCormick Date: Tue, 15 Oct 2019 14:41:20 +0100 Subject: [PATCH] Remove the control-plane stacks dependence on cross stack references, 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. --- .../stack-templates/control-plane.json.tmpl | 12 +++++++--- builtin/files/stack-templates/etcd.json.tmpl | 11 ++++++--- builtin/files/stack-templates/root.json.tmpl | 7 ++++-- core/root/template_params.go | 4 ++++ pkg/model/etcd_node.go | 23 ++++--------------- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/builtin/files/stack-templates/control-plane.json.tmpl b/builtin/files/stack-templates/control-plane.json.tmpl index 305554057..a500d1ea9 100644 --- a/builtin/files/stack-templates/control-plane.json.tmpl +++ b/builtin/files/stack-templates/control-plane.json.tmpl @@ -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}}": { @@ -156,7 +162,7 @@ "ETCD_ENDPOINTS='", {{range $index, $etcdInstance := $.EtcdNodes}} {{if $index}}",", {{end}} "https://", - {{$etcdInstance.ImportedAdvertisedFQDNRef}}, ":2379", + { "Ref" : "{{$etcdInstance.LogicalName}}FQDN" }, ":2379", {{end}} "'\n" ]]} diff --git a/builtin/files/stack-templates/etcd.json.tmpl b/builtin/files/stack-templates/etcd.json.tmpl index 207d42df8..34b052bc6 100644 --- a/builtin/files/stack-templates/etcd.json.tmpl +++ b/builtin/files/stack-templates/etcd.json.tmpl @@ -586,7 +586,6 @@ , {{quote $n}}: {{toJSON $r}} {{end}} - }, "Outputs": { {{range $index, $etcdInstance := $.EtcdNodes}} @@ -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}} } } diff --git a/builtin/files/stack-templates/root.json.tmpl b/builtin/files/stack-templates/root.json.tmpl index cf7d06e02..fc907cb38 100644 --- a/builtin/files/stack-templates/root.json.tmpl +++ b/builtin/files/stack-templates/root.json.tmpl @@ -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" : [ { diff --git a/core/root/template_params.go b/core/root/template_params.go index 62c45d9cc..cbdeb143d 100644 --- a/core/root/template_params.go +++ b/core/root/template_params.go @@ -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, diff --git a/pkg/model/etcd_node.go b/pkg/model/etcd_node.go index 35b045648..47fafaa09 100644 --- a/pkg/model/etcd_node.go +++ b/pkg/model/etcd_node.go @@ -2,6 +2,7 @@ package model import ( "fmt" + "github.com/kubernetes-incubator/kube-aws/pkg/api" ) @@ -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" : [ "-", @@ -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" : [ "-", [ @@ -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 {