From 77d6cc1a7f77185e0910aa737c5da71e8e67cc7c Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Tue, 22 Sep 2020 07:40:31 +0300 Subject: [PATCH] fix (#609): Selector decorators are now applied. --- .../decorator/AddToMatchingLabelsDecorator.java | 10 +++++++--- .../kubernetes/decorator/AddToSelectorDecorator.java | 11 +++++++++-- .../decorator/RemoveFromMatchingLabelsDecorator.java | 4 ++++ .../decorator/RemoveFromSelectorDecorator.java | 12 +++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/dekorate/kubernetes/decorator/AddToMatchingLabelsDecorator.java b/core/src/main/java/io/dekorate/kubernetes/decorator/AddToMatchingLabelsDecorator.java index ad56c24bc..321d21a73 100644 --- a/core/src/main/java/io/dekorate/kubernetes/decorator/AddToMatchingLabelsDecorator.java +++ b/core/src/main/java/io/dekorate/kubernetes/decorator/AddToMatchingLabelsDecorator.java @@ -8,6 +8,10 @@ public class AddToMatchingLabelsDecorator extends NamedResourceDecorator selector, ObjectMeta resourceMeta) { + @Override + public void andThenVisit(LabelSelectorFluent selector, ObjectMeta resourceMeta) { selector.addToMatchLabels(key, value); - } + } @Override public Class[] after() { diff --git a/core/src/main/java/io/dekorate/kubernetes/decorator/AddToSelectorDecorator.java b/core/src/main/java/io/dekorate/kubernetes/decorator/AddToSelectorDecorator.java index b7bb7f371..b9be9befe 100644 --- a/core/src/main/java/io/dekorate/kubernetes/decorator/AddToSelectorDecorator.java +++ b/core/src/main/java/io/dekorate/kubernetes/decorator/AddToSelectorDecorator.java @@ -22,6 +22,7 @@ import io.dekorate.SelectorDecoratorFactories; import io.dekorate.SelectorDecoratorFactory; import io.dekorate.deps.kubernetes.api.builder.VisitableBuilder; +import io.dekorate.deps.kubernetes.api.builder.Visitor; import io.dekorate.deps.kubernetes.api.model.ObjectMeta; public class AddToSelectorDecorator extends NamedResourceDecorator { @@ -51,11 +52,17 @@ public AddToSelectorDecorator(String kind, String name, String key, String value @Override public void andThenVisit(VisitableBuilder builder ,String kind, ObjectMeta resourceMeta) { Optional factory = SelectorDecoratorFactories.find(kind); - factory.ifPresent(f -> f.createAddToSelectorDecorator(resourceMeta.getName(), key, value)); + factory.map(f -> f.createAddToSelectorDecorator(resourceMeta.getName(), key, value)).ifPresent(m -> builder.accept((Visitor) m)); } - @Override + @Override public void andThenVisit(VisitableBuilder item, ObjectMeta resourceMeta) { //Not needed } + + @Override + public Class[] before() { + return new Class[] {AddToSelectorDecorator.class}; + } + } diff --git a/core/src/main/java/io/dekorate/kubernetes/decorator/RemoveFromMatchingLabelsDecorator.java b/core/src/main/java/io/dekorate/kubernetes/decorator/RemoveFromMatchingLabelsDecorator.java index e8655c64e..07ca529e9 100644 --- a/core/src/main/java/io/dekorate/kubernetes/decorator/RemoveFromMatchingLabelsDecorator.java +++ b/core/src/main/java/io/dekorate/kubernetes/decorator/RemoveFromMatchingLabelsDecorator.java @@ -7,6 +7,10 @@ public class RemoveFromMatchingLabelsDecorator extends NamedResourceDecorator { private final String key; + public RemoveFromSelectorDecorator(String key) { + this(ANY, key); + } + public RemoveFromSelectorDecorator(String name, String key) { super(name); this.key = key; @@ -42,11 +47,16 @@ public RemoveFromSelectorDecorator(String kind, String name, String key) { @Override public void andThenVisit(VisitableBuilder builder ,String kind, ObjectMeta resourceMeta) { Optional factory = SelectorDecoratorFactories.find(kind); - factory.ifPresent(f -> f.createRemoveFromSelectorDecorator(resourceMeta.getName(), key)); + factory.map(f -> f.createRemoveFromSelectorDecorator(resourceMeta.getName(), key)).ifPresent(m -> builder.accept((Visitor) m)); } @Override public void andThenVisit(VisitableBuilder item, ObjectMeta resourceMeta) { //Not needed } + + @Override + public Class[] after() { + return new Class[] {ResourceProvidingDecorator.class, AddToSelectorDecorator.class}; + } }