Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Container resolve() throws InfrastructureException {
.withName(buildContainerName(cheContainer.getName()))
.withEnv(toK8sEnv(cheContainer.getEnv()))
.withPorts(getContainerPorts())
.withCommand(cheContainer.getCommand())
.withArgs(cheContainer.getArgs())
.build();

provisionMemoryLimit(container, cheContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,106 @@ public void addToolingInitContainerToAPod() throws Exception {
verifyContainer(toolingInitContainer);
}

@Test
public void addToolingInitContainerWithCommand() throws InfrastructureException {
List<String> command = Arrays.asList("cp", "-rf", "test-file", "/some-volume/test");
lenient().when(podSpec.getInitContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> initContainers = singletonList(createContainer(command, null));
chePlugin.setInitContainers(initContainers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndInitContainersNumber(1);
Container toolingInitContainer = getOnlyOneInitContainerFromPod(internalEnvironment);
verifyContainer(toolingInitContainer);
assertEquals(toolingInitContainer.getCommand(), command);
}

@Test
public void addToolingInitContainerWithArgs() throws InfrastructureException {
List<String> args = Arrays.asList("cp", "-rf", "test-file", "/some-volume/test");
lenient().when(podSpec.getInitContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> initContainers = singletonList(createContainer(null, args));
chePlugin.setInitContainers(initContainers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndInitContainersNumber(1);
Container toolingInitContainer = getOnlyOneInitContainerFromPod(internalEnvironment);
verifyContainer(toolingInitContainer);
assertEquals(toolingInitContainer.getArgs(), args);
}

@Test
public void addToolingInitContainerWithCommandAndArgs() throws InfrastructureException {
List<String> command = singletonList("cp");
List<String> args = Arrays.asList("-rf", "test-file", "/some-volume/test");
lenient().when(podSpec.getInitContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> initContainers = singletonList(createContainer(command, args));
chePlugin.setInitContainers(initContainers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndInitContainersNumber(1);
Container toolingInitContainer = getOnlyOneInitContainerFromPod(internalEnvironment);
verifyContainer(toolingInitContainer);
assertEquals(toolingInitContainer.getCommand(), command);
assertEquals(toolingInitContainer.getArgs(), args);
}

@Test
public void addToolingContainerWithCommand() throws InfrastructureException {
List<String> command = Arrays.asList("tail", "-f", "/dev/null");
lenient().when(podSpec.getContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> containers = singletonList(createContainer(command, null));
chePlugin.setContainers(containers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndContainersNumber(1);
Container toolingContainer = getOneAndOnlyNonUserContainer(internalEnvironment);
verifyContainer(toolingContainer);
assertEquals(toolingContainer.getCommand(), command);
}

@Test
public void addToolingContainerWithArgs() throws InfrastructureException {
List<String> args = Arrays.asList("tail", "-f", "/dev/null");
lenient().when(podSpec.getContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> containers = singletonList(createContainer(null, args));
chePlugin.setContainers(containers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndContainersNumber(1);
Container toolingContainer = getOneAndOnlyNonUserContainer(internalEnvironment);
verifyContainer(toolingContainer);
assertEquals(toolingContainer.getArgs(), args);
}

@Test
public void addToolingContainerWithCommandAndArgs() throws InfrastructureException {
List<String> command = singletonList("tail");
List<String> args = Arrays.asList("-f", "/dev/null");
lenient().when(podSpec.getContainers()).thenReturn(new ArrayList<>());
ChePlugin chePlugin = createChePlugin();
List<CheContainer> containers = singletonList(createContainer(command, args));
chePlugin.setContainers(containers);

applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));

verifyPodAndContainersNumber(1);
Container toolingContainer = getOneAndOnlyNonUserContainer(internalEnvironment);
verifyContainer(toolingContainer);
assertEquals(toolingContainer.getCommand(), command);
assertEquals(toolingContainer.getArgs(), args);
}

@Test
public void createsPodAndAddToolingIfNoPodIsPresent() throws Exception {
internalEnvironment = spy(KubernetesEnvironment.builder().build());
Expand Down Expand Up @@ -670,6 +770,14 @@ private ChePlugin createChePlugin(String name, CheContainer... containers) {
return plugin;
}

private CheContainer createContainer(List<String> command, List<String> args) {
CheContainer container = createContainer();
container.setCommand(command);
container.setArgs(args);

return container;
}

private CheContainer createContainer(Command... commands) {
return createContainer(generate("container", 5), commands);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public class CheContainer {
@JsonProperty("mountSources")
private boolean mountSources = false;

@JsonProperty("command")
private List<String> command;

@JsonProperty("args")
private List<String> args;

public CheContainer image(String image) {
this.image = image;
return this;
Expand Down Expand Up @@ -156,6 +162,38 @@ public void setMountSources(boolean mountSources) {
this.mountSources = mountSources;
}

public CheContainer command(List<String> command) {
this.command = command;
return this;
}

public List<String> getCommand() {
if (command == null) {
return new ArrayList<>();
}
return command;
}

public void setCommand(List<String> command) {
this.command = command;
}

public CheContainer args(List<String> args) {
this.args = args;
return this;
}

public List<String> getArgs() {
if (args == null) {
return new ArrayList<>();
}
return args;
}

public void setArgs(List<String> args) {
this.args = args;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -172,7 +210,9 @@ public boolean equals(Object o) {
&& Objects.equals(getPorts(), that.getPorts())
&& Objects.equals(getMemoryLimit(), that.getMemoryLimit())
&& Objects.equals(getName(), that.getName())
&& isMountSources() == that.isMountSources();
&& isMountSources() == that.isMountSources()
&& Objects.equals(getCommand(), that.getCommand())
&& Objects.equals(getArgs(), that.getArgs());
}

@Override
Expand All @@ -185,7 +225,9 @@ public int hashCode() {
getPorts(),
getMemoryLimit(),
getName(),
isMountSources());
isMountSources(),
getCommand(),
getArgs());
}

@Override
Expand All @@ -208,6 +250,10 @@ public String toString() {
+ name
+ ", mountSources="
+ mountSources
+ ", command="
+ command
+ ", args="
+ args
+ '}';
}
}