Skip to content

Add support for Instance Alias IP Ranges #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/v1beta1/gcpmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ const (
ProvisioningModelSpot ProvisioningModel = "Spot"
)

// 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).
// +kubebuilder:validation:Pattern=`^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$`
// +required
IPCidrRange string `json:"ipCidrRange"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if this will extend to IPv6 and/or DualStack Clusters? Currently it looks like this would support Single Stacks and only IPv4. FYI, I know those aren't supported yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPv6 addresses aren't supported.
https://cloud.google.com/vpc/docs/configure-alias-ip-ranges#vpc_network

This regex includes only ipv4 as well.

// 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 @@ -237,6 +253,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
20 changes: 20 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,27 @@ 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
}

// InstanceNetworkInterfaceAliasIPRangesSpec returns a slice of Alias IP Range specs.
func (m *MachineScope) InstanceNetworkInterfaceAliasIPRangesSpec() []*compute.AliasIpRange {
if len(m.GCPMachine.Spec.AliasIPRanges) == 0 {
return nil
}
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
26 changes: 26 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 @@ -191,6 +191,32 @@ spec:
items:
type: string
type: array
aliasIPRanges:
description: AliasIPRanges let you assign ranges of internal IP addresses
as aliases to a VM's network interfaces.
items:
description: AliasIPRange is an alias IP range 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).
pattern: ^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$
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
confidentialCompute:
description: |-
ConfidentialCompute Defines whether the instance should have confidential compute enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,32 @@ spec:
items:
type: string
type: array
aliasIPRanges:
description: AliasIPRanges let you assign ranges of internal
IP addresses as aliases to a VM's network interfaces.
items:
description: AliasIPRange is an alias IP range 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).
pattern: ^((([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])|(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(/([0-9]|[12][0-9]|3[0-2])))$
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
confidentialCompute:
description: |-
ConfidentialCompute Defines whether the instance should have confidential compute enabled.
Expand Down