diff --git a/api/v1beta1/gcpmachine_types.go b/api/v1beta1/gcpmachine_types.go index 7e27e7845..2b295057f 100644 --- a/api/v1beta1/gcpmachine_types.go +++ b/api/v1beta1/gcpmachine_types.go @@ -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 @@ -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"` diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index 96f745822..25faa1f03 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -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{ diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml index 24955802d..3cac3f99c 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml @@ -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 diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml index 5cc470597..942408b08 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml @@ -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