in karavan-app/src/main/java/org/apache/camel/karavan/kubernetes/KubernetesService.java [165:236]
private Pod getBuilderPod(String name, Map<String, String> labels, String configFragment, boolean hasDockerConfigSecret) {
ObjectMeta meta = new ObjectMetaBuilder()
.withName(name)
.withLabels(labels)
.withNamespace(getNamespace())
.build();
ContainerPort port = new ContainerPortBuilder()
.withContainerPort(8080)
.withName("http")
.withProtocol("TCP")
.build();
List<VolumeMount> volumeMounts = new ArrayList<>();
volumeMounts.add(new VolumeMountBuilder().withName(BUILD_SCRIPT_VOLUME_NAME).withMountPath("/karavan/builder").withReadOnly(true).build());
if (hasDockerConfigSecret) {
volumeMounts.add(new VolumeMountBuilder().withName(BUILD_DOCKER_CONFIG_SECRET).withMountPath("/karavan/.docker").withReadOnly(true).build());
}
if (privateKeyPath.isPresent()) {
volumeMounts.add(new VolumeMountBuilder().withName(PRIVATE_KEY_SECRET_KEY).withMountPath("/karavan/.ssh/id_rsa").withSubPath("id_rsa").withReadOnly(true).build());
volumeMounts.add(new VolumeMountBuilder().withName(KNOWN_HOSTS_SECRET_KEY).withMountPath("/karavan/.ssh/known_hosts").withSubPath("known_hosts").withReadOnly(true).build());
}
Pod pod = Serialization.unmarshal(configFragment, Pod.class);
pod.getSpec().getContainers().get(0).getEnv().add(new EnvVarBuilder().withName(RUN_IN_BUILD_MODE).withValue("true").build());
Container container = new ContainerBuilder()
.withName(name)
.withImage(devmodeImage)
.withPorts(port)
.withImagePullPolicy(devmodeImagePullPolicy.orElse("IfNotPresent"))
.withEnv(pod.getSpec().getContainers().get(0).getEnv())
.withCommand("/bin/sh", "-c", "/karavan/builder/build.sh")
.withVolumeMounts(volumeMounts)
.build();
List<Volume> volumes = new ArrayList<>();
volumes.add(new VolumeBuilder().withName(BUILD_SCRIPT_VOLUME_NAME)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(BUILD_SCRIPT_CONFIG_MAP).withItems(
new KeyToPathBuilder().withKey(BUILD_SCRIPT_FILENAME).withPath(BUILD_SCRIPT_FILENAME).build()
).withDefaultMode(511).build()).build());
if (hasDockerConfigSecret) {
volumes.add(new VolumeBuilder().withName(BUILD_DOCKER_CONFIG_SECRET)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(BUILD_DOCKER_CONFIG_SECRET).withItems(
new KeyToPathBuilder().withKey(".dockerconfigjson").withPath("config.json").build()
).withDefaultMode(511).build()).build());
}
if (privateKeyPath.isPresent()) {
volumes.add(new VolumeBuilder().withName(PRIVATE_KEY_SECRET_KEY)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(secretName).withItems(
new KeyToPathBuilder().withKey(PRIVATE_KEY_SECRET_KEY).withPath("id_rsa").build()
).withDefaultMode(511).build()).build());
volumes.add(new VolumeBuilder().withName(KNOWN_HOSTS_SECRET_KEY)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(secretName).withItems(
new KeyToPathBuilder().withKey(KNOWN_HOSTS_SECRET_KEY).withPath("known_hosts").build()
).withDefaultMode(511).build()).build());
}
PodSpec spec = new PodSpecBuilder()
.withTerminationGracePeriodSeconds(0L)
.withContainers(container)
.withRestartPolicy("Never")
.withServiceAccount(builderServiceAccount)
.withVolumes(volumes)
.build();
return new PodBuilder()
.withMetadata(meta)
.withSpec(spec)
.build();
}