Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the fragment doesnot already have a name #2825

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,10 +54,12 @@ public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
builder.accept(new TypedVisitor<ObjectMetaBuilder>() {
@Override
public void visit(ObjectMetaBuilder resource) {
if (StringUtils.isNotBlank(configuredName)) {
resource.withName(configuredName);
} else if (StringUtils.isBlank(resource.getName())) {
resource.withName(defaultName);
if(StringUtils.isBlank(resource.getName())) {
if (StringUtils.isNotBlank(configuredName)) {
resource.withName(configuredName);
} else {
resource.withName(defaultName);
}
}
}
});
Expand Down
Expand Up @@ -118,7 +118,7 @@ void create_withAlreadyExistingName_shouldKeepExistingName() {
}

@Test
void create_withCustomNameAndAlreadyExistingName_shouldOverrideExistingName() {
void create_withCustomNameAndAlreadyExistingName_shouldKeepExistingName() {
// Given
klb = new KubernetesListBuilder();
properties.put("jkube.enricher.jkube-name.name", "custom-name");
Expand All @@ -128,6 +128,20 @@ void create_withCustomNameAndAlreadyExistingName_shouldOverrideExistingName() {
// Then
assertThat(klb.build().getItems())
.singleElement()
.hasFieldOrPropertyWithValue("metadata.name", "custom-name");
.hasFieldOrPropertyWithValue("metadata.name", "existing-name");
}

@Test
void create_withoutName_shouldSetGivenCustomName() {
// Given
klb = new KubernetesListBuilder();
properties.put("jkube.enricher.jkube-name.name", "custom-name");
// When
klb.addToItems(new ServiceBuilder().withNewMetadata().endMetadata().build());
new NameEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertThat(klb.build().getItems())
.singleElement()
.hasFieldOrPropertyWithValue("metadata.name", "custom-name");
}
}