Skip to content

Commit c570225

Browse files
authored
Make job docker container name meaningful. (#12503)
Closes #9584. This now follows the Kubernetes name convention of <image-name>-<job-id>-<attempt-number>. This should make things easier for oss users doing oncall for docker deployments. Mirror the Kubernetes name convention: https://github.com/airbytehq/airbyte/blob/master/airbyte-workers/src/main/java/io/airbyte/workers/process/KubeProcessFactory.java#L180 We can probably reuse the naming functions across both processes. We are going to do more changes in this area around making things more ergonomic (e.g. instead of always using sync, we want to replace this with the actual operation - discover, check connection etc.) so we'll do refactoring in that PR. I want to unblock this in the time being since open source users are having difficulty debugging now.
1 parent ce1936e commit c570225

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

airbyte-workers/src/main/java/io/airbyte/workers/process/DockerProcessFactory.java

+26
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.concurrent.TimeUnit;
26+
import org.apache.commons.lang3.RandomStringUtils;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

2930
public class DockerProcessFactory implements ProcessFactory {
3031

3132
private static final Logger LOGGER = LoggerFactory.getLogger(DockerProcessFactory.class);
33+
private static final String VERSION_DELIMITER = ":";
34+
private static final String DOCKER_DELIMITER = "/";
3235

3336
private static final Path DATA_MOUNT_DESTINATION = Path.of("/data");
3437
private static final Path LOCAL_MOUNT_DESTINATION = Path.of("/local");
@@ -114,6 +117,9 @@ public Process create(final String jobId,
114117
rebasePath(jobRoot).toString(), // rebases the job root on the job data mount
115118
"--log-driver",
116119
"none");
120+
final String containerName = createContainerName(imageName, jobId, attempt);
121+
cmd.add("--name");
122+
cmd.add(containerName);
117123

118124
if (networkName != null) {
119125
cmd.add("--network");
@@ -163,6 +169,26 @@ public Process create(final String jobId,
163169
}
164170
}
165171

172+
private static String createContainerName(final String fullImagePath, final String jobId, final int attempt) {
173+
final var noVersion = fullImagePath.split(VERSION_DELIMITER)[0];
174+
175+
final var nameParts = noVersion.split(DOCKER_DELIMITER);
176+
var imageName = nameParts[nameParts.length - 1];
177+
178+
final var randSuffix = RandomStringUtils.randomAlphabetic(5).toLowerCase();
179+
final String suffix = "sync" + "-" + jobId + "-" + attempt + "-" + randSuffix;
180+
181+
var podName = imageName + "-" + suffix;
182+
final var podNameLenLimit = 128;
183+
if (podName.length() > podNameLenLimit) {
184+
final var extra = podName.length() - podNameLenLimit;
185+
imageName = imageName.substring(extra);
186+
podName = imageName + "-" + suffix;
187+
}
188+
189+
return podName;
190+
}
191+
166192
private Path rebasePath(final Path jobRoot) {
167193
final Path relativePath = workspaceRoot.relativize(jobRoot);
168194
return DATA_MOUNT_DESTINATION.resolve(relativePath);

0 commit comments

Comments
 (0)