@@ -71,17 +71,17 @@ func (s *Service) CreateInstance(openStackCluster *infrav1.OpenStackCluster, mac
71
71
ServerGroupID : openStackMachine .Spec .ServerGroupID ,
72
72
}
73
73
74
+ // verify that trunk is supported if set at instance level.
74
75
if openStackMachine .Spec .Trunk {
75
- trunkSupport , err := s .networkingService . GetTrunkSupport ()
76
+ trunkSupported , err := s .isTrunkExtSupported ()
76
77
if err != nil {
77
- return nil , fmt . Errorf ( "there was an issue verifying whether trunk support is available, please disable it: %v" , err )
78
+ return nil , err
78
79
}
79
- if ! trunkSupport {
80
- return nil , fmt .Errorf ("there is no trunk support. Please disable it " )
80
+ if ! trunkSupported {
81
+ return nil , fmt .Errorf ("there is no trunk support. please ensure that the trunk extension is enabled in your OpenStack deployment " )
81
82
}
82
- instanceSpec .Trunk = trunkSupport
83
+ instanceSpec .Trunk = true
83
84
}
84
-
85
85
machineTags := []string {}
86
86
87
87
// Append machine specific tags
@@ -113,6 +113,17 @@ func (s *Service) CreateInstance(openStackCluster *infrav1.OpenStackCluster, mac
113
113
if err != nil {
114
114
return nil , err
115
115
}
116
+
117
+ trunkConfigured := s .isTrunkConfigured (nets , instanceSpec .Trunk )
118
+ if trunkConfigured {
119
+ trunkSupported , err := s .isTrunkExtSupported ()
120
+ if err != nil {
121
+ return nil , err
122
+ }
123
+ if ! trunkSupported {
124
+ return nil , fmt .Errorf ("there is no trunk support. please ensure that the trunk extension is enabled in your OpenStack deployment" )
125
+ }
126
+ }
116
127
instanceSpec .Networks = nets
117
128
118
129
return s .createInstance (openStackMachine , clusterName , & instanceSpec )
@@ -444,7 +455,7 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instance *InstanceS
444
455
return err
445
456
}
446
457
447
- trunkSupport , err := s .networkingService . GetTrunkSupport ()
458
+ trunkSupported , err := s .isTrunkExtSupported ()
448
459
if err != nil {
449
460
return fmt .Errorf ("obtaining network extensions: %v" , err )
450
461
}
@@ -454,12 +465,11 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instance *InstanceS
454
465
return err
455
466
}
456
467
457
- if trunkSupport {
468
+ if trunkSupported {
458
469
if err = s .networkingService .DeleteTrunk (eventObject , port .PortID ); err != nil {
459
470
return err
460
471
}
461
472
}
462
-
463
473
if err = s .networkingService .DeletePort (eventObject , port .PortID ); err != nil {
464
474
return err
465
475
}
@@ -615,3 +625,31 @@ func getTimeout(name string, timeout int) time.Duration {
615
625
}
616
626
return time .Duration (timeout )
617
627
}
628
+
629
+ // isTrunkExtSupported verifies trunk setup on the OpenStack deployment.
630
+ func (s * Service ) isTrunkExtSupported () (trunknSupported bool , err error ) {
631
+ trunkSupport , err := s .networkingService .GetTrunkSupport ()
632
+ if err != nil {
633
+ return false , fmt .Errorf ("there was an issue verifying whether trunk support is available, Please try again later: %v" , err )
634
+ }
635
+ if ! trunkSupport {
636
+ return false , nil
637
+ }
638
+ return true , nil
639
+ }
640
+
641
+ // isTrunkConfigured verifies trunk configuration at instance and port levels, useful for avoiding multple api calls to verify trunk support.
642
+ func (s * Service ) isTrunkConfigured (nets []infrav1.Network , instanceLevelTrunk bool ) bool {
643
+ if instanceLevelTrunk {
644
+ return true
645
+ }
646
+ for _ , net := range nets {
647
+ port := net .PortOpts
648
+ if port != nil {
649
+ if port .Trunk != nil && * port .Trunk {
650
+ return true
651
+ }
652
+ }
653
+ }
654
+ return false
655
+ }
0 commit comments