From b0d78dbbcb0e465c194edf14756daca359758a2f Mon Sep 17 00:00:00 2001 From: Matheus Cruz Date: Wed, 9 Oct 2024 15:16:59 -0300 Subject: [PATCH] Apply pull request suggestion --- .../deployment/AddNamespaceDecorator.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java index f4b9e2c5a9761f..30a3ed5d7d61ce 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java @@ -2,17 +2,17 @@ import java.util.List; import java.util.Objects; -import java.util.Set; import java.util.stream.Collectors; import io.dekorate.kubernetes.decorator.Decorator; import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesListBuilder; +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.api.model.ObjectMeta; public class AddNamespaceDecorator extends Decorator { - private static final Set CLUSTERED_RESOURCES = Set.of("ClusterRoleBinding", "ClusterRole"); private final String namespace; public AddNamespaceDecorator(String namespace) { @@ -24,17 +24,17 @@ public void visit(KubernetesListBuilder list) { List buildItems = list.buildItems() .stream() .peek(obj -> { - if (isEligibleForChangingNamespace(obj)) { - obj.setMetadata(obj.getMetadata().edit().withNamespace(namespace).build()); + if (obj instanceof Namespaced) { + final ObjectMeta metadata = obj.getMetadata(); + if (metadata.getNamespace() == null) { + metadata.setNamespace(namespace); + obj.setMetadata(metadata); + } } }).collect(Collectors.toList()); list.withItems(buildItems); } - private boolean isEligibleForChangingNamespace(HasMetadata obj) { - return obj.getMetadata().getNamespace() == null && !CLUSTERED_RESOURCES.contains(obj.getKind()); - } - @Override public Class[] after() { return new Class[] { ResourceProvidingDecorator.class, AddSidecarDecorator.class };