Skip to content

Commit 991d251

Browse files
Merge pull request #1079 from rabi/service_net
Use ServiceNet for ansible vars
2 parents 47b4277 + 9cf9914 commit 991d251

File tree

8 files changed

+68
-43
lines changed

8 files changed

+68
-43
lines changed

apis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/openstack-k8s-operators/glance-operator/api v0.4.1-0.20240910163548-50b7ba5af8fd
1414
github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4264ab1c41
1515
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b
16-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d
16+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36
1717
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905
1818
github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20240906103150-990fe66f2e5d
1919
github.com/openstack-k8s-operators/lib-common/modules/common v0.4.1-0.20240910122823-bdcfe881513b

apis/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4
102102
github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4264ab1c41/go.mod h1:w+8OpHuUfk4nEUSQfFZbYGPZEkn0c1xe3fyZ062fkDA=
103103
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b h1:B4kw/FovC+mKMRA8dahi2k3x751iOuBwglu9DBz0iX4=
104104
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b/go.mod h1:Q9/AUCUCA959gIq3DxzUdTWvkwqDp0lz3ujW0vTPdWg=
105-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d h1:GbkbsL89plNNnyQI06VzDyJ1xe8DhDky3wAPL5g6LBs=
106-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d/go.mod h1:TFh01OyR/NP5Sy7vikMIpQc80AKl0WWPyYDaJBfFiGc=
105+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36 h1:CLWZvSjPEmdJNSUrpcgLRb1UOP2LBGJrwm+8LlCx/FA=
106+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36/go.mod h1:TFh01OyR/NP5Sy7vikMIpQc80AKl0WWPyYDaJBfFiGc=
107107
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905 h1:zPvoW+qHyX9MWZ9K8B0I+nzGmzZk8+YyPBRg56PYMsM=
108108
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905/go.mod h1:iQq0r9XaY6+AN9LaJIvhoetuOwnaGIhU0XkQvHLFT9M=
109109
github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20240906103150-990fe66f2e5d h1:PbTZo4RCo+RFiGZ0q/rllUXoUtxgtWAh4V0IUe3aW5k=

controllers/dataplane/openstackdataplanenodeset_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
230230
}
231231

