Skip to content

Commit fd8910f

Browse files
committed
Add support for Instance Alias IP Ranges
1 parent 9662918 commit fd8910f

5 files changed

+114
-0
lines changed

api/v1beta1/gcpmachine_types.go

+24
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,26 @@ const (
227227
ProvisioningModelSpot ProvisioningModel = "Spot"
228228
)
229229

230+
// AliasIPRange is an alias IP range attached to an instance's network interface.
231+
type AliasIPRange struct {
232+
// IPCidrRange is the IP alias ranges to allocate for this interface. This IP
233+
// CIDR range must belong to the specified subnetwork and cannot contain IP
234+
// addresses reserved by system or used by other network interfaces. This range
235+
// may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
236+
// CIDR-formatted string (such as 10.1.2.0/24).
237+
// +kubebuilder:validation:Required
238+
// +kubebuilder:validation:Pattern=`^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$`
239+
// + ---
240+
// + This regex was constructed from
241+
// + https://blog.markhatton.co.uk/2011/03/15/regular-expressions-for-ip-addresses-cidr-ranges-and-hostnames/
242+
// + (IPv4/mask) or (IPv4) or (mask)
243+
IPCidrRange string `json:"ipCidrRange"`
244+
// SubnetworkRangeName is the name of a subnetwork secondary IP range from which
245+
// to allocate an IP alias range. If not specified, the primary range of the
246+
// subnetwork is used.
247+
SubnetworkRangeName string `json:"subnetworkRangeName,omitempty"`
248+
}
249+
230250
// GCPMachineSpec defines the desired state of GCPMachine.
231251
type GCPMachineSpec struct {
232252
// InstanceType is the type of instance to create. Example: n1.standard-2
@@ -237,6 +257,10 @@ type GCPMachineSpec struct {
237257
// +optional
238258
Subnet *string `json:"subnet,omitempty"`
239259

260+
// AliasIPRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
261+
// +optional
262+
AliasIPRanges []AliasIPRange `json:"aliasIPRanges,omitempty"`
263+
240264
// ProviderID is the unique identifier as specified by the cloud provider.
241265
// +optional
242266
ProviderID *string `json:"providerID,omitempty"`

api/v1beta1/zz_generated.deepcopy.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/scope/machine.go

+18
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,27 @@ func (m *MachineScope) InstanceNetworkInterfaceSpec() *compute.NetworkInterface
341341
networkInterface.Subnetwork = path.Join("projects", m.ClusterGetter.NetworkProject(), "regions", m.ClusterGetter.Region(), "subnetworks", *m.GCPMachine.Spec.Subnet)
342342
}
343343

344+
networkInterface.AliasIpRanges = m.InstanceNetworkInterfaceAliasIPRangesSpec()
345+
344346
return networkInterface
345347
}
346348

349+
// InstanceNetworkInterfaceAliasIPRangesSpec returns a slice of Alias IP Range specs.
350+
func (m *MachineScope) InstanceNetworkInterfaceAliasIPRangesSpec() []*compute.AliasIpRange {
351+
if len(m.GCPMachine.Spec.AliasIPRanges) == 0 {
352+
return nil
353+
}
354+
aliasIPRanges := make([]*compute.AliasIpRange, 0, len(m.GCPMachine.Spec.AliasIPRanges))
355+
for _, alias := range m.GCPMachine.Spec.AliasIPRanges {
356+
aliasIPRange := &compute.AliasIpRange{
357+
IpCidrRange: alias.IPCidrRange,
358+
SubnetworkRangeName: alias.SubnetworkRangeName,
359+
}
360+
aliasIPRanges = append(aliasIPRanges, aliasIPRange)
361+
}
362+
return aliasIPRanges
363+
}
364+
347365
// InstanceServiceAccountsSpec returns service-account spec.
348366
func (m *MachineScope) InstanceServiceAccountsSpec() *compute.ServiceAccount {
349367
serviceAccount := &compute.ServiceAccount{

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,32 @@ spec:
191191
items:
192192
type: string
193193
type: array
194+
aliasIPRanges:
195+
description: AliasIPRanges let you assign ranges of internal IP addresses
196+
as aliases to a VM's network interfaces.
197+
items:
198+
description: AliasIPRange is an alias IP range attached to an instance's
199+
network interface.
200+
properties:
201+
ipCidrRange:
202+
description: |-
203+
IPCidrRange is the IP alias ranges to allocate for this interface. This IP
204+
CIDR range must belong to the specified subnetwork and cannot contain IP
205+
addresses reserved by system or used by other network interfaces. This range
206+
may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
207+
CIDR-formatted string (such as 10.1.2.0/24).
208+
pattern: ^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$
209+
type: string
210+
subnetworkRangeName:
211+
description: |-
212+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
213+
to allocate an IP alias range. If not specified, the primary range of the
214+
subnetwork is used.
215+
type: string
216+
required:
217+
- ipCidrRange
218+
type: object
219+
type: array
194220
confidentialCompute:
195221
description: |-
196222
ConfidentialCompute Defines whether the instance should have confidential compute enabled.

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ spec:
206206
items:
207207
type: string
208208
type: array
209+
aliasIPRanges:
210+
description: AliasIPRanges let you assign ranges of internal
211+
IP addresses as aliases to a VM's network interfaces.
212+
items:
213+
description: AliasIPRange is an alias IP range attached
214+
to an instance's network interface.
215+
properties:
216+
ipCidrRange:
217+
description: |-
218+
IPCidrRange is the IP alias ranges to allocate for this interface. This IP
219+
CIDR range must belong to the specified subnetwork and cannot contain IP
220+
addresses reserved by system or used by other network interfaces. This range
221+
may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
222+
CIDR-formatted string (such as 10.1.2.0/24).
223+
pattern: ^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$
224+
type: string
225+
subnetworkRangeName:
226+
description: |-
227+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
228+
to allocate an IP alias range. If not specified, the primary range of the
229+
subnetwork is used.
230+
type: string
231+
required:
232+
- ipCidrRange
233+
type: object
234+
type: array
209235
confidentialCompute:
210236
description: |-
211237
ConfidentialCompute Defines whether the instance should have confidential compute enabled.

0 commit comments

Comments
 (0)