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

feat(google_container_cluster): add resource_labels to node_config #13104

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6842.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added `resource_labels` field to `node_config` resource
```
16 changes: 16 additions & 0 deletions google/node_config.go
Expand Up @@ -149,6 +149,13 @@ func schemaNodeConfig() *schema.Schema {
Description: `The map of Kubernetes labels (key/value pairs) to be applied to each node. These will added in addition to any default label(s) that Kubernetes may apply to the node.`,
},

"resource_labels": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `The GCE resource labels (a map of key/value pairs) to be applied to the node pool.`,
},

"local_ssd_count": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -525,6 +532,14 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
nc.Labels = m
}

if v, ok := nodeConfig["resource_labels"]; ok {
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
nc.ResourceLabels = m
}

if v, ok := nodeConfig["tags"]; ok {
tagsList := v.([]interface{})
tags := []string{}
Expand Down Expand Up @@ -638,6 +653,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
"metadata": c.Metadata,
"image_type": c.ImageType,
"labels": c.Labels,
"resource_labels": c.ResourceLabels,
"tags": c.Tags,
"preemptible": c.Preemptible,
"spot": c.Spot,
Expand Down
38 changes: 38 additions & 0 deletions google/resource_container_node_pool.go
Expand Up @@ -1143,6 +1143,44 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
log.Printf("[INFO] Updated tags for node pool %s", name)
}

if d.HasChange(prefix + "node_config.0.resource_labels") {
req := &container.UpdateNodePoolRequest{
Name: name,
}

if v, ok := d.GetOk(prefix + "node_config.0.resource_labels"); ok {
resourceLabels := v.(map[string]interface{})
req.ResourceLabels = &container.ResourceLabels{
Labels: convertStringMap(resourceLabels),
}
}

updateF := func() error {
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
if config.UserProjectOverride {
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
}
op, err := clusterNodePoolsUpdateCall.Do()
if err != nil {
return err
}

// Wait until it's updated
return containerOperationWait(config, op,
nodePoolInfo.project,
nodePoolInfo.location,
"updating GKE node pool resource labels", userAgent,
timeout)
}

// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] Updated resource labels for node pool %s", name)
}

if d.HasChange(prefix + "node_config.0.image_type") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
Expand Down
9 changes: 9 additions & 0 deletions google/resource_container_node_pool_test.go
Expand Up @@ -1427,6 +1427,10 @@ resource "google_container_node_pool" "np_with_node_config" {

tags = ["ga"]

resource_labels = {
"key1" = "value"
}

taint {
key = "taint_key"
value = "taint_value"
Expand Down Expand Up @@ -1473,6 +1477,11 @@ resource "google_container_node_pool" "np_with_node_config" {

tags = ["beta"]

resource_labels = {
"key1" = "value1"
"key2" = "value2"
}

taint {
key = "taint_key"
value = "taint_value"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Expand Up @@ -750,6 +750,9 @@ gvnic {
* `labels` - (Optional) The Kubernetes labels (key/value pairs) to be applied to each node. The kubernetes.io/ and k8s.io/ prefixes are
reserved by Kubernetes Core components and cannot be specified.

* `resource_labels` - (Optional) The GCP labels (key/value pairs) to be applied to each node. Refer [here](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-managing-labels)
for how these labels are applied to clusters, node pools and nodes.

* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
attached to each cluster node. Defaults to 0.

Expand Down