@@ -145,19 +145,24 @@ func (s *Service) constructNetworks(openStackCluster *infrav1.OpenStackCluster,
145
145
}
146
146
}
147
147
for i , port := range openStackMachine .Spec .Ports {
148
+ pOpts := & openStackMachine .Spec .Ports [i ]
149
+ // No Trunk field specified for the port, inherit openStackMachine.Spec.Trunk.
150
+ if pOpts .Trunk == nil {
151
+ pOpts .Trunk = & openStackMachine .Spec .Trunk
152
+ }
148
153
if port .NetworkID != "" {
149
154
nets = append (nets , infrav1.Network {
150
155
ID : port .NetworkID ,
151
156
Subnet : & infrav1.Subnet {},
152
- PortOpts : & openStackMachine . Spec . Ports [ i ] ,
157
+ PortOpts : pOpts ,
153
158
})
154
159
} else {
155
160
nets = append (nets , infrav1.Network {
156
161
ID : openStackCluster .Status .Network .ID ,
157
162
Subnet : & infrav1.Subnet {
158
163
ID : openStackCluster .Status .Network .Subnet .ID ,
159
164
},
160
- PortOpts : & openStackMachine . Spec . Ports [ i ] ,
165
+ PortOpts : pOpts ,
161
166
})
162
167
}
163
168
}
@@ -168,6 +173,9 @@ func (s *Service) constructNetworks(openStackCluster *infrav1.OpenStackCluster,
168
173
Subnet : & infrav1.Subnet {
169
174
ID : openStackCluster .Status .Network .Subnet .ID ,
170
175
},
176
+ PortOpts : & infrav1.PortOpts {
177
+ Trunk : & openStackMachine .Spec .Trunk ,
178
+ },
171
179
}}
172
180
}
173
181
return nets , nil
@@ -181,24 +189,16 @@ func (s *Service) createInstance(eventObject runtime.Object, clusterName string,
181
189
if network .ID == "" {
182
190
return nil , fmt .Errorf ("no network was found or provided. Please check your machine configuration and try again" )
183
191
}
184
-
192
+ iTags := []string {}
193
+ if len (instanceSpec .Tags ) > 0 {
194
+ iTags = instanceSpec .Tags
195
+ }
185
196
portName := getPortName (instanceSpec .Name , network .PortOpts , i )
186
- port , err := s .getOrCreatePort (eventObject , clusterName , portName , network , instanceSpec .SecurityGroups )
197
+ port , err := s .getOrCreatePort (eventObject , clusterName , portName , network , & instanceSpec .SecurityGroups , iTags )
187
198
if err != nil {
188
199
return nil , err
189
200
}
190
201
191
- if instanceSpec .Trunk {
192
- trunk , err := s .getOrCreateTrunk (eventObject , clusterName , instanceSpec .Name , port .ID )
193
- if err != nil {
194
- return nil , err
195
- }
196
-
197
- if err = s .replaceAllAttributesTags (eventObject , trunk .ID , instanceSpec .Tags ); err != nil {
198
- return nil , err
199
- }
200
- }
201
-
202
202
for _ , fip := range port .FixedIPs {
203
203
if fip .SubnetID == instanceSpec .Subnet {
204
204
accessIPv4 = fip .IPAddress
@@ -420,7 +420,7 @@ func (s *Service) getServerNetworks(networkParams []infrav1.NetworkParam) ([]inf
420
420
return nets , nil
421
421
}
422
422
423
- func (s * Service ) getOrCreatePort (eventObject runtime.Object , clusterName string , portName string , net infrav1.Network , instanceSecurityGroups []string ) (* ports.Port , error ) {
423
+ func (s * Service ) getOrCreatePort (eventObject runtime.Object , clusterName string , portName string , net infrav1.Network , instanceSecurityGroups * [] string , tags []string ) (* ports.Port , error ) {
424
424
mc := metrics .NewMetricPrometheusContext ("port" , "list" )
425
425
allPages , err := ports .List (s .networkClient , ports.ListOpts {
426
426
Name : portName ,
@@ -467,7 +467,7 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
467
467
468
468
// inherit port security groups from the instance if not explicitly specified
469
469
if securityGroups == nil {
470
- securityGroups = & instanceSecurityGroups
470
+ securityGroups = instanceSecurityGroups
471
471
}
472
472
}
473
473
@@ -523,6 +523,18 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
523
523
}
524
524
525
525
record .Eventf (eventObject , "SuccessfulCreatePort" , "Created port %s with id %s" , port .Name , port .ID )
526
+ if portOpts .Trunk != nil && * portOpts .Trunk {
527
+ trunk , err := s .getOrCreateTrunk (eventObject , clusterName , port .Name , port .ID )
528
+ if err != nil {
529
+ record .Warnf (eventObject , "FailedCreateTrunk" , "Failed to create trunk for port %s: %v" , portName , err )
530
+ return nil , err
531
+ }
532
+ if err = s .replaceAllAttributesTags (eventObject , trunk .ID , tags ); err != nil {
533
+ record .Warnf (eventObject , "FailedReplaceTags" , "Failed to replace trunk tags %s: %v" , portName , err )
534
+ return nil , err
535
+ }
536
+ }
537
+
526
538
return port , nil
527
539
}
528
540
@@ -548,11 +560,11 @@ func (s *Service) getOrCreateTrunk(eventObject runtime.Object, clusterName, trun
548
560
PortID : portID ,
549
561
}).AllPages ()
550
562
if mc .ObserveRequest (err ) != nil {
551
- return nil , fmt .Errorf ("searching for existing trunk for server : %v" , err )
563
+ return nil , fmt .Errorf ("searching for existing trunk for port : %v" , err )
552
564
}
553
565
trunkList , err := trunks .ExtractTrunks (allPages )
554
566
if err != nil {
555
- return nil , fmt .Errorf ("searching for existing trunk for server : %v" , err )
567
+ return nil , fmt .Errorf ("searching for existing trunk for port : %v" , err )
556
568
}
557
569
558
570
if len (trunkList ) != 0 {
0 commit comments