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

[#12620] Allow gke nodepool labels to be updated #6941

Merged
merged 2 commits into from
Dec 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var (
}

forceNewClusterNodeConfigFields = []string{
"labels",
"workload_metadata_config",
}

Expand Down
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 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 @@ -5043,7 +5043,7 @@ resource "google_container_cluster" "with_sandbox_config" {

labels = {
"test.terraform.io/gke-sandbox" = "true"
"test.terraform.io/gke-sandbox-amended" = "also-true"
"test.terraform.io/gke-sandbox-amended" = "also-true"
}

taint {
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