Skip to content
Closed
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 @@ -664,6 +664,10 @@ func TestUnitFlattenClusterNodePools(t *testing.T) {
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{"create_pod_range": {Type: schema.TypeBool}}},
},
"ignore_node_count_changes": {
Type: schema.TypeBool,
Optional: true,
},
},
},
Optional: true,
Expand Down Expand Up @@ -701,6 +705,7 @@ func TestUnitFlattenClusterNodePools(t *testing.T) {
"managed_instance_group_urls": []string{},
"version": "",
"network_config": []map[string]interface{}{},
"ignore_node_count_changes": false,
},
{
"name": "pool-2",
Expand All @@ -713,6 +718,7 @@ func TestUnitFlattenClusterNodePools(t *testing.T) {
"managed_instance_group_urls": []string{},
"version": "",
"network_config": []map[string]interface{}{},
"ignore_node_count_changes": false,
},
},
expectError: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ func TestAccContainerCluster_regionalWithNodePool(t *testing.T) {
ResourceName: "google_container_cluster.regional",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection", "ignore_node_count_changes", "node_pool.0.ignore_node_count_changes"},
ImportStateVerifyIgnore: []string{"deletion_protection", "ignore_node_count_changes", "node_pool.0.ignore_node_count_changes", "node_pool.0.managed_instance_group_urls"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ func (instanceGroupManagerCache *instanceGroupManagerCache) needsRefresh(fullyQu
return time.Since(igm.updateTime) > instanceGroupManagerCache.ttl
}

func (instanceGroupManagerCache *instanceGroupManagerCache) invalidate(igmUrl string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalidateItem? This reads as "invalidate the whole cache" to me on initial read. Also consider adding a comment.

instanceGroupManagerCache.mutex.Lock()
defer instanceGroupManagerCache.mutex.Unlock()

matches := instanceGroupManagerURL.FindStringSubmatch(igmUrl)
if len(matches) >= 4 {
delete(instanceGroupManagerCache.instanceGroupManagers, matches[0])
}
}


// We need to set ttl to 0 to disable caching in VCR testing.
// This ensure all NP/MIG LIST requests are made consistently,
// preventing non-deterministic behavior that would break VCR.
Expand Down Expand Up @@ -1524,6 +1535,7 @@ func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *c
// or leave them empty. Passing the API URLs to igmUrls at least populates them for basic usage.
for _, url := range np.InstanceGroupUrls {
igmUrls = append(igmUrls, url)
igmCache.invalidate(url)
}
} else {
for _, url := range np.InstanceGroupUrls {
Expand Down Expand Up @@ -1563,6 +1575,7 @@ func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *c
"managed_instance_group_urls": managedIgmUrls,
"version": np.Version,
"network_config": flattenNodeNetworkConfig(np.NetworkConfig, d, prefix),
"ignore_node_count_changes": d.Get(prefix + "ignore_node_count_changes"),
}

if np.Autoscaling != nil {
Expand Down Expand Up @@ -1867,6 +1880,11 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
return err
}
if urls, ok := d.GetOk(prefix + "instance_group_urls"); ok {
for _, u := range urls.([]interface{}) {
igmCache.invalidate(u.(string))
}
}
log.Printf("[INFO] GKE node pool %s size has been updated to %d", name, newSize)
}

Expand Down