Syncronize pod creation during resume operation
@@ -63,6 +63,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
@@ -135,6 +137,8 @@ public class DockerContainerOperationManager {
@Value("${pause.run.script.url}")
private String pauseRunScriptUrl;
+ private Lock resumeLock = new ReentrantLock();
+
public PipelineRun commitContainer(PipelineRun run, DockerRegistry registry,
String newImageName, boolean clearContainer, boolean stopPipeline) {
final String containerId = kubernetesManager.getContainerIdFromKubernetesPod(run.getPodId(),
@@ -247,11 +251,7 @@ public class DockerContainerOperationManager {
kubernetesManager.waitForNodeReady(run.getInstance().getNodeName(),
run.getId().toString(), cloudRegion.getRegionCode());
- if (Objects.isNull(kubernetesManager.findPodById(run.getPodId()))) {
- final PipelineConfiguration configuration = getResumeConfiguration(run);
- launcher.launch(run, configuration, endpoints, run.getId().toString(),
- true, run.getPodId(), null, ImagePullPolicy.NEVER);
- }
+ launchPodIfRequired(run, endpoints);
kubernetesManager.removeNodeLabel(run.getInstance().getNodeName(),
KubernetesConstants.PAUSED_NODE_LABEL);
@@ -265,6 +265,17 @@ public class DockerContainerOperationManager {
}
}
+ //method is synchronized to prevent double pod creation
+ private void launchPodIfRequired(final PipelineRun run, final List<String> endpoints) {
+ resumeLock.lock();
+ if (Objects.isNull(kubernetesManager.findPodById(run.getPodId()))) {
+ final PipelineConfiguration configuration = getResumeConfiguration(run);
+ launcher.launch(run, configuration, endpoints, run.getId().toString(),
+ true, run.getPodId(), null, ImagePullPolicy.NEVER);
+ }
+ resumeLock.unlock();
+ }
+
private PipelineConfiguration getResumeConfiguration(final PipelineRun run) {
final PipelineConfiguration configuration = configurationManager.getConfigurationFromRun(run);
final Map<String, String> envs = getResumeRunEnvVars(configuration);
