forked from dekorateio/dekorate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support gRPC probes for Kubernetes, Openshift and Knative
See feature request description in dekorateio#857
- Loading branch information
Showing
12 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2018 The original authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>dekorate-tests</artifactId> | ||
<groupId>io.dekorate</groupId> | ||
<version>2.9-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<groupId>io.dekorate</groupId> | ||
<version>2.9-SNAPSHOT</version> | ||
<artifactId>feat-857-kubernetes-grpc-probes</artifactId> | ||
<name>Dekorate :: Tests :: gRPC Probes :: Kubernetes</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>kubernetes-annotations</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>dekorate-spring-boot</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${version.spring-boot}</version> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>kubernetes-junit</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
tests/feat-857-kubernetes-grpc-probes/src/main/java/io/dekorate/example/Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.dekorate.example; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class Controller { | ||
|
||
@RequestMapping("/") | ||
public String hello() { | ||
return "Hello world"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/feat-857-kubernetes-grpc-probes/src/main/java/io/dekorate/example/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.dekorate.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Main.class, args); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/feat-857-kubernetes-grpc-probes/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Cover simple port mapping | ||
dekorate.kubernetes.readinessProbe.grpcAction=8000 | ||
# Cover port-service mapping | ||
dekorate.kubernetes.livenessProbe.grpcAction=8001:service | ||
dekorate.kubernetes.startupProbe.grpcAction=8002 |
66 changes: 66 additions & 0 deletions
66
...t-857-kubernetes-grpc-probes/src/test/java/io/dekorate/example/GRPCProbesExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.dekorate.example; | ||
|
||
import static io.dekorate.testing.KubernetesResources.findFirst; | ||
import static io.dekorate.testing.KubernetesResources.loadGenerated; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.dekorate.utils.Strings; | ||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.KubernetesList; | ||
import io.fabric8.kubernetes.api.model.Probe; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
|
||
class GRPCProbesExampleTest { | ||
|
||
@Test | ||
public void shouldContainProbes() { | ||
KubernetesList list = loadGenerated("kubernetes"); | ||
Optional<Deployment> deployment = findFirst(list, Deployment.class); | ||
assertTrue(deployment.isPresent(), "Deployment not found!"); | ||
|
||
assertReadinessProbe(deployment.get(), 8000, null); | ||
assertLivenessProbe(deployment.get(), 8001, "service"); | ||
assertStartupProbe(deployment.get(), 8002, null); | ||
} | ||
|
||
private static void assertReadinessProbe(Deployment deployment, int port, String service) { | ||
assertProbe(deployment, Container::getReadinessProbe, port, service); | ||
} | ||
|
||
private static void assertLivenessProbe(Deployment deployment, int port, String service) { | ||
assertProbe(deployment, Container::getLivenessProbe, port, service); | ||
} | ||
|
||
private static void assertStartupProbe(Deployment deployment, int port, String service) { | ||
assertProbe(deployment, Container::getStartupProbe, port, service); | ||
} | ||
|
||
private static void assertProbe(Deployment deployment, Function<Container, Probe> probeFunction, int port, String service) { | ||
|
||
assertTrue(deployment.getSpec().getTemplate().getSpec().getContainers().stream() | ||
.map(probeFunction) | ||
.anyMatch(probe -> Strings.equals(service, probe.getGrpc().getService()) | ||
&& port == probe.getGrpc().getPort())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters