use of io.kubernetes.client.models.V1EnvVar in project weblogic-kubernetes-operator by oracle.
the class PodHelper method addEnvVar.
// Add an environment variable to a container
private static void addEnvVar(V1Container container, String name, String value) {
V1EnvVar envVar = new V1EnvVar();
envVar.setName(name);
envVar.setValue(value);
container.addEnvItem(envVar);
}
use of io.kubernetes.client.models.V1EnvVar 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;
}
use of io.kubernetes.client.models.V1EnvVar 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;
}
use of io.kubernetes.client.models.V1EnvVar in project weblogic-kubernetes-operator by oracle.
the class Main method normalizeDomainSpec.
// -----------------------------------------------------------------------------
//
// Below this point are methods that are called primarily from watch handlers,
// after watch events are received.
//
// -----------------------------------------------------------------------------
private static void normalizeDomainSpec(DomainSpec spec) {
// Normalize DomainSpec so that equals() will work correctly
String imageName = spec.getImage();
if (imageName == null || imageName.length() == 0) {
spec.setImage(imageName = KubernetesConstants.DEFAULT_IMAGE);
}
String imagePullPolicy = spec.getImagePullPolicy();
if (imagePullPolicy == null || imagePullPolicy.length() == 0) {
spec.setImagePullPolicy(imagePullPolicy = (imageName.endsWith(KubernetesConstants.LATEST_IMAGE_SUFFIX)) ? KubernetesConstants.ALWAYS_IMAGEPULLPOLICY : KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY);
}
if (spec.getExportT3Channels() == null) {
spec.setExportT3Channels(new ArrayList<String>());
}
String startupControl = spec.getStartupControl();
if (startupControl == null || startupControl.length() == 0) {
spec.setStartupControl(startupControl = StartupControlConstants.AUTO_STARTUPCONTROL);
}
if (spec.getServerStartup() == null) {
spec.setServerStartup(new ArrayList<ServerStartup>());
} else {
for (ServerStartup ss : spec.getServerStartup()) {
if (ss.getDesiredState() == null) {
ss.setDesiredState(RUNNING_STATE);
}
if (ss.getEnv() == null) {
ss.setEnv(new ArrayList<V1EnvVar>());
}
}
}
if (spec.getClusterStartup() == null) {
spec.setClusterStartup(new ArrayList<ClusterStartup>());
} else {
for (ClusterStartup cs : spec.getClusterStartup()) {
if (cs.getDesiredState() == null) {
cs.setDesiredState(RUNNING_STATE);
}
if (cs.getEnv() == null) {
cs.setEnv(new ArrayList<V1EnvVar>());
}
if (cs.getReplicas() == null) {
cs.setReplicas(1);
}
}
}
if (spec.getReplicas() == null) {
spec.setReplicas(1);
}
}
use of io.kubernetes.client.models.V1EnvVar in project weblogic-kubernetes-operator by oracle.
the class Main method startInAdminMode.
private static List<V1EnvVar> startInAdminMode(List<V1EnvVar> env) {
if (env == null) {
env = new ArrayList<>();
}
// look for JAVA_OPTIONS
V1EnvVar jo = null;
for (V1EnvVar e : env) {
if ("JAVA_OPTIONS".equals(e.getName())) {
jo = e;
if (jo.getValueFrom() != null) {
throw new IllegalStateException();
}
break;
}
}
if (jo == null) {
jo = new V1EnvVar();
jo.setName("JAVA_OPTIONS");
env.add(jo);
}
// create or update value
String startInAdmin = "-Dweblogic.management.startupMode=ADMIN";
String value = jo.getValue();
value = (value != null) ? (startInAdmin + " " + value) : startInAdmin;
jo.setValue(value);
return env;
}
Aggregations