Skip to content

Commit

Permalink
GCE dualstack support
Browse files Browse the repository at this point in the history
Signed-off-by: Artiom Diomin <[email protected]>
  • Loading branch information
kron4eg committed Dec 16, 2024
1 parent 9dbc421 commit e0868c1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
11 changes: 8 additions & 3 deletions examples/terraform/gce/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ data "google_compute_image" "control_plane_image" {
}

data "google_compute_network" "network" {
name = "default"
name = var.google_compute_network
}

data "google_compute_subnetwork" "subnet" {
name = "default"
name = var.google_compute_subnetwork
region = var.region
}

Expand Down Expand Up @@ -176,6 +176,12 @@ resource "google_compute_instance" "control_plane" {
access_config {
nat_ip = ""
}

ipv6_access_config {
network_tier = "PREMIUM"
}

stack_type = "IPV4_IPV6"
}

metadata = {
Expand All @@ -195,4 +201,3 @@ resource "google_compute_instance" "control_plane" {
]
}
}

1 change: 1 addition & 0 deletions examples/terraform/gce/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ output "kubeone_hosts" {
cloud_provider = "gce"
private_address = google_compute_instance.control_plane.*.network_interface.0.network_ip
public_address = google_compute_instance.control_plane.*.network_interface.0.access_config.0.nat_ip
ipv6_addresses = [for ip in google_compute_instance.control_plane.*.network_interface.0.ipv6_access_config.0.external_ipv6 : [ip]]
hostnames = google_compute_instance.control_plane.*.name
ssh_agent_socket = var.ssh_agent_socket
ssh_port = var.ssh_port
Expand Down
12 changes: 12 additions & 0 deletions examples/terraform/gce/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,15 @@ Name of operating system profile for MachineDeployments, only applicable if oper
If not specified, the default value will be added by machine-controller addon.
EOF
}

variable "google_compute_subnetwork" {
default = "default"
type = string
description = "if given, will be used as a subnet"
}

variable "google_compute_network" {
default = "default"
type = string
description = "if given, will be used as a network"
}
2 changes: 1 addition & 1 deletion examples/terraform/gce/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.27.0"
version = "~> 6"
}
}
}
23 changes: 18 additions & 5 deletions pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,15 @@ func validateIPFamily(ipFamily kubeoneapi.IPFamily, prov kubeoneapi.CloudProvide
allErrs = append(allErrs, field.Forbidden(fldPath, "ipv6 and ipv6+ipv4 ip families are currently not supported"))
}

if ipFamily == kubeoneapi.IPFamilyIPv4IPv6 && !(prov.AWS != nil || prov.None != nil || prov.Vsphere != nil) {
allErrs = append(allErrs, field.Forbidden(fldPath, "dualstack is currently supported only on AWS, vSphere and baremetal (none)"))
if ipFamily == kubeoneapi.IPFamilyIPv4IPv6 {
switch {
case prov.AWS != nil:
case prov.GCE != nil:
case prov.Vsphere != nil:
case prov.None != nil:
default:
allErrs = append(allErrs, field.Forbidden(fldPath, "dualstack is currently supported only on AWS, GCE, vSphere and baremetal (none)"))
}
}

return allErrs
Expand Down Expand Up @@ -781,9 +788,15 @@ func ValidateHostConfig(hosts []kubeoneapi.HostConfig, clusterNetwork kubeoneapi
if len(host.PublicAddress) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "no public IP/address given"))
}

if (clusterNetwork.IPFamily == kubeoneapi.IPFamilyIPv6 || clusterNetwork.IPFamily == kubeoneapi.IPFamilyIPv4IPv6 || clusterNetwork.IPFamily == kubeoneapi.IPFamilyIPv6IPv4) && len(host.IPv6Addresses) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "no IPv6 address given"))
switch clusterNetwork.IPFamily {
case kubeoneapi.IPFamilyIPv6:
fallthrough
case kubeoneapi.IPFamilyIPv4IPv6:
fallthrough
case kubeoneapi.IPFamilyIPv6IPv4:
if len(host.IPv6Addresses) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "no IPv6 address given"))
}
}
if len(host.PrivateAddress) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "no private IP/address givevn"))
Expand Down

0 comments on commit e0868c1

Please sign in to comment.