diff --git a/operator/controller/src/main/java/io/apicurio/registry/operator/resource/ResourceFactory.java b/operator/controller/src/main/java/io/apicurio/registry/operator/resource/ResourceFactory.java index f07dae3b69..e02552639c 100644 --- a/operator/controller/src/main/java/io/apicurio/registry/operator/resource/ResourceFactory.java +++ b/operator/controller/src/main/java/io/apicurio/registry/operator/resource/ResourceFactory.java @@ -18,7 +18,6 @@ import static io.apicurio.registry.operator.resource.app.AppDeploymentResource.getContainerFromPodTemplateSpec; import static io.apicurio.registry.operator.utils.Mapper.YAML_MAPPER; import static io.apicurio.registry.operator.utils.Utils.isBlank; -import static io.apicurio.registry.operator.utils.Utils.mergeNotOverride; public class ResourceFactory { @@ -141,7 +140,12 @@ private static void mergeDeploymentPodTemplateSpec( if (c.getPorts() == null) { c.setPorts(new ArrayList<>()); } - mergeNotOverride(c.getPorts(), ports, ContainerPort::getName); + var targetPorts = c.getPorts(); + ports.forEach(sourcePort -> { + if (!targetPorts.stream().anyMatch(targetPort -> sourcePort.getName().equals(targetPort.getName()))) { + targetPorts.add(sourcePort); + } + }); if (c.getReadinessProbe() == null) { c.setReadinessProbe(readinessProbe); } diff --git a/operator/controller/src/main/java/io/apicurio/registry/operator/utils/Utils.java b/operator/controller/src/main/java/io/apicurio/registry/operator/utils/Utils.java index df4f6986e2..8def09677c 100644 --- a/operator/controller/src/main/java/io/apicurio/registry/operator/utils/Utils.java +++ b/operator/controller/src/main/java/io/apicurio/registry/operator/utils/Utils.java @@ -1,11 +1,5 @@ package io.apicurio.registry.operator.utils; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -import static java.util.Objects.requireNonNull; - public class Utils { private Utils() { @@ -15,41 +9,4 @@ public static boolean isBlank(String value) { return value == null || value.isBlank(); } - /** - * Merge source map into target map, NOT overriding any entries with the same key. - * - * @param target must not be null - */ - public static void mergeNotOverride(Map target, Map source) { - requireNonNull(target); - if (source != null) { - source.forEach(target::putIfAbsent); - } - } - - /** - * Merge source list into target list, NOT overriding any items based on the equality of the extracted - * key. - * - * @param target must not be null - */ - public static void mergeNotOverride(List target, List source, Function extractKey) { - requireNonNull(target); - if (source != null) { - for (T sval : source) { - K skey = extractKey.apply(sval); - boolean skip = false; - for (int ti = 0; ti < target.size(); ti++) { - K tkey = extractKey.apply(target.get(ti)); - if (skey.equals(tkey)) { - skip = true; - break; - } - } - if (!skip) { - target.add(sval); - } - } - } - } }