Skip to content

Commit 691a54b

Browse files
committed
add timeout to init container command
1 parent 10f17ef commit 691a54b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ public class KubePodProcess extends Process implements KubePod {
119119
private static final int KILLED_EXIT_CODE = 143;
120120
private static final int STDIN_REMOTE_PORT = 9001;
121121

122+
// init container should fail if SUCCESS_FILE_NAME is not copied within INIT_RETRY_TIMEOUT_MINUTES
123+
private static final double INIT_SLEEP_PERIOD_SECONDS = 0.1;
124+
private static final Duration INIT_RETRY_TIMEOUT_MINUTES = Duration.ofMinutes(5);
125+
private static final double INIT_RETRY_MAX_ITERATIONS = INIT_RETRY_TIMEOUT_MINUTES.toSeconds() / INIT_SLEEP_PERIOD_SECONDS;
126+
122127
private final KubernetesClient fabricClient;
123128
private final Pod podDefinition;
124129
// Necessary since it is not possible to retrieve the pod's actual exit code upon termination. This
@@ -159,7 +164,16 @@ private static Container getInit(final boolean usesStdin,
159164
initEntrypointStr = String.format("mkfifo %s && ", STDIN_PIPE_FILE) + initEntrypointStr;
160165
}
161166

162-
initEntrypointStr = initEntrypointStr + String.format(" && until [ -f %s ]; do sleep 0.1; done;", SUCCESS_FILE_NAME);
167+
initEntrypointStr = initEntrypointStr +
168+
String.format(
169+
" ITERATION=0 && MAX_ITERATION=%s && "
170+
+ "until [ -f %s -o $ITERATION -ge $MAX_ITERATION ]; "
171+
+ "do ((ITERATION=ITERATION+1)) && sleep %s; done; "
172+
+ "if [ -f %s ]; then exit 0; else exit 1; fi",
173+
INIT_RETRY_MAX_ITERATIONS,
174+
SUCCESS_FILE_NAME,
175+
INIT_SLEEP_PERIOD_SECONDS,
176+
SUCCESS_FILE_NAME);
163177

164178
return new ContainerBuilder()
165179
.withName(INIT_CONTAINER_NAME)

0 commit comments

Comments
 (0)