From 4c8f4777222d27c5e6c3d282dd10690d3875d850 Mon Sep 17 00:00:00 2001 From: Claudio Miranda Date: Mon, 12 Aug 2024 17:36:10 +0100 Subject: [PATCH] Change dekorate template to use the intended knative object The dekorate issue is fixed and use the correct knative spec template as per the removed comment. https://github.com/dekorateio/dekorate/issues/869 (cherry picked from commit 9a44982adfe8921b97b9361bcd88ccbc52f4240e) --- .../deployment/KnativeProcessor.java | 87 +++++-------------- .../it/kubernetes/KnativeScaleBoundsTest.java | 4 +- .../KnativeWithExtendedPropertiesTest.java | 4 +- 3 files changed, 26 insertions(+), 69 deletions(-) diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java index 108dceae4c84a..fede6a8105aad 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java @@ -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; @@ -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 @@ -201,55 +199,20 @@ public List 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 -> { @@ -258,17 +221,11 @@ public List 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 -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeScaleBoundsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeScaleBoundsTest.java index 2d98390bb816c..4e88c8b061f0f 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeScaleBoundsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeScaleBoundsTest.java @@ -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 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")); }); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExtendedPropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExtendedPropertiesTest.java index 0b7a1f126641a..803505bec6a01 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExtendedPropertiesTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExtendedPropertiesTest.java @@ -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);