Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 7101055

Browse files
fix(clouddriver-google): Fix logic when Instance Types are available only in selected Zones/Regions
1 parent 8ff849d commit 7101055

File tree

2 files changed

+250
-38
lines changed

2 files changed

+250
-38
lines changed

clouddriver-google/src/main/java/com/netflix/spinnaker/clouddriver/google/deploy/handlers/BasicGoogleDeployHandler.java

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.netflix.spinnaker.clouddriver.google.deploy.GoogleOperationPoller;
5757
import com.netflix.spinnaker.clouddriver.google.deploy.SafeRetry;
5858
import com.netflix.spinnaker.clouddriver.google.deploy.description.BasicGoogleDeployDescription;
59+
import com.netflix.spinnaker.clouddriver.google.deploy.exception.GoogleOperationException;
5960
import com.netflix.spinnaker.clouddriver.google.deploy.ops.GoogleUserDataProvider;
6061
import com.netflix.spinnaker.clouddriver.google.model.GoogleHealthCheck;
6162
import com.netflix.spinnaker.clouddriver.google.model.GoogleLabeledResource;
@@ -289,8 +290,45 @@ protected String getMachineTypeNameFromInput(
289290
if (description.getInstanceType().contains("custom-")) {
290291
return description.getInstanceType();
291292
} else {
292-
return GCEUtil.queryMachineType(
293-
description.getInstanceType(), location, description.getCredentials(), task, BASE_PHASE);
293+
List<String> queryZone =
294+
description.getRegional()
295+
? (description.getSelectZones()
296+
? description.getDistributionPolicy().getZones()
297+
: Collections.singletonList(location))
298+
: Collections.singletonList(location);
299+
String machineTypeName = "";
300+
for (String zoneOrLocation : queryZone) {
301+
String msg =
302+
description.getRegional()
303+
? (description.getSelectZones()
304+
? "Machine type "
305+
+ description.getInstanceType()
306+
+ " not found in zone "
307+
+ zoneOrLocation
308+
+ ". When using selectZones, the machine type must be available in all selected zones."
309+
: "Machine type "
310+
+ description.getInstanceType()
311+
+ " not found in zone "
312+
+ zoneOrLocation
313+
+ ". When using Regional distribution without explicit selection of Zones, the machine type must be available in all zones of the region.")
314+
: "Machine type "
315+
+ description.getInstanceType()
316+
+ " not found in region "
317+
+ zoneOrLocation
318+
+ ".";
319+
try {
320+
machineTypeName =
321+
queryMachineType(
322+
description.getInstanceType(),
323+
zoneOrLocation,
324+
description.getCredentials(),
325+
task,
326+
BASE_PHASE);
327+
} catch (GoogleOperationException e) {
328+
throw new GoogleOperationException(msg);
329+
}
330+
}
331+
return machineTypeName;
294332
}
295333
}
296334

