Skip to content

Commit

Permalink
feat(provider/google): Support private worker pool in gcb CI (#1301)
Browse files Browse the repository at this point in the history
* Support GCB worker pool

* Add test for pool option

---------

Co-authored-by: Himanshu Gusain <[email protected]>
  • Loading branch information
himanhsugusain and himanhsugusain authored Jan 16, 2025
1 parent 7ac8f97 commit 9dbe94d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ GoogleCloudBuildClient create(GoogleCredentials credentials, String projectId) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.api.services.cloudbuild.v1.model.BuildTrigger;
import com.google.api.services.cloudbuild.v1.model.ListBuildTriggersResponse;
import com.google.api.services.cloudbuild.v1.model.Operation;
import com.google.api.services.cloudbuild.v1.model.PoolOption;
import com.google.api.services.cloudbuild.v1.model.RepoSource;
import com.netflix.spinnaker.igor.RedisConfig;
import com.netflix.spinnaker.igor.config.LockManagerConfig;
Expand Down Expand Up @@ -135,6 +136,34 @@ public void presentAccountTest() throws Exception {
assertThat(stubCloudBuildService.findUnmatchedRequests().getRequests()).isEmpty();
}

public void presentAccountTestWithPoolOption() throws Exception {
PoolOption poolOption = new PoolOption();
poolOption.setName(
"projects/spinnaker-gcb-test-2/locations/gcb-location/workerPools/test-pool");
BuildOptions buildOptions = new BuildOptions().setPool(poolOption);
String buildRequest = objectMapper.writeValueAsString(buildRequest().setOptions(buildOptions));
String taggedBuild = objectMapper.writeValueAsString(taggedBuild());
String buildResponse = objectMapper.writeValueAsString(buildResponse());
String operationResponse = objectMapper.writeValueAsString(operationResponse());
stubCloudBuildService.stubFor(
WireMock.post(
urlEqualTo("/v1/projects/spinnaker-gcb-test-2/locations/gcb-locations/builds"))
.withHeader("Authorization", equalTo("Bearer test-token"))
.withRequestBody(equalToJson(taggedBuild))
.willReturn(aResponse().withStatus(200).withBody(operationResponse)));

mockMvc
.perform(
post("/gcb/builds/create/gcb-account")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(buildRequest))
.andExpect(status().is(200))
.andExpect(content().json(buildResponse));

assertThat(stubCloudBuildService.findUnmatchedRequests().getRequests()).isEmpty();
}

@Test
public void updateBuildTest() throws Exception {
String buildId = "f0fc7c14-6035-4e5c-bda1-4848a73af5b4";
Expand Down

0 comments on commit 9dbe94d

Please sign in to comment.