Skip to content

Commit 9e02c2d

Browse files
committed
Add support for Instance Alias IP Ranges
1 parent 67ff6d8 commit 9e02c2d

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-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"`

api/v1beta1/zz_generated.deepcopy.go

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

cloud/scope/machine.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,24 @@ 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+
aliasIPRanges := make([]*compute.AliasIpRange, 0, len(m.GCPMachine.Spec.AliasIPRanges))
352+
for _, alias := range m.GCPMachine.Spec.AliasIPRanges {
353+
aliasIPRange := &compute.AliasIpRange{
354+
IpCidrRange: alias.IPCidrRange,
355+
SubnetworkRangeName: alias.SubnetworkRangeName,
356+
}
357+
aliasIPRanges = append(aliasIPRanges, aliasIPRange)
358+
}
359+
return aliasIPRanges
360+
}
361+
347362
// InstanceServiceAccountsSpec returns service-account spec.
348363
func (m *MachineScope) InstanceServiceAccountsSpec() *compute.ServiceAccount {
349364
serviceAccount := &compute.ServiceAccount{

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,31 @@ spec:
189189
items:
190190
type: string
191191
type: array
192+
aliasIPRanges:
193+
description: AliasIPRanges let you assign ranges of internal IP addresses
194+
as aliases to a VM's network interfaces.
195+
items:
196+
description: AliasIPRange is an alias IP range attached to an instance's
197+
network interface.
198+
properties:
199+
ipCidrRange:
200+
description: |-
201+
IPCidrRange is the IP alias ranges to allocate for this interface. This IP
202+
CIDR range must belong to the specified subnetwork and cannot contain IP
203+
addresses reserved by system or used by other network interfaces. This range
204+
may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
205+
CIDR-formatted string (such as 10.1.2.0/24).
206+
type: string
207+
subnetworkRangeName:
208+
description: |-
209+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
210+
to allocate an IP alias range. If not specified, the primary range of the
211+
subnetwork is used.
212+
type: string
213+
required:
214+
- ipCidrRange
215+
type: object
216+
type: array
192217
confidentialCompute:
193218
description: |-
194219
ConfidentialCompute Defines whether the instance should have confidential compute enabled.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ spec:
204204
items:
205205
type: string
206206
type: array
207+
aliasIPRanges:
208+
description: AliasIPRanges let you assign ranges of internal
209+
IP addresses as aliases to a VM's network interfaces.
210+
items:
211+
description: AliasIPRange is an alias IP range attached
212+
to an instance's network interface.
213+
properties:
214+
ipCidrRange:
215+
description: |-
216+
IPCidrRange is the IP alias ranges to allocate for this interface. This IP
217+
CIDR range must belong to the specified subnetwork and cannot contain IP
218+
addresses reserved by system or used by other network interfaces. This range
219+
may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
220+
CIDR-formatted string (such as 10.1.2.0/24).
221+
type: string
222+
subnetworkRangeName:
223+
description: |-
224+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
225+
to allocate an IP alias range. If not specified, the primary range of the
226+
subnetwork is used.
227+
type: string
228+
required:
229+
- ipCidrRange
230+
type: object
231+
type: array
207232
confidentialCompute:
208233
description: |-
209234
ConfidentialCompute Defines whether the instance should have confidential compute enabled.

0 commit comments

Comments
 (0)