From f41d44a86227b8b6be075b12a666e3c5a2a379f4 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 20 Dec 2022 11:41:30 +0100 Subject: [PATCH] Knative: Do not set get action port to null in custom resources Relates https://github.com/quarkusio/quarkus/issues/29962 --- .../ApplyHttpGetActionPortDecorator.java | 4 ++ .../deployment/KnativeProcessor.java | 2 +- ...iveWithExistingDeploymentResourceTest.java | 66 +++++++++++++++++++ ...rnetesWithExistingCronJobResourceTest.java | 2 +- ...th-existing-deployment-resource.properties | 5 ++ .../knative.yml | 49 ++++++++++++++ 6 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExistingDeploymentResourceTest.java create mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-existing-deployment-resource.properties create mode 100644 integration-tests/kubernetes/quarkus-standard-way/src/test/resources/manifests/knative-with-existing-deployment-resource/knative.yml diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyHttpGetActionPortDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyHttpGetActionPortDecorator.java index 9722e7d4e923c..392539aeae077 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyHttpGetActionPortDecorator.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyHttpGetActionPortDecorator.java @@ -17,6 +17,10 @@ public ApplyHttpGetActionPortDecorator(Integer port) { this(ANY, ANY, port); } + public ApplyHttpGetActionPortDecorator(String deployment, Integer port) { + this(deployment, ANY, port); + } + public ApplyHttpGetActionPortDecorator(String deployment, String container, Integer port) { super(deployment, container); this.port = port; 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 05018bb854db1..4521092657436 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 @@ -277,7 +277,7 @@ public List createDecorators(ApplicationInfoBuildItem applic result.add(new DecoratorBuildItem(KNATIVE, new ApplyServiceTypeDecorator(name, config.getServiceType().name()))); //In Knative its expected that all http ports in probe are omitted (so we set them to null). - result.add(new DecoratorBuildItem(KNATIVE, new ApplyHttpGetActionPortDecorator(null))); + result.add(new DecoratorBuildItem(KNATIVE, new ApplyHttpGetActionPortDecorator(name, null))); //Traffic Splitting config.revisionName.ifPresent(r -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExistingDeploymentResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExistingDeploymentResourceTest.java new file mode 100644 index 0000000000000..dc1a745e169be --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithExistingDeploymentResourceTest.java @@ -0,0 +1,66 @@ + +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.apps.Deployment; +import io.quarkus.kubernetes.spi.CustomProjectRootBuildItem; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class KnativeWithExistingDeploymentResourceTest { + + private static final String APP_NAME = "knative-with-existing-deployment-resource"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(APP_NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource(APP_NAME + ".properties") + .addCustomResourceEntry(Path.of("src", "main", "kubernetes", "knative.yml"), + "manifests/" + APP_NAME + "/knative.yml") + .addBuildChainCustomizerEntries( + new QuarkusProdModeTest.BuildChainCustomizerEntry( + KubernetesWithCustomResourcesTest.CustomProjectRootBuildItemProducerProdMode.class, + Collections.singletonList(CustomProjectRootBuildItem.class), Collections.emptyList())); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")); + + List kubernetesList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("knative.yml")); + + assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind()) + && "example".equals(i.getMetadata().getName())) + .singleElement() + .satisfies(e -> { + assertThat(e).isInstanceOfSatisfying(Deployment.class, deployment -> { + assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).allSatisfy(container -> { + assertThat(container.getLivenessProbe().getHttpGet().getPort().getIntVal()).isEqualTo(8080); + assertThat(container.getReadinessProbe().getHttpGet().getPort().getIntVal()).isEqualTo(8080); + + assertThat(container.getResources().getRequests().get("memory").getAmount()).isEqualTo("128"); + assertThat(container.getResources().getLimits().get("memory").getAmount()).isEqualTo("768"); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java index bba1599d46b1c..d55bff64b5dea 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java @@ -37,7 +37,7 @@ public class KubernetesWithExistingCronJobResourceTest { .addBuildChainCustomizerEntries( new QuarkusProdModeTest.BuildChainCustomizerEntry( KubernetesWithCustomResourcesTest.CustomProjectRootBuildItemProducerProdMode.class, - Collections.singletonList(CustomProjectRootBuildItem.class), Collections.emptyList()));; + Collections.singletonList(CustomProjectRootBuildItem.class), Collections.emptyList())); @ProdBuildResults private ProdModeTestResults prodModeTestResults; diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-existing-deployment-resource.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-existing-deployment-resource.properties new file mode 100644 index 0000000000000..dd506612391bb --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-existing-deployment-resource.properties @@ -0,0 +1,5 @@ +# Configuration file +quarkus.kubernetes.deployment-target=knative + +quarkus.knative.resources.limits.memory=768Mi +quarkus.knative.resources.requests.memory=256Mi \ No newline at end of file diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/manifests/knative-with-existing-deployment-resource/knative.yml b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/manifests/knative-with-existing-deployment-resource/knative.yml new file mode 100644 index 0000000000000..6e317a1744e9d --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/manifests/knative-with-existing-deployment-resource/knative.yml @@ -0,0 +1,49 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: example +spec: + replicas: 1 + selector: + matchLabels: + name: example + template: + metadata: + labels: + name: example + spec: + containers: + - image: docker.io/group/app + name: example + livenessProbe: + failureThreshold: 3 + httpGet: + path: /health/live + port: 8080 + scheme: HTTP + initialDelaySeconds: 0 + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 + readinessProbe: + failureThreshold: 3 + httpGet: + path: /health/ready + port: 8080 + scheme: HTTP + initialDelaySeconds: 0 + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 + ports: + - containerPort: 8080 + name: http + protocol: TCP + env: + - name: REGISTRY_AUTH_ANONYMOUS_READ_ACCESS_ENABLED + value: "true" + resources: + limits: + memory: 768Mi + requests: + memory: 128Mi \ No newline at end of file