Skip to content

Commit dffd907

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

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-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: 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: 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)