Skip to content

Commit 761f9a5

Browse files
authored
fix(instance): prevent crash when server-type is only in PCU (#5437)
1 parent 2d46e5d commit 761f9a5

11 files changed

+2962
-275
lines changed

internal/namespaces/instance/v1/custom_server_type.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func serverTypesListMarshalerFunc(i any, opt *human.MarshalOpt) (string, error)
4444
Arch string
4545
Bandwidth scw.Size
4646
Availability instance.ServerTypesAvailability
47-
MaxFileSystems uint32
47+
MaxFileSystems *uint32
4848
}
4949

5050
customServerTypes := i.([]*customServerType)
@@ -82,7 +82,7 @@ type customServerType struct {
8282
Arch string `json:"arch"`
8383
Bandwidth scw.Size `json:"bandwidth"`
8484
Availability instance.ServerTypesAvailability `json:"availability"`
85-
MaxFileSystems uint32 `json:"max_file_systems"`
85+
MaxFileSystems *uint32 `json:"max_file_systems"`
8686
}
8787

8888
// serverTypeListBuilder transforms the server map into a list to display a
@@ -154,17 +154,19 @@ func serverTypeListBuilder(c *core.Command) *core.Command {
154154
}
155155

156156
name := pcuServerType.Properties.Instance.OfferID
157-
computeServerType := computeServerTypes.Servers[name]
158157
serverType := &customServerType{
159-
Name: name,
160-
HourlyPrice: pcuServerType.Price.RetailPrice,
161-
MaxFileSystems: computeServerType.Capabilities.MaxFileSystems,
158+
Name: name,
159+
HourlyPrice: pcuServerType.Price.RetailPrice,
162160
}
163161

164162
if availability, exists := availabilitiesResponse.Servers[name]; exists {
165163
serverType.Availability = availability.Availability
166164
}
167165

166+
if computeServerType, ok := computeServerTypes.Servers[name]; ok {
167+
serverType.MaxFileSystems = new(computeServerType.Capabilities.MaxFileSystems)
168+
}
169+
168170
if pcuServerType.Properties.Hardware != nil {
169171
if pcuServerType.Properties.Hardware.CPU != nil {
170172
serverType.CPU = pcuServerType.Properties.Hardware.CPU.Virtual.Count

internal/namespaces/instance/v1/custom_server_type_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,39 @@ import (
88
)
99

1010
func Test_ServerTypeList(t *testing.T) {
11-
t.Run("server-type list", core.Test(&core.TestConfig{
11+
t.Run("on fr-par-1", core.Test(&core.TestConfig{
1212
Commands: instance.GetCommands(),
1313
Cmd: "scw instance server-type list",
1414
Check: core.TestCheckCombine(
1515
core.TestCheckGolden(),
1616
core.TestCheckExitCode(0),
1717
),
1818
}))
19+
20+
t.Run("on nl-ams-2", core.Test(&core.TestConfig{
21+
Commands: instance.GetCommands(),
22+
Cmd: "scw instance server-type list zone=nl-ams-2",
23+
Check: core.TestCheckCombine(
24+
core.TestCheckGolden(),
25+
core.TestCheckExitCode(0),
26+
),
27+
}))
28+
29+
t.Run("on pl-waw-1", core.Test(&core.TestConfig{
30+
Commands: instance.GetCommands(),
31+
Cmd: "scw instance server-type list zone=pl-waw-1",
32+
Check: core.TestCheckCombine(
33+
core.TestCheckGolden(),
34+
core.TestCheckExitCode(0),
35+
),
36+
}))
37+
38+
t.Run("on it-mil-1", core.Test(&core.TestConfig{
39+
Commands: instance.GetCommands(),
40+
Cmd: "scw instance server-type list zone=it-mil-1",
41+
Check: core.TestCheckCombine(
42+
core.TestCheckGolden(),
43+
core.TestCheckExitCode(0),
44+
),
45+
}))
1946
}

internal/namespaces/instance/v1/testdata/test-server-type-list-on-fr-par1.cassette.yaml

Lines changed: 276 additions & 0 deletions
Large diffs are not rendered by default.

internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.golden renamed to internal/namespaces/instance/v1/testdata/test-server-type-list-on-fr-par1.golden

Lines changed: 196 additions & 70 deletions
Large diffs are not rendered by default.

internal/namespaces/instance/v1/testdata/test-server-type-list-on-it-mil1.cassette.yaml

Lines changed: 120 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)