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 & azurerm_kubernetes_cluster_node_pool: Support for node_labels #5531

Merged
merged 5 commits into from
Mar 10, 2020

Conversation

dintel
Copy link
Contributor

@dintel dintel commented Jan 27, 2020

Add support for node_labels in azurerm_kubernetes_cluster and azurerm_kubernetes_cluster_node_pool resources.
Fixes #4968

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

Hey @dintel, this looks good so far but I've made a couple minor suggestions. It'd also be good to add some tests to confirm that we can create, update, and remove them

@@ -176,6 +176,14 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
Computed: true,
},

"node_labels": {
Type: schema.TypeMap,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like this is used to get the resource and as such should be swapped to

Suggested change
Optional: true,
Computed: true,

@@ -1230,6 +1238,10 @@ func expandKubernetesClusterAgentPoolProfiles(input []interface{}, isNewResource
return nil, fmt.Errorf("Can't create an AKS cluster with autoscaling enabled but not setting min_count or max_count")
}

if nodeLabels := utils.ExpandMapStringPtrString(config["node_labels"].(map[string]interface{})); len(nodeLabels) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to empty node label struct to the api so people can remove the labels?

Copy link
Contributor Author

@dintel dintel Feb 7, 2020

Choose a reason for hiding this comment

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

From my tests of Azure AKS API node labels can not be changed.
Whenever you try to alter node labels API accepts the update, but labels are never changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) since the agent_pool_profile block is deprecated can we remove this? For the default_node_pool block we can make this ForceNew too - I'll leave a comment there

@@ -286,6 +298,14 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro
name = *agentPool.Name
}

var nodeLabels map[string]string
if agentPool.NodeLabels != nil {
nodeLabels = make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

Might be misreading here but can't we use your nifty flatten function here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExpandMapStringPtrString is almost the same, but it accepts map[string]interface{}, so it can not be used here.

result := make(map[string]*string)
for k, v := range input {
s := v.(string)
result[k] = &s
Copy link
Member

Choose a reason for hiding this comment

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

I think we can consolidate this just a bit

Suggested change
result[k] = &s
result[k] = utils.String(v.(string))

func FlattenMapStringPtrString(input map[string]*string) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range input {
result[k] = *v
Copy link
Member

Choose a reason for hiding this comment

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

We'll want to confirm that v isn't nil before pointing to it

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @dintel

Thanks for this PR / pushing those changes - I've taken a look through and left some other minor comments inline but this is otherwise looking good 👍

Thanks!

@@ -223,6 +223,14 @@ func resourceArmKubernetesCluster() *schema.Resource {
ForceNew: true,
},

"node_labels": {
Type: schema.TypeMap,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

since these can't be updated we'll also need to make this:

Suggested change
Optional: true,
Optional: true,
ForceNew: true,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tombuildsstuff since agent the agent_pool_profile block is deprecated, do not you want to drop it here too?

nodeLabelsRaw := d.Get("node_labels").(map[string]interface{})
nodeLabels := utils.ExpandMapStringPtrString(nodeLabelsRaw)
props.NodeLabels = nodeLabels
}
Copy link
Contributor

Choose a reason for hiding this comment

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

since these can't be updated at this time could we remove this for the moment?

@@ -1230,6 +1238,10 @@ func expandKubernetesClusterAgentPoolProfiles(input []interface{}, isNewResource
return nil, fmt.Errorf("Can't create an AKS cluster with autoscaling enabled but not setting min_count or max_count")
}

if nodeLabels := utils.ExpandMapStringPtrString(config["node_labels"].(map[string]interface{})); len(nodeLabels) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) since the agent_pool_profile block is deprecated can we remove this? For the default_node_pool block we can make this ForceNew too - I'll leave a comment there

@@ -184,6 +184,8 @@ A `agent_pool_profile` block supports the following:

* `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created.

* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) since the agent_pool_profile block is deprecated could we remove this:

Suggested change
* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).

@@ -70,6 +70,8 @@ The following arguments are supported:

* `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created.

* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).
Copy link
Contributor

Choose a reason for hiding this comment

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

could we make this:

Suggested change
* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).
* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in this Node Pool.

@@ -239,6 +241,8 @@ A `default_node_pool` block supports the following:

* `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created.

* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).
Copy link
Contributor

Choose a reason for hiding this comment

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

could we make this:

Suggested change
* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`).
* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the Default Node Pool.

(since this is a Map users can imply it's:

foo = {
  Hello = "World"
}

as such we can remove this example)

@dintel
Copy link
Contributor Author

dintel commented Feb 14, 2020

@tombuildsstuff @mbfrahry I made changes as you guys requested. Could you please review again?

@dintel
Copy link
Contributor Author

dintel commented Feb 26, 2020

@tombuildsstuff @mbfrahry could you guys review this PR? I made some changes to reflect new version changes.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

Hey @dintel, I'm struggling to get a couple of the tests working.

--- FAIL: TestAccAzureRMKubernetesCluster_nodeLabels (80.00s)
    testing.go:640: Step 0 error: errors during apply:
        
        Error: Error creating Managed Kubernetes Cluster "acctestaks200304233511150885" (Resource Group "acctestRG-200304233511150885"): containerservice.ManagedClustersClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="CanNotTaintAllAgentPools" Message="Operation failed due to insufficient nodes for system pod scheduling. Placing custom taints on all node pools is not supported. Retry the operation and leave at least one node pool untainted."

Looking at what we are sending to the api, it seems like the label is being appended to the taint attribute.

"nodeLabels": {},
"nodeTaints": ["key=value:PreferNoSchedule"],

And then the datasource config seems off

--- FAIL: TestAccDataSourceAzureRMKubernetesCluster_nodeLabels (0.02s)
    testing.go:640: Step 0 error: Missing item separator: On /opt/teamcity-agent/temp/buildTmp/tf-test852087197/main.tf line 19: Expected a comma to mark the beginning of the next item.

@dintel dintel requested a review from mbfrahry March 9, 2020 10:13
@dintel
Copy link
Contributor Author

dintel commented Mar 9, 2020

@mbfrahry Please check now.

@ghost ghost removed the waiting-response label Mar 9, 2020
Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your taking the time to get this in

@mbfrahry mbfrahry changed the title Add support of node_labels in AKS azurerm_kubernetes_cluster & azurerm_kubernetes_cluster_node_pool: Support for node_labels Mar 10, 2020
@mbfrahry mbfrahry merged commit 4c5ae77 into hashicorp:master Mar 10, 2020
mbfrahry added a commit that referenced this pull request Mar 10, 2020
@ghost
Copy link

ghost commented Apr 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm_kubernetes_cluster does not support labels in an agent_pool_profile
4 participants