@@ -171,42 +171,34 @@ func (s *Service) normalizePorts(ports []infrav1.PortOpts, openStackCluster *inf
171
171
return normalizedPorts , nil
172
172
}
173
173
174
- // constructNetworks builds an array of networks from the network, subnet and ports items in the instance spec.
175
- // If no networks or ports are in the spec, returns a single network item for a network connection to the default cluster network.
176
- func (s * Service ) constructNetworks (openStackCluster * infrav1.OpenStackCluster , instanceSpec * InstanceSpec ) ([]infrav1.Network , error ) {
174
+ // constructPorts builds an array of ports from the instance spec.
175
+ // If no ports are in the spec, returns a single port for a network connection to the default cluster network.
176
+ func (s * Service ) constructPorts (openStackCluster * infrav1.OpenStackCluster , instanceSpec * InstanceSpec ) ([]infrav1.PortOpts , error ) {
177
177
// Ensure user-specified ports have all required fields
178
178
ports , err := s .normalizePorts (instanceSpec .Ports , openStackCluster , instanceSpec )
179
179
if err != nil {
180
180
return nil , err
181
181
}
182
- nets := make ([]infrav1.Network , 0 , len (ports ))
183
- for i := range ports {
184
- port := & ports [i ]
185
- nets = append (nets , infrav1.Network {
186
- ID : port .Network .ID ,
187
- Subnet : & infrav1.Subnet {},
188
- PortOpts : port ,
189
- })
190
- }
191
182
192
183
// no networks or ports found in the spec, so create a port on the cluster network
193
- if len (nets ) == 0 {
194
- nets = []infrav1.Network {{
195
- ID : openStackCluster .Status .Network .ID ,
196
- Subnet : & infrav1.Subnet {
197
- ID : openStackCluster .Status .Network .Subnet .ID ,
198
- },
199
- PortOpts : & infrav1.PortOpts {
200
- Trunk : & instanceSpec .Trunk ,
184
+ if len (ports ) == 0 {
185
+ ports = []infrav1.PortOpts {{
186
+ Network : & infrav1.NetworkFilter {
187
+ ID : openStackCluster .Status .Network .ID ,
201
188
},
189
+ FixedIPs : []infrav1.FixedIP {{
190
+ Subnet : & infrav1.SubnetFilter {
191
+ ID : openStackCluster .Status .Network .Subnet .ID ,
192
+ },
193
+ }},
194
+ Trunk : & instanceSpec .Trunk ,
202
195
}}
203
196
}
204
197
205
198
// trunk support is required if any port has trunk enabled
206
199
portUsesTrunk := func () bool {
207
- for _ , net := range nets {
208
- port := net .PortOpts
209
- if port != nil && port .Trunk != nil && * port .Trunk {
200
+ for _ , port := range ports {
201
+ if port .Trunk != nil && * port .Trunk {
210
202
return true
211
203
}
212
204
}
@@ -222,7 +214,7 @@ func (s *Service) constructNetworks(openStackCluster *infrav1.OpenStackCluster,
222
214
}
223
215
}
224
216
225
- return nets , nil
217
+ return ports , nil
226
218
}
227
219
228
220
func (s * Service ) CreateInstance (eventObject runtime.Object , openStackCluster * infrav1.OpenStackCluster , instanceSpec * InstanceSpec , clusterName string , isBastion bool ) (* InstanceStatus , error ) {
@@ -266,7 +258,7 @@ func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluste
266
258
}
267
259
}()
268
260
269
- nets , err := s .constructNetworks (openStackCluster , instanceSpec )
261
+ ports , err := s .constructPorts (openStackCluster , instanceSpec )
270
262
if err != nil {
271
263
return nil , err
272
264
}
@@ -281,16 +273,14 @@ func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluste
281
273
return nil , fmt .Errorf ("error getting security groups: %v" , err )
282
274
}
283
275
284
- for i , network := range nets {
285
- if network .ID == "" {
286
- return nil , fmt .Errorf ("no network was found or provided. Please check your machine configuration and try again" )
287
- }
276
+ for i := range ports {
277
+ portOpts := & ports [i ]
288
278
iTags := []string {}
289
279
if len (instanceSpec .Tags ) > 0 {
290
280
iTags = instanceSpec .Tags
291
281
}
292
- portName := getPortName (instanceSpec .Name , network . PortOpts , i )
293
- port , err := networkingService .GetOrCreatePort (eventObject , clusterName , portName , network , securityGroups , iTags )
282
+ portName := getPortName (instanceSpec .Name , portOpts , i )
283
+ port , err := networkingService .GetOrCreatePort (eventObject , clusterName , portName , portOpts , securityGroups , iTags )
294
284
if err != nil {
295
285
return nil , err
296
286
}
0 commit comments