@@ -50,6 +50,8 @@ type DNSDetails struct {
5050 AllIPs map [string ]map [infranetworkv1.NetNameStr ]string
5151 // DNSDataLabelSelectorValue to match configmaps dnsmasqhosts label
5252 DNSDataLabelSelectorValue string
53+ // NetServiceNetMap network name to service network mapping
54+ NetServiceNetMap map [string ]string
5355}
5456
5557// checkDNSService checks if DNS is configured and ready
@@ -81,10 +83,23 @@ func checkDNSService(ctx context.Context, helper *helper.Helper,
8183 dnsDetails .ClusterAddresses = dnsmasqList .Items [0 ].Status .DNSClusterAddresses
8284 dnsDetails .ServerAddresses = dnsmasqList .Items [0 ].Status .DNSAddresses
8385 dnsDetails .DNSDataLabelSelectorValue = dnsmasqList .Items [0 ].Spec .DNSDataLabelSelectorValue
84-
8586 return nil
8687}
8788
89+ // createNetServiceNetMap Creates a map of net and ServiceNet
90+ func BuildNetServiceNetMap (netconfig infranetworkv1.NetConfig ) map [string ]string {
91+ serviceNetMap := make (map [string ]string )
92+ for _ , net := range netconfig .Spec .Networks {
93+ netLower := strings .ToLower (string (net .Name ))
94+ if net .ServiceNetwork == "" {
95+ serviceNetMap [netLower ] = netLower
96+ } else {
97+ serviceNetMap [netLower ] = string (net .ServiceNetwork )
98+ }
99+ }
100+ return serviceNetMap
101+ }
102+
88103// createOrPatchDNSData builds the DNSData
89104func createOrPatchDNSData (ctx context.Context , helper * helper.Helper ,
90105 instance * dataplanev1.OpenStackDataPlaneNodeSet ,
@@ -240,7 +255,7 @@ func EnsureDNSData(ctx context.Context, helper *helper.Helper,
240255// EnsureIPSets Creates the IPSets
241256func EnsureIPSets (ctx context.Context , helper * helper.Helper ,
242257 instance * dataplanev1.OpenStackDataPlaneNodeSet ,
243- ) (map [string ]infranetworkv1.IPSet , bool , error ) {
258+ ) (map [string ]infranetworkv1.IPSet , map [ string ] string , bool , error ) {
244259 // Cleanup the stale reservations first
245260 err := cleanupStaleReservations (ctx , helper , instance )
246261 if err != nil {
@@ -250,16 +265,16 @@ func EnsureIPSets(ctx context.Context, helper *helper.Helper,
250265 condition .ErrorReason , condition .SeverityError ,
251266 dataplanev1 .NodeSetIPReservationReadyErrorMessage ,
252267 err .Error ())
253- return nil , false , err
268+ return nil , nil , false , err
254269 }
255- allIPSets , err := reserveIPs (ctx , helper , instance )
270+ allIPSets , netServiceNetMap , err := reserveIPs (ctx , helper , instance )
256271 if err != nil {
257272 instance .Status .Conditions .MarkFalse (
258273 dataplanev1 .NodeSetIPReservationReadyCondition ,
259274 condition .ErrorReason , condition .SeverityError ,
260275 dataplanev1 .NodeSetIPReservationReadyErrorMessage ,
261276 err .Error ())
262- return nil , false , err
277+ return nil , netServiceNetMap , false , err
263278 }
264279
265280 for _ , s := range allIPSets {
@@ -268,13 +283,13 @@ func EnsureIPSets(ctx context.Context, helper *helper.Helper,
268283 dataplanev1 .NodeSetIPReservationReadyCondition ,
269284 condition .RequestedReason , condition .SeverityInfo ,
270285 dataplanev1 .NodeSetIPReservationReadyWaitingMessage )
271- return nil , false , nil
286+ return nil , netServiceNetMap , false , nil
272287 }
273288 }
274289 instance .Status .Conditions .MarkTrue (
275290 dataplanev1 .NodeSetIPReservationReadyCondition ,
276291 dataplanev1 .NodeSetIPReservationReadyMessage )
277- return allIPSets , true , nil
292+ return allIPSets , netServiceNetMap , true , nil
278293}
279294
280295// cleanupStaleReservations Cleanup stale ipset reservations
@@ -318,22 +333,22 @@ func cleanupStaleReservations(ctx context.Context, helper *helper.Helper,
318333// reserveIPs Reserves IPs by creating IPSets
319334func reserveIPs (ctx context.Context , helper * helper.Helper ,
320335 instance * dataplanev1.OpenStackDataPlaneNodeSet ,
321- ) (map [string ]infranetworkv1.IPSet , error ) {
336+ ) (map [string ]infranetworkv1.IPSet , map [ string ] string , error ) {
322337 // Verify NetConfig CRs exist
323338 netConfigList := & infranetworkv1.NetConfigList {}
324339 listOpts := []client.ListOption {
325340 client .InNamespace (instance .GetNamespace ()),
326341 }
327342 err := helper .GetClient ().List (ctx , netConfigList , listOpts ... )
328343 if err != nil {
329- return nil , err
344+ return nil , nil , err
330345 }
331346 if len (netConfigList .Items ) == 0 {
332347 errMsg := "no NetConfig CR exists yet"
333348 util .LogForObject (helper , errMsg , instance )
334- return nil , fmt .Errorf (errMsg )
349+ return nil , nil , fmt .Errorf (errMsg )
335350 }
336-
351+ netServiceNetMap := BuildNetServiceNetMap ( netConfigList . Items [ 0 ])
337352 allIPSets := make (map [string ]infranetworkv1.IPSet )
338353
339354 // CreateOrPatch IPSets
@@ -361,14 +376,14 @@ func reserveIPs(ctx context.Context, helper *helper.Helper,
361376 return err
362377 })
363378 if err != nil {
364- return nil , err
379+ return nil , netServiceNetMap , err
365380 }
366381 allIPSets [hostName ] = * ipSet
367382 } else {
368383 msg := fmt .Sprintf ("No Networks defined for node %s or template" , nodeName )
369384 util .LogForObject (helper , msg , instance )
370- return nil , fmt .Errorf (msg )
385+ return nil , netServiceNetMap , fmt .Errorf (msg )
371386 }
372387 }
373- return allIPSets , nil
388+ return allIPSets , netServiceNetMap , nil
374389}
0 commit comments