Skip to content

Commit

Permalink
Make job docker container name meaningful. (#12503)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davinchia committed May 3, 2022
1 parent ce1936e commit c570225
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DockerProcessFactory implements ProcessFactory {

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

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

if (networkName != null) {
cmd.add("--network");
Expand Down Expand Up @@ -163,6 +169,26 @@ public Process create(final String jobId,
}
}

private static String createContainerName(final String fullImagePath, final String jobId, final int attempt) {
final var noVersion = fullImagePath.split(VERSION_DELIMITER)[0];

final var nameParts = noVersion.split(DOCKER_DELIMITER);
var imageName = nameParts[nameParts.length - 1];

final var randSuffix = RandomStringUtils.randomAlphabetic(5).toLowerCase();
final String suffix = "sync" + "-" + jobId + "-" + attempt + "-" + randSuffix;

var podName = imageName + "-" + suffix;
final var podNameLenLimit = 128;
if (podName.length() > podNameLenLimit) {
final var extra = podName.length() - podNameLenLimit;
imageName = imageName.substring(extra);
podName = imageName + "-" + suffix;
}

return podName;
}

private Path rebasePath(final Path jobRoot) {
final Path relativePath = workspaceRoot.relativize(jobRoot);
return DATA_MOUNT_DESTINATION.resolve(relativePath);
Expand Down

0 comments on commit c570225

Please sign in to comment.