Skip to content

Commit f430036

Browse files
committed
aws: set machine pool defaults for EBS volume type
Set the default type EBS volume for machine pools: - Controlplane, arbiter and worker pool default to gp3 volume. - Edge pool default to gp2 volume. The default decision is taken from existing code [0]. This commit just makes the defaulting earlier. Reference [0] https://github.com/openshift/installer/blob/fd5a518e4951510b82705eee8184b3dd4f2723b2/pkg/asset/machines/worker.go#L102-L117
1 parent d93d030 commit f430036

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package defaults
2+
3+
import (
4+
"github.com/openshift/installer/pkg/types"
5+
"github.com/openshift/installer/pkg/types/aws"
6+
)
7+
8+
// SetMachinePoolDefaults sets the defaults for the platform.
9+
func SetMachinePoolDefaults(pool *aws.MachinePool, role string) {
10+
if pool == nil {
11+
return
12+
}
13+
14+
// Set the default volume type for machine pool.
15+
// The current default is gp3 for control plane and worker pool.
16+
// For edge pool, the current default is gp2.
17+
// See: https://github.com/openshift/installer/blob/fd5a518e4951510b82705eee8184b3dd4f2723b2/pkg/asset/machines/worker.go#L102-L117
18+
if pool.EC2RootVolume.Type == "" {
19+
defaultEBSType := aws.VolumeTypeGp3
20+
if role == types.MachinePoolEdgeRoleName {
21+
defaultEBSType = aws.VolumeTypeGp2
22+
}
23+
pool.EC2RootVolume.Type = defaultEBSType
24+
}
25+
}
26+
27+
// Apply sets values from the default machine platform to the machinepool.
28+
func Apply(defaultMachinePlatform, machinePool *aws.MachinePool) {
29+
// Construct a temporary machine pool so we can set the
30+
// defaults first, without overwriting the pool-sepcific values,
31+
// which have precedence.
32+
tempMP := &aws.MachinePool{}
33+
tempMP.Set(defaultMachinePlatform)
34+
tempMP.Set(machinePool)
35+
machinePool.Set(tempMP)
36+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package defaults
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/openshift/installer/pkg/types"
9+
"github.com/openshift/installer/pkg/types/aws"
10+
)
11+
12+
func TestSetMachinePoolDefaults(t *testing.T) {
13+
cases := []struct {
14+
name string
15+
pool *aws.MachinePool
16+
role string
17+
expected *aws.MachinePool
18+
}{
19+
{
20+
name: "nil pool",
21+
pool: nil,
22+
role: types.MachinePoolComputeRoleName,
23+
expected: nil,
24+
},
25+
{
26+
name: "empty pool - worker pool sets gp3",
27+
pool: &aws.MachinePool{},
28+
role: types.MachinePoolComputeRoleName,
29+
expected: &aws.MachinePool{
30+
EC2RootVolume: aws.EC2RootVolume{
31+
Type: aws.VolumeTypeGp3,
32+
},
33+
},
34+
},
35+
{
36+
name: "empty pool - control plane pool sets gp3",
37+
pool: &aws.MachinePool{},
38+
role: types.MachinePoolControlPlaneRoleName,
39+
expected: &aws.MachinePool{
40+
EC2RootVolume: aws.EC2RootVolume{
41+
Type: aws.VolumeTypeGp3,
42+
},
43+
},
44+
},
45+
{
46+
name: "empty pool - arbiter pool sets gp3",
47+
pool: &aws.MachinePool{},
48+
role: types.MachinePoolArbiterRoleName,
49+
expected: &aws.MachinePool{
50+
EC2RootVolume: aws.EC2RootVolume{
51+
Type: aws.VolumeTypeGp3,
52+
},
53+
},
54+
},
55+
{
56+
name: "empty pool - edge pool sets gp2",
57+
pool: &aws.MachinePool{},
58+
role: types.MachinePoolEdgeRoleName,
59+
expected: &aws.MachinePool{
60+
EC2RootVolume: aws.EC2RootVolume{
61+
Type: aws.VolumeTypeGp2,
62+
},
63+
},
64+
},
65+
{
66+
name: "pool with existing volume type - should not override",
67+
pool: &aws.MachinePool{
68+
EC2RootVolume: aws.EC2RootVolume{
69+
Type: aws.VolumeTypeGp2,
70+
},
71+
},
72+
role: types.MachinePoolComputeRoleName,
73+
expected: &aws.MachinePool{
74+
EC2RootVolume: aws.EC2RootVolume{
75+
Type: aws.VolumeTypeGp2,
76+
},
77+
},
78+
},
79+
}
80+
81+
for _, tc := range cases {
82+
t.Run(tc.name, func(t *testing.T) {
83+
SetMachinePoolDefaults(tc.pool, tc.role)
84+
assert.Equal(t, tc.expected, tc.pool, "unexpected machine pool defaults")
85+
})
86+
}
87+
}

pkg/types/defaults/machinepools.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package defaults
22

33
import (
44
"github.com/openshift/installer/pkg/types"
5+
"github.com/openshift/installer/pkg/types/aws"
6+
awsdefaults "github.com/openshift/installer/pkg/types/aws/defaults"
57
"github.com/openshift/installer/pkg/types/azure"
68
azuredefaults "github.com/openshift/installer/pkg/types/azure/defaults"
79
"github.com/openshift/installer/pkg/types/gcp"
@@ -26,6 +28,12 @@ func SetMachinePoolDefaults(p *types.MachinePool, platform *types.Platform) {
2628
}
2729

2830
switch platform.Name() {
31+
case aws.Name:
32+
if p.Platform.AWS == nil && platform.AWS.DefaultMachinePlatform != nil {
33+
p.Platform.AWS = &aws.MachinePool{}
34+
}
35+
awsdefaults.Apply(platform.AWS.DefaultMachinePlatform, p.Platform.AWS)
36+
awsdefaults.SetMachinePoolDefaults(p.Platform.AWS, p.Name)
2937
case azure.Name:
3038
if p.Platform.Azure == nil && platform.Azure.DefaultMachinePlatform != nil {
3139
p.Platform.Azure = &azure.MachinePool{}

0 commit comments

Comments
 (0)