Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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"`

// IP address of a port from this subnet will be marked as AccessIPv4 on the created compute instance
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what happens if networks and subnet which is not part of networks are given.
If we do not accept the case comment it here. Or add the check logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess below discussion covered this? maybe need some comments update?

if AccessSubnet is set we will get a hit here and have a value for accessIPv4
otherwise accessIPv4 and we have no change to before this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, got it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added f5ff1bf.
The instance creation will fail if no ports with fixed IP are found in the specified subnet. This also covers the case when this subnet does not exist or is not in .Networks.
I didn't notice the ...

Ok, got it.

... until now, so please let me know if you'd like to keep this change. I can drop this commit if not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsen- Thanks for adding checking logic which is better to be added. Keep the commit, please.

AccessSubnetUUID string `json:"accessSubnetUuid,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Other variables does not start with Access. Subnet is easy to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed AccessSubnetUUID to Subnet

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsen- Thanks updating.


// 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 @@ -59,6 +59,10 @@ spec:
spec:
description: OpenStackMachineSpec defines the desired state of OpenStackMachine
properties:
accessSubnetUuid:
description: IP address of a port from this subnet will be marked
as AccessIPv4 on the created compute instance
type: string
cloudName:
description: The name of the cloud to use from the clouds secret
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
description: Spec is the specification of the desired behavior
of the machine.
properties:
accessSubnetUuid:
description: IP address of a port from this subnet will be
marked as AccessIPv4 on the created compute instance
type: string
cloudName:
description: The name of the cloud to use from the clouds
secret
Expand Down
9 changes: 9 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.AccessSubnetUUID,
}

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 @@ -233,6 +241,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