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

Commit 7508322

Browse files
Update v0.15.x branch for v0.15.0 release (#1801)
* Detect existence of nodepool stacks and change dependencies accordingly. * remove used state field - now moved into the stack object * Add autoscaling:DescribeAutoScalingGroups policy for node drainer. (#1799)
1 parent f64ddb6 commit 7508322

File tree

9 files changed

+54
-21
lines changed

9 files changed

+54
-21
lines changed

builtin/files/stack-templates/etcd.json.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@
530530
}
531531
},
532532
"DependsOn": [
533-
{{if $.StackExists}}{{if not $.EtcdMigrationEnabled }}{{if $etcdIndex}}"{{$etcdInstance.LogicalNameForIndex (sub $etcdIndex 1)}}",{{end}}{{end}}{{end}}
533+
{{if $.Stack.StackExists}}{{if not $.EtcdMigrationEnabled }}{{if $etcdIndex}}"{{$etcdInstance.LogicalNameForIndex (sub $etcdIndex 1)}}",{{end}}{{end}}{{end}}
534534
{{if $etcdInstance.EIPManaged}}
535535
"{{$etcdInstance.EIPLogicalName}}",
536536
{{end}}

builtin/files/stack-templates/node-pool.json.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@
461461
{
462462
"Action": [
463463
"autoscaling:DescribeAutoScalingInstances",
464+
"autoscaling:DescribeAutoScalingGroups",
464465
"autoscaling:DescribeLifecycleHooks"
465466
],
466467
"Effect": "Allow",

builtin/files/stack-templates/root.json.tmpl

+11-9
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@
107107
},
108108
"DependsOn": [
109109
"{{$.ControlPlane.Name}}"
110-
{{ if eq $p.NodePoolRollingStrategy "Sequential" -}}
111-
{{ if $i -}}
112-
,"{{ (index $.NodePools (sub $i 1)).Name}}"
113-
{{ end -}}
114-
{{ end -}}
115-
{{ if eq $p.NodePoolRollingStrategy "AvailabilityZone" -}}
116-
{{- if ne ($.NodePoolAvailabilityZoneDependencies $p $.Subnets) "" }}
117-
,{{ $.NodePoolAvailabilityZoneDependencies $p $.Subnets }}
110+
{{- if $p.StackExists }}
111+
{{- if eq $p.NodePoolRollingStrategy "Sequential" }}
112+
{{- if $i }}
113+
,"{{ (index $.NodePools (sub $i 1)).Name}}"
114+
{{- end }}
118115
{{- end }}
119-
{{ end -}}
116+
{{- if eq $p.NodePoolRollingStrategy "AvailabilityZone" }}
117+
{{- if ne ($.NodePoolAvailabilityZoneDependencies $p $.Subnets) "" }}
118+
,{{ $.NodePoolAvailabilityZoneDependencies $p $.Subnets }}
119+
{{- end }}
120+
{{- end }}
121+
{{- end }}
120122
]
121123
}{{end}}
122124
{{range $n, $r := .ExtraCfnResources}}

core/root/cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (cl *Cluster) ensureNestedStacksLoaded() error {
228228
}
229229
npExtras := extras
230230
npExtras.Configs = npCfg.Plugins
231-
np, err := model.NewWorkerStack(cfg, npCfg, npOpts, npExtras, assetsConfig)
231+
np, err := model.NewWorkerStack(cfg, npCfg, npOpts, npExtras, assetsConfig, cl.context())
232232
if err != nil {
233233
return fmt.Errorf("failed to load node pool #%d: %v", i, err)
234234
}

core/root/template_params.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func (p nodePool) NeedToExportIAMroles() bool {
177177
return p.nodePool.NodePoolConfig.IAMConfig.InstanceProfile.Arn == ""
178178
}
179179

