@@ -119,6 +119,12 @@ 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 no new data copied into the init container within
123
+ // INIT_RETRY_TIMEOUT_MINUTES
124
+ private static final double INIT_SLEEP_PERIOD_SECONDS = 0.1 ;
125
+ private static final Duration INIT_RETRY_TIMEOUT_MINUTES = Duration .ofMinutes (1 );
126
+ private static final int INIT_RETRY_MAX_ITERATIONS = (int ) (INIT_RETRY_TIMEOUT_MINUTES .toSeconds () / INIT_SLEEP_PERIOD_SECONDS );
127
+
122
128
private final KubernetesClient fabricClient ;
123
129
private final Pod podDefinition ;
124
130
// Necessary since it is not possible to retrieve the pod's actual exit code upon termination. This
@@ -152,20 +158,23 @@ public static String getPodIP(final KubernetesClient client, final String podNam
152
158
153
159
private static Container getInit (final boolean usesStdin ,
154
160
final List <VolumeMount > mainVolumeMounts ,
155
- final String busyboxImage ) {
156
- var initEntrypointStr = String .format ("mkfifo %s && mkfifo %s" , STDOUT_PIPE_FILE , STDERR_PIPE_FILE );
157
-
158
- if (usesStdin ) {
159
- initEntrypointStr = String .format ("mkfifo %s && " , STDIN_PIPE_FILE ) + initEntrypointStr ;
160
- }
161
+ final String busyboxImage )
162
+ throws IOException {
161
163
162
- initEntrypointStr = initEntrypointStr + String .format (" && until [ -f %s ]; do sleep 0.1; done;" , SUCCESS_FILE_NAME );
164
+ final var initCommand = MoreResources .readResource ("entrypoints/sync/init.sh" )
165
+ .replaceAll ("USES_STDIN_VALUE" , String .valueOf (usesStdin ))
166
+ .replaceAll ("STDOUT_PIPE_FILE_VALUE" , STDOUT_PIPE_FILE )
167
+ .replaceAll ("STDERR_PIPE_FILE_VALUE" , STDERR_PIPE_FILE )
168
+ .replaceAll ("STDIN_PIPE_FILE_VALUE" , STDIN_PIPE_FILE )
169
+ .replaceAll ("MAX_ITERATION_VALUE" , String .valueOf (INIT_RETRY_MAX_ITERATIONS ))
170
+ .replaceAll ("SUCCESS_FILE_NAME_VALUE" , SUCCESS_FILE_NAME )
171
+ .replaceAll ("SLEEP_PERIOD_VALUE" , String .valueOf (INIT_SLEEP_PERIOD_SECONDS ));
163
172
164
173
return new ContainerBuilder ()
165
174
.withName (INIT_CONTAINER_NAME )
166
175
.withImage (busyboxImage )
167
176
.withWorkingDir (CONFIG_DIR )
168
- .withCommand ("sh" , "-c" , initEntrypointStr )
177
+ .withCommand ("sh" , "-c" , initCommand )
169
178
.withVolumeMounts (mainVolumeMounts )
170
179
.build ();
171
180
}
0 commit comments