Skip to content

Commit 4f446f4

Browse files
committed
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 commit is very much based on the work on @jsen-: kubernetes-sigs#778 and also aims to bring Cluster API OpenStack provider into greater alignment with the OpenShift fork.
1 parent b132628 commit 4f446f4

9 files changed

+590
-64
lines changed

api/v1alpha3/conversion.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ package v1alpha3
1818

1919
import (
2020
conversion "k8s.io/apimachinery/pkg/conversion"
21-
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
22-
2321
"sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
22+
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2423
)
2524

2625
var _ ctrlconversion.Convertible = &OpenStackCluster{}
@@ -118,3 +117,15 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *
118117
func Convert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1alpha4.OpenStackMachineSpec, s conversion.Scope) error {
119118
return autoConvert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in, out, s)
120119
}
120+
121+
// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new portOpts
122+
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
123+
func Convert_v1alpha4_Network_To_v1alpha3_Network(in *v1alpha4.Network, out *Network, s conversion.Scope) error {
124+
return autoConvert_v1alpha4_Network_To_v1alpha3_Network(in, out, s)
125+
}
126+
127+
// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new ports
128+
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
129+
func Convert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in *v1alpha4.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
130+
return autoConvert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in, out, s)
131+
}

api/v1alpha3/zz_generated.conversion.go

Lines changed: 82 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: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ 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+
133+
// The ID of the host where the port is allocated
134+
HostID string `json:"hostId,omitempty"`
135+
136+
// The virtual network interface card (vNIC) type that is bound to the
137+
// 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+
119146
type Instance struct {
120147
ID string `json:"id,omitempty"`
121148
Name string `json:"name,omitempty"`
@@ -145,7 +172,7 @@ type RootVolume struct {
145172
Size int `json:"diskSize,omitempty"`
146173
}
147174

148-
// Network represents basic information about the associated OpenStach Neutron Network.
175+
// Network represents basic information about an OpenStack Neutron Network associated with an instance's port
149176
type Network struct {
150177
Name string `json:"name"`
151178
ID string `json:"id"`
@@ -154,6 +181,7 @@ type Network struct {
154181
Tags []string `json:"tags,omitempty"`
155182

156183
Subnet *Subnet `json:"subnet,omitempty"`
184+
PortOpts *PortOpts `json:"port,omitempty"`
157185
Router *Router `json:"router,omitempty"`
158186

159187
// Be careful when using APIServerLoadBalancer, because this field is optional and therefore not

api/v1alpha4/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)