diff --git a/api/v1beta1/gcpmachine_types.go b/api/v1beta1/gcpmachine_types.go index dc7c3c012..ace1ce3f9 100644 --- a/api/v1beta1/gcpmachine_types.go +++ b/api/v1beta1/gcpmachine_types.go @@ -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"` + // 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 @@ -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"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 3c8560ad9..946d639f0 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -27,6 +27,21 @@ import ( "sigs.k8s.io/cluster-api/errors" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AliasIPRange) DeepCopyInto(out *AliasIPRange) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AliasIPRange. +func (in *AliasIPRange) DeepCopy() *AliasIPRange { + if in == nil { + return nil + } + out := new(AliasIPRange) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AttachedDiskSpec) DeepCopyInto(out *AttachedDiskSpec) { *out = *in @@ -414,6 +429,11 @@ func (in *GCPMachineSpec) DeepCopyInto(out *GCPMachineSpec) { *out = new(string) **out = **in } + if in.AliasIPRanges != nil { + in, out := &in.AliasIPRanges, &out.AliasIPRanges + *out = make([]AliasIPRange, len(*in)) + copy(*out, *in) + } if in.ProviderID != nil { in, out := &in.ProviderID, &out.ProviderID *out = new(string) diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index ce5d02d55..94901120c 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -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{ 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 5dbe18c8a..c7ee0b02c 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml @@ -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. 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 ece5bc8d8..bced8bf0b 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml @@ -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.