use of io.fabric8.kubernetes.api.model.SecretVolumeSource in project devspaces-images by redhat-developer.
the class CertificateProvisionerTest method verifyVolumeIsPresent.
private void verifyVolumeIsPresent(Pod pod) {
List<Volume> podVolumes = pod.getSpec().getVolumes();
assertEquals(podVolumes.size(), 1);
Volume certVolume = podVolumes.get(0);
assertEquals(certVolume.getName(), CHE_SELF_SIGNED_CERT_VOLUME);
SecretVolumeSource volumeSecret = certVolume.getSecret();
assertNotNull(volumeSecret);
assertEquals(volumeSecret.getSecretName(), EXPECTED_CERT_NAME);
}
use of io.fabric8.kubernetes.api.model.SecretVolumeSource in project styx by spotify.
the class KubernetesDockerRunnerTest method shouldEnsureAndMountServiceAccountSecret.
@Test
public void shouldEnsureAndMountServiceAccountSecret() throws IOException {
when(serviceAccountSecretManager.ensureServiceAccountKeySecret(WORKFLOW_INSTANCE.workflowId().toString(), SERVICE_ACCOUNT)).thenReturn(SERVICE_ACCOUNT_SECRET);
kdr.start(RUN_STATE, RUN_SPEC_WITH_SA);
verify(serviceAccountSecretManager).ensureServiceAccountKeySecret(WORKFLOW_INSTANCE.workflowId().toString(), SERVICE_ACCOUNT);
verify(k8sClient).createPod(podCaptor.capture());
final Pod pod = podCaptor.getValue();
final Optional<SecretVolumeSource> serviceAccountSecretVolume = pod.getSpec().getVolumes().stream().map(Volume::getSecret).filter(Objects::nonNull).filter(v -> SERVICE_ACCOUNT_SECRET.equals(v.getSecretName())).findAny();
assertThat(serviceAccountSecretVolume.isPresent(), is(true));
}
use of io.fabric8.kubernetes.api.model.SecretVolumeSource in project styx by spotify.
the class KubernetesDockerRunner method createPod.
@VisibleForTesting
static Pod createPod(WorkflowInstance workflowInstance, RunSpec runSpec, KubernetesSecretSpec secretSpec, String styxEnvironment, PodMutator podMutator, final Map<String, String> executionEnvVars) {
final String imageWithTag = runSpec.imageName().contains(":") ? runSpec.imageName() : runSpec.imageName() + ":latest";
final String executionId = runSpec.executionId();
final PodBuilder podBuilder = new PodBuilder().withNewMetadata().withName(executionId).addToAnnotations(STYX_WORKFLOW_INSTANCE_ANNOTATION, workflowInstance.toKey()).addToAnnotations(DOCKER_TERMINATION_LOGGING_ANNOTATION, String.valueOf(runSpec.terminationLogging())).addToLabels(tryBuildLabels(workflowInstance, runSpec, styxEnvironment)).endMetadata();
final PodSpecBuilder specBuilder = new PodSpecBuilder().withRestartPolicy("Never");
final ResourceRequirementsBuilder resourceRequirements = new ResourceRequirementsBuilder();
runSpec.memRequest().ifPresent(s -> resourceRequirements.addToRequests("memory", new Quantity(s)));
runSpec.memLimit().ifPresent(s -> resourceRequirements.addToLimits("memory", new Quantity(s)));
final ContainerBuilder mainContainerBuilder = new ContainerBuilder().withName(MAIN_CONTAINER_NAME).withImage(imageWithTag).withArgs(runSpec.args()).withEnv(buildEnv(workflowInstance, runSpec, styxEnvironment, executionEnvVars)).withResources(resourceRequirements.build());
secretSpec.serviceAccountSecret().ifPresent(serviceAccountSecret -> {
final SecretVolumeSource saVolumeSource = new SecretVolumeSourceBuilder().withSecretName(serviceAccountSecret).build();
final Volume saVolume = new VolumeBuilder().withName(STYX_WORKFLOW_SA_SECRET_NAME).withSecret(saVolumeSource).build();
specBuilder.addToVolumes(saVolume);
final VolumeMount saMount = new VolumeMountBuilder().withMountPath(STYX_WORKFLOW_SA_SECRET_MOUNT_PATH).withName(saVolume.getName()).withReadOnly(true).build();
mainContainerBuilder.addToVolumeMounts(saMount);
mainContainerBuilder.addToEnv(envVar(STYX_WORKFLOW_SA_ENV_VARIABLE, saMount.getMountPath() + STYX_WORKFLOW_SA_JSON_KEY));
});
specBuilder.addToContainers(mainContainerBuilder.build());
specBuilder.addToContainers(keepaliveContainer());
podBuilder.withSpec(specBuilder.build());
return podMutator.mutate(workflowInstance, runSpec, styxEnvironment, podBuilder.build());
}
use of io.fabric8.kubernetes.api.model.SecretVolumeSource in project strimzi by strimzi.
the class VolumeUtils method createSecretVolume.
/**
* Creates a secret volume with given items
*
* @param name Name of the Volume
* @param secretName Name of the Secret
* @param items contents of the Secret
* @param isOpenshift true if underlying cluster OpenShift
* @return The Volume created
*/
public static Volume createSecretVolume(String name, String secretName, Map<String, String> items, boolean isOpenshift) {
String validName = getValidVolumeName(name);
int mode = 0444;
if (isOpenshift) {
mode = 0440;
}
List<KeyToPath> keysPaths = new ArrayList<>();
for (Map.Entry<String, String> item : items.entrySet()) {
KeyToPath keyPath = new KeyToPathBuilder().withKey(item.getKey()).withPath(item.getValue()).build();
keysPaths.add(keyPath);
}
SecretVolumeSource secretVolumeSource = new SecretVolumeSourceBuilder().withDefaultMode(mode).withSecretName(secretName).withItems(keysPaths).build();
Volume volume = new VolumeBuilder().withName(validName).withSecret(secretVolumeSource).build();
return volume;
}
use of io.fabric8.kubernetes.api.model.SecretVolumeSource in project strimzi by strimzi.
the class VolumeUtils method createSecretVolume.
/**
* Creates a secret volume
*
* @param name Name of the Volume
* @param secretName Name of the Secret
* @param isOpenshift true if underlying cluster OpenShift
* @return The Volume created
*/
public static Volume createSecretVolume(String name, String secretName, boolean isOpenshift) {
String validName = getValidVolumeName(name);
int mode = 0444;
if (isOpenshift) {
mode = 0440;
}
SecretVolumeSource secretVolumeSource = new SecretVolumeSourceBuilder().withDefaultMode(mode).withSecretName(secretName).build();
Volume volume = new VolumeBuilder().withName(validName).withSecret(secretVolumeSource).build();
return volume;
}
Aggregations