Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - gate node_os_channel_upgrade check s…
Browse files Browse the repository at this point in the history
…ince it's a preview feature (#22284)

* gate node_os_channel_upgrade check since it's a preview feature

* conditionally set node_os_upgrade_channel

* skip import check temporarily
  • Loading branch information
stephybun authored Jun 28, 2023
1 parent 2518162 commit ed8e0b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
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 @@ -1483,14 +1483,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 @@ -1953,16 +1959,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 @@ -2313,7 +2320,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)
}

customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates)
d.Set("custom_ca_trust_certificates_base64", customCaTrustCertList)
Expand Down

0 comments on commit ed8e0b6

Please sign in to comment.