Skip to content

Commit

Permalink
Add support for Instance Alias IP Ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmay2012 committed Sep 18, 2024
1 parent 67ff6d8 commit 03a062f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1beta1/gcpmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ type CustomerEncryptionKey struct {
SuppliedKey *SuppliedKey `json:"suppliedKey,omitempty"`
}

// AliasIpRange is an alias IP range attached to an instance's network interface.
type AliasIpRange struct {
// IpCidrRange is the IP alias ranges to allocate for this interface. This IP
// CIDR range must belong to the specified subnetwork and cannot contain IP
// addresses reserved by system or used by other network interfaces. This range
// may be a single IP address (such as 10.2.3.4), a netmask (such as /24) or a
// CIDR-formatted string (such as 10.1.2.0/24).
IpCidrRange string `json:"ipCidrRange"`
// SubnetworkRangeName is the name of a subnetwork secondary IP range from which
// to allocate an IP alias range. If not specified, the primary range of the
// subnetwork is used.
SubnetworkRangeName string `json:"subnetworkRangeName,omitempty"`
}

// GCPMachineSpec defines the desired state of GCPMachine.
type GCPMachineSpec struct {
// InstanceType is the type of instance to create. Example: n1.standard-2
Expand All @@ -227,6 +241,10 @@ type GCPMachineSpec struct {
// +optional
Subnet *string `json:"subnet,omitempty"`

// AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
// +optional
AliasIpRanges []AliasIpRange `json:"aliasIpRanges,omitempty"`

// ProviderID is the unique identifier as specified by the cloud provider.
// +optional
ProviderID *string `json:"providerID,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,23 @@ func (m *MachineScope) InstanceNetworkInterfaceSpec() *compute.NetworkInterface
networkInterface.Subnetwork = path.Join("projects", m.ClusterGetter.NetworkProject(), "regions", m.ClusterGetter.Region(), "subnetworks", *m.GCPMachine.Spec.Subnet)
}

networkInterface.AliasIpRanges = m.InstanceNetworkInterfaceAliasIpRangesSpec()

return networkInterface
}

func (m *MachineScope) InstanceNetworkInterfaceAliasIpRangesSpec() []*compute.AliasIpRange {
aliasIpRanges := make([]*compute.AliasIpRange, 0, len(m.GCPMachine.Spec.AliasIpRanges))
for _, alias := range m.GCPMachine.Spec.AliasIpRanges {
aliasIpRange := &compute.AliasIpRange{
IpCidrRange: alias.IpCidrRange,
SubnetworkRangeName: alias.SubnetworkRangeName,
}
aliasIpRanges = append(aliasIpRanges, aliasIpRange)
}
return aliasIpRanges
}

// InstanceServiceAccountsSpec returns service-account spec.
func (m *MachineScope) InstanceServiceAccountsSpec() *compute.ServiceAccount {
serviceAccount := &compute.ServiceAccount{
Expand Down
22 changes: 22 additions & 0 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,28 @@ spec:
Subnet is a reference to the subnetwork to use for this instance. If not specified,
the first subnetwork retrieved from the Cluster Region and Network is picked.
type: string
aliasIpRanges:
description: |-
AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
items:
description: AliasIpRange defines a range to be attached to an instance's network interface.
properties:
ipCidrRange:
description: |-
IpCidrRange is the IP alias ranges to allocate for this interface. This IP CIDR range
must belong to the specified subnetwork and cannot contain IP addresses reserved by system or
used by other network interfaces. This range may be a single IP address (such as 10.2.3.4),
a netmask (such as /24) or a CIDR-formatted string (such as 10.1.2.0/24)
type: string
subnetworkRangeName:
description: |-
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
to allocate an IP alias range. If not specified, the primary range of the subnetwork is used.
type: string
required:
- ipCidrRange
type: object
type: array
required:
- instanceType
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,28 @@ spec:
Subnet is a reference to the subnetwork to use for this instance. If not specified,
the first subnetwork retrieved from the Cluster Region and Network is picked.
type: string
aliasIpRanges:
description: |-
AliasIpRanges let you assign ranges of internal IP addresses as aliases to a VM's network interfaces.
items:
description: AliasIpRange defines a range to be attached to an instance's network interface.
properties:
ipCidrRange:
description: |-
IpCidrRange is the IP alias ranges to allocate for this interface. This IP CIDR range
must belong to the specified subnetwork and cannot contain IP addresses reserved by system or
used by other network interfaces. This range may be a single IP address (such as 10.2.3.4),
a netmask (such as /24) or a CIDR-formatted string (such as 10.1.2.0/24)
type: string
subnetworkRangeName:
description: |-
SubnetworkRangeName is the name of a subnetwork secondary IP range from which
to allocate an IP alias range. If not specified, the primary range of the subnetwork is used.
type: string
required:
- ipCidrRange
type: object
type: array
required:
- instanceType
type: object
Expand Down

0 comments on commit 03a062f

Please sign in to comment.