io.fabric8.kubernetes.api.model.ExecAction Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ExecAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAddProbeDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Override
public void andThenVisit(ContainerFluent<?> container) {
  if (probe == null) {
    return;
  }

  final ExecAction execAction = execAction(probe);
  final TCPSocketAction tcpSocketAction = tcpSocketAction(probe);
  final boolean defaultToHttpGetAction = (execAction == null) && (tcpSocketAction == null);
  final HTTPGetAction httpGetAction = defaultToHttpGetAction ? httpGetAction(probe, container) : null;
  if (defaultToHttpGetAction && (httpGetAction == null)) {
    return;
  }

  doCreateProbe(container, new Actions(execAction, tcpSocketAction, httpGetAction));
}
 
Example #2
Source File: DockerHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private Probe getProbe(ImageConfiguration image) {
    if (hasHealthCheck(image)) {
        HealthCheckConfiguration health = image.getBuildConfiguration().getHealthCheck();
        return new ProbeBuilder()
                .withExec(new ExecAction(health.getCmd().asStrings()))
                .withTimeoutSeconds(durationSeconds(health.getTimeout()))
                .withPeriodSeconds(durationSeconds(health.getInterval()))
                .withFailureThreshold(health.getRetries())
                .build();
    }

    return null;
}
 
Example #3
Source File: ProbeHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public Probe getProbe(ProbeConfig probeConfig)  {
    if (probeConfig == null) {
        return null;
    }

    Probe probe = new Probe();
    Integer initialDelaySeconds = probeConfig.getInitialDelaySeconds();
    if (initialDelaySeconds != null) {
        probe.setInitialDelaySeconds(initialDelaySeconds);
    }
    Integer timeoutSeconds = probeConfig.getTimeoutSeconds();
    if (timeoutSeconds != null) {
        probe.setTimeoutSeconds(timeoutSeconds);
    }
    Integer failureThreshold = probeConfig.getFailureThreshold();
    if(failureThreshold != null) {
        probe.setFailureThreshold(failureThreshold);
    }
    Integer successThreshold = probeConfig.getSuccessThreshold();
    if(successThreshold != null) {
        probe.setSuccessThreshold(successThreshold);
    }
    HTTPGetAction getAction = getHTTPGetAction(probeConfig.getGetUrl());
    if (getAction != null) {
        probe.setHttpGet(getAction);
        return probe;
    }
    ExecAction execAction = getExecAction(probeConfig.getExec());
    if (execAction != null) {
        probe.setExec(execAction);
        return probe;
    }
    TCPSocketAction tcpSocketAction = getTCPSocketAction(probeConfig.getGetUrl(), probeConfig.getTcpPort());
    if (tcpSocketAction != null) {
        probe.setTcpSocket(tcpSocketAction);
        return probe;
    }

    return null;
}
 
Example #4
Source File: ProbeHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private ExecAction getExecAction(String execCmd) {
    if (isNotBlank(execCmd)) {
        List<String> splitCommandLine = CommandLine.translateCommandline(execCmd);
        if (!splitCommandLine.isEmpty()) {
            return new ExecAction(splitCommandLine);
        }
    }
    return null;
}
 
Example #5
Source File: K8sContainerResolver.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private io.fabric8.kubernetes.api.model.Handler toK8sHandler(Handler handler) {
  if (handler == null || handler.getExec() == null) {
    return null;
  }
  ExecAction exec = toExecAction(handler.getExec());
  if (exec == null) {
    return null;
  }
  // TODO: add 'httpGetAction' and 'tcpSocketAction' support
  io.fabric8.kubernetes.api.model.Handler k8SHandler =
      new io.fabric8.kubernetes.api.model.Handler(exec, null, null);
  return k8SHandler;
}
 
Example #6
Source File: AbstractAddProbeDecorator.java    From dekorate with Apache License 2.0 4 votes vote down vote up
private ExecAction execAction(Probe probe) {
  if (Strings.isNullOrEmpty(probe.getExecAction())) {
    return null;
  }
  return new ExecAction(Arrays.asList(probe.getExecAction().split(" ")));
}
 
