Skip to content

Commit cd33199

Browse files
committed
Correctly override apache/beam containers for RC on Dataflow runner job submission
1 parent 6251f10 commit cd33199

2 files changed

Lines changed: 55 additions & 65 deletions

File tree

runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,10 +1026,17 @@ protected RunnerApi.Pipeline applySdkEnvironmentOverrides(
10261026
if (containerImage.startsWith("apache/beam")
10271027
&& !updated
10281028
// don't update if the container image is already configured by DataflowRunner
1029+
<<<<<<< Updated upstream
10291030
&& !containerImage.equals(getV2SdkHarnessContainerImageForJob(options))) {
1031+
=======
1032+
&& !containerImage.equals(getContainerImageForJob(options))) {
1033+
String imageAndTag =
1034+
normalizeDataflowImageAndTag(
1035+
containerImage.substring(containerImage.lastIndexOf("/")));
1036+
>>>>>>> Stashed changes
10301037
containerImage =
10311038
DataflowRunnerInfo.getDataflowRunnerInfo().getContainerImageBaseRepository()
1032-
+ containerImage.substring(containerImage.lastIndexOf("/"));
1039+
+ imageAndTag;
10331040
}
10341041
environmentBuilder.setPayload(
10351042
RunnerApi.DockerPayload.newBuilder()
@@ -1042,6 +1049,21 @@ protected RunnerApi.Pipeline applySdkEnvironmentOverrides(
10421049
return pipelineBuilder.build();
10431050
}
10441051

1052+
static String normalizeDataflowImageAndTag(String imageAndTag) {
1053+
if (imageAndTag.startsWith("/beam_python") || imageAndTag.startsWith("/beam_go_")) {
1054+
int tagIdx = imageAndTag.lastIndexOf(":");
1055+
if (tagIdx > 0) {
1056+
// For release candidates, apache/beam_ images has rc tag while Dataflow does not
1057+
String tag = imageAndTag.substring(tagIdx); // e,g, ":2.xx.0"
1058+
int mayRc = tag.toLowerCase().lastIndexOf("rc");
1059+
if (mayRc > 0) {
1060+
imageAndTag = imageAndTag.substring(0, tagIdx) + tag.substring(0, mayRc);
1061+
}
1062+
}
1063+
}
1064+
return imageAndTag;
1065+
}
1066+
10451067
@VisibleForTesting
10461068
protected RunnerApi.Pipeline resolveArtifacts(RunnerApi.Pipeline pipeline) {
10471069
RunnerApi.Pipeline.Builder pipelineBuilder = pipeline.toBuilder();

runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowRunnerTest.java

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,45 +1201,32 @@ public void testNoStagingLocationAndNoTempLocationFails() {
12011201
DataflowRunner.fromOptions(options);
12021202
}
12031203

1204+
private static RunnerApi.Pipeline containerUrlToPipeline(String url) {
1205+
return RunnerApi.Pipeline.newBuilder()
1206+
.setComponents(
1207+
RunnerApi.Components.newBuilder()
1208+
.putEnvironments(
1209+
"env",
1210+
RunnerApi.Environment.newBuilder()
1211+
.setUrn(BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER))
1212+
.setPayload(
1213+
RunnerApi.DockerPayload.newBuilder()
1214+
.setContainerImage(url)
1215+
.build()
1216+
.toByteString())
1217+
.build()))
1218+
.build();
1219+
}
1220+
12041221
@Test
12051222
public void testApplySdkEnvironmentOverrides() throws IOException {
12061223
DataflowPipelineOptions options = buildPipelineOptions();
12071224
String dockerHubPythonContainerUrl = "apache/beam_python3.9_sdk:latest";
12081225
String gcrPythonContainerUrl = "gcr.io/apache-beam-testing/beam-sdk/beam_python3.9_sdk:latest";
12091226
options.setSdkHarnessContainerImageOverrides(".*python.*," + gcrPythonContainerUrl);
12101227
DataflowRunner runner = DataflowRunner.fromOptions(options);
1211-
RunnerApi.Pipeline pipeline =
1212-
RunnerApi.Pipeline.newBuilder()
1213-
.setComponents(
1214-
RunnerApi.Components.newBuilder()
1215-
.putEnvironments(
1216-
"env",
1217-
RunnerApi.Environment.newBuilder()
1218-
.setUrn(
1219-
BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER))
1220-
.setPayload(
1221-
RunnerApi.DockerPayload.newBuilder()
1222-
.setContainerImage(dockerHubPythonContainerUrl)
1223-
.build()
1224-
.toByteString())
1225-
.build()))
1226-
.build();
1227-
RunnerApi.Pipeline expectedPipeline =
1228-
RunnerApi.Pipeline.newBuilder()
1229-
.setComponents(
1230-
RunnerApi.Components.newBuilder()
1231-
.putEnvironments(
1232-
"env",
1233-
RunnerApi.Environment.newBuilder()
1234-
.setUrn(
1235-
BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER))
1236-
.setPayload(
1237-
RunnerApi.DockerPayload.newBuilder()
1238-
.setContainerImage(gcrPythonContainerUrl)
1239-
.build()
1240-
.toByteString())
1241-
.build()))
1242-
.build();
1228+
RunnerApi.Pipeline pipeline = containerUrlToPipeline(dockerHubPythonContainerUrl);
1229+
RunnerApi.Pipeline expectedPipeline = containerUrlToPipeline(gcrPythonContainerUrl);
12431230
assertThat(runner.applySdkEnvironmentOverrides(pipeline, options), equalTo(expectedPipeline));
12441231
}
12451232

