From f6fc88ceb54d90dd77459fc4c5e20141aecc3858 Mon Sep 17 00:00:00 2001 From: Arthur Caron Date: Mon, 9 Dec 2024 18:13:30 +0100 Subject: [PATCH] ComputeEnginerInstance terminate instance without checking if it still exists. --- .../plugins/computeengine/ComputeEngineInstance.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineInstance.java b/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineInstance.java index 6bf1bd8e..db3cbea5 100644 --- a/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineInstance.java +++ b/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineInstance.java @@ -134,16 +134,8 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted .createSnapshotSync(cloud.getProjectId(), this.zone, this.getNodeName(), createSnapshotTimeout); } - Map filterLabel = ImmutableMap.of(CLOUD_ID_LABEL_KEY, cloud.getInstanceId()); - var instanceExistsInCloud = - cloud.getClient().listInstancesWithLabel(cloud.getProjectId(), filterLabel).stream() - .anyMatch(instance -> instance.getName().equals(name)); - - // If the instance exists in the cloud, attempt to terminate it. This is an async call and we // return immediately, hoping for the best. - if (instanceExistsInCloud) { - cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name); - } + cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name); } catch (CloudNotFoundException cnfe) { listener.error(cnfe.getMessage()); } catch (OperationException oe) {