Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - Update Azure CNI to Azure CNI Overlay …
Browse files Browse the repository at this point in the history
…enabled (#22709)

* `azurerm_kubernetes_cluster` - Update Azure CNI to Azure CNI Overlay enabled

* fmt

* Test data naming improved

* Validate reverse overlay

* Make the upgrade one-way

* Update kubernetes_cluster_resource.go

Co-authored-by: stephybun <[email protected]>

---------

Co-authored-by: stephybun <[email protected]>
  • Loading branch information
aristosvo and stephybun authored Sep 7, 2023
1 parent fafe7fe commit 3a37d96
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,28 @@ func TestAccKubernetesCluster_networkPluginMode(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.networkPluginBase(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
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{}
Expand Down Expand Up @@ -3521,6 +3543,52 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.Locations.Primary, data.RandomInteger, ebpfDataPlaneValue)
}

func (KubernetesClusterResource) networkPluginBase(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 {
network_plugin = "azure"
}
}
`, "westcentralus", data.RandomInteger)
}

func (KubernetesClusterResource) networkPluginMode(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
5 changes: 3 additions & 2 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
}
return nil
},
pluginsdk.ForceNewIfChange("network_profile.0.network_plugin_mode", func(ctx context.Context, _, new, meta interface{}) bool {
return !strings.EqualFold(new.(string), string(managedclusters.NetworkPluginModeOverlay))
}),
),

Timeouts: &pluginsdk.ResourceTimeout{
Expand Down Expand Up @@ -1072,7 +1075,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
"network_plugin_mode": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.NetworkPluginModeOverlay),
}, false),
Expand Down Expand Up @@ -1546,7 +1548,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
resource.Schema["network_profile"].Elem.(*pluginsdk.Resource).Schema["network_plugin_mode"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.NetworkPluginModeOverlay),
"Overlay",
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ A `network_profile` block supports the following:

-> **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.
* `network_plugin_mode` - (Optional) Specifies the network plugin mode used for building the Kubernetes network. Possible value is `overlay`.

~> **Note:** When `network_plugin_mode` is set to `overlay`, the `network_plugin` field can only be set to `azure`.
~> **Note:** When `network_plugin_mode` is set to `overlay`, the `network_plugin` field can only be set to `azure`. When upgrading from Azure CNI without overlay, `pod_subnet_id` must be specified.

* `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.

Expand Down

0 comments on commit 3a37d96

Please sign in to comment.