use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project che-server by eclipse-che.
the class EnvironmentVariableSecretApplierTest 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);
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, "false")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// only first container has env set
assertEquals(container_match1.getEnv().size(), 1);
EnvVar var = container_match1.getEnv().get(0);
assertEquals(var.getName(), "MY_FOO");
assertEquals(var.getValueFrom().getSecretKeyRef().getName(), "test_secret");
assertEquals(var.getValueFrom().getSecretKeyRef().getKey(), "foo");
assertEquals(container_match2.getEnv().size(), 0);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project che-server by eclipse-che.
the class URLFactoryBuilderTest method checkWithCustomDevfileAndRecipe.
@Test
public void checkWithCustomDevfileAndRecipe() throws Exception {
DevfileImpl devfile = new DevfileImpl();
WorkspaceConfigImpl workspaceConfigImpl = new WorkspaceConfigImpl();
String myLocation = "http://foo-location/";
RecipeImpl expectedRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "application/x-yaml", "content", "");
EnvironmentImpl expectedEnv = new EnvironmentImpl(expectedRecipe, emptyMap());
workspaceConfigImpl.setEnvironments(singletonMap("name", expectedEnv));
workspaceConfigImpl.setDefaultEnv("name");
when(devfileParser.parseYamlRaw(anyString())).thenReturn(new ObjectNode(JsonNodeFactory.instance));
when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDto);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project che-server by eclipse-che.
the class URLFactoryBuilderTest method devfiles.
@DataProvider
public Object[][] devfiles() {
final String NAME = "name";
final String GEN_NAME = "genName";
DevfileImpl devfileTemplate = new DevfileImpl();
devfileTemplate.setApiVersion("1.0.0");
MetadataImpl metadataTemplate = new MetadataImpl();
metadataTemplate.setName(NAME);
devfileTemplate.setMetadata(metadataTemplate);
DevfileImpl justName = new DevfileImpl(devfileTemplate);
metadataTemplate.setName(null);
metadataTemplate.setGenerateName(GEN_NAME);
devfileTemplate.setMetadata(metadataTemplate);
DevfileImpl justGenerateName = new DevfileImpl(devfileTemplate);
metadataTemplate.setName(NAME);
metadataTemplate.setGenerateName(GEN_NAME);
devfileTemplate.setMetadata(metadataTemplate);
DevfileImpl bothNames = new DevfileImpl(devfileTemplate);
return new Object[][] { { justName, NAME }, { justGenerateName, GEN_NAME }, { bothNames, GEN_NAME } };
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project che-server by eclipse-che.
the class URLFactoryBuilder method ensureToUseGenerateName.
/**
* Creates devfile with only `generateName` and no `name`. We take `generateName` with precedence.
* See doc of {@link URLFactoryBuilder#createFactoryFromDevfile(RemoteFactoryUrl,
* FileContentProvider, Map)} for explanation why.
*/
private DevfileImpl ensureToUseGenerateName(DevfileImpl devfile) {
MetadataImpl devfileMetadata = new MetadataImpl(devfile.getMetadata());
if (isNullOrEmpty(devfileMetadata.getGenerateName())) {
devfileMetadata.setGenerateName(devfileMetadata.getName());
}
devfileMetadata.setName(null);
DevfileImpl devfileWithProperName = new DevfileImpl(devfile);
devfileWithProperName.setMetadata(devfileMetadata);
return devfileWithProperName;
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project che-server by eclipse-che.
the class WorkspaceManagerTest method startsWorkspaceWithDevfile.
@Test
public void startsWorkspaceWithDevfile() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, INFRA_NAMESPACE));
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
}
Aggregations