in karavan-app/src/main/java/org/apache/camel/karavan/kubernetes/KubernetesService.java [400:468]
private Pod getDevModePod(String name, Boolean verbose, Boolean compile, Map<String, String> labels, String projectDevmodeImage, String deploymentFragment, Map<String, String> envVars) {
Deployment deployment = Serialization.unmarshal(deploymentFragment, Deployment.class);
PodSpec podSpec = null;
try {
podSpec = deployment.getSpec().getTemplate().getSpec();
} catch (Exception ignored) {
podSpec = new PodSpec();
}
List<VolumeMount> volumeMounts = new ArrayList<>();
try {
volumeMounts = podSpec.getContainers().get(0).getVolumeMounts();
} catch (Exception ignored) {}
Map<String, String> containerResources = CodeService.DEFAULT_CONTAINER_RESOURCES;
ResourceRequirements resources = getResourceRequirements(containerResources);
ObjectMeta meta = new ObjectMetaBuilder()
.withName(name)
.withLabels(labels)
.withNamespace(getNamespace())
.build();
ContainerPort port = new ContainerPortBuilder()
.withContainerPort(8080)
.withName("http")
.withProtocol("TCP")
.build();
List<EnvVar> environmentVariables = new ArrayList<>();
try {
environmentVariables = new ArrayList<>(podSpec.getContainers().get(0).getEnv());
} catch (Exception ignored) {}
for (Map.Entry<String, String> entry : envVars.entrySet()) {
String k = entry.getKey();
String v = entry.getValue();
environmentVariables.add(new EnvVarBuilder().withName(k).withValue(v).build());
}
if (verbose) {
environmentVariables.add(new EnvVarBuilder().withName(ENV_VAR_VERBOSE_OPTION_NAME).withValue(ENV_VAR_VERBOSE_OPTION_VALUE).build());
}
if (compile) {
environmentVariables.add(new EnvVarBuilder().withName(RUN_IN_COMPILE_MODE).withValue("true").build());
}
Container container = new ContainerBuilder()
.withName(name)
.withImage(projectDevmodeImage != null ? projectDevmodeImage : devmodeImage)
.withPorts(port)
.withResources(resources)
.withImagePullPolicy(devmodeImagePullPolicy.orElse("IfNotPresent"))
.withEnv(environmentVariables)
.withVolumeMounts(volumeMounts)
.build();
podSpec.setTerminationGracePeriodSeconds(0L);
podSpec.setContainers(List.of(container));
podSpec.setRestartPolicy("Never");
podSpec.setServiceAccount(devModeServiceAccount);
if (devmodePVC.orElse(false)) {
podSpec.getVolumes().add(new VolumeBuilder().withName(name).withNewPersistentVolumeClaim(name, false).build());
}
return new PodBuilder()
.withMetadata(meta)
.withSpec(podSpec)
.build();
}