Skip to content

Commit 03a062f

Browse files
committed
Add support for Instance Alias IP Ranges
1 parent 67ff6d8 commit 03a062f

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

api/v1beta1/gcpmachine_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ type CustomerEncryptionKey struct {
217217
SuppliedKey *SuppliedKey `json:"suppliedKey,omitempty"`
218218
}
219219

220+
// AliasIpRange is an alias IP range attached to an instance's network interface.
221+
type AliasIpRange struct {
222+
// IpCidrRange is the IP alias ranges to allocate for this interface. This IP
223+
// CIDR range must belong to the specified subnetwork and cannot contain IP
224+
// addresses reserved by system or used by other network interfaces. This range
225+
// may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
226+
// CIDR-formatted string (such as 10.1.2.0/24).
227+
IpCidrRange string `json:"ipCidrRange"`
228+
// SubnetworkRangeName is the name of a subnetwork secondary IP range from which
229+
// to allocate an IP alias range. If not specified, the primary range of the
230+
// subnetwork is used.
231+
SubnetworkRangeName string `json:"subnetworkRangeName,omitempty"`
232+
}
233+
220234
// GCPMachineSpec defines the desired state of GCPMachine.
221235
type GCPMachineSpec struct {
222236
// InstanceType is the type of instance to create. Example: n1.standard-2
@@ -227,6 +241,10 @@ type GCPMachineSpec struct {
227241
// +optional
228242
Subnet *string `json:"subnet,omitempty"`
229243

244+
// AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
245+
// +optional
246+
AliasIpRanges []AliasIpRange `json:"aliasIpRanges,omitempty"`
247+
230248
// ProviderID is the unique identifier as specified by the cloud provider.
231249
// +optional
232250
ProviderID *string `json:"providerID,omitempty"`

cloud/scope/machine.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,23 @@ 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+
func (m *MachineScope) InstanceNetworkInterfaceAliasIpRangesSpec() []*compute.AliasIpRange {
350+
aliasIpRanges := make([]*compute.AliasIpRange, 0, len(m.GCPMachine.Spec.AliasIpRanges))
351+
for _, alias := range m.GCPMachine.Spec.AliasIpRanges {
352+
aliasIpRange := &compute.AliasIpRange{
353+
IpCidrRange: alias.IpCidrRange,
354+
SubnetworkRangeName: alias.SubnetworkRangeName,
355+
}
356+
aliasIpRanges = append(aliasIpRanges, aliasIpRange)
357+
}
358+
return aliasIpRanges
359+
}
360+
347361
// InstanceServiceAccountsSpec returns service-account spec.
348362
func (m *MachineScope) InstanceServiceAccountsSpec() *compute.ServiceAccount {
349363
serviceAccount := &compute.ServiceAccount{

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,28 @@ spec:
422422
Subnet is a reference to the subnetwork to use for this instance. If not specified,
423423
the first subnetwork retrieved from the Cluster Region and Network is picked.
424424
type: string
425+
aliasIpRanges:
426+
description: |-
427+
AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
428+
items:
429+
description: AliasIpRange defines a range to be attached to an instance's network interface.
430+
properties:
431+
ipCidrRange:
432+
description: |-
433+
IpCidrRange is the IP alias ranges to allocate for this interface. This IP CIDR range
434+
must belong to the specified subnetwork and cannot contain IP addresses reserved by system or
435+
used by other network interfaces. This range may be a single IP address (such as 10.2.3.4),
436+
a netmask (such as /24) or a CIDR-formatted string (such as 10.1.2.0/24)
437+
type: string
438+
subnetworkRangeName:
439+
description: |-
440+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
441+
to allocate an IP alias range. If not specified, the primary range of the subnetwork is used.
442+
type: string
443+
required:
444+
- ipCidrRange
445+
type: object
446+
type: array
425447
required:
426448
- instanceType
427449
type: object

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,28 @@ spec:
439439
Subnet is a reference to the subnetwork to use for this instance. If not specified,
440440
the first subnetwork retrieved from the Cluster Region and Network is picked.
441441
type: string
442+
aliasIpRanges:
443+
description: |-
444+
AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
445+
items:
446+
description: AliasIpRange defines a range to be attached to an instance's network interface.
447+
properties:
448+
ipCidrRange:
449+
description: |-
450+
IpCidrRange is the IP alias ranges to allocate for this interface. This IP CIDR range
451+
must belong to the specified subnetwork and cannot contain IP addresses reserved by system or
452+
used by other network interfaces. This range may be a single IP address (such as 10.2.3.4),
453+
a netmask (such as /24) or a CIDR-formatted string (such as 10.1.2.0/24)
454+
type: string
455+
subnetworkRangeName:
456+
description: |-
457+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
458+
to allocate an IP alias range. If not specified, the primary range of the subnetwork is used.
459+
type: string
460+
required:
461+
- ipCidrRange
462+
type: object
463+
type: array
442464
required:
443465
- instanceType
444466
type: object

0 commit comments

Comments
 (0)