Skip to content

Commit

Permalink
Merge pull request #42491 from claudio4j/fix_kn_repldeco
Browse files Browse the repository at this point in the history
Change dekorate template to use the intended knative object
  • Loading branch information
gsmet committed Sep 3, 2024
2 parents 2539288 + 9a44982 commit 3af742f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
import io.dekorate.knative.decorator.AddPvcVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddSecretVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddSidecarToRevisionDecorator;
import io.dekorate.knative.decorator.ApplyAnnotationsToServiceTemplate;
import io.dekorate.knative.decorator.ApplyGlobalAutoscalingClassDecorator;
import io.dekorate.knative.decorator.ApplyGlobalContainerConcurrencyDecorator;
import io.dekorate.knative.decorator.ApplyGlobalRequestsPerSecondTargetDecorator;
import io.dekorate.knative.decorator.ApplyGlobalTargetUtilizationDecorator;
import io.dekorate.knative.decorator.ApplyLocalAutoscalingClassDecorator;
import io.dekorate.knative.decorator.ApplyLocalAutoscalingMetricDecorator;
import io.dekorate.knative.decorator.ApplyLocalAutoscalingTargetDecorator;
import io.dekorate.knative.decorator.ApplyLocalContainerConcurrencyDecorator;
import io.dekorate.knative.decorator.ApplyLocalTargetUtilizationPercentageDecorator;
import io.dekorate.knative.decorator.ApplyMaxScaleDecorator;
import io.dekorate.knative.decorator.ApplyMinScaleDecorator;
import io.dekorate.knative.decorator.ApplyRevisionNameDecorator;
import io.dekorate.knative.decorator.ApplyServiceAccountToRevisionSpecDecorator;
import io.dekorate.knative.decorator.ApplyTrafficDecorator;
Expand Down Expand Up @@ -82,14 +88,6 @@ public class KnativeProcessor {
private static final String KNATIVE_CONFIG_AUTOSCALER = "config-autoscaler";
private static final String KNATIVE_CONFIG_DEFAULTS = "config-defaults";
private static final String KNATIVE_SERVING = "knative-serving";
private static final String KNATIVE_MIN_SCALE = "autoscaling.knative.dev/minScale";
private static final String KNATIVE_MAX_SCALE = "autoscaling.knative.dev/maxScale";
private static final String KNATIVE_AUTOSCALING_METRIC = "autoscaling.knative.dev/metric";
private static final String KNATIVE_AUTOSCALING_CLASS = "autoscaling.knative.dev/class";
private static final String KNATIVE_AUTOSCALING_CLASS_SUFFIX = ".autoscaling.knative.dev";
private static final String KNATIVE_UTILIZATION_PERCENTAGE = "autoscaling.knative.dev/target-utilization-percentage";
private static final String KNATIVE_AUTOSCALING_TARGET = "autoscaling.knative.dev/target";
private static final String KNATIVE_CONTAINER_CONCURRENCY = "container-concurrency";
private static final String KNATIVE_DEV_VISIBILITY = "networking.knative.dev/visibility";

@BuildStep
Expand Down Expand Up @@ -201,55 +199,20 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
result.add(new DecoratorBuildItem(KNATIVE,
new AddLabelDecorator(name, KNATIVE_DEV_VISIBILITY, "cluster-local")));
}

}

/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyMinScaleDecorator.
*/
config.minScale.map(String::valueOf).ifPresent(min -> result.add(new DecoratorBuildItem(KNATIVE,
new ApplyAnnotationsToServiceTemplate(name, KNATIVE_MIN_SCALE, min))));
/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyMaxScaleDecorator.
*/
config.maxScale.map(String::valueOf).ifPresent(max -> result.add(new DecoratorBuildItem(KNATIVE,
new ApplyAnnotationsToServiceTemplate(name, KNATIVE_MAX_SCALE, max))));
/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyLocalAutoscalingClassDecorator.
*/
config.minScale.ifPresent(min -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyMinScaleDecorator(name, min))));
config.maxScale.ifPresent(max -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyMaxScaleDecorator(name, max))));
config.revisionAutoScaling.autoScalerClass.map(AutoScalerClassConverter::convert)
.ifPresent(a -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyAnnotationsToServiceTemplate(name,
KNATIVE_AUTOSCALING_CLASS, a.name().toLowerCase() + KNATIVE_AUTOSCALING_CLASS_SUFFIX))));
/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyLocalAutoscalingMetricDecorator.
*/
.ifPresent(a -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalAutoscalingClassDecorator(name, a))));
config.revisionAutoScaling.metric.map(AutoScalingMetricConverter::convert)
.ifPresent(m -> result.add(new DecoratorBuildItem(KNATIVE,
new ApplyAnnotationsToServiceTemplate(name, KNATIVE_AUTOSCALING_METRIC, m.name().toLowerCase()))));

