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 #6842

Merged
merged 1 commit into from
Nov 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,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
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,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 @@ -1786,6 +1790,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
16 changes: 16 additions & 0 deletions mmv1/third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ func schemaNodeConfig() *schema.Schema {
<% end -%>
},

"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 @@ -644,6 +651,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 @@ -830,6 +845,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
Original file line number Diff line number Diff line change
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