Skip to content

Commit

Permalink
fix(PodTemplateUtils): override parent activeDeadlineSeconds by child…
Browse files Browse the repository at this point in the history
… value if not null (#1595)
  • Loading branch information
a1k0u authored Aug 12, 2024
1 parent 0889b96 commit 50ed5f6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ public static Pod combine(Pod parent, Pod template) {
? parent.getSpec().getSchedulerName()
: template.getSpec().getSchedulerName();

Long activeDeadlineSeconds = template.getSpec().getActiveDeadlineSeconds() != null
? template.getSpec().getActiveDeadlineSeconds()
: parent.getSpec().getActiveDeadlineSeconds();
Boolean hostNetwork = template.getSpec().getHostNetwork() != null
? template.getSpec().getHostNetwork()
: parent.getSpec().getHostNetwork();
Expand Down Expand Up @@ -387,6 +390,7 @@ public static Pod combine(Pod parent, Pod template) {
.withServiceAccount(serviceAccount) //
.withServiceAccountName(serviceAccountName) //
.withSchedulerName(schedulerName)
.withActiveDeadlineSeconds(activeDeadlineSeconds) //
.withHostNetwork(hostNetwork) //
.withShareProcessNamespace(shareProcessNamespace) //
.withContainers(combinedContainers) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,47 @@ public void shouldCombineAllPodKeyValueEnvVars() {
assertThat(result.getEnvVars(), contains(podEnvVar1, podEnvVar2, podEnvVar3));
}

@Test
public void childShouldOverrideParentActiveDeadlineSeconds() {
Pod parentPod = new PodBuilder()
.withNewMetadata()
.endMetadata()
.withNewSpec()
.withActiveDeadlineSeconds(1L)
.endSpec()
.build();
Pod childPod = new PodBuilder()
.withNewMetadata()
.endMetadata()
.withNewSpec()
.withActiveDeadlineSeconds(2L)
.endSpec()
.build();

Pod combinedPod = combine(parentPod, childPod);
assertEquals(combinedPod.getSpec().getActiveDeadlineSeconds(), Long.valueOf(2L));
}

@Test
public void shouldCombineActiveDeadlineSeconds() {
Pod parentPod = new PodBuilder()
.withNewMetadata()
.endMetadata()
.withNewSpec()
.withActiveDeadlineSeconds(1L)
.endSpec()
.build();
Pod childPod = new PodBuilder()
.withNewMetadata()
.endMetadata()
.withNewSpec()
.endSpec()
.build();

Pod combinedPod = combine(parentPod, childPod);
assertEquals(combinedPod.getSpec().getActiveDeadlineSeconds(), Long.valueOf(1L));
}

@Test
public void shouldFilterOutNullOrEmptyPodKeyValueEnvVars() {
PodTemplate template1 = new PodTemplate();
Expand Down

0 comments on commit 50ed5f6

Please sign in to comment.