Search in sources :

Example 1 with V1Container

use of io.kubernetes.client.models.V1Container in project weblogic-kubernetes-operator by oracle.

the class CreateOperatorGeneratedFilesDebugEnabledTest method getExpectedWeblogicOperatorDeployment.

@Override
public ExtensionsV1beta1Deployment getExpectedWeblogicOperatorDeployment() {
    ExtensionsV1beta1Deployment expected = super.getExpectedWeblogicOperatorDeployment();
    V1Container operatorContainer = expected.getSpec().getTemplate().getSpec().getContainers().get(0);
    operatorContainer.addEnvItem(newEnvVar().name("REMOTE_DEBUG_PORT").value(getInputs().getInternalDebugHttpPort()));
    return expected;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) ExtensionsV1beta1Deployment(io.kubernetes.client.models.ExtensionsV1beta1Deployment)

Example 2 with V1Container

use of io.kubernetes.client.models.V1Container in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method constructPodTemplate.

public static V1PodTemplateSpec constructPodTemplate(ResourceContainer reqContainer, String serviceLabel, long jobFileSize, Config config) {
    V1PodTemplateSpec template = new V1PodTemplateSpec();
    V1ObjectMeta templateMetaData = new V1ObjectMeta();
    HashMap<String, String> labels = new HashMap<String, String>();
    labels.put("app", serviceLabel);
    templateMetaData.setLabels(labels);
    template.setMetadata(templateMetaData);
    V1PodSpec podSpec = new V1PodSpec();
    podSpec.setTerminationGracePeriodSeconds(0L);
    V1Volume volume = new V1Volume();
    volume.setName(POD_SHARED_VOLUME_NAME);
    V1EmptyDirVolumeSource volumeSource = new V1EmptyDirVolumeSource();
    volumeSource.setMedium("Memory");
    volume.setEmptyDir(volumeSource);
    podSpec.setVolumes(Arrays.asList(volume));
    int containersPerPod = KubernetesContext.containersPerPod(config);
    int basePort = KubernetesContext.workerBasePort(config);
    ArrayList<V1Container> containers = new ArrayList<V1Container>();
    for (int i = 0; i < containersPerPod; i++) {
        containers.add(constructContainer(i, reqContainer, jobFileSize, basePort + 1, config));
    }
    podSpec.setContainers(containers);
    template.setSpec(podSpec);
    return template;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1Volume(io.kubernetes.client.models.V1Volume) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1EmptyDirVolumeSource(io.kubernetes.client.models.V1EmptyDirVolumeSource) ArrayList(java.util.ArrayList) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodSpec(io.kubernetes.client.models.V1PodSpec)

Example 3 with V1Container

use of io.kubernetes.client.models.V1Container in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method constructContainer.

/**
 * construct a container
 * @param containerIndex
 * @param reqContainer
 * @param jobFileSize
 * @param containerPort
 * @param config
 * @return
 */
public static V1Container constructContainer(int containerIndex, ResourceContainer reqContainer, long jobFileSize, int containerPort, Config config) {
    // construct container and add it to podSpec
    V1Container container = new V1Container();
    String containerName = createContainerName(containerIndex);
    container.setName(containerName);
    container.setImage(TWISTER2_DOCKER_IMAGE);
    // by default: IfNotPresent
    // can be set to Always from client.yaml
    container.setImagePullPolicy(KubernetesContext.imagePullPolicy(config));
    // container.setArgs(Arrays.asList("1000000")); parameter to the main method
    // container.setCommand(Arrays.asList("java", TWISTER2_WORKER_CLASS));
    V1EnvVar var1 = new V1EnvVar().name(KubernetesField.JOB_PACKAGE_FILENAME + "").value(SchedulerContext.jobPackageFileName(config));
    V1EnvVar var2 = new V1EnvVar().name(KubernetesField.JOB_PACKAGE_FILE_SIZE + "").value(jobFileSize + "");
    V1EnvVar var3 = new V1EnvVar().name(KubernetesField.CONTAINER_NAME + "").value(containerName);
    V1EnvVar var4 = new V1EnvVar().name(KubernetesField.USER_JOB_JAR_FILE + "").value(SchedulerContext.userJobJarFile(config));
    V1EnvVar var5 = new V1EnvVar().name(KubernetesField.JOB_DESCRIPTION_FILE + "").value(SchedulerContext.jobDescriptionFile(config));
    // POD_IP with downward API
    V1ObjectFieldSelector fieldSelector = new V1ObjectFieldSelector();
    fieldSelector.setFieldPath("status.podIP");
    V1EnvVarSource varSource = new V1EnvVarSource();
    varSource.setFieldRef(fieldSelector);
    V1EnvVar var6 = new V1EnvVar().name(KubernetesField.POD_IP + "").valueFrom(varSource);
    container.setEnv(Arrays.asList(var1, var2, var3, var4, var5, var6));
    V1ResourceRequirements resReq = new V1ResourceRequirements();
    resReq.putRequestsItem("cpu", reqContainer.getNoOfCpus() + "");
    resReq.putRequestsItem("memory", reqContainer.getMemoryMegaBytes() + "Mi");
    container.setResources(resReq);
    V1VolumeMount volumeMount = new V1VolumeMount();
    volumeMount.setName(POD_SHARED_VOLUME_NAME);
    volumeMount.setMountPath(POD_SHARED_VOLUME);
    container.setVolumeMounts(Arrays.asList(volumeMount));
    V1ContainerPort port = new V1ContainerPort().name("port1").containerPort(containerPort);
    port.setProtocol("TCP");
    container.setPorts(Arrays.asList(port));
    return container;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1EnvVarSource(io.kubernetes.client.models.V1EnvVarSource) V1ContainerPort(io.kubernetes.client.models.V1ContainerPort) V1ObjectFieldSelector(io.kubernetes.client.models.V1ObjectFieldSelector) IntOrString(io.kubernetes.client.custom.IntOrString) V1EnvVar(io.kubernetes.client.models.V1EnvVar) V1ResourceRequirements(io.kubernetes.client.models.V1ResourceRequirements) V1VolumeMount(io.kubernetes.client.models.V1VolumeMount)

Example 4 with V1Container

use of io.kubernetes.client.models.V1Container in project incubator-heron by apache.

the class AppsV1beta1Controller method getContainer.

private V1Container getContainer(List<String> executorCommand, Resource resource, int numberOfInstances) {
    final Config configuration = getConfiguration();
    final V1Container container = new V1Container().name("executor");
    // set up the container images
    container.setImage(KubernetesContext.getExecutorDockerImage(configuration));
    // set up the container command
    container.setCommand(executorCommand);
    if (KubernetesContext.hasImagePullPolicy(configuration)) {
        container.setImagePullPolicy(KubernetesContext.getKubernetesImagePullPolicy(configuration));
    }
    // setup the environment variables for the container
    final V1EnvVar envVarHost = new V1EnvVar();
    envVarHost.name(KubernetesConstants.ENV_HOST).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath(KubernetesConstants.POD_IP)));
    final V1EnvVar envVarPodName = new V1EnvVar();
    envVarPodName.name(KubernetesConstants.ENV_POD_NAME).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath(KubernetesConstants.POD_NAME)));
    container.setEnv(Arrays.asList(envVarHost, envVarPodName));
    // set container resources
    final V1ResourceRequirements resourceRequirements = new V1ResourceRequirements();
    final Map<String, String> requests = new HashMap<>();
    requests.put(KubernetesConstants.MEMORY, KubernetesUtils.Megabytes(resource.getRam()));
    requests.put(KubernetesConstants.CPU, Double.toString(resource.getCpu()));
    resourceRequirements.setRequests(requests);
    container.setResources(resourceRequirements);
    // set container ports
    final boolean debuggingEnabled = TopologyUtils.getTopologyRemoteDebuggingEnabled(Runtime.topology(getRuntimeConfiguration()));
    container.setPorts(getContainerPorts(debuggingEnabled, numberOfInstances));
    // setup volume mounts
    mountVolumeIfPresent(container);
    return container;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1EnvVarSource(io.kubernetes.client.models.V1EnvVarSource) HashMap(java.util.HashMap) Config(com.twitter.heron.spi.common.Config) V1ObjectFieldSelector(io.kubernetes.client.models.V1ObjectFieldSelector) V1EnvVar(io.kubernetes.client.models.V1EnvVar) V1ResourceRequirements(io.kubernetes.client.models.V1ResourceRequirements)

