Skip to content

Commit ec3be4d

Browse files
committed
Define routes of the management network in the operator
In case the gateway of the management network is not defined in the NAD Select an address in the CIDR and use it for the gateway
1 parent d36c6df commit ec3be4d

13 files changed

+127
-17
lines changed

api/bases/octavia.openstack.org_octaviaamphoracontrollers.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ spec:
127127
description: NodeSelector to target subset of worker nodes running
128128
this service
129129
type: object
130+
octaviaProviderSubnetCIDR:
131+
description: OctaviaProviderSubnetCIDR -
132+
type: string
133+
octaviaProviderSubnetGateway:
134+
description: OctaviaProviderSubnetGateway -
135+
type: string
130136
passwordSelectors:
131137
default:
132138
service: OctaviaPassword

api/bases/octavia.openstack.org_octavias.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,12 @@ spec:
580580
description: NodeSelector to target subset of worker nodes running
581581
this service
582582
type: object
583+
octaviaProviderSubnetCIDR:
584+
description: OctaviaProviderSubnetCIDR -
585+
type: string
586+
octaviaProviderSubnetGateway:
587+
description: OctaviaProviderSubnetGateway -
588+
type: string
583589
passwordSelectors:
584590
default:
585591
service: OctaviaPassword
@@ -775,6 +781,12 @@ spec:
775781
description: NodeSelector to target subset of worker nodes running
776782
this service
777783
type: object
784+
octaviaProviderSubnetCIDR:
785+
description: OctaviaProviderSubnetCIDR -
786+
type: string
787+
octaviaProviderSubnetGateway:
788+
description: OctaviaProviderSubnetGateway -
789+
type: string
778790
passwordSelectors:
779791
default:
780792
service: OctaviaPassword
@@ -975,6 +987,12 @@ spec:
975987
description: NodeSelector to target subset of worker nodes running
976988
this service
977989
type: object
990+
octaviaProviderSubnetCIDR:
991+
description: OctaviaProviderSubnetCIDR -
992+
type: string
993+
octaviaProviderSubnetGateway:
994+
description: OctaviaProviderSubnetGateway -
995+
type: string
978996
passwordSelectors:
979997
default:
980998
service: OctaviaPassword

api/v1beta1/amphoracontroller_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ type OctaviaAmphoraControllerSpecCore struct {
143143
// +operator-sdk:csv:customresourcedefinitions:type=spec
144144
// TLS - Parameters related to the TLS
145145
TLS tls.Ca `json:"tls,omitempty"`
146+
147+
// +kubebuilder:validation:Optional
148+
// OctaviaProviderSubnetGateway -
149+
OctaviaProviderSubnetGateway string `json:"octaviaProviderSubnetGateway"`
150+
151+
// +kubebuilder:validation:Optional
152+
// OctaviaProviderSubnetCIDR -
153+
OctaviaProviderSubnetCIDR string `json:"octaviaProviderSubnetCIDR"`
146154
}
147155

148156
// OctaviaAmphoraControllerStatus defines the observed state of the Octavia Amphora Controller

config/crd/bases/octavia.openstack.org_octaviaamphoracontrollers.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ spec:
127127
description: NodeSelector to target subset of worker nodes running
128128
this service
129129
type: object
130+
octaviaProviderSubnetCIDR:
131+
description: OctaviaProviderSubnetCIDR -
132+
type: string
133+
octaviaProviderSubnetGateway:
134+
description: OctaviaProviderSubnetGateway -
135+
type: string
130136
passwordSelectors:
131137
default:
132138
service: OctaviaPassword

config/crd/bases/octavia.openstack.org_octavias.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,12 @@ spec:
580580
description: NodeSelector to target subset of worker nodes running
581581
this service
582582
type: object
583+
octaviaProviderSubnetCIDR:
584+
description: OctaviaProviderSubnetCIDR -
585+
type: string
586+
octaviaProviderSubnetGateway:
587+
description: OctaviaProviderSubnetGateway -
588+
type: string
583589
passwordSelectors:
584590
default:
585591
service: OctaviaPassword
@@ -775,6 +781,12 @@ spec:
775781
description: NodeSelector to target subset of worker nodes running
776782
this service
777783
type: object
784+
octaviaProviderSubnetCIDR:
785+
description: OctaviaProviderSubnetCIDR -
786+
type: string
787+
octaviaProviderSubnetGateway:
788+
description: OctaviaProviderSubnetGateway -
789+
type: string
778790
passwordSelectors:
779791
default:
780792
service: OctaviaPassword
@@ -975,6 +987,12 @@ spec:
975987
description: NodeSelector to target subset of worker nodes running
976988
this service
977989
type: object
990+
octaviaProviderSubnetCIDR:
991+
description: OctaviaProviderSubnetCIDR -
992+
type: string
993+
octaviaProviderSubnetGateway:
994+
description: OctaviaProviderSubnetGateway -
995+
type: string
978996
passwordSelectors:
979997
default:
980998
service: OctaviaPassword

