Skip to content

Commit

Permalink
[#12620] Allow gke nodepool labels to be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Prete committed Dec 11, 2022
1 parent 18b1357 commit dac0257
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,45 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node

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


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

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

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 labels", userAgent,
timeout)
}

// Call update serially.
if err := retryWhileIncompatibleOperation(timeout, npLockKey, 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 @@ -1888,12 +1888,6 @@ resource "google_container_node_pool" "np_with_node_config" {
]
preemptible = true
min_cpu_platform = "Intel Broadwell"

tags = ["ga"]

resource_labels = {
"key1" = "value"
}

taint {
key = "taint_key"
Expand All @@ -1909,6 +1903,16 @@ resource "google_container_node_pool" "np_with_node_config" {

// Updatable fields
image_type = "COS_CONTAINERD"

tags = ["foo"]

labels = {
"test.terraform.io/key1" = "foo"
}

resource_labels = {
"key1" = "foo"
}
}
}
`, cluster, nodePool)
Expand Down Expand Up @@ -1939,13 +1943,6 @@ resource "google_container_node_pool" "np_with_node_config" {
preemptible = true
min_cpu_platform = "Intel Broadwell"

tags = ["beta"]

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

taint {
key = "taint_key"
value = "taint_value"
Expand All @@ -1960,6 +1957,18 @@ resource "google_container_node_pool" "np_with_node_config" {

// Updatable fields
image_type = "UBUNTU_CONTAINERD"

tags = ["bar", "foobar"]

labels = {
"test.terraform.io/key1" = "bar"
"test.terraform.io/key2" = "foo"
}

resource_labels = {
"key1" = "bar"
"key2" = "foo"
}
}
}
`, cluster, nodePool)
Expand Down
1 change: 0 additions & 1 deletion mmv1/third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func schemaNodeConfig() *schema.Schema {
Optional: true,
// Computed=true because GKE Sandbox will automatically add labels to nodes that can/cannot run sandboxed pods.
Computed: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
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.`,
<% unless version.nil? || version == 'ga' -%>
Expand Down

0 comments on commit dac0257

Please sign in to comment.