-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Conversation
6173692
to
a6d9ef2
Compare
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
azurerm/utils/common_marshal.go
Outdated
result := make(map[string]*string) | ||
for k, v := range input { | ||
s := v.(string) | ||
result[k] = &s |
There was a problem hiding this comment.
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
result[k] = &s | |
result[k] = utils.String(v.(string)) |
azurerm/utils/common_marshal.go
Outdated
func FlattenMapStringPtrString(input map[string]*string) map[string]interface{} { | ||
result := make(map[string]interface{}) | ||
for k, v := range input { | ||
result[k] = *v |
There was a problem hiding this comment.
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
There was a problem hiding this 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, |
There was a problem hiding this comment.
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:
Optional: true, | |
Optional: true, | |
ForceNew: true, |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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?
azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go
Show resolved
Hide resolved
@@ -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 { |
There was a problem hiding this comment.
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"}`). |
There was a problem hiding this comment.
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:
* `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"}`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make this:
* `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"}`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make this:
* `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)
099f40a
to
0c9a51b
Compare
@tombuildsstuff @mbfrahry I made changes as you guys requested. Could you please review again? |
…_kubernetes_cluster_node_pool resources hashicorp#4968
@tombuildsstuff @mbfrahry could you guys review this PR? I made some changes to reflect new version changes. |
There was a problem hiding this 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.
@mbfrahry Please check now. |
There was a problem hiding this 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
azurerm_kubernetes_cluster
& azurerm_kubernetes_cluster_node_pool
: Support for node_labels
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! |
Add support for
node_labels
inazurerm_kubernetes_cluster
andazurerm_kubernetes_cluster_node_pool
resources.Fixes #4968