use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithOneContainer.
@Test(dependsOnMethods = "shouldFilterRecipeWithGivenSelectors", enabled = false)
public void shouldSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithOneContainer() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
final Map<String, String> selector = singletonMap("app.kubernetes.io/component", "webapp");
ComponentImpl component = new ComponentImpl();
component.setType(OPENSHIFT_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setSelector(selector);
CommandImpl command = new CommandImpl();
command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME);
workspaceConfig.getCommands().add(command);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
CommandImpl actualCommand = workspaceConfig.getCommands().get(0);
assertEquals(actualCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "petclinic/server");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionEndpointWithAttributes.
@Test
public void shouldProvisionEndpointWithAttributes() throws IOException, ValidationException, InfrastructureException, DevfileException {
// given
String endpointName = "petclinic-endpoint";
Integer endpointPort = 8081;
String endpointProtocol = "tcp";
String endpointPath = "path";
String endpointPublic = "false";
String endpointSecure = "false";
String yamlRecipeContent = getResource("devfile/petclinicPods.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setEndpoints(singletonList(new EndpointImpl(endpointName, endpointPort, ImmutableMap.of("protocol", endpointProtocol, "path", endpointPath, "public", endpointPublic, "secure", endpointSecure))));
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
@SuppressWarnings("unchecked") ArgumentCaptor<Map<String, MachineConfigImpl>> objectsCaptor = ArgumentCaptor.forClass(Map.class);
verify(k8sEnvProvisioner).provision(any(), any(), any(), objectsCaptor.capture());
Map<String, MachineConfigImpl> configs = objectsCaptor.getValue();
assertEquals(configs.size(), 3);
configs.values().forEach(machineConfig -> {
Map<String, ServerConfigImpl> serverConfigs = machineConfig.getServers();
assertEquals(serverConfigs.size(), 1);
assertTrue(serverConfigs.containsKey(endpointName));
assertEquals(serverConfigs.get(endpointName).getPort(), endpointPort.toString());
assertEquals(serverConfigs.get(endpointName).getPath(), endpointPath);
assertEquals(serverConfigs.get(endpointName).getProtocol(), endpointProtocol);
assertEquals(serverConfigs.get(endpointName).getAttributes().get(REQUIRE_SUBDOMAIN), "true");
assertEquals(serverConfigs.get(endpointName).isSecure(), Boolean.parseBoolean(endpointSecure));
assertEquals(serverConfigs.get(endpointName).isInternal(), !Boolean.parseBoolean(endpointPublic));
});
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionEnvIntoK8SList.
@Test
public void shouldProvisionEnvIntoK8SList() throws Exception {
// given
List<HasMetadata> k8sList = new ArrayList<>();
Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").endMetadata().withNewSpec().endSpec().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").endMetadata().withNewSpec().endSpec().build();
k8sList.add(pod1);
k8sList.add(pod2);
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
List<EnvImpl> envToApply = singletonList(new EnvImpl("TEST_ENV", "anyValue"));
component.setEnv(envToApply);
// when
applier.apply(workspaceConfig, component, s -> "content");
// then
envVars.apply(new PodData(pod1), envToApply);
envVars.apply(new PodData(pod2), envToApply);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldChangeEntrypointsOnMatchingContainers.
@Test
public void shouldChangeEntrypointsOnMatchingContainers() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
List<String> command = asList("teh", "command");
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
EntrypointImpl entrypoint = new EntrypointImpl();
entrypoint.setParentName("petclinic");
entrypoint.setCommand(command);
component.setEntrypoints(singletonList(entrypoint));
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), objectsCaptor.capture(), any());
List<HasMetadata> list = objectsCaptor.getValue();
for (HasMetadata o : list) {
if (o instanceof Pod) {
Pod p = (Pod) o;
// ignore pods that don't have containers
if (p.getSpec() == null) {
continue;
}
Container c = p.getSpec().getContainers().get(0);
if (o.getMetadata().getName().equals("petclinic")) {
assertEquals(c.getCommand(), command);
} else {
assertTrue(c.getCommand() == null || c.getCommand().isEmpty());
}
}
}
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldBeAbleToOverrideImagePullPolicy.
@Test
public void shouldBeAbleToOverrideImagePullPolicy() throws Exception {
// given
applier = new KubernetesComponentToWorkspaceApplier(k8sRecipeParser, k8sEnvProvisioner, envVars, PROJECT_MOUNT_PATH, "1Gi", "ReadWriteOnce", "", "Never", MULTI_HOST_STRATEGY, k8sBasedComponents);
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), objectsCaptor.capture(), any());
List<HasMetadata> list = objectsCaptor.getValue();
for (HasMetadata o : list) {
if (o instanceof Pod) {
Pod p = (Pod) o;
// ignore pods that don't have containers
if (p.getSpec() == null) {
continue;
}
List<Container> containers = new ArrayList<>();
containers.addAll(p.getSpec().getContainers());
containers.addAll(p.getSpec().getInitContainers());
for (Container con : containers) {
assertEquals(con.getImagePullPolicy(), "Never");
}
}
}
}
Aggregations