config.revisionAutoScaling.containerConcurrency
.ifPresent(
c -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(name, c))));

/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyLocalTargetUtilizationPercentageDecorator.
*/
config.revisionAutoScaling.targetUtilizationPercentage.map(String::valueOf)
.ifPresent(t -> result
.add(new DecoratorBuildItem(KNATIVE,
new ApplyAnnotationsToServiceTemplate(name, KNATIVE_UTILIZATION_PERCENTAGE, t))));
/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyLocalAutoscalingTargetDecorator.
*/
config.revisionAutoScaling.target.map(String::valueOf)
.ifPresent(t -> result.add(new DecoratorBuildItem(KNATIVE,
new ApplyAnnotationsToServiceTemplate(name, KNATIVE_AUTOSCALING_TARGET, t))));
.ifPresent(m -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalAutoscalingMetricDecorator(name, m))));
config.revisionAutoScaling.containerConcurrency.ifPresent(
c -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(name, c))));
config.revisionAutoScaling.targetUtilizationPercentage.ifPresent(t -> result
.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalTargetUtilizationPercentageDecorator(name, t))));
config.revisionAutoScaling.target
.ifPresent(t -> result.add(new DecoratorBuildItem(KNATIVE, new ApplyLocalAutoscalingTargetDecorator(name, t))));
config.globalAutoScaling.autoScalerClass
.map(AutoScalerClassConverter::convert)
.ifPresent(a -> {
Expand All @@ -258,17 +221,11 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
new AddConfigMapResourceProvidingDecorator(KNATIVE_CONFIG_AUTOSCALER, KNATIVE_SERVING)));
result.add(new DecoratorBuildItem(KNATIVE, new ApplyGlobalAutoscalingClassDecorator(a)));
});
config.globalAutoScaling.containerConcurrency.map(String::valueOf)
.ifPresent(c -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddConfigMapResourceProvidingDecorator(KNATIVE_CONFIG_DEFAULTS, KNATIVE_SERVING)));
/**
* Once the Dekorate issue is fixed https://github.com/dekorateio/dekorate/issues/869,
* we should replace ApplyAnnotationsToServiceTemplate by ApplyGlobalContainerConcurrencyDecorator.
*/
result.add(new DecoratorBuildItem(KNATIVE,
new AddConfigMapDataDecorator(KNATIVE_CONFIG_DEFAULTS, KNATIVE_CONTAINER_CONCURRENCY, c)));
});
config.globalAutoScaling.containerConcurrency.ifPresent(c -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddConfigMapResourceProvidingDecorator(KNATIVE_CONFIG_DEFAULTS, KNATIVE_SERVING)));
result.add(new DecoratorBuildItem(KNATIVE, new ApplyGlobalContainerConcurrencyDecorator(c)));
});

config.globalAutoScaling.requestsPerSecond
.ifPresent(r -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void assertGeneratedResources() throws IOException {
assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
Service service = (Service) i;
Map<String, String> annotations = service.getSpec().getTemplate().getMetadata().getAnnotations();
assertThat(annotations).contains(entry("autoscaling.knative.dev/minScale", "3"));
assertThat(annotations).contains(entry("autoscaling.knative.dev/maxScale", "5"));
assertThat(annotations).contains(entry("autoscaling.knative.dev/min-scale", "3"));
assertThat(annotations).contains(entry("autoscaling.knative.dev/max-scale", "5"));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void assertGeneratedResources() throws IOException {
assertThat(s.getSpec()).satisfies(serviceSpec -> {
assertThat(serviceSpec.getTemplate()).satisfies(template -> {
assertThat(template.getMetadata()).satisfies(m -> {
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/minScale", "5"));
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/maxScale", "10"));
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/min-scale", "5"));
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/max-scale", "10"));
});
assertThat(template.getSpec()).satisfies(revisionSpec -> {
assertThat(revisionSpec.getContainerConcurrency()).isEqualTo(5);
Expand Down

0 comments on commit 3af742f

Please sign in to comment.