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

chore: centralize handling of container decorator order #1193

Merged
merged 1 commit into from
May 10, 2023
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 @@ -63,12 +63,6 @@ public Class<? extends Decorator>[] before() {
return new Class[] { RemoveAnnotationDecorator.class };
}

@Override
public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ public int hashCode() {
return Objects.hash(env);
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}

@Override
public List<ConfigReference> getConfigReferences() {
if (env.getValue() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ public void andThenVisit(ObjectMetaFluent item, ObjectMeta resourceMeta) {
}
}

@Override
public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,4 @@ public void andThenVisit(ContainerBuilder container) {
.withReadOnly(mount.isReadOnly())
.endVolumeMount();
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class, AddInitContainerDecorator.class };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,4 @@ public int hashCode() {

return Objects.hash(port);
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ protected boolean isApplicable(ContainerFluent<?> container) {
public abstract void andThenVisit(T item);

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class };
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class, AddSidecarDecorator.class,
AddInitContainerDecorator.class };
}

private class DeploymentVisitor extends TypedVisitor<ContainerBuilder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public void andThenVisit(ContainerFluent container) {
container.withArgs(argument);
}
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,4 @@ public void andThenVisit(ContainerFluent container) {
container.withCommand(command);
}
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public void andThenVisit(ContainerFluent container) {
container.withImage(image);
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class };
}

@Override
public List<ConfigReference> getConfigReferences() {
return Arrays.asList(buildConfigReferenceForImage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,4 @@ public ApplyImagePullPolicyDecorator(String imagePullPolicy) {
public void andThenVisit(ContainerFluent<?> container) {
container.withImagePullPolicy(imagePullPolicy != null ? imagePullPolicy.name() : "IfNotPresent");
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class, AddSidecarDecorator.class,
AddInitContainerDecorator.class };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,4 @@ public ApplyLimitsCpuDecorator(String deploymentName, String containerName, Stri
public void andThenVisit(ContainerFluent<?> container) {
container.editOrNewResources().addToLimits(CPU, new Quantity(amount)).endResources();
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class, AddInitContainerDecorator.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public ApplyLimitsMemoryDecorator(String deploymentName, String containerName, S
public void andThenVisit(ContainerFluent<?> container) {
container.editOrNewResources().addToLimits(MEM, new Quantity(amount)).endResources();
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class, AddInitContainerDecorator.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashSet;
import java.util.Set;

import io.dekorate.utils.Decorators;
import io.fabric8.kubernetes.api.model.ContainerPortFluent;

public class ApplyPortNameDecorator extends ApplicationContainerDecorator<ContainerPortFluent<?>> {
Expand All @@ -43,7 +44,6 @@ public void andThenVisit(ContainerPortFluent<?> port) {

@Override
public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class, AddSidecarDecorator.class,
AddPortDecorator.class };
return Decorators.append(super.after(), AddPortDecorator.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,4 @@ public void andThenVisit(ContainerFluent<?> container) {
System.out.println("Apply requests cpu to:" + container.getName());
container.editOrNewResources().addToRequests(CPU, new Quantity(amount)).endResources();
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class, AddInitContainerDecorator.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public ApplyRequestsMemoryDecorator(String deploymentName, String containerName,
public void andThenVisit(ContainerFluent<?> container) {
container.editOrNewResources().addToRequests(MEM, new Quantity(amount)).endResources();
}

public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, ApplyApplicationContainerDecorator.class,
AddSidecarDecorator.class, AddInitContainerDecorator.class };
}
}
35 changes: 35 additions & 0 deletions core/src/main/java/io/dekorate/utils/Decorators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2018 The original authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.dekorate.utils;

import io.dekorate.kubernetes.decorator.Decorator;

public final class Decorators {

private Decorators() {
//Utility classs
}

public static Class<? extends Decorator>[] append(Class<? extends Decorator>[] original,
Class<? extends Decorator>... additional) {
Class<? extends Decorator>[] result = new Class[original.length + additional.length];
System.arraycopy(original, 0, result, 0, original.length);
for (int i = 0; i < additional.length; i++) {
result[original.length + i] = additional[i];
}
return result;
}
}