package org.csanchez.jenkins.plugins.kubernetes;

import hudson.plugins.sshslaves.SSHLauncher;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.DelegatingComputerLauncher;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.github.kubernetes.java.client.model.Container;
import com.github.kubernetes.java.client.model.Pod;
import com.github.kubernetes.java.client.model.Port;
import com.google.common.base.Preconditions;
import com.nirima.jenkins.plugins.docker.DockerTemplate;
import com.nirima.jenkins.plugins.docker.utils.RetryingComputerLauncher;

/**
 * {@link hudson.slaves.ComputerLauncher} for Docker that waits for the instance
 * to really come up before proceeding to the real user-specified
 * {@link hudson.slaves.ComputerLauncher}.
 */
public class KubernetesComputerLauncher extends DelegatingComputerLauncher {

    private static final Logger LOGGER = Logger.getLogger(KubernetesComputerLauncher.class.getName());

    public KubernetesComputerLauncher(Pod pod, DockerTemplate template) {
        super(makeLauncher(pod, template));
    }

    private static ComputerLauncher makeLauncher(Pod pod, DockerTemplate template) {
        SSHLauncher sshLauncher = getSSHLauncher(pod, template);
        return new RetryingComputerLauncher(sshLauncher);
    }

    private static SSHLauncher getSSHLauncher(Pod pod, DockerTemplate template) {
        Preconditions.checkNotNull(pod);
        Preconditions.checkNotNull(template);

        String host = pod.getCurrentState().getHostIP();
        List<Container> containers = pod.getDesiredState().getManifest().getContainers();
        Container container = containers.get(0);
        List<Port> ports = container.getPorts();
        int port = ports.get(0).getHostPort();

        LOGGER.log(Level.INFO, "Creating slave SSH launcher for " + host + ":" + port);

        StandardUsernameCredentials credentials = SSHLauncher.lookupSystemCredentials(template.credentialsId);

        return new SSHLauncher( //
                host, //
                port, //
                credentials, //
                template.jvmOptions, //
                template.javaPath, //
                template.prefixStartSlaveCmd, //
                template.suffixStartSlaveCmd, //
                60 // template.getSSHLaunchTimeoutMinutes() * 60
        );

    }
}

@@ -92,47 +92,8 @@
 er;%0A
-import hudson.slaves.ComputerLauncher;%0A
 impo
@@ -133,24 +133,24 @@
 erLauncher;%0A
+
 %0Aimport java
@@ -572,81 +572,8 @@
 ate;
-%0Aimport com.nirima.jenkins.plugins.docker.utils.RetryingComputerLauncher;
 %0A%0A/*
@@ -1042,250 +1042,37 @@
 per(
-makeLauncher(pod, template));%0A    %7D%0A%0A    private static ComputerLauncher makeLauncher(Pod pod, DockerTemplate template) %7B%0A        SSHLauncher sshLauncher = getSSHLauncher(pod, template);%0A        return new RetryingComputerLauncher(sshLauncher
+getSSHLauncher(pod, template)
 );%0A 
@@ -2053,14 +2053,8 @@
     
- 60 //
  tem
@@ -2092,16 +2092,64 @@
 s() * 60
+, //%0A                6, //%0A                10 //
 %0A       

Use newer SSHLauncher that allows retries