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

0.12.x selector fix #636

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ private void addVisitors(ComponentConfig config) {
Map<String, String> allLabels = new HashMap<>();
allLabels.put(Labels.NAME, config.getName());

System.out.println("Component version:" + config.getVersion()+".");
if (Strings.isNotNullOrEmpty(config.getVersion())) {
allLabels.put(Labels.VERSION, config.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public ApplyDeploymentStrategyDecorator(String name, DeploymentStrategy strategy
@Override
public void andThenVisit(final DeploymentSpecFluent<?> spec, final ObjectMeta resourceMeta) {
boolean hasCustomRollingUpdate = hasCusomRollingUpdateConfig(rollingUpdate);
System.out.println("Custom rolling update:" + hasCustomRollingUpdate);
if (strategy == DeploymentStrategy.Recreate) {
if (hasCustomRollingUpdate) {
throw new IllegalStateException("Detected both Recreate strategy and custom Rolling Update config. Please use one or the other!");
Expand All @@ -47,7 +46,6 @@ public void andThenVisit(final DeploymentSpecFluent<?> spec, final ObjectMeta re
.withType("Recreate")
.endStrategy();
} else if (strategy == DeploymentStrategy.RollingUpdate || hasCustomRollingUpdate) {
System.out.println("Applying rolling update!");
spec.withNewStrategy()
.withType("RollingUpdate")
.withNewRollingUpdate()
Expand Down
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.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<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.dekorate.deps.kubernetes.api.builder.VisitableBuilder;
import io.dekorate.deps.kubernetes.api.builder.Visitor;
import io.dekorate.deps.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};
}
}