Skip to content

Commit 18e82bf

Browse files
committed
fix(ske): make generate cluster payload work for eu02
relates to STACKITCLI-258 / #997
1 parent 85f5d79 commit 18e82bf

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

internal/pkg/services/ske/utils/utils.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ import (
1616
)
1717

1818
const (
19-
defaultNodepoolAvailabilityZone = "eu01-3"
2019
defaultNodepoolCRI = ske.CRINAME_CONTAINERD
21-
defaultNodepoolMachineType = "b1.2"
2220
defaultNodepoolMachineImageName = "flatcar"
23-
defaultNodepoolMaxSurge = 1
2421
defaultNodepoolMaxUnavailable = 0
25-
defaultNodepoolMaximum = 2
2622
defaultNodepoolMinimum = 1
2723
defaultNodepoolName = "pool-default"
2824
defaultNodepoolVolumeType = "storage_premium_perf2"
@@ -110,22 +106,34 @@ func getDefaultPayloadKubernetes(resp *ske.ProviderOptions) (*ske.Kubernetes, er
110106
}
111107

112108
func getDefaultPayloadNodepool(resp *ske.ProviderOptions) (*ske.Nodepool, error) {
109+
if resp.AvailabilityZones == nil || len(*resp.AvailabilityZones) == 0 {
110+
return nil, fmt.Errorf("no availability zones found")
111+
}
112+
availabilityZones := make([]string, len(*resp.AvailabilityZones))
113+
for i := range *resp.AvailabilityZones {
114+
availabilityZones[i] = (*resp.AvailabilityZones)[i].GetName()
115+
}
116+
117+
if resp.MachineTypes == nil || len(*resp.MachineTypes) == 0 {
118+
return nil, fmt.Errorf("no machine types found")
119+
}
120+
machineType := (*resp.MachineTypes)[0].GetName()
121+
113122
output := &ske.Nodepool{
114-
AvailabilityZones: &[]string{
115-
defaultNodepoolAvailabilityZone,
116-
},
123+
AvailabilityZones: &availabilityZones,
117124
Cri: &ske.CRI{
118125
Name: utils.Ptr(defaultNodepoolCRI),
119126
},
120127
Machine: &ske.Machine{
121-
Type: utils.Ptr(defaultNodepoolMachineType),
128+
Type: &machineType,
122129
Image: &ske.Image{
123130
Name: utils.Ptr(defaultNodepoolMachineImageName),
124131
},
125132
},
126-
MaxSurge: utils.Ptr(int64(defaultNodepoolMaxSurge)),
133+
// there must be as many nodes as availability zones are given
134+
MaxSurge: utils.Ptr(int64(len(availabilityZones))),
127135
MaxUnavailable: utils.Ptr(int64(defaultNodepoolMaxUnavailable)),
128-
Maximum: utils.Ptr(int64(defaultNodepoolMaximum)),
136+
Maximum: utils.Ptr(int64(len(availabilityZones))),
129137
Minimum: utils.Ptr(int64(defaultNodepoolMinimum)),
130138
Name: utils.Ptr(defaultNodepoolName),
131139
Volume: &ske.Volume{

internal/pkg/services/ske/utils/utils_test.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ func TestClusterExists(t *testing.T) {
146146

147147
func fixtureProviderOptions(mods ...func(*ske.ProviderOptions)) *ske.ProviderOptions {
148148
providerOptions := &ske.ProviderOptions{
149+
AvailabilityZones: &[]ske.AvailabilityZone{
150+
{Name: utils.Ptr("eu01-m")},
151+
{Name: utils.Ptr("eu01-1")},
152+
{Name: utils.Ptr("eu01-2")},
153+
{Name: utils.Ptr("eu01-3")},
154+
},
155+
MachineTypes: &[]ske.MachineType{
156+
{
157+
Name: utils.Ptr("b1.2"),
158+
},
159+
},
149160
KubernetesVersions: &[]ske.KubernetesVersion{
150161
{
151162
State: utils.Ptr("supported"),
@@ -263,6 +274,9 @@ func fixtureGetDefaultPayload(mods ...func(*ske.CreateOrUpdateClusterPayload)) *
263274
Nodepools: &[]ske.Nodepool{
264275
{
265276
AvailabilityZones: &[]string{
277+
"eu01-m",
278+
"eu01-1",
279+
"eu01-2",
266280
"eu01-3",
267281
},
268282
Cri: &ske.CRI{
@@ -275,9 +289,9 @@ func fixtureGetDefaultPayload(mods ...func(*ske.CreateOrUpdateClusterPayload)) *
275289
Name: utils.Ptr("flatcar"),
276290
},
277291
},
278-
MaxSurge: utils.Ptr(int64(1)),
292+
MaxSurge: utils.Ptr(int64(4)),
279293
MaxUnavailable: utils.Ptr(int64(0)),
280-
Maximum: utils.Ptr(int64(2)),
294+
Maximum: utils.Ptr(int64(4)),
281295
Minimum: utils.Ptr(int64(1)),
282296
Name: utils.Ptr("pool-default"),
283297
Volume: &ske.Volume{
@@ -312,6 +326,34 @@ func TestGetDefaultPayload(t *testing.T) {
312326
listProviderOptionsFails: true,
313327
isValid: false,
314328
},
329+
{
330+
description: "availability zones nil",
331+
listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) {
332+
po.AvailabilityZones = nil
333+
}),
334+
isValid: false,
335+
},
336+
{
337+
description: "no availability zones",
338+
listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) {
339+
po.AvailabilityZones = &[]ske.AvailabilityZone{}
340+
}),
341+
isValid: false,
342+
},
343+
{
344+
description: "machine types nil",
345+
listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) {
346+
po.MachineTypes = nil
347+
}),
348+
isValid: false,
349+
},
350+
{
351+
description: "no machine types",
352+
listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) {
353+
po.MachineTypes = &[]ske.MachineType{}
354+
}),
355+
isValid: false,
356+
},
315357
{
316358
description: "no Kubernetes versions 1",
317359
listProviderOptionsResp: fixtureProviderOptions(func(po *ske.ProviderOptions) {

0 commit comments

Comments
 (0)