180+
func (p nodePool) StackExists() bool {
181+
return p.nodePool.StackExists
182+
}
183+
180184
func (p TemplateParams) ControlPlane() controlPlane {
181185
return controlPlane{
182186
controlPlane: p.cluster.controlPlaneStack,

pkg/api/existing_etcd.go

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api
22

33
// ExistingState describes the existing state of the etcd cluster
44
type EtcdExistingState struct {
5-
StackExists bool
65
EtcdMigrationEnabled bool
76
EtcdMigrationExistingEndpoints string
87
}

pkg/model/context.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ func (s *Context) stackProvisioner(c *Stack) *cfnstack.Provisioner {
4949
)
5050
}
5151

52-
func (s *Context) InspectEtcdExistingState(c *Config) (api.EtcdExistingState, error) {
52+
func (s *Context) InspectEtcdExistingState(c *Config) (bool, api.EtcdExistingState, error) {
5353
var err error
54+
var exists bool
55+
5456
if s.ProvidedCFInterrogator == nil {
5557
s.ProvidedCFInterrogator = cloudformation.New(s.Session)
5658
}
@@ -59,18 +61,18 @@ func (s *Context) InspectEtcdExistingState(c *Config) (api.EtcdExistingState, er
5961
}
6062

6163
state := api.EtcdExistingState{}
62-
state.StackExists, err = cfnstack.NestedStackExists(s.ProvidedCFInterrogator, c.ClusterName, naming.FromStackToCfnResource(c.Etcd.LogicalName()))
64+
exists, err = cfnstack.NestedStackExists(s.ProvidedCFInterrogator, c.ClusterName, naming.FromStackToCfnResource(c.Etcd.LogicalName()))
6365
if err != nil {
64-
return state, fmt.Errorf("failed to check for existence of etcd cloud-formation stack: %v", err)
66+
return exists, state, fmt.Errorf("failed to check for existence of etcd cloud-formation stack: %v", err)
6567
}
6668
// when the Etcd stack exists we need to check for the MajorMinor version of Etcd running and trigger a migration if different to ours.
67-
if state.StackExists {
69+
if exists {
6870
if state.EtcdMigrationEnabled, err = s.isAMajorEtcdUpgrade(c); err != nil {
69-
return state, fmt.Errorf("failed to check existing etcd major minor version: %v", err)
71+
return exists, state, fmt.Errorf("failed to check existing etcd major minor version: %v", err)
7072
}
7173
if state.EtcdMigrationEnabled {
7274
if state.EtcdMigrationExistingEndpoints, err = s.lookupExistingEtcdEndpoints(c); err != nil {
73-
return state, fmt.Errorf("failed to lookup existing etcd endpoints: %v", err)
75+
return exists, state, fmt.Errorf("failed to lookup existing etcd endpoints: %v", err)
7476
}
7577
logger.Warn("Performing a Major Etcd Version Upgrade: -")
7678
logger.Warn("To do this we will spin up new etcd servers and then export the existing kubernetes state to them.")
@@ -80,7 +82,23 @@ func (s *Context) InspectEtcdExistingState(c *Config) (api.EtcdExistingState, er
8082
logger.Warn("This operation is best scheduled for a quiet time or in an outage window.")
8183
}
8284
}
83-
return state, nil
85+
return exists, state, nil
86+
}
87+
88+
// Check for the existence of a worker nodepool stack by looking it up in cloudformation.
89+
func (s *Context) InspectWorkerExistingState(npconf *NodePoolConfig) (bool, error) {
90+
var err error
91+
var exists bool
92+
93+
if s.ProvidedCFInterrogator == nil {
94+
s.ProvidedCFInterrogator = cloudformation.New(s.Session)
95+
}
96+
97+
exists, err = cfnstack.NestedStackExists(s.ProvidedCFInterrogator, npconf.ClusterName, npconf.NestedStackName())
98+
if err != nil {
99+
return exists, fmt.Errorf("failed to check worker cloud-formation stack %s: %v", npconf.NestedStackName(), err)
100+
}
101+
return exists, nil
84102
}
85103

86104
// isAMajorEtcdUpgrade looks for etcd instances using tag kube-aws:etcd_upgrade_group and the config clusters major-minor version.

pkg/model/stack_new.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ func NewEtcdStack(conf *Config, opts api.StackTemplateOptions, extras clusterext
159159
assetsConfig,
160160
func(stack *Stack) (interface{}, error) {
161161
// create the context that will be used to build the assets (combination of config + existing state)
162-
existingState, err := s.InspectEtcdExistingState(conf)
162+
exists, existingState, err := s.InspectEtcdExistingState(conf)
163163
if err != nil {
164164
return nil, fmt.Errorf("Could not inspect existing etcd state: %v", err)
165165
}
166+
stack.StackExists = exists
166167

167168
// Import all the managed subnets from the network stack
168169
subnets, err := stack.Config.Subnets.ImportFromNetworkStackRetainingNames()
@@ -222,14 +223,21 @@ func NewEtcdStack(conf *Config, opts api.StackTemplateOptions, extras clusterext
222223
)
223224
}
224225

225-
func NewWorkerStack(conf *Config, npconf *NodePoolConfig, opts api.StackTemplateOptions, extras clusterextension.ClusterExtension, assetsConfig *credential.CompactAssets) (*Stack, error) {
226+
func NewWorkerStack(conf *Config, npconf *NodePoolConfig, opts api.StackTemplateOptions, extras clusterextension.ClusterExtension, assetsConfig *credential.CompactAssets, s *Context) (*Stack, error) {
226227
logger.Debugf("Generating new Worker stack %s...", npconf.NodePoolName)
227228
return newStack(
228229
npconf.StackName(),
229230
conf,
230231
opts,
231232
assetsConfig,
232233
func(stack *Stack) (interface{}, error) {
234+
// create the context that will be used to build the assets (combination of config + existing state)
235+
exists, err := s.InspectWorkerExistingState(npconf)
236+
if err != nil {
237+
return nil, fmt.Errorf("Could not inspect existing nodepool state: %v", err)
238+
}
239+
stack.StackExists = exists
240+
233241
return WorkerTmplCtx{
234242
Stack: stack,
235243
NodePoolConfig: npconf,

pkg/model/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Stack struct {
1919
StackName string
2020
S3URI string
2121
ClusterName string
22+
StackExists bool
2223
Region api.Region
2324

2425
Config *Config

0 commit comments

Comments
 (0)