Skip to content

Commit

Permalink
Add feature to create ports with custom options
Browse files Browse the repository at this point in the history
This commit adds a new field to the v1alpha4 API:
OpenStackMachineTemplateSpec.ports.

The list of ports are added per instance. Each port may be customized
with options. These ports are created in addition to any ports created
in the `networks:` field.

If `networks:` is not specified, only the ports specified in `ports:`
will be created and attached to the instance. If neither `networks:` nor
`ports:` are specified, the instance will be connected to the default
cluster network and subnet.

This feature is very much based on the work on jsen-, and a lot of
credit goes there for the implementation:

#778
  • Loading branch information
macaptain committed May 24, 2021
1 parent b132628 commit 8efb99d
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 55 deletions.
15 changes: 13 additions & 2 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package v1alpha3

import (
conversion "k8s.io/apimachinery/pkg/conversion"
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"

"sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
)

var _ ctrlconversion.Convertible = &OpenStackCluster{}
Expand Down Expand Up @@ -118,3 +117,15 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *
func Convert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1alpha4.OpenStackMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in, out, s)
}

// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new portOpts
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
func Convert_v1alpha4_Network_To_v1alpha3_Network(in *v1alpha4.Network, out *Network, s conversion.Scope) error {
return autoConvert_v1alpha4_Network_To_v1alpha3_Network(in, out, s)
}

// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new ports
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
func Convert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in *v1alpha4.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in, out, s)
}
110 changes: 82 additions & 28 deletions api/v1alpha3/zz_generated.conversion.go

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

6 changes: 5 additions & 1 deletion api/v1alpha4/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ type OpenStackMachineSpec struct {
SSHKeyName string `json:"sshKeyName,omitempty"`

// 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.
// When you do not specify both networks and ports parameters, the server attaches to the only network created for the current tenant.
Networks []NetworkParam `json:"networks,omitempty"`

// Ports to be attached to the server instance. They are created if a port with the given name does not already exist.
// When you do not specify both networks and ports parameters, the server attaches to the only network created for the current tenant.
Ports []PortOpts `json:"ports,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"`

Expand Down
33 changes: 30 additions & 3 deletions api/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ type SubnetFilter struct {
NotTagsAny string `json:"notTagsAny,omitempty"`
}

type PortOpts struct {
// ID of the OpenStack network on which to create the port. If unspecified, create the port on the default cluster network.
NetworkID string `json:"networkId,omitempty"`
// Used to make the name of the port unique. If unspecified, instead the 0-based index of the port in the list is used.
NameSuffix string `json:"nameSuffix,omitempty"`
Description string `json:"description,omitempty"`
AdminStateUp *bool `json:"adminStateUp,omitempty"`
MACAddress string `json:"macAddress,omitempty"`
// Specify pairs of subnet and/or IP address. These should be subnets of the network with the given NetworkID.
FixedIPs []FixedIP `json:"fixedIps,omitempty"`
TenantID string `json:"tenantId,omitempty"`
ProjectID string `json:"projectId,omitempty"`
SecurityGroups *[]string `json:"securityGroups,omitempty"`

// The ID of the host where the port is allocated
HostID string `json:"hostId,omitempty"`

// The virtual network interface card (vNIC) type that is bound to the neutron port.
VNICType string `json:"vnicType,omitempty"`
}

type FixedIP struct {
SubnetID string `json:"subnetId"`
IPAddress string `json:"ipAddress,omitempty"`
}

type Instance struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -145,16 +171,17 @@ type RootVolume struct {
Size int `json:"diskSize,omitempty"`
}

// Network represents basic information about the associated OpenStach Neutron Network.
// Network represents basic information about an OpenStack Neutron Network associated with an instance's port
type Network struct {
Name string `json:"name"`
ID string `json:"id"`

//+optional
Tags []string `json:"tags,omitempty"`

Subnet *Subnet `json:"subnet,omitempty"`
Router *Router `json:"router,omitempty"`
Subnet *Subnet `json:"subnet,omitempty"`
PortOpts *PortOpts `json:"port,omitempty"`
Router *Router `json:"router,omitempty"`

// Be careful when using APIServerLoadBalancer, because this field is optional and therefore not
// set in all cases
Expand Down
61 changes: 61 additions & 0 deletions api/v1alpha4/zz_generated.deepcopy.go

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

Loading

0 comments on commit 8efb99d

Please sign in to comment.