@@ -24,6 +24,8 @@ import (
24
24
"github.com/golang/mock/gomock"
25
25
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
26
26
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
27
+ "github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
28
+ "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
27
29
. "github.com/onsi/ginkgo/v2"
28
30
. "github.com/onsi/gomega"
29
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -207,6 +209,63 @@ var _ = Describe("OpenStackCluster controller", func() {
207
209
err = deleteBastion (scope , capiCluster , testCluster )
208
210
Expect (err ).To (BeNil ())
209
211
})
212
+ It ("should implicitly filter cluster subnets by cluster network" , func () {
213
+ const externalNetworkID = "a42211a2-4d2c-426f-9413-830e4b4abbbc"
214
+ const clusterNetworkID = "6c90b532-7ba0-418a-a276-5ae55060b5b0"
215
+ const clusterSubnetID = "cad5a91a-36de-4388-823b-b0cc82cadfdc"
216
+
217
+ testCluster .SetName ("subnet-filtering" )
218
+ testCluster .Spec = infrav1.OpenStackClusterSpec {
219
+ DisableAPIServerFloatingIP : true ,
220
+ APIServerFixedIP : "10.0.0.1" ,
221
+ ExternalNetworkID : externalNetworkID ,
222
+ Network : infrav1.NetworkFilter {
223
+ ID : clusterNetworkID ,
224
+ },
225
+ }
226
+ err := k8sClient .Create (ctx , testCluster )
227
+ Expect (err ).To (BeNil ())
228
+ err = k8sClient .Create (ctx , capiCluster )
229
+ Expect (err ).To (BeNil ())
230
+ scope , err := mockScopeFactory .NewClientScopeFromCluster (ctx , k8sClient , testCluster , nil , logr .Discard ())
231
+ Expect (err ).To (BeNil ())
232
+
233
+ networkClientRecorder := mockScopeFactory .NetworkClient .EXPECT ()
234
+
235
+ // Fetch external network
236
+ networkClientRecorder .ListNetwork (networks.ListOpts {
237
+ ID : externalNetworkID ,
238
+ }).Return ([]networks.Network {
239
+ {
240
+ ID : externalNetworkID ,
241
+ Name : "external-network" ,
242
+ },
243
+ }, nil )
244
+
245
+ // Fetch cluster network
246
+ networkClientRecorder .ListNetwork (& networks.ListOpts {
247
+ ID : clusterNetworkID ,
248
+ }).Return ([]networks.Network {
249
+ {
250
+ ID : clusterNetworkID ,
251
+ Name : "cluster-network" ,
252
+ },
253
+ }, nil )
254
+
255
+ // Fetching cluster subnets should be filtered by cluster network id
256
+ networkClientRecorder .ListSubnet (subnets.ListOpts {
257
+ NetworkID : clusterNetworkID ,
258
+ }).Return ([]subnets.Subnet {
259
+ {
260
+ ID : clusterSubnetID ,
261
+ Name : "cluster-subnet" ,
262
+ CIDR : "192.168.0.0/24" ,
263
+ },
264
+ }, nil )
265
+
266
+ err = reconcileNetworkComponents (scope , capiCluster , testCluster )
267
+ Expect (err ).To (BeNil ())
268
+ })
210
269
})
211
270
212
271
func createRequestFromOSCluster (openStackCluster * infrav1.OpenStackCluster ) reconcile.Request {
0 commit comments