jkube
jkube copied to clipboard
Prevent ProjectLabelEnricher from overriding fragment defined labels
Component
No response
Is your enhancement related to a problem? Please describe
If I define multiple services (see #1668) the ProjectLabelEnricher overwrites the custom app
label I defined in the additional service fragments (deployment, service, etc.)
Describe the solution you'd like
We should analyze if we might want to prevent this from happening by giving priority to Fragment defined labels.
Describe alternatives you've considered
No response
Additional context
No response
A possible solution is to check if the Resource already contains a defined matching label.
- If the label exists we won't overwrite.
- ??? provide a config option to overwrite ???
Sorry but I'm not able to reproduce this issue. I tried with a unit test with a service resource having app
label already set but it's passing for me.
@Test
public void createAndEnrich_withAlreadyExistingAppLabel_shouldNotOverrideInSelector() {
// Given
KubernetesListBuilder builder = new KubernetesListBuilder()
.withItems(new ServiceBuilder()
.withNewMetadata()
.addToLabels("app", "already-existing-label")
.endMetadata()
.withNewSpec()
.addToSelector("app", "already-existing-label")
.endSpec()
.build());
// When
projectLabelEnricher.create(PlatformMode.kubernetes, builder);
projectLabelEnricher.enrich(PlatformMode.kubernetes, builder);
// Then
assertThat((Service) builder.buildFirstItem())
.hasFieldOrPropertyWithValue("metadata.labels.app", "already-existing-label")
.hasFieldOrPropertyWithValue("spec.selector.app", "already-existing-label");
}
I also tried placing a service fragment in a test project with custom app
label but it doesn't seem to get overridden. What could I be missing? Do you have your project where you were facing this issue?
Looking at the code, our current behavior seems to modify selectors only when they're absent: https://github.com/eclipse/jkube/blob/29f6e76f4be2cc7c63a44ea5e04e001253479f13/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ProjectLabelEnricher.java#L167 Same with generated labels in metadata: https://github.com/eclipse/jkube/blob/29f6e76f4be2cc7c63a44ea5e04e001253479f13/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ProjectLabelEnricher.java#L176-L183
Maybe the fix we did to allow multiple service fragments took care of this.
Try with a previous JKube version to see if you can reproduce, if not I need to see what I was exactly referring to when I created the issue.
I just tried with v1.11-SNAPSHOT, v1.10.1, v1.9.1, v1.8.0, v1.7.0 but seeing same behavior.
We need to create an integration test that includes multiple services (not sure if we did that in scope of #1668) with different project labels. At least one of them should include values read from properties (pom.xml).