@@ -1249,38 +1236,19 @@ public void testApplySdkEnvironmentOverridesByDefault() throws IOException {
12491236
String dockerHubPythonContainerUrl = "apache/beam_python3.9_sdk:latest";
12501237
String gcrPythonContainerUrl = "gcr.io/cloud-dataflow/v1beta3/beam_python3.9_sdk:latest";
12511238
DataflowRunner runner = DataflowRunner.fromOptions(options);
1252-
RunnerApi.Pipeline pipeline =
1253-
RunnerApi.Pipeline.newBuilder()
1254-
.setComponents(
1255-
RunnerApi.Components.newBuilder()
1256-
.putEnvironments(
1257-
"env",
1258-
RunnerApi.Environment.newBuilder()
1259-
.setUrn(
1260-
BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER))
1261-
.setPayload(
1262-
RunnerApi.DockerPayload.newBuilder()
1263-
.setContainerImage(dockerHubPythonContainerUrl)
1264-
.build()
1265-
.toByteString())
1266-
.build()))
1267-
.build();
1268-
RunnerApi.Pipeline expectedPipeline =
1269-
RunnerApi.Pipeline.newBuilder()
1270-
.setComponents(
1271-
RunnerApi.Components.newBuilder()
1272-
.putEnvironments(
1273-
"env",
1274-
RunnerApi.Environment.newBuilder()
1275-
.setUrn(
1276-
BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER))
1277-
.setPayload(
1278-
RunnerApi.DockerPayload.newBuilder()
1279-
.setContainerImage(gcrPythonContainerUrl)
1280-
.build()
1281-
.toByteString())
1282-
.build()))
1283-
.build();
1239+
RunnerApi.Pipeline pipeline = containerUrlToPipeline(dockerHubPythonContainerUrl);
1240+
RunnerApi.Pipeline expectedPipeline = containerUrlToPipeline(gcrPythonContainerUrl);
1241+
assertThat(runner.applySdkEnvironmentOverrides(pipeline, options), equalTo(expectedPipeline));
1242+
}
1243+
1244+
@Test
1245+
public void testApplySdkEnvironmentOverridesRcByDefault() throws IOException {
1246+
DataflowPipelineOptions options = buildPipelineOptions();
1247+
String dockerHubPythonContainerUrl = "apache/beam_python3.9_sdk:2.68.0rc2";
1248+
String gcrPythonContainerUrl = "gcr.io/cloud-dataflow/v1beta3/beam_python3.9_sdk:2.68.0";
1249+
DataflowRunner runner = DataflowRunner.fromOptions(options);
1250+
RunnerApi.Pipeline pipeline = containerUrlToPipeline(dockerHubPythonContainerUrl);
1251+
RunnerApi.Pipeline expectedPipeline = containerUrlToPipeline(gcrPythonContainerUrl);
12841252
assertThat(runner.applySdkEnvironmentOverrides(pipeline, options), equalTo(expectedPipeline));
12851253
}
12861254

0 commit comments

Comments
 (0)