Skip to content

Commit c3d9408

Browse files
authored
tgc-revival: container node pool bugs (GoogleCloudPlatform#16463)
1 parent cbc1ed4 commit c3d9408

File tree

3 files changed

+11
-42
lines changed

3 files changed

+11
-42
lines changed

mmv1/third_party/tgc_next/pkg/services/container/node_config.go

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,34 +1618,6 @@ func expandNodeConfig(d tpgresource.TerraformResourceData, prefix string, v inte
16181618

16191619
if v, ok := nodeConfig["kubelet_config"]; ok {
16201620
nc.KubeletConfig = expandKubeletConfig(v)
1621-
1622-
// // start cpu_cfs_quota fix https://github.com/hashicorp/terraform-provider-google/issues/15767
1623-
// // this makes the field conditional on appearance in configuration. This allows the API `true` default
1624-
// // to override null, where currently we force-send null as false, which is wrong.
1625-
// rawConfigNPRoot := d.GetRawConfig()
1626-
// // if we have a prefix, we're in `node_pool.N.` in GKE Cluster. Traverse the RawConfig object to reach that
1627-
// // root, at which point local references work going forwards.
1628-
// if prefix != "" {
1629-
// parts := strings.Split(prefix, ".") // "node_pool.N." -> ["node_pool" "N", ""]
1630-
// npIndex, err := strconv.Atoi(parts[1])
1631-
// if err != nil { // no error return from expander
1632-
// panic(fmt.Errorf("unexpected format for node pool path prefix: %w. value: %v", err, prefix))
1633-
// }
1634-
1635-
// rawConfigNPRoot = rawConfigNPRoot.GetAttr("node_pool").Index(cty.NumberIntVal(int64(npIndex)))
1636-
// }
1637-
1638-
// if vNC := rawConfigNPRoot.GetAttr("node_config"); vNC.LengthInt() > 0 {
1639-
// if vKC := vNC.Index(cty.NumberIntVal(0)).GetAttr("kubelet_config"); vKC.LengthInt() > 0 {
1640-
// v := vKC.Index(cty.NumberIntVal(0)).GetAttr("cpu_cfs_quota")
1641-
// if v == cty.NullVal(cty.Bool) {
1642-
// nc.KubeletConfig.CpuCfsQuota = true
1643-
// } else if v.False() { // force-send explicit false to API
1644-
// nc.KubeletConfig.ForceSendFields = append(nc.KubeletConfig.ForceSendFields, "CpuCfsQuota")
1645-
// }
1646-
// }
1647-
// }
1648-
// end cpu_cfs_quota fix
16491621
}
16501622

16511623
if v, ok := nodeConfig["linux_node_config"]; ok {
@@ -2377,16 +2349,6 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
23772349
return config
23782350
}
23792351

2380-
// default to no prior taint state if there are any issues
2381-
oldTaints := []interface{}{}
2382-
oldNodeConfigSchemaContainer := v.([]interface{})
2383-
if len(oldNodeConfigSchemaContainer) != 0 {
2384-
oldNodeConfigSchema := oldNodeConfigSchemaContainer[0].(map[string]interface{})
2385-
if vt, ok := oldNodeConfigSchema["taint"]; ok && len(vt.([]interface{})) > 0 {
2386-
oldTaints = vt.([]interface{})
2387-
}
2388-
}
2389-
23902352
config = append(config, map[string]interface{}{
23912353
"machine_type": c.MachineType,
23922354
"containerd_config": flattenContainerdConfig(c.ContainerdConfig),
@@ -2413,8 +2375,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
24132375
"spot": c.Spot,
24142376
"min_cpu_platform": c.MinCpuPlatform,
24152377
"shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig),
2416-
"taint": flattenTaints(c.Taints, oldTaints),
2417-
"effective_taints": flattenEffectiveTaints(c.Taints),
2378+
"taint": flattenEffectiveTaints(c.Taints),
24182379
"workload_metadata_config": flattenWorkloadMetadataConfig(c.WorkloadMetadataConfig),
24192380
"confidential_nodes": flattenConfidentialNodes(c.ConfidentialNodes),
24202381
"boot_disk_kms_key": c.BootDiskKmsKey,

mmv1/third_party/tgc_next/pkg/services/container/resource_node_pool_cai2hcl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (c *ContainerNodePoolCai2hclConverter) convertResourceData(asset caiasset.A
6363

6464
hclData := make(map[string]interface{})
6565

66+
outputFields := map[string]struct{}{}
67+
an := strings.Replace(asset.Name, "/zones/", "/locations/", 1)
68+
utils.ParseUrlParamValuesFromAssetName(an, "//container.googleapis.com/projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/nodePools/{{name}}", outputFields, hclData)
69+
6670
npMap, err := flattenNodePool(d, config, nodePool, "")
6771
if err != nil {
6872
return nil, err

mmv1/third_party/tgc_next/pkg/services/container/resource_node_pool_tfplan2cai.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package container
33
import (
44
"fmt"
55
"reflect"
6+
"strings"
67

78
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/caiasset"
89
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/tfplan2cai/converters/cai"
@@ -13,14 +14,17 @@ import (
1314
"google.golang.org/api/container/v1"
1415
)
1516

16-
func NodePoolTfplan2caiConverter() cai.Tfplan2caiConverter {
17+
func ContainerNodePoolTfplan2caiConverter() cai.Tfplan2caiConverter {
1718
return cai.Tfplan2caiConverter{
1819
Convert: GetContainerNodePoolCaiObject,
1920
}
2021
}
2122

2223
func GetContainerNodePoolCaiObject(d tpgresource.TerraformResourceData, config *transport.Config) ([]caiasset.Asset, error) {
2324
name, err := cai.AssetName(d, config, "//container.googleapis.com/projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/nodePools/{{name}}")
25+
if v, ok := d.GetOk("location"); ok && tpgresource.IsZone(v.(string)) {
26+
name = strings.Replace(name, "/locations/", "/zones/", 1)
27+
}
2428
if err != nil {
2529
return []caiasset.Asset{}, err
2630
}
@@ -281,7 +285,7 @@ func expandContainerNodePoolNodeConfigGuestAccelerator(v interface{}, d tpgresou
281285
}
282286

283287
func expandContainerNodePoolNodeConfigGuestAcceleratorCount(v interface{}, d tpgresource.TerraformResourceData, config *transport.Config) (interface{}, error) {
284-
return v, nil
288+
return fmt.Sprintf("%d", v.(int)), nil
285289
}
286290

287291
func expandContainerNodePoolNodeConfigGuestAcceleratorType(v interface{}, d tpgresource.TerraformResourceData, config *transport.Config) (interface{}, error) {

0 commit comments

Comments
 (0)