@@ -148,6 +148,7 @@ func (c *client) CreateIsolatedNetwork(fd *infrav1.CloudStackFailureDomain, isoN
148148 isoNet .Spec .ID = resp .Id
149149 isoNet .Spec .Gateway = resp .Gateway
150150 isoNet .Spec .Netmask = resp .Netmask
151+ isoNet .Status .NetworkMode = resp .Ip4routing
151152 return c .AddCreatedByCAPCTag (ResourceTypeNetwork , isoNet .Spec .ID )
152153}
153154
@@ -171,17 +172,28 @@ func (c *client) OpenFirewallRules(isoNet *infrav1.CloudStackIsolatedNetwork) (r
171172
172173 protocols := []string {NetworkProtocolTCP , NetworkProtocolUDP , NetworkProtocolICMP }
173174 for _ , proto := range protocols {
174- p := c .cs .Firewall .NewCreateEgressFirewallRuleParams (isoNet .Spec .ID , proto )
175+ var err error
176+ if isoNet .Status .NetworkMode != "" {
177+ p := c .cs .Firewall .NewCreateRoutingFirewallRuleParams (isoNet .Spec .ID , proto )
178+ if proto == "icmp" {
179+ p .SetIcmptype (- 1 )
180+ p .SetIcmpcode (- 1 )
181+ }
182+ _ , err = c .cs .Firewall .CreateRoutingFirewallRule (p )
183+ } else {
184+ p := c .cs .Firewall .NewCreateEgressFirewallRuleParams (isoNet .Spec .ID , proto )
175185
176- if proto == "icmp" {
177- p .SetIcmptype (- 1 )
178- p .SetIcmpcode (- 1 )
179- }
186+ if proto == "icmp" {
187+ p .SetIcmptype (- 1 )
188+ p .SetIcmpcode (- 1 )
189+ }
180190
181- _ , err := c .cs .Firewall .CreateEgressFirewallRule (p )
191+ _ , err = c .cs .Firewall .CreateEgressFirewallRule (p )
192+ }
182193 if err != nil &&
183- // Ignore errors regarding already existing fw rules for TCP/UDP
194+ // Ignore errors regarding already existing fw rules for TCP/UDP for non-dynamic routing mode
184195 ! strings .Contains (strings .ToLower (err .Error ()), "there is already" ) &&
196+ ! strings .Contains (strings .ToLower (err .Error ()), "conflicts with rule" ) &&
185197 // Ignore errors regarding already existing fw rule for ICMP
186198 ! strings .Contains (strings .ToLower (err .Error ()), "new rule conflicts with existing rule" ) {
187199 retErr = errors .Wrapf (
@@ -298,6 +310,7 @@ func (c *client) GetOrCreateIsolatedNetwork(
298310 isoNet .Spec .ID = net .ID
299311 isoNet .Spec .Gateway = net .Gateway
300312 isoNet .Spec .Netmask = net .Netmask
313+ isoNet .Status .NetworkMode = net .NetworkMode
301314 if net .VPC != nil && net .VPC .ID != "" {
302315 isoNet .Spec .VPC = net .VPC
303316 }
@@ -316,14 +329,17 @@ func (c *client) GetOrCreateIsolatedNetwork(
316329 }
317330 }
318331
319- // Associate Public IP with CloudStackIsolatedNetwork
320- if err := c .AssociatePublicIPAddress (fd , isoNet , csCluster ); err != nil {
321- return errors .Wrapf (err , "associating public IP address to csCluster" )
322- }
332+ // Handle control plane endpoint based on network type
333+ if isoNet .Status .NetworkMode == "" {
334+ // For non-routed networks, use public IP and load balancer
335+ if err := c .AssociatePublicIPAddress (fd , isoNet , csCluster ); err != nil {
336+ return errors .Wrapf (err , "associating public IP address to csCluster" )
337+ }
323338
324- // Setup a load balancing rule to map VMs to Public IP.
325- if err := c .GetOrCreateLoadBalancerRule (isoNet , csCluster ); err != nil {
326- return errors .Wrap (err , "getting or creating load balancing rule" )
339+ // Setup a load balancing rule to map VMs to Public IP.
340+ if err := c .GetOrCreateLoadBalancerRule (isoNet , csCluster ); err != nil {
341+ return errors .Wrap (err , "getting or creating load balancing rule" )
342+ }
327343 }
328344
329345 // Open the Isolated Network on endopint port.
0 commit comments