@@ -300,15 +338,15 @@ protected GoogleNetwork buildNetworkFromInput(
300338
StringUtils.isNotBlank(description.getNetwork())
301339
? description.getNetwork()
302340
: DEFAULT_NETWORK_NAME;
303-
return GCEUtil.queryNetwork(
341+
return queryNetwork(
304342
description.getAccountName(), networkName, task, BASE_PHASE, googleNetworkProvider);
305343
}
306344

307345
protected GoogleSubnet buildSubnetFromInput(
308346
BasicGoogleDeployDescription description, Task task, GoogleNetwork network, String region) {
309347
GoogleSubnet subnet =
310348
StringUtils.isNotBlank(description.getSubnet())
311-
? GCEUtil.querySubnet(
349+
? querySubnet(
312350
description.getAccountName(),
313351
region,
314352
description.getSubnet(),
@@ -323,7 +361,7 @@ protected GoogleSubnet buildSubnetFromInput(
323361
if (subnet != null && network.getId().contains("/") && network.getAutoCreateSubnets()) {
324362
// Auto-created subnets have the same name as the containing network.
325363
subnet =
326-
GCEUtil.querySubnet(
364+
querySubnet(
327365
description.getAccountName(),
328366
region,
329367
network.getId(),
@@ -346,7 +384,7 @@ protected LoadBalancerInfo getLoadBalancerToUpdateFromInput(
346384
// GCEUtil.queryAllLoadBalancers() will throw an exception if a referenced load balancer cannot
347385
// be resolved.
348386
List<GoogleLoadBalancerView> foundLB =
349-
GCEUtil.queryAllLoadBalancers(
387+
queryAllLoadBalancers(
350388
googleLoadBalancerProvider, description.getLoadBalancers(), task, BASE_PHASE);
351389
// Queue ILBs to update, but wait to update metadata until Https LBs are calculated.
352390
info.internalLoadBalancers =
@@ -381,7 +419,7 @@ protected LoadBalancerInfo getLoadBalancerToUpdateFromInput(
381419
}
382420

383421
protected Image buildBootImage(BasicGoogleDeployDescription description, Task task) {
384-
return GCEUtil.getBootImage(
422+
return getBootImage(
385423
description,
386424
task,
387425
BASE_PHASE,
@@ -488,7 +526,7 @@ protected List<BackendService> getBackendServiceToUpdate(
488526
.map(GoogleLoadBalancerView::getName)
489527
.collect(Collectors.toList()));
490528
globalLbNames.addAll(
491-
GCEUtil.resolveHttpLoadBalancerNamesMetadata(
529+
resolveHttpLoadBalancerNamesMetadata(
492530
backendServices,
493531
description.getCredentials().getCompute(),
494532
description.getCredentials().getProject(),
@@ -500,15 +538,15 @@ protected List<BackendService> getBackendServiceToUpdate(
500538
try {
501539
BackendService backendService =
502540
getBackendServiceFromProvider(description.getCredentials(), backendServiceName);
503-
GCEUtil.updateMetadataWithLoadBalancingPolicy(policy, instanceMetadata, objectMapper);
504-
Backend backendToAdd = GCEUtil.backendFromLoadBalancingPolicy(policy);
541+
updateMetadataWithLoadBalancingPolicy(policy, instanceMetadata, objectMapper);
542+
Backend backendToAdd = backendFromLoadBalancingPolicy(policy);
505543
if (description.getRegional()) {
506544
backendToAdd.setGroup(
507-
GCEUtil.buildRegionalServerGroupUrl(
545+
buildRegionalServerGroupUrl(
508546
description.getCredentials().getProject(), region, serverGroupName));
509547
} else {
510548
backendToAdd.setGroup(
511-
GCEUtil.buildZonalServerGroupUrl(
549+
buildZonalServerGroupUrl(
512550
description.getCredentials().getProject(),
513551
description.getZone(),
514552
serverGroupName));
@@ -587,17 +625,17 @@ protected List<BackendService> getRegionBackendServicesToUpdate(
587625
description.getCredentials(), region, serverGroupName);
588626
Backend backendToAdd;
589627
if (internalHttpLbBackendServices.contains(backendServiceName)) {
590-
backendToAdd = GCEUtil.backendFromLoadBalancingPolicy(policy);
628+
backendToAdd = backendFromLoadBalancingPolicy(policy);
591629
} else {
592630
backendToAdd = new Backend();
593631
}
594632
if (description.getRegional()) {
595633
backendToAdd.setGroup(
596-
GCEUtil.buildRegionalServerGroupUrl(
634+
buildRegionalServerGroupUrl(
597635
description.getCredentials().getProject(), region, serverGroupName));
598636
} else {
599637
backendToAdd.setGroup(
600-
GCEUtil.buildZonalServerGroupUrl(
638+
buildZonalServerGroupUrl(
601639
description.getCredentials().getProject(),
602640
description.getZone(),
603641
serverGroupName));
@@ -659,11 +697,11 @@ protected void addSelectZonesToInstanceMetadata(BasicGoogleDeployDescription des
659697
}
660698

661699
protected Metadata buildMetadataFromInstanceMetadata(BasicGoogleDeployDescription description) {
662-
return GCEUtil.buildMetadataFromMap(description.getInstanceMetadata());
700+
return buildMetadataFromMap(description.getInstanceMetadata());
663701
}
664702

665703
protected Tags buildTagsFromInput(BasicGoogleDeployDescription description) {
666-
return GCEUtil.buildTagsFromList(description.getTags());
704+
return buildTagsFromList(description.getTags());
667705
}
668706

669707
protected List<ServiceAccount> buildServiceAccountFromInput(
@@ -673,12 +711,11 @@ protected List<ServiceAccount> buildServiceAccountFromInput(
673711
description.setServiceAccountEmail("default");
674712
}
675713

676-
return GCEUtil.buildServiceAccount(
677-
description.getServiceAccountEmail(), description.getAuthScopes());
714+
return buildServiceAccount(description.getServiceAccountEmail(), description.getAuthScopes());
678715
}
679716

680717
protected Scheduling buildSchedulingFromInput(BasicGoogleDeployDescription description) {
681-
return GCEUtil.buildScheduling(description);
718+
return buildScheduling(description);
682719
}
683720

684721
protected Map<String, String> buildLabelsFromInput(
@@ -762,8 +799,8 @@ protected void addShieldedVmConfigToInstanceProperties(
762799
BasicGoogleDeployDescription description,
763800
InstanceProperties instanceProperties,
764801
Image bootImage) {
765-
if (GCEUtil.isShieldedVmCompatible(bootImage)) {
766-
instanceProperties.setShieldedVmConfig(GCEUtil.buildShieldedVmConfig(description));
802+
if (isShieldedVmCompatible(bootImage)) {
803+
instanceProperties.setShieldedVmConfig(buildShieldedVmConfig(description));
767804
}
768805
}
769806

@@ -790,7 +827,7 @@ protected void setAutoscalerCapacityFromInput(BasicGoogleDeployDescription descr
790827
description.getAutoscalingPolicy().setMinNumReplicas(description.getCapacity().getMin());
791828
description.getAutoscalingPolicy().setMaxNumReplicas(description.getCapacity().getMax());
792829
}
793-
GCEUtil.calibrateTargetSizeWithAutoscaler(description);
830+
calibrateTargetSizeWithAutoscaler(description);
794831
}
795832
}
796833

@@ -817,7 +854,7 @@ protected void setCapacityFromSource(BasicGoogleDeployDescription description, T
817854

818855
// Locate the ancestor server group.
819856
GoogleServerGroup.View ancestorServerGroup =
820-
GCEUtil.queryServerGroup(
857+
queryServerGroup(
821858
googleClusterProvider,
822859
description.getAccountName(),
823860
source.getRegion(),
@@ -834,7 +871,7 @@ protected List<InstanceGroupManagerAutoHealingPolicy> buildAutoHealingPolicyFrom
834871
&& StringUtils.isNotBlank(description.getAutoHealingPolicy().getHealthCheck())) {
835872
autoHealingHealthCheck =
836873
(GoogleHealthCheck)
837-
GCEUtil.queryHealthCheck(
874+
queryHealthCheck(
838875
description.getCredentials().getProject(),
839876
description.getAccountName(),
840877
description.getAutoHealingPolicy().getHealthCheck(),
@@ -972,9 +1009,7 @@ protected void setDistributionPolicyToInstanceGroup(
9721009
.map(
9731010
it ->
9741011
new DistributionPolicyZoneConfiguration()
975-
.setZone(
976-
GCEUtil.buildZoneUrl(
977-
description.getCredentials().getProject(), it)))
1012+
.setZone(buildZoneUrl(description.getCredentials().getProject(), it)))
9781013
.collect(Collectors.toList());
9791014
distributionPolicy.setZones(selectedZones);
9801015
}
@@ -1118,7 +1153,7 @@ private String createInstanceTemplateAndWait(
11181153
instanceTemplateCreateOperation.getName(),
11191154
null,
11201155
task,
1121-
"instance template " + GCEUtil.getLocalName(instanceTemplateUrl),
1156+
"instance template " + getLocalName(instanceTemplateUrl),
11221157
BASE_PHASE);
11231158
return instanceTemplateUrl;
11241159
}
@@ -1176,7 +1211,7 @@ protected void createRegionalAutoscaler(
11761211
BASE_PHASE, String.format("Creating regional autoscaler for %s...", serverGroupName));
11771212

11781213
Autoscaler autoscaler =
1179-
GCEUtil.buildAutoscaler(serverGroupName, targetLink, description.getAutoscalingPolicy());
1214+
buildAutoscaler(serverGroupName, targetLink, description.getAutoscalingPolicy());
11801215

11811216
timeExecute(
11821217
description
@@ -1246,7 +1281,7 @@ protected void createAutoscaler(
12461281
BASE_PHASE, String.format("Creating zonal autoscaler for %s...", serverGroupName));
12471282

12481283
Autoscaler autoscaler =
1249-
GCEUtil.buildAutoscaler(serverGroupName, targetLink, description.getAutoscalingPolicy());
1284+
buildAutoscaler(serverGroupName, targetLink, description.getAutoscalingPolicy());
12501285

12511286
timeExecute(
12521287
description

0 commit comments

Comments
 (0)