@@ -17,14 +17,15 @@ limitations under the License.
17
17
package v1alpha3
18
18
19
19
import (
20
- "unsafe "
20
+ "fmt "
21
21
22
22
apiconversion "k8s.io/apimachinery/pkg/conversion"
23
- infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
24
23
clusterv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
25
24
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
26
25
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
27
26
"sigs.k8s.io/controller-runtime/pkg/conversion"
27
+
28
+ infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
28
29
)
29
30
30
31
// ConvertTo converts the v1alpha3 AWSCluster receiver to a v1beta1 AWSCluster.
@@ -55,6 +56,37 @@ func (r *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
55
56
}
56
57
57
58
dst .Spec .S3Bucket = restored .Spec .S3Bucket
59
+ if restored .Spec .NetworkSpec .VPC .IPv6 != nil {
60
+ if dst .Spec .NetworkSpec .VPC .IPv6 == nil {
61
+ dst .Spec .NetworkSpec .VPC .IPv6 = & infrav1.IPv6 {}
62
+ }
63
+ dst .Spec .NetworkSpec .VPC .IPv6 .EgressOnlyInternetGatewayID = restored .Spec .NetworkSpec .VPC .IPv6 .EgressOnlyInternetGatewayID
64
+ dst .Spec .NetworkSpec .VPC .IPv6 .CidrBlock = restored .Spec .NetworkSpec .VPC .IPv6 .CidrBlock
65
+ dst .Spec .NetworkSpec .VPC .IPv6 .PoolID = restored .Spec .NetworkSpec .VPC .IPv6 .PoolID
66
+ }
67
+
68
+ for i := range dst .Spec .NetworkSpec .Subnets {
69
+ var found bool
70
+ for k := range restored .Spec .NetworkSpec .Subnets {
71
+ if dst .Spec .NetworkSpec .Subnets [i ].ID == restored .Spec .NetworkSpec .Subnets [k ].ID {
72
+ dst .Spec .NetworkSpec .Subnets [i ].IsIPv6 = restored .Spec .NetworkSpec .Subnets [i ].IsIPv6
73
+ dst .Spec .NetworkSpec .Subnets [i ].IPv6CidrBlock = restored .Spec .NetworkSpec .Subnets [i ].IPv6CidrBlock
74
+ found = true
75
+ break
76
+ }
77
+ }
78
+ if ! found {
79
+ return fmt .Errorf ("subnet with id %s not found amongst restored subnets" , dst .Spec .NetworkSpec .Subnets [i ].ID )
80
+ }
81
+ }
82
+
83
+ for k , v := range restored .Status .Network .SecurityGroups {
84
+ if dst .Status .Network .SecurityGroups == nil {
85
+ dst .Status .Network .SecurityGroups = make (map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup )
86
+ }
87
+ // This will overwrite the whole rule set... But maybe that's fine?
88
+ dst .Status .Network .SecurityGroups [k ] = v
89
+ }
58
90
59
91
return nil
60
92
}
@@ -108,7 +140,19 @@ func Convert_v1beta1_APIEndpoint_To_v1alpha3_APIEndpoint(in *clusterv1.APIEndpoi
108
140
109
141
// Convert_v1alpha3_Network_To_v1alpha4_NetworkStatus is based on the autogenerated function and handles the renaming of the Network struct to NetworkStatus
110
142
func Convert_v1alpha3_Network_To_v1beta1_NetworkStatus (in * Network , out * infrav1.NetworkStatus , s apiconversion.Scope ) error {
111
- out .SecurityGroups = * (* map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup )(unsafe .Pointer (& in .SecurityGroups ))
143
+ if in .SecurityGroups != nil {
144
+ in , out := & in .SecurityGroups , & out .SecurityGroups
145
+ * out = make (map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup , len (* in ))
146
+ for key , val := range * in {
147
+ newVal := new (infrav1.SecurityGroup )
148
+ if err := Convert_v1alpha3_SecurityGroup_To_v1beta1_SecurityGroup (& val , newVal , s ); err != nil {
149
+ return err
150
+ }
151
+ (* out )[infrav1 .SecurityGroupRole (key )] = * newVal
152
+ }
153
+ } else {
154
+ out .SecurityGroups = nil
155
+ }
112
156
if err := Convert_v1alpha3_ClassicELB_To_v1beta1_ClassicELB (& in .APIServerELB , & out .APIServerELB , s ); err != nil {
113
157
return err
114
158
}
@@ -117,7 +161,19 @@ func Convert_v1alpha3_Network_To_v1beta1_NetworkStatus(in *Network, out *infrav1
117
161
118
162
// Convert_v1alpha4_NetworkStatus_To_v1alpha3_Network is based on the autogenerated function and handles the renaming of the NetworkStatus struct to Network
119
163
func Convert_v1beta1_NetworkStatus_To_v1alpha3_Network (in * infrav1.NetworkStatus , out * Network , s apiconversion.Scope ) error {
120
- out .SecurityGroups = * (* map [SecurityGroupRole ]SecurityGroup )(unsafe .Pointer (& in .SecurityGroups ))
164
+ if in .SecurityGroups != nil {
165
+ in , out := & in .SecurityGroups , & out .SecurityGroups
166
+ * out = make (map [SecurityGroupRole ]SecurityGroup , len (* in ))
167
+ for key , val := range * in {
168
+ newVal := new (SecurityGroup )
169
+ if err := Convert_v1beta1_SecurityGroup_To_v1alpha3_SecurityGroup (& val , newVal , s ); err != nil {
170
+ return err
171
+ }
172
+ (* out )[SecurityGroupRole (key )] = * newVal
173
+ }
174
+ } else {
175
+ out .SecurityGroups = nil
176
+ }
121
177
if err := Convert_v1beta1_ClassicELB_To_v1alpha3_ClassicELB (& in .APIServerELB , & out .APIServerELB , s ); err != nil {
122
178
return err
123
179
}
@@ -131,3 +187,15 @@ func Convert_v1beta1_AWSLoadBalancerSpec_To_v1alpha3_AWSLoadBalancerSpec(in *inf
131
187
func Convert_v1beta1_AWSClusterSpec_To_v1alpha3_AWSClusterSpec (in * infrav1.AWSClusterSpec , out * AWSClusterSpec , s apiconversion.Scope ) error {
132
188
return autoConvert_v1beta1_AWSClusterSpec_To_v1alpha3_AWSClusterSpec (in , out , s )
133
189
}
190
+
191
+ func Convert_v1beta1_VPCSpec_To_v1alpha3_VPCSpec (in * infrav1.VPCSpec , out * VPCSpec , s apiconversion.Scope ) error {
192
+ return autoConvert_v1beta1_VPCSpec_To_v1alpha3_VPCSpec (in , out , s )
193
+ }
194
+
195
+ func Convert_v1beta1_SubnetSpec_To_v1alpha3_SubnetSpec (in * infrav1.SubnetSpec , out * SubnetSpec , s apiconversion.Scope ) error {
196
+ return autoConvert_v1beta1_SubnetSpec_To_v1alpha3_SubnetSpec (in , out , s )
197
+ }
198
+
199
+ func Convert_v1beta1_IngressRule_To_v1alpha3_IngressRule (in * infrav1.IngressRule , out * IngressRule , s apiconversion.Scope ) error {
200
+ return autoConvert_v1beta1_IngressRule_To_v1alpha3_IngressRule (in , out , s )
201
+ }
0 commit comments