Skip to content

Commit 9dbe94d

Browse files
feat(provider/google): Support private worker pool in gcb CI (#1301)
* Support GCB worker pool * Add test for pool option --------- Co-authored-by: Himanshu Gusain <[email protected]>
1 parent 7ac8f97 commit 9dbe94d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

igor-web/src/main/java/com/netflix/spinnaker/igor/gcb/GoogleCloudBuildClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ GoogleCloudBuildClient create(GoogleCredentials credentials, String projectId) {
5555
}
5656

5757
Operation createBuild(Build build) {
58+
if (build.getOptions() != null && build.getOptions().getPool() != null) {
59+
String[] parts = build.getOptions().getPool().getName().split("/");
60+
String parent = "projects/" + parts[1] + "/locations/" + parts[3];
61+
return executor.execute(
62+
() -> cloudBuild.projects().locations().builds().create(parent, build));
63+
}
5864
return executor.execute(() -> cloudBuild.projects().builds().create(projectId, build));
5965
}
6066

igor-web/src/test/groovy/com/netflix/spinnaker/igor/gcb/GoogleCloudBuildTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.api.services.cloudbuild.v1.model.BuildTrigger;
3737
import com.google.api.services.cloudbuild.v1.model.ListBuildTriggersResponse;
3838
import com.google.api.services.cloudbuild.v1.model.Operation;
39+
import com.google.api.services.cloudbuild.v1.model.PoolOption;
3940
import com.google.api.services.cloudbuild.v1.model.RepoSource;
4041
import com.netflix.spinnaker.igor.RedisConfig;
4142
import com.netflix.spinnaker.igor.config.LockManagerConfig;
@@ -135,6 +136,34 @@ public void presentAccountTest() throws Exception {
135136
assertThat(stubCloudBuildService.findUnmatchedRequests().getRequests()).isEmpty();
136137
}
137138

139+
public void presentAccountTestWithPoolOption() throws Exception {
140+
PoolOption poolOption = new PoolOption();
141+
poolOption.setName(
142+
"projects/spinnaker-gcb-test-2/locations/gcb-location/workerPools/test-pool");
143+
BuildOptions buildOptions = new BuildOptions().setPool(poolOption);
144+
String buildRequest = objectMapper.writeValueAsString(buildRequest().setOptions(buildOptions));
145+
String taggedBuild = objectMapper.writeValueAsString(taggedBuild());
146+
String buildResponse = objectMapper.writeValueAsString(buildResponse());
147+
String operationResponse = objectMapper.writeValueAsString(operationResponse());
148+
stubCloudBuildService.stubFor(
149+
WireMock.post(
150+
urlEqualTo("/v1/projects/spinnaker-gcb-test-2/locations/gcb-locations/builds"))
151+
.withHeader("Authorization", equalTo("Bearer test-token"))
152+
.withRequestBody(equalToJson(taggedBuild))
153+
.willReturn(aResponse().withStatus(200).withBody(operationResponse)));
154+
155+
mockMvc
156+
.perform(
157+
post("/gcb/builds/create/gcb-account")
158+
.accept(MediaType.APPLICATION_JSON)
159+
.contentType(MediaType.APPLICATION_JSON)
160+
.content(buildRequest))
161+
.andExpect(status().is(200))
162+
.andExpect(content().json(buildResponse));
163+
164+
assertThat(stubCloudBuildService.findUnmatchedRequests().getRequests()).isEmpty();
165+
}
166+
138167
@Test
139168
public void updateBuildTest() throws Exception {
140169
String buildId = "f0fc7c14-6035-4e5c-bda1-4848a73af5b4";

0 commit comments

Comments
 (0)