Example 5 with V1Container

use of io.kubernetes.client.models.V1Container in project weblogic-kubernetes-operator by oracle.

the class PodHelper method validateCurrentPod.

private static boolean validateCurrentPod(V1Pod build, V1Pod current) {
    if (!AnnotationHelper.checkFormatAnnotation(current.getMetadata())) {
        return false;
    }
    V1PodSpec buildSpec = build.getSpec();
    V1PodSpec currentSpec = current.getSpec();
    List<V1Container> buildContainers = buildSpec.getContainers();
    List<V1Container> currentContainers = currentSpec.getContainers();
    if (buildContainers != null) {
        if (currentContainers == null) {
            return false;
        }
        for (V1Container bc : buildContainers) {
            V1Container fcc = null;
            for (V1Container cc : currentContainers) {
                if (cc.getName().equals(bc.getName())) {
                    fcc = cc;
                    break;
                }
            }
            if (fcc == null) {
                return false;
            }
            if (!fcc.getImage().equals(bc.getImage()) || !fcc.getImagePullPolicy().equals(bc.getImagePullPolicy())) {
                return false;
            }
            if (!compareUnordered(fcc.getPorts(), bc.getPorts())) {
                return false;
            }
            if (!compareUnordered(fcc.getEnv(), bc.getEnv())) {
                return false;
            }
            if (!compareUnordered(fcc.getEnvFrom(), bc.getEnvFrom())) {
                return false;
            }
        }
    }
    return true;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1PodSpec(io.kubernetes.client.models.V1PodSpec)

Aggregations

V1Container (io.kubernetes.client.models.V1Container)6 IntOrString (io.kubernetes.client.custom.IntOrString)2 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)2 V1EnvVar (io.kubernetes.client.models.V1EnvVar)2 V1EnvVarSource (io.kubernetes.client.models.V1EnvVarSource)2 V1ObjectFieldSelector (io.kubernetes.client.models.V1ObjectFieldSelector)2 V1PodSpec (io.kubernetes.client.models.V1PodSpec)2 V1ResourceRequirements (io.kubernetes.client.models.V1ResourceRequirements)2 HashMap (java.util.HashMap)2 Config (com.twitter.heron.spi.common.Config)1 V1ContainerPort (io.kubernetes.client.models.V1ContainerPort)1 V1EmptyDirVolumeSource (io.kubernetes.client.models.V1EmptyDirVolumeSource)1 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)1 V1Volume (io.kubernetes.client.models.V1Volume)1 V1VolumeMount (io.kubernetes.client.models.V1VolumeMount)1 ArrayList (java.util.ArrayList)1