Skip to content

Commit

Permalink
Knative: Do not set get action port to null in custom resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario authored and ebullient committed Jan 24, 2023
1 parent 9ce21e6 commit 397b750
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public List<DecoratorBuildItem> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HasMetadata> 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");
});
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Configuration file
quarkus.kubernetes.deployment-target=knative

quarkus.knative.resources.limits.memory=768Mi
quarkus.knative.resources.requests.memory=256Mi
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 397b750

Please sign in to comment.