Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ string
</tr>
<tr>
<td>
<code>subnetIDs</code></br>
<em>
[]string
</em>
</td>
<td>
<p>SubnetIDs is a list of IDs of the subnets the instance should belong to.</p>
</td>
</tr>
<tr>
<td>
<code>podNetworkCidr</code></br>
<em>
string
Expand Down Expand Up @@ -368,6 +379,17 @@ string
</tr>
<tr>
<td>
<code>subnetIDs</code></br>
<em>
[]string
</em>
</td>
<td>
<p>SubnetIDs is a list of IDs of the subnets the instance should belong to.</p>
</td>
</tr>
<tr>
<td>
<code>podNetworkCidr</code></br>
<em>
string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type MachineProviderConfigSpec struct {
NetworkID string
// SubnetID is the ID of the subnet the instance should belong to. If SubnetID is not specified
SubnetID *string
// SubnetIDs is a list of IDs of the subnets the instance should belong to.
SubnetIDs []string
// PodNetworkCidr is the CIDR range for the pods assigned to this instance.
// Deprecated - use `PodNetworkCIDRs` instead.
PodNetworkCidr string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type MachineProviderConfigSpec struct {
// SubnetID is the ID of the subnet the instance should belong to. If SubnetID is not specified
// +optional
SubnetID *string `json:"subnetID,omitempty"`
// SubnetIDs is a list of IDs of the subnets the instance should belong to.
SubnetIDs []string `json:"subnetIDs,omitempty"`
// PodNetworkCidr is the CIDR range for the pods assigned to this instance.
// Deprecated: use PodNetworkCIDRs instead
// +optional
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions pkg/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (ex *Executor) getOrCreatePort(ctx context.Context, machineName string) (st
port, err := ex.Network.CreatePort(ctx, &ports.CreateOpts{
Name: machineName,
NetworkID: ex.Config.Spec.NetworkID,
FixedIPs: []ports.IP{{SubnetID: *ex.Config.Spec.SubnetID}},
FixedIPs: ex.buildFixedIPs(),
SecurityGroups: &securityGroupIDs,
})
if err != nil {
Expand All @@ -542,6 +542,32 @@ func (ex *Executor) getOrCreatePort(ctx context.Context, machineName string) (st
return port.ID, nil
}

// buildFixedIPs creates a list of FixedIPs from SubnetID and SubnetIDs, avoiding duplicates
func (ex *Executor) buildFixedIPs() []ports.IP {
// Use a set to track unique subnet IDs and avoid duplicates
subnetIDSet := sets.NewString()

// Add the single SubnetID if specified
if ex.Config.Spec.SubnetID != nil && *ex.Config.Spec.SubnetID != "" {
subnetIDSet.Insert(*ex.Config.Spec.SubnetID)
}

// Add all SubnetIDs if specified
for _, subnetID := range ex.Config.Spec.SubnetIDs {
if subnetID != "" {
subnetIDSet.Insert(subnetID)
}
}

// Convert to []ports.IP
var fixedIPs []ports.IP
for _, subnetID := range subnetIDSet.List() {
fixedIPs = append(fixedIPs, ports.IP{SubnetID: subnetID})
}

return fixedIPs
}

func (ex *Executor) deletePort(ctx context.Context, machineName string) error {
portList, err := ex.Network.ListPorts(ctx, ports.ListOpts{
Name: machineName,
Expand Down Expand Up @@ -698,5 +724,9 @@ func (ex *Executor) listServers(ctx context.Context) ([]servers.Server, error) {

// isUserManagedNetwork returns true if the port used by the machine will be created and managed by MCM.
func (ex *Executor) isUserManagedNetwork() bool {
return !isEmptyString(ptr.To(ex.Config.Spec.NetworkID)) && !isEmptyString(ex.Config.Spec.SubnetID)
hasNetworkID := !isEmptyString(ptr.To(ex.Config.Spec.NetworkID))
hasSubnetID := !isEmptyString(ex.Config.Spec.SubnetID)
hasSubnetIDs := len(ex.Config.Spec.SubnetIDs) > 0

return hasNetworkID && (hasSubnetID || hasSubnetIDs)
}