Skip to content

Commit 8ab6d85

Browse files
committed
allow setting allocation_class if provided
1 parent a857b88 commit 8ab6d85

File tree

2 files changed

+139
-13
lines changed

2 files changed

+139
-13
lines changed

internal/controller/linodevpc_controller_helpers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ func linodeVPCSpecToVPCCreateConfig(vpcSpec infrav1alpha2.LinodeVPCSpec) *linode
171171
vpcIPv6[idx] = linodego.VPCCreateOptionsIPv6{
172172
Range: ipv6.Range,
173173
}
174+
if ipv6.AllocationClass != nil {
175+
vpcIPv6[idx].AllocationClass = ipv6.AllocationClass
176+
}
174177
}
175178

176179
subnets := make([]linodego.VPCSubnetCreateOptions, len(vpcSpec.Subnets))
Lines changed: 136 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,150 @@
11
package controller
22

33
import (
4+
"reflect"
45
"testing"
56

6-
"github.com/stretchr/testify/assert"
7+
"github.com/linode/linodego"
8+
"k8s.io/utils/ptr"
79

810
infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2"
911
)
1012

11-
func TestLinodeVPCSpecToCreateVPCConfig(t *testing.T) {
13+
func Test_linodeVPCSpecToVPCCreateConfig(t *testing.T) {
1214
t.Parallel()
13-
14-
vpcSpec := infrav1alpha2.LinodeVPCSpec{
15-
Description: "description",
16-
Region: "region",
17-
Subnets: []infrav1alpha2.VPCSubnetCreateOptions{
18-
{
19-
Label: "subnet",
20-
IPv4: "ipv4",
15+
type args struct {
16+
vpcSpec infrav1alpha2.LinodeVPCSpec
17+
}
18+
tests := []struct {
19+
name string
20+
args args
21+
want *linodego.VPCCreateOptions
22+
}{
23+
{
24+
name: "no ipv6 ranges",
25+
args: args{
26+
vpcSpec: infrav1alpha2.LinodeVPCSpec{
27+
Description: "description",
28+
Region: "region",
29+
Subnets: []infrav1alpha2.VPCSubnetCreateOptions{
30+
{
31+
Label: "subnet",
32+
IPv4: "ipv4",
33+
},
34+
},
35+
},
36+
},
37+
want: &linodego.VPCCreateOptions{
38+
Description: "description",
39+
Region: "region",
40+
Subnets: []linodego.VPCSubnetCreateOptions{
41+
{
42+
Label: "subnet",
43+
IPv4: "ipv4",
44+
IPv6: []linodego.VPCSubnetCreateOptionsIPv6{},
45+
},
46+
},
47+
IPv6: []linodego.VPCCreateOptionsIPv6{},
48+
},
49+
},
50+
{
51+
name: "ipv6 ranges without allocation_class",
52+
args: args{
53+
vpcSpec: infrav1alpha2.LinodeVPCSpec{
54+
Description: "description",
55+
Region: "region",
56+
IPv6Range: []infrav1alpha2.VPCCreateOptionsIPv6{
57+
{
58+
Range: ptr.To("2001:db8::/52"),
59+
},
60+
},
61+
Subnets: []infrav1alpha2.VPCSubnetCreateOptions{
62+
{
63+
Label: "subnet",
64+
IPv4: "ipv4",
65+
IPv6Range: []infrav1alpha2.VPCSubnetCreateOptionsIPv6{
66+
{
67+
Range: ptr.To("2001:db8:1::/56"),
68+
},
69+
},
70+
},
71+
},
72+
},
73+
},
74+
want: &linodego.VPCCreateOptions{
75+
Description: "description",
76+
Region: "region",
77+
Subnets: []linodego.VPCSubnetCreateOptions{
78+
{
79+
Label: "subnet",
80+
IPv4: "ipv4",
81+
IPv6: []linodego.VPCSubnetCreateOptionsIPv6{
82+
{
83+
Range: ptr.To("2001:db8:1::/56"),
84+
},
85+
},
86+
},
87+
},
88+
IPv6: []linodego.VPCCreateOptionsIPv6{
89+
{
90+
Range: ptr.To("2001:db8::/52"),
91+
},
92+
},
93+
},
94+
},
95+
{
96+
name: "ipv6 ranges with allocation_class",
97+
args: args{
98+
vpcSpec: infrav1alpha2.LinodeVPCSpec{
99+
Description: "description",
100+
Region: "region",
101+
IPv6Range: []infrav1alpha2.VPCCreateOptionsIPv6{
102+
{
103+
Range: ptr.To("2001:db8::/52"),
104+
AllocationClass: ptr.To("myclass"),
105+
},
106+
},
107+
Subnets: []infrav1alpha2.VPCSubnetCreateOptions{
108+
{
109+
Label: "subnet",
110+
IPv4: "ipv4",
111+
IPv6Range: []infrav1alpha2.VPCSubnetCreateOptionsIPv6{
112+
{
113+
Range: ptr.To("2001:db8:1::/56"),
114+
},
115+
},
116+
},
117+
},
118+
},
119+
},
120+
want: &linodego.VPCCreateOptions{
121+
Description: "description",
122+
Region: "region",
123+
Subnets: []linodego.VPCSubnetCreateOptions{
124+
{
125+
Label: "subnet",
126+
IPv4: "ipv4",
127+
IPv6: []linodego.VPCSubnetCreateOptionsIPv6{
128+
{
129+
Range: ptr.To("2001:db8:1::/56"),
130+
},
131+
},
132+
},
133+
},
134+
IPv6: []linodego.VPCCreateOptionsIPv6{
135+
{
136+
Range: ptr.To("2001:db8::/52"),
137+
AllocationClass: ptr.To("myclass"),
138+
},
139+
},
21140
},
22141
},
23142
}
24-
25-
createConfig := linodeVPCSpecToVPCCreateConfig(vpcSpec)
26-
assert.NotNil(t, createConfig, "Failed to convert LinodeVPCSpec to VPCCreateOptions")
143+
for _, tt := range tests {
144+
t.Run(tt.name, func(t *testing.T) {
145+
if got := linodeVPCSpecToVPCCreateConfig(tt.args.vpcSpec); !reflect.DeepEqual(got, tt.want) {
146+
t.Errorf("linodeVPCSpecToVPCCreateConfig() = %v, want %v", got, tt.want)
147+
}
148+
})
149+
}
27150
}

0 commit comments

Comments
 (0)