Skip to content

Commit

Permalink
Allow defining empty taint, remove old DSF (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson authored and slevenick committed Nov 7, 2019
1 parent 0aae86a commit 579c71e
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ var schemaNodeConfig = &schema.Schema{
// Computed=true because GKE Sandbox will automatically add taints to nodes that can/cannot run sandboxed pods.
Computed: true,
ForceNew: true,
DiffSuppressFunc: taintDiffSuppress,
// Legacy config mode allows explicitly defining an empty taint.
// See https://www.terraform.io/docs/configuration/attr-as-blocks.html
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Expand Down Expand Up @@ -469,20 +471,3 @@ func flattenSandboxConfig(c *containerBeta.SandboxConfig) []map[string]interface
return result
}
<% end -%>

func taintDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
if strings.HasSuffix(k, "#") {
oldCount, oldErr := strconv.Atoi(old)
newCount, newErr := strconv.Atoi(new)
// If either of them isn't a number somehow, or if there's one that we didn't have before.
return oldErr != nil || newErr != nil || oldCount == newCount+1
} else {
lastDot := strings.LastIndex(k, ".")
taintKey := d.Get(k[:lastDot] + ".key").(string)
if taintKey == "nvidia.com/gpu" {
return true
} else {
return false
}
}
}

0 comments on commit 579c71e

Please sign in to comment.