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

Do not set get action port to null in custom resources for Knative #29972

Merged
merged 1 commit into from
Dec 21, 2022
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 @@ -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