Skip to content

Commit

Permalink
fix (dekorateio#609): Selector decorators are now applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 22, 2020
1 parent cfecb0c commit 0269de7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class AddToMatchingLabelsDecorator extends NamedResourceDecorator<LabelSe

private String key;
private String value;

public AddToMatchingLabelsDecorator(String key, String value) {
this(ANY, key, value);
}

public AddToMatchingLabelsDecorator(String name, String key, String value) {
super(name);
Expand All @@ -21,10 +25,10 @@ public AddToMatchingLabelsDecorator(String kind, String name, String key, String
this.value = value;
}

@Override
public void andThenVisit(LabelSelectorFluent<?> selector, ObjectMeta resourceMeta) {
@Override
public void andThenVisit(LabelSelectorFluent<?> selector, ObjectMeta resourceMeta) {
selector.addToMatchLabels(key, value);
}
}

@Override
public Class<? extends Decorator>[] after() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.dekorate.SelectorDecoratorFactories;
import io.dekorate.SelectorDecoratorFactory;
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import io.fabric8.kubernetes.api.builder.Visitor;
import io.fabric8.kubernetes.api.model.ObjectMeta;

public class AddToSelectorDecorator extends NamedResourceDecorator<VisitableBuilder> {
Expand Down Expand Up @@ -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<SelectorDecoratorFactory> 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<? extends Decorator>[] before() {
return new Class[] {AddToSelectorDecorator.class};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class RemoveFromMatchingLabelsDecorator extends NamedResourceDecorator<La

private String key;

public RemoveFromMatchingLabelsDecorator(String key) {
this(ANY, key);
}

public RemoveFromMatchingLabelsDecorator(String name, String key) {
super(name);
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
import io.dekorate.SelectorDecoratorFactories;
import io.dekorate.SelectorDecoratorFactory;
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import io.fabric8.kubernetes.api.builder.Visitor;
import io.fabric8.kubernetes.api.model.ObjectMeta;

public class RemoveFromSelectorDecorator extends NamedResourceDecorator<VisitableBuilder> {

private final String key;

public RemoveFromSelectorDecorator(String key) {
this(ANY, key);
}

public RemoveFromSelectorDecorator(String name, String key) {
super(name);
this.key = key;
Expand All @@ -42,11 +47,16 @@ public RemoveFromSelectorDecorator(String kind, String name, String key) {
@Override
public void andThenVisit(VisitableBuilder builder ,String kind, ObjectMeta resourceMeta) {
Optional<SelectorDecoratorFactory> 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<? extends Decorator>[] after() {
return new Class[] {ResourceProvidingDecorator.class, AddToSelectorDecorator.class};
}
}

0 comments on commit 0269de7

Please sign in to comment.