Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding skaffold for gateway, adding new porject for kubernetesclient …
…tests
- Loading branch information
Piotr Mińkowski
committed
Dec 22, 2019
1 parent
653c93c
commit 54a6cac
Showing
8 changed files
with
191 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
</parent> | ||
<artifactId>api-test</artifactId> | ||
<groupId>pl.piomin.services</groupId> | ||
<version>1.1</version> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Hoxton.RELEASE</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-kubernetes-all</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
55 changes: 55 additions & 0 deletions
55
api-test/src/main/java/pl/piomin/services/api/ApiApplication.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,55 @@ | ||
package pl.piomin.services.api; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import io.fabric8.kubernetes.api.model.EndpointSubset; | ||
import io.fabric8.kubernetes.api.model.Endpoints; | ||
import io.fabric8.kubernetes.api.model.EndpointsList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ApiApplication { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ApiApplication.class); | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ApiApplication.class, args); | ||
} | ||
|
||
@Autowired | ||
KubernetesClient client; | ||
|
||
@PostConstruct | ||
public void init() { | ||
Endpoints e = client.endpoints().inNamespace("c").withName("employee").get(); | ||
printEndpoints(e); | ||
|
||
EndpointsList el = client.endpoints().inAnyNamespace().list(); | ||
Stream<Endpoints> s = el.getItems().stream().filter(endpoint -> endpoint.getMetadata().getName().equals("employee")); | ||
Map<String, List<Endpoints>> m = s.collect(Collectors.groupingBy(endpoints -> endpoints.getMetadata().getNamespace())); | ||
if (m.keySet().size() > 1) | ||
LOGGER.info("Non unique name across many namespaces"); | ||
s.forEach(this::printEndpoints); | ||
} | ||
|
||
private void printEndpoints(Endpoints e) { | ||
List<EndpointSubset> s = e.getSubsets(); | ||
s.forEach(subset -> { | ||
subset.getAddresses().forEach(address -> { | ||
LOGGER.info("IP: {}.{}->{}", e.getMetadata().getName(), e.getMetadata().getNamespace(), address.getIp()); | ||
}); | ||
}); | ||
} | ||
|
||
} |
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 @@ | ||
spring.application.name: api-test | ||
|
||
spring: | ||
cloud: | ||
kubernetes: | ||
client: | ||
masterUrl: 192.168.99.100:8443 | ||
namespace: false | ||
trustCerts: true |
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,56 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: gateway | ||
data: | ||
application.yaml: |- | ||
logging.pattern.console: "%d{HH:mm:ss} ${LOG_LEVEL_PATTERN:-%5p} %m%n" | ||
spring.cloud.kubernetes.discovery.all-namespaces: true | ||
spring.cloud.kubernetes.ribbon.allNamespaces: true | ||
spring: | ||
data: | ||
mongodb: | ||
database: admin | ||
host: mongodb.default | ||
zuul.routes.department.path: /department/** | ||
zuul.routes.employee.path: /employee/** | ||
zuul.routes.organization.path: /organization/** | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: gateway | ||
namespace: d | ||
labels: | ||
app: gateway | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: gateway | ||
template: | ||
metadata: | ||
labels: | ||
app: gateway | ||
spec: | ||
containers: | ||
- name: gateway | ||
image: piomin/gateway:1.1 | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: gateway | ||
namespace: d | ||
labels: | ||
app: gateway | ||
spec: | ||
ports: | ||
- port: 8080 | ||
protocol: TCP | ||
targetPort: 8080 | ||
selector: | ||
app: gateway | ||
type: NodePort |
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,11 @@ | ||
apiVersion: skaffold/v2alpha1 | ||
kind: Config | ||
metadata: | ||
name: gateway-service | ||
build: | ||
artifacts: | ||
- image: piomin/gateway | ||
deploy: | ||
kubectl: | ||
manifests: | ||
- kubernetes\deployment.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
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