Skip to content

Commit e21cb7f

Browse files
committed
Add support for Instance Alias IP Ranges
1 parent 5b4ab44 commit e21cb7f

5 files changed

+106
-0
lines changed

api/v1beta1/gcpmachine_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ 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+
IPCidrRange string `json:"ipCidrRange"`
238+
// SubnetworkRangeName is the name of a subnetwork secondary IP range from which
239+
// to allocate an IP alias range. If not specified, the primary range of the
240+
// subnetwork is used.
241+
SubnetworkRangeName string `json:"subnetworkRangeName,omitempty"`
242+
}
243+
230244
// GCPMachineSpec defines the desired state of GCPMachine.
231245
type GCPMachineSpec struct {
232246
// InstanceType is the type of instance to create. Example: n1.standard-2
@@ -237,6 +251,10 @@ type GCPMachineSpec struct {
237251
// +optional
238252
Subnet *string `json:"subnet,omitempty"`
239253

254+
// AliasIPRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
255+
// +optional
256+
AliasIPRanges []AliasIPRange `json:"aliasIPRanges,omitempty"`
257+
240258
// ProviderID is the unique identifier as specified by the cloud provider.
241259
// +optional
242260
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: 18 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ 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+
type: string
209+
subnetworkRangeName:
210+
description: |-
211+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
212+
to allocate an IP alias range. If not specified, the primary range of the
213+
subnetwork is used.
214+
type: string
215+
required:
216+
- ipCidrRange
217+
type: object
218+
type: array
194219
confidentialCompute:
195220
description: |-
196221
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
@@ -206,6 +206,31 @@ 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+
type: string
224+
subnetworkRangeName:
225+
description: |-
226+
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
227+
to allocate an IP alias range. If not specified, the primary range of the
228+
subnetwork is used.
229+
type: string
230+
required:
231+
- ipCidrRange
232+
type: object
233+
type: array
209234
confidentialCompute:
210235
description: |-
211236
ConfidentialCompute Defines whether the instance should have confidential compute enabled.

0 commit comments

Comments
 (0)