@@ -119,6 +119,11 @@ public class KubePodProcess extends Process implements KubePod {
119
119
private static final int KILLED_EXIT_CODE = 143 ;
120
120
private static final int STDIN_REMOTE_PORT = 9001 ;
121
121
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
+
122
127
private final KubernetesClient fabricClient ;
123
128
private final Pod podDefinition ;
124
129
// 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,
159
164
initEntrypointStr = String .format ("mkfifo %s && " , STDIN_PIPE_FILE ) + initEntrypointStr ;
160
165
}
161
166
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 );
163
177
164
178
return new ContainerBuilder ()
165
179
.withName (INIT_CONTAINER_NAME )
0 commit comments