-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* initial profile and check * initial istio aware profile impl * adding initial docs * fixing parent * using BootstrapConfiguration for istio profile check * Improve log messages * Add Istio integration tests * Remove unused IstioClient * Remove redundant parent * Revert "Remove redundant parent" This reverts commit c41271f * Fix startup error * Add name to istio module * Move IstioClient out of bootstrap configuration This is needed because the Kubernetes Config is not a bean in the bootstrap context. Furthermore the IstioClient is not used anywhere in the bootstrap context * Polish * Ensure this IstioClient is actually injected * Fix integration test setup * more refinements * aligning property name * adding headers and small refinements
- Loading branch information
1 parent
b3de20b
commit ef51d11
Showing
20 changed files
with
504 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: istio-test | ||
labels: | ||
istio-injection: enabled |
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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
== Kubernetes Awareness | ||
== Kubernetes Ecosystem Awareness | ||
|
||
All of the features described above will work equally well regardless of whether your application is running inside | ||
Kubernetes or not. This is really helpful for development and troubleshooting. | ||
From a development point of view, this is really helpful as you can start your Spring Boot application and debug one | ||
of the modules part of this project. It is not required to deploy it in Kubernetes | ||
as the code of the project relies on the | ||
[Fabric8 Kubernetes Java client](https://github.com/fabric8io/kubernetes-client) which is a fluent DSL able to | ||
https://github.com/fabric8io/kubernetes-client[Fabric8 Kubernetes Java client] which is a fluent DSL able to | ||
communicate using `http` protocol to the REST API of Kubernetes Server. | ||
|
||
=== Kubernetes Profile Autoconfiguration | ||
|
||
When the application runs as a pod inside Kubernetes a Spring profile named `kubernetes` will automatically get activated. | ||
This allows the developer to customize the configuration, to define beans that will be applied when the Spring Boot application is deployed | ||
within the Kubernetes platform *(e.g. different dev and prod configuration)*. | ||
|
||
=== Istio Awareness | ||
|
||
When including the **spring-cloud-kubernetes-istio** module into the application classpath a new profile will be added to the application, | ||
if the application is running inside a Kubernetes Cluster with http://istio.io[Istio] installed. Then you can use | ||
spring **@Profile("istio")** annotations into your Beans and **@Configuration**'s. | ||
|
||
The Istio awareness module uses the **me.snowdrop:istio-client** to interact with Istio APIs enabling us to discover traffic rules, circuit breakers, etc. | ||
Making it easy for our Spring Boot applications to consume this data to dynamically configure themselves according the environment. |
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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-kubernetes-integration-tests</artifactId> | ||
<version>1.0.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>Spring Cloud Kubernetes :: Integration Tests :: Istio</name> | ||
<artifactId>istio</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-actuator-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-kubernetes-istio</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.arquillian.cube</groupId> | ||
<artifactId>arquillian-cube-kubernetes</artifactId> | ||
<version>${arquillian-cube.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>undertow-core</artifactId> | ||
<groupId>io.undertow</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.junit</groupId> | ||
<artifactId>arquillian-junit-standalone</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
spring-cloud-kubernetes-integration-tests/istio/src/main/fabric8/deployment.yml
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,10 @@ | ||
# We need this fragment in order for the kubernetes client to talk to | ||
# the Kubernetes API without caring about proper certificates | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- env: | ||
- name: KUBERNETES_TRUST_CERTIFICATES | ||
value: true | ||
|
15 changes: 15 additions & 0 deletions
15
spring-cloud-kubernetes-integration-tests/istio/src/main/fabric8/svc.yml
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,15 @@ | ||
# we are using an FMP fragment to ensure that NodePort is used correctly | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: ${project.artifactId} | ||
labels: | ||
app: ${project.artifactId} | ||
spec: | ||
selector: | ||
app: ${project.artifactId} | ||
ports: | ||
- protocol: TCP | ||
port: 8080 | ||
nodePort: ${nodeport.value} | ||
type: NodePort |
34 changes: 34 additions & 0 deletions
34
...n-tests/istio/src/main/java/org/springframework/cloud/kubernetes/it/IstioApplication.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,34 @@ | ||
package org.springframework.cloud.kubernetes.it; | ||
|
||
import me.snowdrop.istio.client.IstioClient; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
@RestController | ||
public class IstioApplication { | ||
|
||
@Autowired | ||
private Environment environment; | ||
|
||
// used just to ensure that the IstioClient is properly injected into the context | ||
@Autowired | ||
private IstioClient istioClient; | ||
|
||
@GetMapping("/profiles") | ||
public List<String> profiles() { | ||
return Arrays.asList(environment.getActiveProfiles()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(IstioApplication.class, args); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
spring-cloud-kubernetes-integration-tests/istio/src/main/resources/bootstrap.yaml
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 @@ | ||
spring: | ||
cloud: | ||
istio: | ||
client: | ||
envoyPort: 15000 |
28 changes: 28 additions & 0 deletions
28
...gration-tests/istio/src/test/java/org/springframework/cloud/kubernetes/it/ProfilesIT.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 @@ | ||
package org.springframework.cloud.kubernetes.it; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; | ||
import org.hamcrest.core.StringContains; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RequiresKubernetes | ||
@RunWith(Arquillian.class) | ||
public class ProfilesIT { | ||
|
||
private static final String HOST = System.getProperty("service.host"); | ||
private static final Integer PORT = Integer.valueOf(System.getProperty("service.port")); | ||
|
||
@Test | ||
public void testProfileEndpoint() { | ||
given() | ||
.baseUri(String.format("http://%s:%d", HOST, PORT)) | ||
.get("profiles") | ||
.then() | ||
.statusCode(200) | ||
.body(new StringContains("istio")); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
spring-cloud-kubernetes-integration-tests/istio/src/test/resources/arquillian.xml
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,9 @@ | ||
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://jboss.org/schema/arquillian" | ||
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
|
||
<extension qualifier="kubernetes"> | ||
<property name="namespace.use.existing">istio-test</property> | ||
</extension> | ||
|
||
</arquillian> |
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<parent> | ||
<artifactId>spring-cloud-kubernetes</artifactId> | ||
<groupId>org.springframework.cloud</groupId> | ||
<version>1.0.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-cloud-kubernetes-istio</artifactId> | ||
<name>Spring Cloud Kubernetes :: Istio</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-kubernetes-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>me.snowdrop</groupId> | ||
<artifactId>istio-client</artifactId> | ||
</dependency> | ||
<!-- Testing Dependencies --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
...stio/src/main/java/org/springframework/cloud/kubernetes/istio/IstioAutoConfiguration.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,36 @@ | ||
/* | ||
* Copyright 2013-2018 the original author or 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 org.springframework.cloud.kubernetes.istio; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import me.snowdrop.istio.client.DefaultIstioClient; | ||
import me.snowdrop.istio.client.IstioClient; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(value = "spring.cloud.istio.enabled", matchIfMissing = true) | ||
public class IstioAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public IstioClient istioClient(Config config) { | ||
return new DefaultIstioClient(config); | ||
} | ||
} |
Oops, something went wrong.