Skip to content

Commit

Permalink
AddNamespaceDecorator doesn't override already set namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Dec 13, 2022
1 parent 78397f4 commit 4291255
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Expand Up @@ -19,7 +19,9 @@ public AddNamespaceDecorator(String namespace) {

@Override
public void andThenVisit(ObjectMetaBuilder builder, ObjectMeta resourceMeta) {
builder.withNamespace(namespace);
if (!builder.hasNamespace()) {
builder.withNamespace(namespace);
}
}

@Override
Expand Down
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.fabric8.kubernetes.api.model.ObjectMeta;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class WithKubernetesClientAndExistingResourcesTest {
.withConfigurationResource("kubernetes-with-" + APPLICATION_NAME + ".properties")
.addCustomResourceEntry(Path.of("src", "main", "kubernetes", "kubernetes.yml"),
"manifests/kubernetes-with-" + APPLICATION_NAME + "/kubernetes.yml")
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes-client", Version.getVersion())))
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes-client", Version.getVersion()), Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion())))
.addBuildChainCustomizerEntries(
new QuarkusProdModeTest.BuildChainCustomizerEntry(
KubernetesWithCustomResourcesTest.CustomProjectRootBuildItemProducerProdMode.class,
Expand Down Expand Up @@ -58,12 +59,17 @@ public void assertGeneratedResources() throws IOException {
}
});

assertThat(kubernetesList).filteredOn(h -> "ServiceAccount".equals(h.getKind())).singleElement().satisfies(h -> {
assertThat(h.getMetadata().getName()).isEqualTo(APPLICATION_NAME);
});
assertThat(kubernetesList).filteredOn(h -> "ServiceAccount".equals(h.getKind())).singleElement()
.satisfies(h -> assertThat(h.getMetadata().getName()).isEqualTo(APPLICATION_NAME));

assertThat(kubernetesList).filteredOn(h -> "RoleBinding".equals(h.getKind())).singleElement()
.satisfies(h -> assertThat(h.getMetadata().getName()).isEqualTo(APPLICATION_NAME + "-view"));

assertThat(kubernetesList).filteredOn(h -> "RoleBinding".equals(h.getKind())).singleElement().satisfies(h -> {
assertThat(h.getMetadata().getName()).isEqualTo(APPLICATION_NAME + "-view");
// check that if quarkus.kubernetes.namespace is set, "manually" set namespaces are not overwritten
assertThat(kubernetesList).filteredOn(h -> "ConfigMap".equals(h.getKind())).singleElement().satisfies(h -> {
final var metadata = h.getMetadata();
assertThat(metadata.getName()).isEqualTo("foo");
assertThat(metadata.getNamespace()).isEqualTo("foo");
});
}
}
@@ -0,0 +1 @@
quarkus.kubernetes.namespace=bar
Expand Up @@ -30,4 +30,11 @@ spec:
targetPort: 27017
selector:
name: my-service
type: ClusterIP
type: ClusterIP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: foo
namespace: foo
---

0 comments on commit 4291255

Please sign in to comment.