Skip to content

Commit

Permalink
Ensure initContainer(s) will configure args provided. (#474)
Browse files Browse the repository at this point in the history
Fixes #473
  • Loading branch information
corneil authored Sep 4, 2024
1 parent 293a986 commit 2d25f0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ private Container containerFromProps(InitContainer initContainerProps) {
.withName(initContainerProps.getContainerName())
.withImage(initContainerProps.getImageName())
.withCommand(initContainerProps.getCommands())
.withArgs(initContainerProps.getArgs())
.withEnv(toEnvironmentVariables(initContainerProps.getEnvironmentVariables()))
.addAllToVolumeMounts(Optional.ofNullable(initContainerProps.getVolumeMounts()).orElse(Collections.emptyList()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public static class ContainerProperties {
private String containerName;

private List<String> commands;

private List<String> args;
private List<VolumeMount> volumeMounts;

/**
Expand Down Expand Up @@ -925,6 +925,14 @@ public void setCommands(List<String> commands) {
this.commands = commands;
}

public List<String> getArgs() {
return args;
}

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

public List<VolumeMount> getVolumeMounts() {
return volumeMounts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ public void testMultipleInitContainerProperties() {
props.put("spring.cloud.deployer.kubernetes.initContainers[1].imageName", "busybox:2");
props.put("spring.cloud.deployer.kubernetes.initContainers[1].containerName", "bb_s2");
props.put("spring.cloud.deployer.kubernetes.initContainers[1].commands", "sh,-c,script2.sh");
props.put("spring.cloud.deployer.kubernetes.initContainers[2]", "{ \"imageName\": \"busybox:3\", \"containerName\": \"bb_s3\", \"commands\": [\"sh\", \"-c\", \"script3.sh\"], \"volumeMounts\": [{\"mountPath\": \"/data\", \"name\": \"s3vol\", \"readOnly\": true}] }");
props.put("spring.cloud.deployer.kubernetes.initContainers[2]", "{ \"imageName\": \"busybox:3\", \"containerName\": \"bb_s3\", \"args\": [\"-c\", \"script3.sh\"], \"volumeMounts\": [{\"mountPath\": \"/data\", \"name\": \"s3vol\", \"readOnly\": true}] }");

AppDefinition definition = new AppDefinition("app-test", null);
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
Expand All @@ -951,7 +951,7 @@ public void testMultipleInitContainerProperties() {
Container container2 = podSpec.getInitContainers().get(2);
assertThat(container2.getImage()).isEqualTo("busybox:3");
assertThat(container2.getName()).isEqualTo("bb_s3");
assertThat(container2.getCommand()).containsExactly("sh", "-c", "script3.sh");
assertThat(container2.getArgs()).containsExactly("-c", "script3.sh");
assertThat(container2.getVolumeMounts()).isNotEmpty();
assertThat(container2.getVolumeMounts().get(0).getName()).isEqualTo("s3vol");
assertThat(container2.getVolumeMounts().get(0).getMountPath()).isEqualTo("/data");
Expand Down

0 comments on commit 2d25f0e

Please sign in to comment.