use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldFilterRecipeWithGivenSelectors.
@Test
public void shouldFilterRecipeWithGivenSelectors() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
final Map<String, String> selector = singletonMap("app.kubernetes.io/component", "webapp");
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setSelector(selector);
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), anyMap());
List<HasMetadata> resultItemsList = objectsCaptor.getValue();
assertEquals(resultItemsList.size(), 3);
assertEquals(1, resultItemsList.stream().filter(it -> "Pod".equals(it.getKind())).count());
assertEquals(1, resultItemsList.stream().filter(it -> "Service".equals(it.getKind())).count());
assertEquals(1, resultItemsList.stream().filter(it -> "Route".equals(it.getKind())).count());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class FileSecretApplierTest method shouldProvisionAsFilesWithPathOverride.
@Test
public void shouldProvisionAsFilesWithPathOverride() throws Exception {
Container container = new ContainerBuilder().withName("maven").build();
DevfileImpl mock_defvile = mock(DevfileImpl.class);
ComponentImpl component = new ComponentImpl();
component.setAlias("maven");
component.getVolumes().add(new VolumeImpl("test_secret", "/path/to/override"));
InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
when(environment.getDevfile()).thenReturn(mock_defvile);
when(mock_defvile.getComponents()).thenReturn(singletonList(component));
PodSpec localSpec = new PodSpecBuilder().withContainers(ImmutableList.of(container)).build();
when(podData.getSpec()).thenReturn(localSpec);
Secret secret = new SecretBuilder().withData(ImmutableMap.of("settings.xml", "random", "another.xml", "freedom")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_MOUNT_AS, "file", ANNOTATION_MOUNT_PATH, "/home/user/.m2", ANNOTATION_AUTOMOUNT, "true")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// pod has volume created
assertEquals(environment.getPodsData().get("pod1").getSpec().getVolumes().size(), 1);
Volume volume = environment.getPodsData().get("pod1").getSpec().getVolumes().get(0);
assertEquals(volume.getName(), "test_secret");
assertEquals(volume.getSecret().getSecretName(), "test_secret");
// both containers has mounts set
assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().size(), 2);
VolumeMount mount1 = environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().get(0);
assertEquals(mount1.getName(), "test_secret");
assertEquals(mount1.getMountPath(), "/path/to/override/settings.xml");
assertTrue(mount1.getReadOnly());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class FileSecretApplierTest method shouldNotProvisionContainersWithAutomountOverrideFalse.
@Test
public void shouldNotProvisionContainersWithAutomountOverrideFalse() throws Exception {
Container container_match1 = new ContainerBuilder().withName("maven").build();
Container container_match2 = new ContainerBuilder().withName("other").build();
DevfileImpl mock_defvile = mock(DevfileImpl.class);
ComponentImpl component = new ComponentImpl();
component.setAlias("maven");
component.setAutomountWorkspaceSecrets(false);
InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
when(environment.getDevfile()).thenReturn(mock_defvile);
when(mock_defvile.getComponents()).thenReturn(singletonList(component));
PodSpec localSpec = new PodSpecBuilder().withContainers(ImmutableList.of(container_match1, container_match2)).build();
when(podData.getSpec()).thenReturn(localSpec);
Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_MOUNT_AS, "file", ANNOTATION_MOUNT_PATH, "/home/user/.m2", ANNOTATION_AUTOMOUNT, "true")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// only second container has mounts
assertEquals(environment.getPodsData().get("pod1").getSpec().getVolumes().size(), 1);
Volume volume = environment.getPodsData().get("pod1").getSpec().getVolumes().get(0);
assertEquals(volume.getName(), "test_secret");
assertEquals(volume.getSecret().getSecretName(), "test_secret");
assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().size(), 0);
assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(1).getVolumeMounts().size(), 1);
VolumeMount mount2 = environment.getPodsData().get("pod1").getSpec().getContainers().get(1).getVolumeMounts().get(0);
assertEquals(mount2.getName(), "test_secret");
assertEquals(mount2.getMountPath(), "/home/user/.m2/foo");
assertTrue(mount2.getReadOnly());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class EnvironmentVariableSecretApplierTest method shouldNotProvisionContainersWithAutomountOverrideFalse.
@Test
public void shouldNotProvisionContainersWithAutomountOverrideFalse() throws Exception {
Container container_match1 = new ContainerBuilder().withName("maven").build();
Container container_match2 = new ContainerBuilder().withName("other").build();
DevfileImpl mock_defvile = mock(DevfileImpl.class);
ComponentImpl component = new ComponentImpl();
component.setAlias("maven");
component.setAutomountWorkspaceSecrets(false);
when(podSpec.getContainers()).thenReturn(ImmutableList.of(container_match1, container_match2));
InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
when(environment.getDevfile()).thenReturn(mock_defvile);
when(mock_defvile.getComponents()).thenReturn(singletonList(component));
Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_ENV_NAME, "MY_FOO", ANNOTATION_MOUNT_AS, "env", ANNOTATION_AUTOMOUNT, "true")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// only second container has env set
assertEquals(container_match1.getEnv().size(), 0);
assertEquals(container_match2.getEnv().size(), 1);
EnvVar var2 = container_match2.getEnv().get(0);
assertEquals(var2.getName(), "MY_FOO");
assertEquals(var2.getValueFrom().getSecretKeyRef().getName(), "test_secret");
assertEquals(var2.getValueFrom().getSecretKeyRef().getKey(), "foo");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class FileSecretApplierTest method shouldProvisionContainersWithAutomountOverrideTrue.
@Test
public void shouldProvisionContainersWithAutomountOverrideTrue() throws Exception {
Container container_match1 = new ContainerBuilder().withName("maven").build();
Container container_match2 = new ContainerBuilder().withName("other").build();
DevfileImpl mock_defvile = mock(DevfileImpl.class);
ComponentImpl component = new ComponentImpl();
component.setAlias("maven");
component.setAutomountWorkspaceSecrets(true);
InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
when(environment.getDevfile()).thenReturn(mock_defvile);
when(mock_defvile.getComponents()).thenReturn(singletonList(component));
PodSpec localSpec = new PodSpecBuilder().withContainers(ImmutableList.of(container_match1, container_match2)).build();
when(podData.getSpec()).thenReturn(localSpec);
Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_MOUNT_AS, "file", ANNOTATION_MOUNT_PATH, "/home/user/.m2", ANNOTATION_AUTOMOUNT, "false")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// pod has volume created
assertEquals(environment.getPodsData().get("pod1").getSpec().getVolumes().size(), 1);
Volume volume = environment.getPodsData().get("pod1").getSpec().getVolumes().get(0);
assertEquals(volume.getName(), "test_secret");
assertEquals(volume.getSecret().getSecretName(), "test_secret");
// first container has mount set
assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().size(), 1);
VolumeMount mount1 = environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().get(0);
assertEquals(mount1.getName(), "test_secret");
assertEquals(mount1.getMountPath(), "/home/user/.m2/foo");
assertTrue(mount1.getReadOnly());
// second container has no mounts
assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(1).getVolumeMounts().size(), 0);
}
Aggregations