Skip to content

Commit 1d36337

Browse files
modular-magicianslevenick
authored andcommitted
Add DSF on resource_labels in node_config (#12877) (#21082)
[upstream:8e47ba07a90f6b6aa3376fda0fcd7529e99a529b] Signed-off-by: Modular Magician <[email protected]>
1 parent 44d5c8b commit 1d36337

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

.changelog/12877.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed a diff caused by server-side set values for `node_config.resource_labels`
3+
```

google/services/container/node_config.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package container
44

55
import (
66
"log"
7+
"strings"
78
"time"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -233,10 +234,11 @@ func schemaNodeConfig() *schema.Schema {
233234
},
234235

235236
"resource_labels": {
236-
Type: schema.TypeMap,
237-
Optional: true,
238-
Elem: &schema.Schema{Type: schema.TypeString},
239-
Description: `The GCE resource labels (a map of key/value pairs) to be applied to the node pool.`,
237+
Type: schema.TypeMap,
238+
Optional: true,
239+
Elem: &schema.Schema{Type: schema.TypeString},
240+
DiffSuppressFunc: containerNodePoolResourceLabelsDiffSuppress,
241+
Description: `The GCE resource labels (a map of key/value pairs) to be applied to the node pool.`,
240242
},
241243

242244
"local_ssd_count": {
@@ -1692,6 +1694,21 @@ func flattenWorkloadMetadataConfig(c *container.WorkloadMetadataConfig) []map[st
16921694
return result
16931695
}
16941696

1697+
func containerNodePoolResourceLabelsDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
1698+
// Suppress diffs for server-specified labels prefixed with "goog-gke"
1699+
if strings.Contains(k, "resource_labels.goog-gke") && new == "" {
1700+
return true
1701+
}
1702+
1703+
// Let diff be determined by resource_labels (above)
1704+
if strings.Contains(k, "resource_labels.%") {
1705+
return true
1706+
}
1707+
1708+
// For other keys, don't suppress diff.
1709+
return false
1710+
}
1711+
16951712
func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface{} {
16961713
result := []map[string]interface{}{}
16971714
if c != nil {

0 commit comments

Comments
 (0)