Skip to content

Commit eb06990

Browse files
macaptainpierreprinetti
authored andcommitted
Add feature to create ports with custom options
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: kubernetes-sigs#778
1 parent 47d32dc commit eb06990

10 files changed

+818
-92
lines changed

api/v1alpha3/conversion.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,39 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *
118118
func Convert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1alpha4.OpenStackMachineSpec, s conversion.Scope) error {
119119
return autoConvert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in, out, s)
120120
}
121+
122+
// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new portOpts
123+
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
124+
func Convert_v1alpha4_Network_To_v1alpha3_Network(in *v1alpha4.Network, out *Network, s conversion.Scope) error {
125+
return autoConvert_v1alpha4_Network_To_v1alpha3_Network(in, out, s)
126+
}
127+
128+
// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new ports
129+
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
130+
func Convert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in *v1alpha4.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
131+
return autoConvert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in, out, s)
132+
}
133+
134+
func Convert_Slice_v1alpha4_Network_To_Slice_v1alpha3_Network(in *[]v1alpha4.Network, out *[]Network, s conversion.Scope) error {
135+
for i := range *in {
136+
inNet := &(*in)[i]
137+
outNet := new(Network)
138+
if err := autoConvert_v1alpha4_Network_To_v1alpha3_Network(inNet, outNet, s); err != nil {
139+
return err
140+
}
141+
*out = append(*out, *outNet)
142+
}
143+
return nil
144+
}
145+
146+
func Convert_Slice_v1alpha3_Network_To_Slice_v1alpha4_Network(in *[]Network, out *[]v1alpha4.Network, s conversion.Scope) error {
147+
for i := range *in {
148+
inNet := &(*in)[i]
149+
outNet := new(v1alpha4.Network)
150+
if err := autoConvert_v1alpha3_Network_To_v1alpha4_Network(inNet, outNet, s); err != nil {
151+
return err
152+
}
153+
*out = append(*out, *outNet)
154+
}
155+
return nil
156+
}

api/v1alpha3/zz_generated.conversion.go

Lines changed: 94 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/openstackmachine_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ type OpenStackMachineSpec struct {
5555
SSHKeyName string `json:"sshKeyName,omitempty"`
5656

5757
// A networks object. Required parameter when there are multiple networks defined for the tenant.
58-
// When you do not specify the networks parameter, the server attaches to the only network created for the current tenant.
58+
// When you do not specify both networks and ports parameters, the server attaches to the only network created for the current tenant.
5959
Networks []NetworkParam `json:"networks,omitempty"`
6060

61+
// Ports to be attached to the server instance. They are created if a port with the given name does not already exist.
62+
// When you do not specify both networks and ports parameters, the server attaches to the only network created for the current tenant.
63+
Ports []PortOpts `json:"ports,omitempty"`
64+
6165
// UUID, IP address of a port from this subnet will be marked as AccessIPv4 on the created compute instance
6266
Subnet string `json:"subnet,omitempty"`
6367

api/v1alpha4/types.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type NetworkParam struct {
5858
// The UUID of the network. Required if you omit the port attribute.
5959
UUID string `json:"uuid,omitempty"`
6060
// A fixed IPv4 address for the NIC.
61-
FixedIP string `json:"fixedIp,omitempty"`
61+
FixedIP string `json:"fixedIP,omitempty"`
6262
// Filters for optional network query
6363
Filter Filter `json:"filter,omitempty"`
6464
// Subnet within a network to use
@@ -116,6 +116,38 @@ type SubnetFilter struct {
116116
NotTagsAny string `json:"notTagsAny,omitempty"`
117117
}
118118

119+
type PortOpts struct {
120+
// ID of the OpenStack network on which to create the port. If unspecified, create the port on the default cluster network.
121+
NetworkID string `json:"networkId,omitempty"`
122+
// Used to make the name of the port unique. If unspecified, instead the 0-based index of the port in the list is used.
123+
NameSuffix string `json:"nameSuffix,omitempty"`
124+
Description string `json:"description,omitempty"`
125+
AdminStateUp *bool `json:"adminStateUp,omitempty"`
126+
MACAddress string `json:"macAddress,omitempty"`
127+
// Specify pairs of subnet and/or IP address. These should be subnets of the network with the given NetworkID.
128+
FixedIPs []FixedIP `json:"fixedIPs,omitempty"`
129+
TenantID string `json:"tenantId,omitempty"`
130+
ProjectID string `json:"projectId,omitempty"`
131+
SecurityGroups *[]string `json:"securityGroups,omitempty"`
132+
AllowedAddressPairs []AddressPair `json:"allowedAddressPairs,omitempty"`
133+
134+
// The ID of the host where the port is allocated
135+
HostID string `json:"hostId,omitempty"`
136+
137+
// The virtual network interface card (vNIC) type that is bound to the neutron port.
138+
VNICType string `json:"vnicType,omitempty"`
139+
}
140+
141+
type FixedIP struct {
142+
SubnetID string `json:"subnetId"`
143+
IPAddress string `json:"ipAddress,omitempty"`
144+
}
145+
146+
type AddressPair struct {
147+
IPAddress string `json:"ipAddress,omitempty"`
148+
MACAddress string `json:"macAddress,omitempty"`
149+
}
150+
119151
type Instance struct {
120152
ID string `json:"id,omitempty"`
121153
Name string `json:"name,omitempty"`
@@ -145,16 +177,17 @@ type RootVolume struct {
145177
Size int `json:"diskSize,omitempty"`
146178
}
147179

148-
// Network represents basic information about the associated OpenStach Neutron Network.
180+
// Network represents basic information about an OpenStack Neutron Network associated with an instance's port.
149181
type Network struct {
150182
Name string `json:"name"`
151183
ID string `json:"id"`
152184

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

156-
Subnet *Subnet `json:"subnet,omitempty"`
157-
Router *Router `json:"router,omitempty"`
188+
Subnet *Subnet `json:"subnet,omitempty"`
189+
PortOpts *PortOpts `json:"port,omitempty"`
190+
Router *Router `json:"router,omitempty"`
158191

159192
// Be careful when using APIServerLoadBalancer, because this field is optional and therefore not
160193
// set in all cases

0 commit comments

Comments
 (0)