Example #7
Source File: AbstractAddProbeDecorator.java    From dekorate with Apache License 2.0 4 votes vote down vote up
protected Actions(ExecAction execAction, TCPSocketAction tcpSocketAction, HTTPGetAction httpGetAction) {
  this.execAction = execAction;
  this.tcpSocketAction = tcpSocketAction;
  this.httpGetAction = httpGetAction;
}
 
Example #8
Source File: K8sContainerResolver.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private ExecAction toExecAction(Exec exec) {
  if (exec == null || exec.getCommand().isEmpty()) {
    return null;
  }
  return new ExecAction(exec.getCommand());
}
 
Example #9
Source File: PodTemplateBuilder.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
private Container createContainer(ContainerTemplate containerTemplate, Collection<TemplateEnvVar> globalEnvVars,
        Collection<VolumeMount> volumeMounts) {
    Map<String, EnvVar> envVarsMap = new HashMap<>();
    String workingDir = substituteEnv(containerTemplate.getWorkingDir());
    if (JNLP_NAME.equals(containerTemplate.getName())) {
        envVarsMap.putAll(jnlpEnvVars(workingDir));
    }
    envVarsMap.putAll(defaultEnvVars(globalEnvVars));

    if (containerTemplate.getEnvVars() != null) {
        containerTemplate.getEnvVars().forEach(item ->
                envVarsMap.put(item.getKey(), item.buildEnvVar())
        );
    }

    EnvVar[] envVars = envVarsMap.values().stream().toArray(EnvVar[]::new);

    String cmd = containerTemplate.getArgs();
    if (slave != null && cmd != null) {
        SlaveComputer computer = slave.getComputer();
        if (computer != null) {
            cmd = cmd.replaceAll(JNLPMAC_REF, computer.getJnlpMac()) //
                    .replaceAll(NAME_REF, computer.getName());
        }
    }
    List<String> arguments = Strings.isNullOrEmpty(containerTemplate.getArgs()) ? Collections.emptyList()
            : parseDockerCommand(cmd);

    ContainerPort[] ports = containerTemplate.getPorts().stream().map(entry -> entry.toPort()).toArray(size -> new ContainerPort[size]);


    List<VolumeMount> containerMounts = getContainerVolumeMounts(volumeMounts, workingDir);

    ContainerLivenessProbe clp = containerTemplate.getLivenessProbe();
    Probe livenessProbe = null;
    if (clp != null && parseLivenessProbe(clp.getExecArgs()) != null) {
        livenessProbe = new ProbeBuilder()
                .withExec(new ExecAction(parseLivenessProbe(clp.getExecArgs())))
                .withInitialDelaySeconds(clp.getInitialDelaySeconds())
                .withTimeoutSeconds(clp.getTimeoutSeconds())
                .withFailureThreshold(clp.getFailureThreshold())
                .withPeriodSeconds(clp.getPeriodSeconds())
                .withSuccessThreshold(clp.getSuccessThreshold())
                .build();
    }

    return new ContainerBuilder()
            .withName(substituteEnv(containerTemplate.getName()))
            .withImage(substituteEnv(containerTemplate.getImage()))
            .withImagePullPolicy(containerTemplate.isAlwaysPullImage() ? "Always" : "IfNotPresent")
            .withNewSecurityContext()
            .withPrivileged(containerTemplate.isPrivileged())
            .withRunAsUser(containerTemplate.getRunAsUserAsLong())
            .withRunAsGroup(containerTemplate.getRunAsGroupAsLong())
            .endSecurityContext()
            .withWorkingDir(workingDir)
            .withVolumeMounts(containerMounts.toArray(new VolumeMount[containerMounts.size()]))
            .addToEnv(envVars)
            .addToPorts(ports)
            .withCommand(parseDockerCommand(containerTemplate.getCommand()))
            .withArgs(arguments)
            .withLivenessProbe(livenessProbe)
            .withTty(containerTemplate.isTtyEnabled())
            .withNewResources()
            .withRequests(getResourcesMap(containerTemplate.getResourceRequestMemory(), containerTemplate.getResourceRequestCpu()))
            .withLimits(getResourcesMap(containerTemplate.getResourceLimitMemory(), containerTemplate.getResourceLimitCpu()))
            .endResources()
            .build();
}