232232
// Ensure IPSets Required for Nodes
233-
allIPSets, isReady, err := deployment.EnsureIPSets(ctx, helper, instance)
233+
allIPSets, netServiceNetMap, isReady, err := deployment.EnsureIPSets(ctx, helper, instance)
234234
if err != nil || !isReady {
235235
return ctrl.Result{}, err
236236
}
@@ -390,7 +390,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
390390
if !isDeploymentRunning && !isDeploymentFailed {
391391
// Generate NodeSet Inventory
392392
_, err = deployment.GenerateNodeSetInventory(ctx, helper, instance,
393-
allIPSets, dnsDetails.ServerAddresses, containerImages)
393+
allIPSets, dnsDetails.ServerAddresses, containerImages, netServiceNetMap)
394394
if err != nil {
395395
errorMsg := fmt.Sprintf("Unable to generate inventory for %s", instance.Name)
396396
util.LogErrorForObject(helper, err, errorMsg, instance)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/openstack-k8s-operators/glance-operator/api v0.4.1-0.20240910163548-50b7ba5af8fd
1919
github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4264ab1c41
2020
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b
21-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d
21+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36
2222
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905
2323
github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20240906103150-990fe66f2e5d
2424
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.4.1-0.20240910122823-bdcfe881513b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4
108108
github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20240913120324-5a4264ab1c41/go.mod h1:w+8OpHuUfk4nEUSQfFZbYGPZEkn0c1xe3fyZ062fkDA=
109109
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b h1:B4kw/FovC+mKMRA8dahi2k3x751iOuBwglu9DBz0iX4=
110110
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20240906120219-9c3e4ba4077b/go.mod h1:Q9/AUCUCA959gIq3DxzUdTWvkwqDp0lz3ujW0vTPdWg=
111-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d h1:GbkbsL89plNNnyQI06VzDyJ1xe8DhDky3wAPL5g6LBs=
112-
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240912140341-4066f2ead41d/go.mod h1:TFh01OyR/NP5Sy7vikMIpQc80AKl0WWPyYDaJBfFiGc=
111+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36 h1:CLWZvSjPEmdJNSUrpcgLRb1UOP2LBGJrwm+8LlCx/FA=
112+
github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20240917142819-7e2d29023d36/go.mod h1:TFh01OyR/NP5Sy7vikMIpQc80AKl0WWPyYDaJBfFiGc=
113113
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905 h1:zPvoW+qHyX9MWZ9K8B0I+nzGmzZk8+YyPBRg56PYMsM=
114114
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20240913082854-93e827d3a905/go.mod h1:iQq0r9XaY6+AN9LaJIvhoetuOwnaGIhU0XkQvHLFT9M=
115115
github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20240906103150-990fe66f2e5d h1:PbTZo4RCo+RFiGZ0q/rllUXoUtxgtWAh4V0IUe3aW5k=

pkg/dataplane/inventory.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func getAnsibleVarsFrom(ctx context.Context, helper *helper.Helper, namespace st
8989
func GenerateNodeSetInventory(ctx context.Context, helper *helper.Helper,
9090
instance *dataplanev1.OpenStackDataPlaneNodeSet,
9191
allIPSets map[string]infranetworkv1.IPSet, dnsAddresses []string,
92-
containerImages openstackv1.ContainerImages) (string, error) {
92+
containerImages openstackv1.ContainerImages,
93+
netServiceNetMap map[string]string) (string, error) {
9394
inventory := ansible.MakeInventory()
9495
nodeSetGroup := inventory.AddGroup(instance.Name)
9596
groupVars, err := getAnsibleVarsFrom(ctx, helper, instance.Namespace, &instance.Spec.NodeTemplate.Ansible)
@@ -100,7 +101,8 @@ func GenerateNodeSetInventory(ctx context.Context, helper *helper.Helper,
100101
for k, v := range groupVars {
101102
nodeSetGroup.Vars[k] = v
102103
}
103-
err = resolveGroupAnsibleVars(&instance.Spec.NodeTemplate, &nodeSetGroup, containerImages)
104+
err = resolveGroupAnsibleVars(&instance.Spec.NodeTemplate,
105+
&nodeSetGroup, containerImages, netServiceNetMap)
104106
if err != nil {
105107
utils.LogErrorForObject(helper, err, "Could not resolve ansible group vars", instance)
106108
return "", err
@@ -151,7 +153,7 @@ func GenerateNodeSetInventory(ctx context.Context, helper *helper.Helper,
151153
host.Vars["ansible_host"] = node.HostName
152154
}
153155

154-
err = resolveHostAnsibleVars(&node, &host)
156+
err = resolveHostAnsibleVars(&node, &host, netServiceNetMap)
155157
if err != nil {
156158
utils.LogErrorForObject(helper, err, "could not resolve ansible host vars", instance)
157159
return "", err
@@ -207,7 +209,7 @@ func populateInventoryFromIPAM(
207209
var dnsSearchDomains []string
208210
for _, res := range ipSet.Status.Reservation {
209211
// Build the vars for ips/routes etc
210-
entry := strings.ToLower(string(res.Network))
212+
entry := string(res.ServiceNetwork)
211213
host.Vars[entry+"_ip"] = res.Address
212214
_, ipnet, err := net.ParseCIDR(res.Cidr)
213215
if err == nil {
@@ -240,7 +242,8 @@ func populateInventoryFromIPAM(
240242

241243
// set group ansible vars from NodeTemplate
242244
func resolveGroupAnsibleVars(template *dataplanev1.NodeTemplate, group *ansible.Group,
243-
containerImages openstackv1.ContainerImages) error {
245+
containerImages openstackv1.ContainerImages,
246+
netServiceNetMap map[string]string) error {
244247

245248
if template.Ansible.AnsibleUser != "" {
246249
group.Vars["ansible_user"] = template.Ansible.AnsibleUser
@@ -302,16 +305,19 @@ func resolveGroupAnsibleVars(template *dataplanev1.NodeTemplate, group *ansible.
302305
return err
303306
}
304307
if len(template.Networks) != 0 {
305-
nets, netsLower := buildNetworkVars(template.Networks)
308+
nets, serviceNetMap := buildNetworkVars(template.Networks, netServiceNetMap)
306309
group.Vars["nodeset_networks"] = nets
307-
group.Vars["networks_lower"] = netsLower
310+
// We may get rid of networks_lower var after changing it's usage
311+
group.Vars["networks_lower"] = serviceNetMap
312+
group.Vars["network_servicenet_map"] = serviceNetMap
308313
}
309314

310315
return nil
311316
}
312317

313318
// set host ansible vars from NodeSection
314-
func resolveHostAnsibleVars(node *dataplanev1.NodeSection, host *ansible.Host) error {
319+
func resolveHostAnsibleVars(node *dataplanev1.NodeSection,
320+
host *ansible.Host, netServiceNetMap map[string]string) error {
315321

316322
if node.Ansible.AnsibleUser != "" {
317323
host.Vars["ansible_user"] = node.Ansible.AnsibleUser
@@ -328,9 +334,11 @@ func resolveHostAnsibleVars(node *dataplanev1.NodeSection, host *ansible.Host) e
328334
return err
329335
}
330336
if len(node.Networks) != 0 {
331-
nets, netsLower := buildNetworkVars(node.Networks)
337+
nets, serviceNetMap := buildNetworkVars(node.Networks, netServiceNetMap)
332338
host.Vars["nodeset_networks"] = nets
333-
host.Vars["networks_lower"] = netsLower
339+
// We may get rid of networks_lower var after changing it's usage
340+
host.Vars["networks_lower"] = serviceNetMap
341+
host.Vars["network_servicenet_map"] = serviceNetMap
334342
}
335343
return nil
336344

@@ -351,16 +359,17 @@ func unmarshalAnsibleVars(ansibleVars map[string]json.RawMessage,
351359
return nil
352360
}
353361

354-
func buildNetworkVars(networks []infranetworkv1.IPSetNetwork) ([]string, map[string]string) {
355-
netsLower := make(map[string]string)
362+
func buildNetworkVars(networks []infranetworkv1.IPSetNetwork,
363+
netServiceNetMap map[string]string) ([]string, map[string]string) {
364+
serviceNetMap := make(map[string]string)
356365
var nets []string
357366
for _, network := range networks {
358367
netName := string(network.Name)
359-
if strings.EqualFold(netName, dataplanev1.CtlPlaneNetwork) {
368+
if netServiceNetMap[strings.ToLower(netName)] == dataplanev1.CtlPlaneNetwork {
360369
continue
361370
}
362371
nets = append(nets, netName)
363-
netsLower[netName] = strings.ToLower(netName)
372+
serviceNetMap[netName] = netServiceNetMap[strings.ToLower(netName)]
364373
}
365-
return nets, netsLower
374+
return nets, serviceNetMap
366375
}

pkg/dataplane/ipam.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
89104
func 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
241256
func 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
319334
func 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
}

tests/functional/dataplane/base_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,13 @@ func SimulateIPSetComplete(name types.NamespacedName) {
350350
gateway := "172.20.12.1"
351351
IPSet.Status.Reservation = []infrav1.IPSetReservation{
352352
{
353-
Address: "172.20.12.76",
354-
Cidr: "172.20.12.0/16",
355-
MTU: 1500,
356-
Network: "CtlPlane",
357-
Subnet: "subnet1",
358-
Gateway: &gateway,
353+
Address: "172.20.12.76",
354+
Cidr: "172.20.12.0/16",
355+
MTU: 1500,
356+
Network: "CtlPlane",
357+
Subnet: "subnet1",
358+
Gateway: &gateway,
359+
ServiceNetwork: "ctlplane",
359360
},
360361
}
361362
// This can return conflict so we have the gomega.Eventually block to retry

0 commit comments

Comments
 (0)