refactor(gce): Remove some redundant arguments from GCEUtil.queryImage
MODIFY
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtil.groovy
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtil.groovy
@@ -83,10 +83,8 @@ class GCEUtil {
}
}
- static Image queryImage(String projectName,
- String imageName,
+ static Image queryImage(String imageName,
GoogleNamedAccountCredentials credentials,
- Compute compute,
Task task,
String phase,
String clouddriverUserAgentApplicationName,
@@ -95,10 +93,10 @@ class GCEUtil {
task.updateStatus phase, "Looking up image $imageName..."
def filter = "name eq $imageName"
- def imageProjects = [projectName] + credentials?.imageProjects + baseImageProjects - null
+ def imageProjects = [credentials.project] + credentials?.imageProjects + baseImageProjects - null
def sourceImage = null
- def imageListBatch = new GoogleBatchRequest(compute, clouddriverUserAgentApplicationName)
+ def imageListBatch = new GoogleBatchRequest(credentials.compute, clouddriverUserAgentApplicationName)
def imageListCallback = new JsonBatchCallback<ImageList>() {
@Override
void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
@@ -114,7 +112,7 @@ class GCEUtil {
}
imageProjects.each { imageProject ->
- def imagesList = compute.images().list(imageProject)
+ def imagesList = credentials.compute.images().list(imageProject)
imagesList.setFilter(filter)
imageListBatch.queue(imagesList, imageListCallback)
}
@@ -176,10 +174,8 @@ class GCEUtil {
executor
)
} else {
- return queryImage(description.credentials.project,
- description.image,
+ return queryImage(description.image,
description.credentials,
- description.credentials.compute,
task,
phase,
clouddriverUserAgentApplicationName,
@@ -799,10 +795,8 @@ class GCEUtil {
sourceImage =
disk.is(firstPersistentDisk)
? bootImage
- : queryImage(credentials.project,
- disk.sourceImage,
+ : queryImage(disk.sourceImage,
credentials,
- credentials.compute,
task,
phase,
clouddriverUserAgentApplicationName,

MODIFY
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/ops/UpsertGoogleImageTagsAtomicOperation.groovy
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/ops/UpsertGoogleImageTagsAtomicOperation.groovy
@@ -22,7 +22,6 @@ import com.netflix.spinnaker.clouddriver.data.task.TaskRepository
import com.netflix.spinnaker.clouddriver.google.config.GoogleConfigurationProperties
import com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil
import com.netflix.spinnaker.clouddriver.google.deploy.description.UpsertGoogleImageTagsDescription
-import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation
import org.springframework.beans.factory.annotation.Autowired
/**
@@ -62,10 +61,8 @@ class UpsertGoogleImageTagsAtomicOperation extends GoogleAtomicOperation<Void> {
def project = credentials.project
def imageName = description.imageName
def tags = description.tags
- def image = GCEUtil.queryImage(project,
- imageName,
+ def image = GCEUtil.queryImage(imageName,
credentials,
- compute,
task,
BASE_PHASE,
clouddriverUserAgentApplicationName,

MODIFY
clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtilSpec.groovy
clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtilSpec.groovy
@@ -39,6 +39,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleHttpLoadBalancer
import com.netflix.spinnaker.clouddriver.google.model.loadbalancing.GoogleNetworkLoadBalancer
import com.netflix.spinnaker.clouddriver.google.provider.view.GoogleLoadBalancerProvider
+ import com.netflix.spinnaker.clouddriver.google.security.FakeGoogleCredentials
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials
import com.netflix.spinnaker.kork.artifacts.model.Artifact
import spock.lang.Shared
@@ -92,6 +93,10 @@ package com.netflix.spinnaker.clouddriver.google.deploy
new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).build()
def compute = new Compute.Builder(
httpTransport, jsonFactory, httpRequestInitializer).setApplicationName(GOOGLE_APPLICATION_NAME).build()
+ GoogleNamedAccountCredentials credentials = new GoogleNamedAccountCredentials.Builder().project(PROJECT_NAME)
+ .compute(compute)
+ .credentials(new FakeGoogleCredentials(PROJECT_NAME))
+ .build();
def soughtImage = new Image(name: IMAGE_NAME)
def imageList = new ImageList(
selfLink: "https://compute.googleapis.com/compute/alpha/projects/$PROJECT_NAME/global/images",
@@ -99,7 +104,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy
)
when:
- def sourceImage = GCEUtil.queryImage(PROJECT_NAME, IMAGE_NAME, null, compute, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
+ def sourceImage = GCEUtil.queryImage(IMAGE_NAME, credentials, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
then:
1 * executorMock.timeExecuteBatch(_, "findImage", _) >> {
@@ -124,7 +129,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy
new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).build()
def compute = new Compute.Builder(
httpTransport, jsonFactory, httpRequestInitializer).setApplicationName(GOOGLE_APPLICATION_NAME).build()
- def credentials = new GoogleNamedAccountCredentials.Builder().compute(compute).imageProjects([IMAGE_PROJECT_NAME]).build()
+ def credentials = new GoogleNamedAccountCredentials.Builder().project(PROJECT_NAME).compute(compute).imageProjects([IMAGE_PROJECT_NAME]).build()
def soughtImage = new Image(name: IMAGE_NAME)
def imageList = new ImageList(
selfLink: "https://compute.googleapis.com/compute/alpha/projects/$PROJECT_NAME/global/images",
@@ -132,7 +137,7 @@ package com.netflix.spinnaker.clouddriver.google.deploy
)
when:
- def sourceImage = GCEUtil.queryImage(PROJECT_NAME, IMAGE_NAME, credentials, compute, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
+ def sourceImage = GCEUtil.queryImage(IMAGE_NAME, credentials, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
then:
1 * executorMock.timeExecuteBatch(_, "findImage", _) >> {
@@ -157,10 +162,14 @@ package com.netflix.spinnaker.clouddriver.google.deploy
new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).build()
def compute = new Compute.Builder(
httpTransport, jsonFactory, httpRequestInitializer).setApplicationName(GOOGLE_APPLICATION_NAME).build()
+ GoogleNamedAccountCredentials credentials = new GoogleNamedAccountCredentials.Builder().project(PROJECT_NAME)
+ .compute(compute)
+ .credentials(new FakeGoogleCredentials(PROJECT_NAME))
+ .build();
def emptyImageList = new ImageList()
when:
- GCEUtil.queryImage(PROJECT_NAME, IMAGE_NAME, null, compute, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
+ GCEUtil.queryImage(IMAGE_NAME, credentials, taskMock, PHASE, GOOGLE_APPLICATION_NAME, BASE_IMAGE_PROJECTS, executorMock)
then:
1 * executorMock.timeExecuteBatch(_, "findImage", _) >> {
@@ -247,10 +256,8 @@ package com.netflix.spinnaker.clouddriver.google.deploy
executor)
then:
- 1 * GCEUtil.queryImage(PROJECT_NAME,
- IMAGE_NAME,
+ 1 * GCEUtil.queryImage(IMAGE_NAME,
credentials,
- compute,
taskMock,
PHASE,
GOOGLE_APPLICATION_NAME,

refactor(gce): Remove some redundant arguments from GCEUtil.queryImage (#3624)