controllers/octavia_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ func (r *OctaviaReconciler) amphoraControllerDaemonSetCreateOrUpdate(
13331333
daemonset.Spec.AmphoraCustomFlavors = instance.Spec.AmphoraCustomFlavors
13341334
daemonset.Spec.TLS = instance.Spec.OctaviaAPI.TLS.Ca
13351335
daemonset.Spec.AmphoraImageOwnerID = ampImageOwnerID
1336+
daemonset.Spec.OctaviaProviderSubnetGateway = networkInfo.ManagementSubnetGateway
1337+
daemonset.Spec.OctaviaProviderSubnetCIDR = networkInfo.ManagementSubnetCIDR
13361338
if len(daemonset.Spec.NodeSelector) == 0 {
13371339
daemonset.Spec.NodeSelector = instance.Spec.NodeSelector
13381340
}

pkg/amphoracontrollers/daemonset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func DaemonSet(
8484
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
8585
envVars["CONFIG_HASH"] = env.SetValue(configHash)
8686

87+
envVars["MGMT_CIDR"] = env.SetValue(instance.Spec.OctaviaProviderSubnetCIDR)
88+
envVars["MGMT_GATEWAY"] = env.SetValue(instance.Spec.OctaviaProviderSubnetGateway)
89+
8790
// Add the CA bundle
8891
if instance.Spec.TLS.CaBundleSecretName != "" {
8992
volumes = append(volumes, instance.Spec.TLS.CreateVolume())

pkg/octavia/lb_mgmt_network.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import (
3333
)
3434

3535
type NetworkProvisioningSummary struct {
36-
TenantNetworkID string
37-
TenantSubnetID string
38-
TenantRouterPortID string
39-
ProviderNetworkID string
40-
RouterID string
41-
SecurityGroupID string
36+
TenantNetworkID string
37+
TenantSubnetID string
38+
TenantRouterPortID string
39+
ProviderNetworkID string
40+
RouterID string
41+
SecurityGroupID string
42+
ManagementSubnetCIDR string
43+
ManagementSubnetGateway string
4244
}
4345

4446
//
@@ -870,11 +872,13 @@ func EnsureAmphoraManagementNetwork(
870872
}
871873

872874
return NetworkProvisioningSummary{
873-
TenantNetworkID: tenantNetwork.ID,
874-
TenantSubnetID: tenantSubnet.ID,
875-
TenantRouterPortID: tenantRouterPort.ID,
876-
ProviderNetworkID: providerNetwork.ID,
877-
RouterID: router.ID,
878-
SecurityGroupID: lbMgmtSecurityGroupID,
875+
TenantNetworkID: tenantNetwork.ID,
876+
TenantSubnetID: tenantSubnet.ID,
877+
TenantRouterPortID: tenantRouterPort.ID,
878+
ProviderNetworkID: providerNetwork.ID,
879+
RouterID: router.ID,
880+
SecurityGroupID: lbMgmtSecurityGroupID,
881+
ManagementSubnetCIDR: networkParameters.TenantCIDR.String(),
882+
ManagementSubnetGateway: networkParameters.ProviderGateway.String(),
879883
}, nil
880884
}

templates/octaviaamphoracontroller/bin/octavia_healthmanager_start.sh renamed to templates/octaviaamphoracontroller/bin/octavia_controller_start.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# under the License.
1616
set -ex
1717

18-
/usr/local/bin/container-scripts/octavia_hm_advertisement.py octavia
18+
/usr/local/bin/container-scripts/octavia_mgmt_subnet_route.py octavia "$MGMT_CIDR" "$MGMT_GATEWAY"
1919

20-
exec /usr/bin/octavia-health-manager --config-file /usr/share/octavia/octavia-dist.conf --config-file /etc/octavia/octavia.conf
20+
if [ "$1" = "octavia-health-manager" ]; then
21+
/usr/local/bin/container-scripts/octavia_hm_advertisement.py octavia
22+
fi
23+
24+
exec /usr/bin/$1 --config-file /usr/share/octavia/octavia-dist.conf --config-file /etc/octavia/octavia.conf
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2024 Red Hat Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
import sys
18+
import socket
19+
20+
from pyroute2 import IPRoute
21+
22+
try:
23+
interface_name = sys.argv[1]
24+
dst = sys.argv[2]
25+
gateway = sys.argv[3]
26+
except IndexError:
27+
print(f"usage: {sys.argv[0]} <interface_name> <dst> <gateway>")
28+
sys.exit(1)
29+
30+
ip = IPRoute()
31+
32+
try:
33+
idx = ip.link_lookup(ifname=interface_name)[0]
34+
except IndexError:
35+
print(f"Cannot find interface '{interface_name}', skipping")
36+
sys.exit(0)
37+
38+
try:
39+
ip.route('add', index=idx, dst=dst, gateway=gateway)
40+
except Exception as e:
41+
print(f"Cannot set route {dst} via {gateway}: {e}")

0 commit comments

Comments
 (0)