Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions api/v1alpha3/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ type OpenStackMachineSpec struct {
// A networks object. Required parameter when there are multiple networks defined for the tenant.
// When you do not specify the networks parameter, the server attaches to the only network created for the current tenant.
Networks []NetworkParam `json:"networks,omitempty"`

// UUID, IP address of a port from this subnet will be marked as AccessIPv4 on the created compute instance
Subnet string `json:"subnet,omitempty"`

// The floatingIP which will be associated to the machine, only used for master.
// The floatingIP should have been created and haven't been associated.
FloatingIP string `json:"floatingIP,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type Instance struct {
FailureDomain string `json:"failureDomain,omitempty"`
SecurityGroups *[]string `json:"securigyGroups,omitempty"`
Networks *[]Network `json:"networks,omitempty"`
AccessSubnet string `json:"accessSubnet,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm does it make sense to call the property in instance differently than the one in the spec?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm maybe I missed something / or read it incorrectly. Could it be that this adds the Subnet property to the OpenStackMachine and the AccessSubnet to the Instance struct which seems to be only used for the status of the Bastion host?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instance struct seems to be used as a status of bastion and as a holder of state of a created VM, but at the same time, it is used as an input for createInstance. I don't know why this is so, but I wanted to minimize the impact of this PR.
There are basically two possibilities how to forward the subnet UUID into the createInstance function:

  • add this property to this Instance struct (what I did)
  • add another (optional) parameter to createInstance function
    The second option seemed inappropriate, taking into consideration the current signature:
func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infrav1.Instance, error)

Adding accessSubnetUUID string does not feel right, but now that I'm thinking about it, the advantage would be that it would not change the public contract in bastion host status.

Just let me know, I can add another commit and forward the subnet UUID in an additional argument.

It also might make sense to keep it as it is and add the same possibility to specify subnet UUID for bastion host as well (adding similar Subnet property to Bastion struct

type Bastion struct {
//+optional
Enabled bool `json:"enabled"`
//+optional
Flavor string `json:"flavor,omitempty"`
//+optional
Image string `json:"image,omitempty"`
//+optional
SSHKeyName string `json:"sshKeyName,omitempty"`
//+optional
Networks []NetworkParam `json:"networks,omitempty"`
//+optional
FloatingIP string `json:"floatingIP,omitempty"`
//+optional
SecurityGroups []SecurityGroupParam `json:"securityGroups,omitempty"`
}
)
Then having this property in Bastion status starts making sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccessSubnet is also better to be renamed to Subnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Tags []string `json:"tags,omitempty"`
Image string `json:"image,omitempty"`
Flavor string `json:"flavor,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ spec:
properties:
bastion:
properties:
accessSubnet:
type: string
configDrive:
type: boolean
failureDomain:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ spec:
sshKeyName:
description: The ssh key to inject in the instance
type: string
subnet:
description: UUID, IP address of a port from this subnet will be marked
as AccessIPv4 on the created compute instance
type: string
tags:
description: Machine tags Requires Nova api 2.52 minimum!
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ spec:
sshKeyName:
description: The ssh key to inject in the instance
type: string
subnet:
description: UUID, IP address of a port from this subnet will
be marked as AccessIPv4 on the created compute instance
type: string
tags:
description: Machine tags Requires Nova api 2.52 minimum!
items:
Expand Down
13 changes: 13 additions & 0 deletions pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
ConfigDrive: openStackMachine.Spec.ConfigDrive,
FailureDomain: *machine.Spec.FailureDomain,
RootVolume: openStackMachine.Spec.RootVolume,
AccessSubnet: openStackMachine.Spec.Subnet,
}

if openStackMachine.Spec.Trunk {
Expand Down Expand Up @@ -153,6 +154,7 @@ func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infr
return nil, fmt.Errorf("create new server err: %v", err)
}

accessIPv4 := ""
nets := i.Networks
portsList := []servers.Network{}
for _, net := range *nets {
Expand Down Expand Up @@ -182,6 +184,12 @@ func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infr
port = portList[0]
}

for _, fip := range port.FixedIPs {
if fip.SubnetID == i.AccessSubnet {
accessIPv4 = fip.IPAddress
}
}

portsList = append(portsList, servers.Network{
Port: port.ID,
})
Expand Down Expand Up @@ -221,6 +229,10 @@ func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infr
}
}
}
if i.AccessSubnet != "" && accessIPv4 == "" {
return nil, fmt.Errorf("no ports with fixed IPs found on AccessSubnet \"%s\"", i.AccessSubnet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If AccessSubnet is renamed to Subnet, This comment would be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}

var serverCreateOpts servers.CreateOptsBuilder = servers.CreateOpts{
Name: i.Name,
ImageRef: imageID,
Expand All @@ -233,6 +245,7 @@ func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infr
Tags: i.Tags,
Metadata: i.Metadata,
ConfigDrive: i.ConfigDrive,
AccessIPv4: accessIPv4,
}

serverCreateOpts = applyRootVolume(serverCreateOpts, i.RootVolume)
Expand Down