Skip to content
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

azurerm_kubernetes_cluster - support for the network_plugin_mode ebpf_data_plane properties #19527

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,36 @@ func TestAccKubernetesCluster_publicNetworkAccess(t *testing.T) {
})
}

func TestAccKubernetesCluster_networkPluginMode(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.networkPluginMode(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_ebpfDataPlane(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.ebpfDataPlane(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (KubernetesClusterResource) advancedNetworkingConfig(data acceptance.TestData, networkPlugin string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -3087,3 +3117,100 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, enabled, authorizedIPConfig)
}

func (KubernetesClusterResource) ebpfDataPlane(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestRG-vnet-%[2]d"
address_space = ["10.0.0.0/8"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestRG-subnet-%[2]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.10.0.0/16"]

}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
vnet_subnet_id = azurerm_subnet.test.id
}
identity {
type = "SystemAssigned"
}
network_profile {
pod_cidr = "192.168.0.0/16"
network_plugin = "azure"
ebpf_data_plane = "cilium"
network_plugin_mode = "Overlay"
}
}
`, "westcentralus", data.RandomInteger)
}

func (KubernetesClusterResource) networkPluginMode(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestRG-vnet-%[2]d"
address_space = ["10.0.0.0/8"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestRG-subnet-%[2]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.10.0.0/16"]

}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
vnet_subnet_id = azurerm_subnet.test.id
}
identity {
type = "SystemAssigned"
}
network_profile {
pod_cidr = "192.168.0.0/16"
network_plugin = "azure"
network_plugin_mode = "Overlay"
}
}
`, "westcentralus", data.RandomInteger)
}
40 changes: 40 additions & 0 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,24 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
ValidateFunc: validate.CIDR,
},

"ebpf_data_plane": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.EbpfDataplaneCilium),
}, false),
},

"network_plugin_mode": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.NetworkPluginModeOverlay),
}, false),
},

"pod_cidr": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -2439,6 +2457,13 @@ func expandKubernetesClusterNetworkProfile(input []interface{}) (*managedcluster
IPFamilies: ipVersions,
}

if ebpfDataPlane := config["ebpf_data_plane"].(string); ebpfDataPlane != "" {
networkProfile.EbpfDataplane = utils.ToPtr(managedclusters.EbpfDataplane(ebpfDataPlane))
}
if networkPluginMode := config["network_plugin_mode"].(string); networkPluginMode != "" {
networkProfile.NetworkPluginMode = utils.ToPtr(managedclusters.NetworkPluginMode(networkPluginMode))
}

if len(loadBalancerProfileRaw) > 0 {
if !strings.EqualFold(loadBalancerSku, "standard") {
return nil, fmt.Errorf("only load balancer SKU 'Standard' supports load balancer profiles. Provided load balancer type: %s", loadBalancerSku)
Expand Down Expand Up @@ -2725,15 +2750,30 @@ func flattenKubernetesClusterNetworkProfile(profile *managedclusters.ContainerSe
}
}

networkPluginMode := ""
if profile.NetworkPluginMode != nil {
// The returned value has inconsistent casing
// TODO: Remove the normalization codes once the following issue is fixed.
// Issue: https://github.com/Azure/azure-rest-api-specs/issues/21810
if strings.EqualFold(string(*profile.NetworkPluginMode), string(managedclusters.NetworkPluginModeOverlay)) {
networkPluginMode = string(managedclusters.NetworkPluginModeOverlay)
}
}
ebpfDataPlane := ""
if profile.EbpfDataplane != nil {
ebpfDataPlane = string(*profile.EbpfDataplane)
}
return []interface{}{
map[string]interface{}{
"dns_service_ip": dnsServiceIP,
"docker_bridge_cidr": dockerBridgeCidr,
"ebpf_data_plane": ebpfDataPlane,
"load_balancer_sku": string(*sku),
"load_balancer_profile": lbProfiles,
"nat_gateway_profile": ngwProfiles,
"ip_versions": ipVersions,
"network_plugin": networkPlugin,
"network_plugin_mode": networkPluginMode,
"network_mode": networkMode,
"network_policy": networkPolicy,
"pod_cidr": podCidr,
Expand Down
5 changes: 3 additions & 2 deletions internal/services/containers/kubernetes_cluster_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ func validateKubernetesCluster(d *pluginsdk.ResourceData, cluster *managedcluste
podCidr := profile["pod_cidr"].(string)
podCidrs := profile["pod_cidrs"].([]interface{})
serviceCidrs := profile["service_cidrs"].([]interface{})
networkPluginMode := profile["network_plugin_mode"].(string)
isServiceCidrSet := serviceCidr != "" || len(serviceCidrs) != 0

// Azure network plugin is not compatible with pod_cidr
if podCidr != "" && networkPlugin == "azure" {
return fmt.Errorf("`pod_cidr` and `azure` cannot be set together")
if podCidr != "" && networkPlugin == "azure" && networkPluginMode != string(managedclusters.NetworkPluginModeOverlay) {
return fmt.Errorf("`pod_cidr` and `azure` cannot be set together unless specifying `network_plugin_mode` to `overlay`")
}

// if not All empty values or All set values.
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ A `network_profile` block supports the following:

* `docker_bridge_cidr` - (Optional) IP address (in CIDR notation) used as the Docker bridge IP address on nodes. Changing this forces a new resource to be created.

* `ebpf_data_plane` - (Optional) Specifies the eBPF data plane used for building the Kubernetes network. Possible value is `cilium`. Changing this forces a new resource to be created.

-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/CiliumDataplanePreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://learn.microsoft.com/en-us/azure/aks/azure-cni-powered-by-cilium) for more information.

* `network_plugin_mode` - (Optional) Specifies the network plugin mode used for building the Kubernetes network. Possible value is `overlay`. Changing this forces a new resource to be created.

-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/AzureOverlayPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://learn.microsoft.com/en-us/azure/aks/azure-cni-overlay) for more information.

* `outbound_type` - (Optional) The outbound (egress) routing method which should be used for this Kubernetes Cluster. Possible values are `loadBalancer`, `userDefinedRouting`, `managedNATGateway` and `userAssignedNATGateway`. Defaults to `loadBalancer`. Changing this forces a new resource to be created.

* `pod_cidr` - (Optional) The CIDR to use for pod IP addresses. This field can only be set when `network_plugin` is set to `kubenet`. Changing this forces a new resource to be created.
Expand Down