Skip to content

Commit

Permalink
Fix NodeSelector propogation in PodMerger; (eclipse-che#18698)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Shaposhnik <mshaposh@redhat.com>
  • Loading branch information
mshaposhnik authored Dec 25, 2020
1 parent 35a4032 commit 6791ed4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public Deployment merge(List<PodData> podsData) throws ValidationException {
mergeServiceAccountName(
baseSpec.getServiceAccountName(), podData.getSpec().getServiceAccountName()));

baseSpec.setNodeSelector(
mergeNodeSelector(baseSpec.getNodeSelector(), podData.getSpec().getNodeSelector()));

// if there are entries with such keys then values will be overridden
baseSpec.getAdditionalProperties().putAll(podData.getSpec().getAdditionalProperties());
}
Expand Down Expand Up @@ -203,4 +206,16 @@ private static <T> T nonNullOrEqual(@Nullable T a, @Nullable T b, String errorMe
throw new ValidationException(String.format(errorMessageTemplate, a, b));
}
}

private Map<String, String> mergeNodeSelector(
@Nullable Map<String, String> base, @Nullable Map<String, String> nodeSelector) {
Map<String, String> mergedMap = base;
if (nodeSelector != null && !nodeSelector.isEmpty()) {
if (mergedMap == null) {
mergedMap = new HashMap<>();
}
mergedMap.putAll(nodeSelector);
}
return mergedMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void shouldMergeSpecsOfPodsData() throws Exception {
.withContainers(new ContainerBuilder().withName("c1").build())
.withInitContainers(new ContainerBuilder().withName("initC1").build())
.withVolumes(new VolumeBuilder().withName("v1").build())
.withNodeSelector(Map.of("foo1", "bar1"))
.withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret1").build())
.build();
podSpec1.setAdditionalProperty("add1", 1L);
Expand All @@ -126,6 +127,7 @@ public void shouldMergeSpecsOfPodsData() throws Exception {
.withContainers(new ContainerBuilder().withName("c2").build())
.withInitContainers(new ContainerBuilder().withName("initC2").build())
.withVolumes(new VolumeBuilder().withName("v2").build())
.withNodeSelector(Map.of("foo2", "bar2"))
.withImagePullSecrets(new LocalObjectReferenceBuilder().withName("secret2").build())
.build();
podSpec2.setAdditionalProperty("add2", 2L);
Expand Down Expand Up @@ -439,6 +441,8 @@ private void verifyContainsAllFrom(PodSpec source, PodSpec toCheck) {
assertTrue(source.getInitContainers().containsAll(toCheck.getInitContainers()));
assertTrue(source.getVolumes().containsAll(toCheck.getVolumes()));
assertTrue(source.getImagePullSecrets().containsAll(toCheck.getImagePullSecrets()));
assertTrue(
source.getNodeSelector().entrySet().containsAll(toCheck.getNodeSelector().entrySet()));
assertTrue(
source
.getAdditionalProperties()
Expand Down

0 comments on commit 6791ed4

Please sign in to comment.