Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure operations on a cluster are applied serially #937

Merged
merged 1 commit into from
Jan 9, 2018
Merged
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
29 changes: 28 additions & 1 deletion google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
Cluster: cluster,
}

mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Create(
project, zoneName, req).Do()
if err != nil {
Expand Down Expand Up @@ -677,6 +679,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredMasterAuthorizedNetworksConfig: expandMasterAuthorizedNetworksConfig(c),
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -713,6 +717,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredMasterVersion: desiredMasterVersion,
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -740,6 +746,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredNodeVersion: desiredNodeVersion,
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand All @@ -765,6 +773,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredAddonsConfig: expandClusterAddonsConfig(ac),
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -794,7 +804,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
NullFields: []string{"MaintenancePolicy"},
}
}

mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.SetMaintenancePolicy(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -824,6 +835,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredLocations: locations,
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand All @@ -848,6 +861,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
Enabled: enabled,
ForceSendFields: []string{"Enabled"},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.LegacyAbac(project, zoneName, clusterName, req).Do()
if err != nil {
return err
Expand All @@ -872,6 +887,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
DesiredMonitoringService: desiredMonitoringService,
},
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand All @@ -895,6 +912,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
req := &container.SetNetworkPolicyRequest{
NetworkPolicy: expandNetworkPolicy(np),
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.SetNetworkPolicy(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -927,6 +946,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
req := &container.SetLoggingServiceRequest{
LoggingService: logging,
}
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Logging(
project, zoneName, clusterName, req).Do()
if err != nil {
Expand Down Expand Up @@ -965,6 +986,8 @@ func resourceContainerClusterDelete(d *schema.ResourceData, meta interface{}) er
timeoutInMinutes := int(d.Timeout(schema.TimeoutDelete).Minutes())

log.Printf("[DEBUG] Deleting GKE cluster %s", d.Get("name").(string))
mutexKV.Lock(containerClusterMutexKey(project, zoneName, clusterName))
defer mutexKV.Unlock(containerClusterMutexKey(project, zoneName, clusterName))
op, err := config.clientContainer.Projects.Zones.Clusters.Delete(
project, zoneName, clusterName).Do()
if err != nil {
Expand Down Expand Up @@ -1211,3 +1234,7 @@ func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interfac

return []*schema.ResourceData{d}, nil
}

func containerClusterMutexKey(project, zone, clusterName string) string {
return fmt.Sprintf("google-container-cluster/%s/%s/%s", project, zone, clusterName)
}
11 changes: 11 additions & 0 deletions google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e
}
cluster := d.Get("cluster").(string)

mutexKV.Lock(containerClusterMutexKey(project, zone, cluster))
defer mutexKV.Unlock(containerClusterMutexKey(project, zone, cluster))
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Create(project, zone, cluster, req).Do()

if err != nil {
Expand Down Expand Up @@ -241,6 +243,8 @@ func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) e
cluster := d.Get("cluster").(string)
timeoutInMinutes := int(d.Timeout(schema.TimeoutDelete).Minutes())

mutexKV.Lock(containerClusterMutexKey(project, zone, cluster))
defer mutexKV.Unlock(containerClusterMutexKey(project, zone, cluster))
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Delete(
project, zone, cluster, name).Do()
if err != nil {
Expand Down Expand Up @@ -406,6 +410,7 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
if err != nil {
return err
}
cluster := d.Get("cluster").(string)
npName := d.Get(prefix + "name").(string)

if d.HasChange(prefix + "autoscaling") {
Expand All @@ -429,6 +434,8 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
req := &container.UpdateClusterRequest{
Update: update,
}
mutexKV.Lock(containerClusterMutexKey(project, zone, cluster))
defer mutexKV.Unlock(containerClusterMutexKey(project, zone, cluster))
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zone, clusterName, req).Do()
if err != nil {
Expand All @@ -453,6 +460,8 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
req := &container.SetNodePoolSizeRequest{
NodeCount: newSize,
}
mutexKV.Lock(containerClusterMutexKey(project, zone, cluster))
defer mutexKV.Unlock(containerClusterMutexKey(project, zone, cluster))
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.SetSize(project, zone, clusterName, npName, req).Do()
if err != nil {
return err
Expand Down Expand Up @@ -482,6 +491,8 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
req := &container.SetNodePoolManagementRequest{
Management: management,
}
mutexKV.Lock(containerClusterMutexKey(project, zone, cluster))
defer mutexKV.Unlock(containerClusterMutexKey(project, zone, cluster))
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.SetManagement(
project, zone, clusterName, npName, req).Do()

Expand Down