use of io.kubernetes.client.openapi.models.V1ObjectFieldSelector in project heron by twitter.
the class V1Controller method getExecutorEnvVars.
/**
* Generates a list of <code>Environment Variables</code> required by Heron to function.
* @return A list of configured <code>Environment Variables</code> required by Heron to function.
*/
@VisibleForTesting
protected static List<V1EnvVar> getExecutorEnvVars() {
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)));
return Arrays.asList(envVarHost, envVarPodName);
}
use of io.kubernetes.client.openapi.models.V1ObjectFieldSelector in project heron by twitter.
the class V1ControllerTest method testConfigureContainerEnvVars.
@Test
public void testConfigureContainerEnvVars() {
final List<V1EnvVar> heronEnvVars = Collections.unmodifiableList(V1Controller.getExecutorEnvVars());
final V1EnvVar additionEnvVar = new V1EnvVar().name("env-variable-to-be-kept").valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("env-variable-was-kept")));
final List<V1EnvVar> inputEnvVars = Arrays.asList(new V1EnvVar().name(KubernetesConstants.ENV_HOST).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("env-host-to-be-replaced"))), new V1EnvVar().name(KubernetesConstants.ENV_POD_NAME).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("pod-name-to-be-replaced"))), additionEnvVar);
// Null env vars. This is the default case.
V1Container containerWithNullEnvVars = new V1ContainerBuilder().build();
v1ControllerWithPodTemplate.configureContainerEnvVars(containerWithNullEnvVars);
Assert.assertTrue("ENV_HOST & ENV_POD_NAME in container with null Env Vars should match", CollectionUtils.containsAll(containerWithNullEnvVars.getEnv(), heronEnvVars));
// Empty env vars.
V1Container containerWithEmptyEnvVars = new V1ContainerBuilder().withEnv(new LinkedList<>()).build();
v1ControllerWithPodTemplate.configureContainerEnvVars(containerWithEmptyEnvVars);
Assert.assertTrue("ENV_HOST & ENV_POD_NAME in container with empty Env Vars should match", CollectionUtils.containsAll(containerWithEmptyEnvVars.getEnv(), heronEnvVars));
// Env Var overriding.
final List<V1EnvVar> expectedOverriding = new LinkedList<>(heronEnvVars);
expectedOverriding.add(additionEnvVar);
V1Container containerWithEnvVars = new V1ContainerBuilder().withEnv(inputEnvVars).build();
v1ControllerWithPodTemplate.configureContainerEnvVars(containerWithEnvVars);
Assert.assertTrue("ENV_HOST & ENV_POD_NAME in container with Env Vars should be overridden", CollectionUtils.containsAll(containerWithEnvVars.getEnv(), expectedOverriding));
}
use of io.kubernetes.client.openapi.models.V1ObjectFieldSelector in project heron by twitter.
the class KubernetesUtilsTest method testMergeListsDedupe.
@Test
public void testMergeListsDedupe() {
final String description = "Pod Template Environment Variables";
final List<V1EnvVar> heronEnvVars = Collections.unmodifiableList(V1Controller.getExecutorEnvVars());
final V1EnvVar additionEnvVar = new V1EnvVar().name("env-variable-to-be-kept").valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("env-variable-was-kept")));
final List<V1EnvVar> expectedEnvVars = Collections.unmodifiableList(new LinkedList<V1EnvVar>(V1Controller.getExecutorEnvVars()) {
{
add(additionEnvVar);
}
});
final List<V1EnvVar> inputEnvVars = Arrays.asList(new V1EnvVar().name(KubernetesConstants.ENV_HOST).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("env-host-to-be-replaced"))), new V1EnvVar().name(KubernetesConstants.ENV_POD_NAME).valueFrom(new V1EnvVarSource().fieldRef(new V1ObjectFieldSelector().fieldPath("pod-name-to-be-replaced"))), additionEnvVar);
KubernetesUtils.V1ControllerUtils<V1EnvVar> v1ControllerUtils = new KubernetesUtils.V1ControllerUtils<>();
// Both input lists are null.
Assert.assertNull("Both input lists are <null>", v1ControllerUtils.mergeListsDedupe(null, null, Comparator.comparing(V1EnvVar::getName), description));
// <primaryList> is <null>.
Assert.assertEquals("<primaryList> is null and <secondaryList> should be returned", inputEnvVars, v1ControllerUtils.mergeListsDedupe(null, inputEnvVars, Comparator.comparing(V1EnvVar::getName), description));
// <primaryList> is empty.
Assert.assertEquals("<primaryList> is empty and <secondaryList> should be returned", inputEnvVars, v1ControllerUtils.mergeListsDedupe(new LinkedList<>(), inputEnvVars, Comparator.comparing(V1EnvVar::getName), description));
// <secondaryList> is <null>.
Assert.assertEquals("<secondaryList> is null and <primaryList> should be returned", heronEnvVars, v1ControllerUtils.mergeListsDedupe(heronEnvVars, null, Comparator.comparing(V1EnvVar::getName), description));
// <secondaryList> is empty.
Assert.assertEquals("<secondaryList> is empty and <primaryList> should be returned", heronEnvVars, v1ControllerUtils.mergeListsDedupe(heronEnvVars, new LinkedList<>(), Comparator.comparing(V1EnvVar::getName), description));
// Merge both lists.
Assert.assertTrue("<primaryList> and <secondaryList> merged and deduplicated", expectedEnvVars.containsAll(v1ControllerUtils.mergeListsDedupe(heronEnvVars, inputEnvVars, Comparator.comparing(V1EnvVar::getName), description)));
// Expect thrown error.
String errorMessage = "";
try {
v1ControllerUtils.mergeListsDedupe(heronEnvVars, Collections.singletonList(new V1EnvVar()), Comparator.comparing(V1EnvVar::getName), description);
} catch (TopologySubmissionException e) {
errorMessage = e.getMessage();
}
Assert.assertTrue("Expecting error to be thrown for null deduplication key", errorMessage.contains(description));
}
use of io.kubernetes.client.openapi.models.V1ObjectFieldSelector in project twister2 by DSC-SPIDAL.
the class RequestObjectBuilder method getCommonEnvVars.
/**
* add common environment variables to both jm and workers
*/
public static ArrayList<V1EnvVar> getCommonEnvVars() {
ArrayList<V1EnvVar> envVars = new ArrayList<>();
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_ID.name()).value(jobID));
envVars.add(new V1EnvVar().name(K8sEnvVariables.ENCODED_NODE_INFO_LIST.name()).value(encodedNodeInfoList));
// POD_NAME with downward API
V1ObjectFieldSelector fieldSelector = new V1ObjectFieldSelector();
fieldSelector.setFieldPath("metadata.name");
V1EnvVarSource varSource = new V1EnvVarSource();
varSource.setFieldRef(fieldSelector);
envVars.add(new V1EnvVar().name(K8sEnvVariables.POD_NAME.name()).valueFrom(varSource));
// HOST_IP (node-ip) with downward API
fieldSelector = new V1ObjectFieldSelector();
fieldSelector.setFieldPath("status.hostIP");
varSource = new V1EnvVarSource();
varSource.setFieldRef(fieldSelector);
envVars.add(new V1EnvVar().name(K8sEnvVariables.HOST_IP.name()).valueFrom(varSource));
// HOST_NAME (node-name) with downward API
fieldSelector = new V1ObjectFieldSelector();
fieldSelector.setFieldPath("spec.nodeName");
varSource = new V1EnvVarSource();
varSource.setFieldRef(fieldSelector);
envVars.add(new V1EnvVar().name(K8sEnvVariables.HOST_NAME.name()).valueFrom(varSource));
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_PACKAGE_FILE_SIZE.name()).value(jobPackageFileSize + ""));
envVars.add(new V1EnvVar().name(K8sEnvVariables.USER_JOB_JAR_FILE.name()).value(SchedulerContext.userJobJarFile(config)));
envVars.add(new V1EnvVar().name(K8sEnvVariables.POD_MEMORY_VOLUME.name()).value(KubernetesConstants.POD_MEMORY_VOLUME));
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_ARCHIVE_DIRECTORY.name()).value(Context.JOB_ARCHIVE_DIRECTORY));
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_PACKAGE_FILENAME.name()).value(JobUtils.createJobPackageFileName(jobID)));
envVars.add(new V1EnvVar().name(K8sEnvVariables.UPLOAD_METHOD.name()).value(uploadMethod));
String uri = null;
if (SchedulerContext.jobPackageUri(config) != null) {
uri = SchedulerContext.jobPackageUri(config).toString();
}
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_PACKAGE_URI.name()).value(uri));
envVars.add(new V1EnvVar().name(K8sEnvVariables.LOGGER_PROPERTIES_FILE.name()).value(LoggingContext.LOGGER_PROPERTIES_FILE));
envVars.add(new V1EnvVar().name(K8sEnvVariables.JOB_SUBMISSION_TIME.name()).value(jobSubmissionTime + ""));
envVars.add(new V1EnvVar().name(K8sEnvVariables.RESTORE_JOB.name()).value(Boolean.toString(CheckpointingContext.startingFromACheckpoint(config))));
return envVars;
}
Aggregations