Skip to content

Commit

Permalink
Container node pool empty guest accelerator (GoogleCloudPlatform#12027)
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge authored Oct 17, 2024
1 parent 071d515 commit 91654fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2236,12 +2236,18 @@ func ResourceContainerCluster() *schema.Resource {
// by only comparing the blocks with a positive count and ignoring those with count=0
//
// One quirk with this approach is that configs with mixed count=0 and count>0 accelerator blocks will
// show a confusing diff if one of there are config changes that result in a legitimate diff as the count=0
// show a confusing diff if there are config changes that result in a legitimate diff as the count=0
// blocks will not be in state.
func resourceNodeConfigEmptyGuestAccelerator(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
func resourceNodeConfigEmptyGuestAccelerator(_ context.Context, diff *schema.ResourceDiff, meta any) error {
old, new := diff.GetChange("node_config.0.guest_accelerator")
oList := old.([]interface{})
nList := new.([]interface{})
oList, ok := old.([]any)
if !ok {
return fmt.Errorf("type assertion failed, expected []any, got %T", old)
}
nList, ok := new.([]any)
if !ok {
return fmt.Errorf("type assertion failed, expected []any, got %T", new)
}

if len(nList) == len(oList) || len(nList) == 0 {
return nil
Expand All @@ -2251,9 +2257,12 @@ func resourceNodeConfigEmptyGuestAccelerator(_ context.Context, diff *schema.Res
// will be longer than the current state.
// this index tracks the location of positive count accelerator blocks
index := 0
for i, item := range nList {
accel := item.(map[string]interface{})
if accel["count"].(int) == 0 {
for _, item := range nList {
nAccel, ok := item.(map[string]any)
if !ok {
return fmt.Errorf("type assertion failed, expected []any, got %T", item)
}
if nAccel["count"].(int) == 0 {
hasAcceleratorWithEmptyCount = true
// Ignore any 'empty' accelerators because they aren't sent to the API
continue
Expand All @@ -2264,7 +2273,14 @@ func resourceNodeConfigEmptyGuestAccelerator(_ context.Context, diff *schema.Res
// This will prevent array index overruns
return nil
}
if !reflect.DeepEqual(nList[i], oList[index]) {
// Delete Optional + Computed field from old and new map.
oAccel, ok := oList[index].(map[string]any)
if !ok {
return fmt.Errorf("type assertion failed, expected []any, got %T", oList[index])
}
delete(nAccel, "gpu_driver_installation_config")
delete(oAccel, "gpu_driver_installation_config")
if !reflect.DeepEqual(oAccel, nAccel) {
return nil
}
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3839,7 +3839,7 @@ resource "google_container_node_pool" "np" {
count = 0
type = "nvidia-tesla-p100"
}
machine_type = "n1-highmem-4"
machine_type = "n1-highmem-4"
}
}
`, cluster, networkName, subnetworkName, np)
Expand Down Expand Up @@ -3872,7 +3872,7 @@ resource "google_container_node_pool" "np" {
count = %d
type = "nvidia-tesla-p100"
}
machine_type = "n1-highmem-4"
machine_type = "n1-highmem-4"
}
}
`, cluster, networkName, subnetworkName, np, count)
Expand Down

0 comments on commit 91654fd

Please sign in to comment.