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_node_pool - os_sku supports update #26139

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 @@ -67,6 +67,18 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource {
Schema: resourceKubernetesClusterNodePoolSchema(),

CustomizeDiff: pluginsdk.CustomDiffInSequence(
pluginsdk.ForceNewIfChange("os_sku", func(ctx context.Context, old, new, meta interface{}) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CustomDiff only applies to azurerm_kubernetes_cluster_node_pool resources.

We need a copy of it in kubernetes_cluster_resource.go too so that the logic applies when validating default_node_pool in azurerm_kubernetes_cluster.

// Ubuntu and AzureLinux are currently the only allowed Linux OSSKU Migration targets.
if old != string(agentpools.OSSKUUbuntu) && old != string(agentpools.OSSKUAzureLinux) {
return true
}

if new != string(agentpools.OSSKUUbuntu) && new != string(agentpools.OSSKUAzureLinux) {
return true
}

return false
}),
// The behaviour of the API requires this, but this could be removed when https://github.com/Azure/azure-rest-api-specs/issues/27373 has been addressed
pluginsdk.ForceNewIfChange("upgrade_settings.0.drain_timeout_in_minutes", func(ctx context.Context, old, new, meta interface{}) bool {
return old != 0 && new == 0
Expand Down Expand Up @@ -269,7 +281,6 @@ func resourceKubernetesClusterNodePoolSchema() map[string]*pluginsdk.Schema {
"os_sku": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove "default_node_pool.0.os_sku", from cycleNodePoolProperties in kubernetes_cluster_resource.go because a temporary_name_for_rotation is no longer required since we can in-place upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I opened a separate PR for kubernetes_cluster_resource

Computed: true, // defaults to Ubuntu if using Linux
ValidateFunc: validation.StringInSlice([]string{
string(agentpools.OSSKUAzureLinux),
Expand Down Expand Up @@ -840,6 +851,10 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int
props.Tags = tags.Expand(t)
}

if d.HasChange("os_sku") {
props.OsSKU = pointer.To(agentpools.OSSKU(d.Get("os_sku").(string)))
}

if d.HasChange("upgrade_settings") {
upgradeSettingsRaw := d.Get("upgrade_settings").([]interface{})
props.UpgradeSettings = expandAgentPoolUpgradeSettings(upgradeSettingsRaw)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,35 @@ func TestAccKubernetesClusterNodePool_osSkuMariner(t *testing.T) {
})
}

func TestAccKubernetesClusterNodePool_osSkuMigration(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}

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

func TestAccKubernetesClusterNodePool_dedicatedHost(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/kubernetes_cluster_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ The following arguments are supported:

* `pod_subnet_id` - (Optional) The ID of the Subnet where the pods in the Node Pool should exist. Changing this forces a new resource to be created.

* `os_sku` - (Optional) Specifies the OS SKU used by the agent pool. Possible values are `AzureLinux`, `Ubuntu`, `Windows2019` and `Windows2022`. If not specified, the default is `Ubuntu` if OSType=Linux or `Windows2019` if OSType=Windows. And the default Windows OSSKU will be changed to `Windows2022` after Windows2019 is deprecated. Changing this forces a new resource to be created.
* `os_sku` - (Optional) Specifies the OS SKU used by the agent pool. Possible values are `AzureLinux`, `Ubuntu`, `Windows2019` and `Windows2022`. If not specified, the default is `Ubuntu` if OSType=Linux or `Windows2019` if OSType=Windows. And the default Windows OSSKU will be changed to `Windows2022` after Windows2019 is deprecated. Changing this from `AzureLinux` or `Ubuntu` to `AzureLinux` or `Ubuntu` will not replace the resource, otherwise it forces a new resource to be created.

-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/OSSKUMigrationPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://learn.microsoft.com/en-us/azure/azure-linux/tutorial-azure-linux-migration) for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed if it's not really a preview feature anymore

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it when it's GA, currently we still need this feature registered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it though? That flag isn't registered on our testing subscription

$ az feature show --namespace "Microsoft.ContainerService" --name "OSSKUMigrationPreview"
{
  "id": "/subscriptions/*/providers/Microsoft.Features/providers/microsoft.ContainerService/features/OSSKUMigrationPreview",
  "name": "microsoft.ContainerService/OSSKUMigrationPreview",
  "properties": {
    "state": "NotRegistered"
  },
  "type": "Microsoft.Features/providers/features"
}

And the test passes
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'll remove the notice.


* `os_type` - (Optional) The Operating System which should be used for this Node Pool. Changing this forces a new resource to be created. Possible values are `Linux` and `Windows`. Defaults to `Linux`.

Expand Down
Loading