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 - gate node_os_channel_upgrade check since it's a preview feature #22284

Merged
merged 3 commits into from
Jun 28, 2023
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 @@ -804,31 +804,33 @@ func TestAccKubernetesCluster_nodeOsUpgradeChannel(t *testing.T) {
check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("Unmanaged"),
),
},
data.ImportStep(),
// TODO add this back in when upgrading to 2023-06-02-preview
// temporarily skip the import check because of the behaviour of this feature
// data.ImportStep(),
{
Config: r.nodeOsUpgradeChannel(data, "SecurityPatch"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("SecurityPatch"),
),
},
data.ImportStep(),
// data.ImportStep(),
{
Config: r.nodeOsUpgradeChannel(data, "NodeImage"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("NodeImage"),
),
},
data.ImportStep(),
// data.ImportStep(),
{
Config: r.nodeOsUpgradeChannel(data, "None"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("node_os_channel_upgrade").HasValue("None"),
),
},
data.ImportStep(),
// data.ImportStep(),
})
}

Expand Down
22 changes: 17 additions & 5 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,20 @@ func resourceKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interface{}
autoUpgradeProfile := &managedclusters.ManagedClusterAutoUpgradeProfile{}
autoChannelUpgrade := d.Get("automatic_channel_upgrade").(string)
nodeOsChannelUpgrade := d.Get("node_os_channel_upgrade").(string)
if autoChannelUpgrade != "" {

// this check needs to be separate and gated since node_os_channel_upgrade is a preview feature
if nodeOsChannelUpgrade != "" && autoChannelUpgrade != "" {
if autoChannelUpgrade == string(managedclusters.UpgradeChannelNodeNegativeimage) && nodeOsChannelUpgrade != string(managedclusters.NodeOSUpgradeChannelNodeImage) {
return fmt.Errorf("`node_os_channel_upgrade` cannot be set to a value other than `NodeImage` if `automatic_channel_upgrade` is set to `node-image`")
}
}

if autoChannelUpgrade != "" {
autoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannel(autoChannelUpgrade))
} else {
autoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannelNone)
}

if nodeOsChannelUpgrade != "" {
autoUpgradeProfile.NodeOSUpgradeChannel = pointer.To(managedclusters.NodeOSUpgradeChannel(nodeOsChannelUpgrade))
}
Expand Down Expand Up @@ -1939,16 +1945,17 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
existing.Model.Properties.AutoUpgradeProfile = &managedclusters.ManagedClusterAutoUpgradeProfile{}
}
channel := d.Get("automatic_channel_upgrade").(string)
if channel == string(managedclusters.UpgradeChannelNodeNegativeimage) && d.Get("node_os_channel_upgrade").(string) != string(managedclusters.NodeOSUpgradeChannelNodeImage) {
return fmt.Errorf("`node_os_channel_upgrade` must be set to `NodeImage` if `automatic_channel_upgrade` is set to `node-image`")
}
if channel == "" {
channel = string(managedclusters.UpgradeChannelNone)
}
existing.Model.Properties.AutoUpgradeProfile.UpgradeChannel = pointer.To(managedclusters.UpgradeChannel(channel))
}

if d.HasChange("node_os_channel_upgrade") {
updateCluster = true
if d.Get("automatic_channel_upgrade").(string) == string(managedclusters.UpgradeChannelNodeNegativeimage) && d.Get("node_os_channel_upgrade").(string) != string(managedclusters.NodeOSUpgradeChannelNodeImage) {
return fmt.Errorf("`node_os_channel_upgrade` must be set to `NodeImage` if `automatic_channel_upgrade` is set to `node-image`")
}
if existing.Model.Properties.AutoUpgradeProfile == nil {
existing.Model.Properties.AutoUpgradeProfile = &managedclusters.ManagedClusterAutoUpgradeProfile{}
}
Expand Down Expand Up @@ -2293,7 +2300,12 @@ func resourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{})
}
}
d.Set("automatic_channel_upgrade", upgradeChannel)
d.Set("node_os_channel_upgrade", nodeOSUpgradeChannel)

// the API returns `node_os_channel_upgrade` when `automatic_channel_upgrade` is set to `node-image`
// since it's a preview feature we will only set this if it's explicitly been set in the config for the time being
if v, ok := d.GetOk("node_os_channel_upgrade"); ok && v.(string) != "" {
d.Set("node_os_channel_upgrade", nodeOSUpgradeChannel)
}

enablePrivateCluster := false
enablePrivateClusterPublicFQDN := false
Expand Down