forked from eclipse-jkube/jkube
-
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.
Added a Quickstart for Implementing your own Custom Enricher
Added a Quickstart for JKube Kit Enricher API on how you can extend JKube Kit and add an enricher for your own Custom Use case. This quickstart contains a simple Spring Boot application which uses a custom made enricher to generate dummy Istio Gateway.
- Loading branch information
1 parent
bb25bc6
commit 881c315
Showing
9 changed files
with
404 additions
and
0 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,71 @@ | ||
# JKube Kit - Custom Enricher Using Eclipse JKube Enricher API | ||
|
||
This example demonstrates how you can extend Eclipse JKube Kit's Enricher API to make your own enricher and use it to enrich or generate manifests as per your requirements. This is a multi module project which contains these modules: | ||
|
||
- istio-enricher : A basic IstioEnricher which generates a dummy `networking.istio.io/v1alpha3` Gateway manifest | ||
- app : A basic spring boot application which uses this enricher with Eclipse JKube | ||
|
||
# How to Build: | ||
Just need to run: | ||
```bash | ||
mvn clean install | ||
``` | ||
|
||
# How to Run: | ||
This project demonstrates use of Custom Enricher. You can check `pom.xml` of `app/` project to see how Custom Enricher is integrated into it. When you would run resource goal, you should be able to see enricher in action: | ||
|
||
``` | ||
custom-istio-enricher : $ cd app/ | ||
app : $ mvn k8s:resource | ||
[INFO] Scanning for projects... | ||
[INFO] | ||
[INFO] --< org.eclipse.jkube.quickstarts.kit:eclipse-jkube-sample-custom-enricher-app >-- | ||
[INFO] Building Eclipse JKube :: Sample :: Custom Enricher :: App 1.1.0-SNAPSHOT | ||
[INFO] --------------------------------[ jar ]--------------------------------- | ||
[INFO] | ||
[INFO] --- kubernetes-maven-plugin:1.1.0-SNAPSHOT:resource (default-cli) @ eclipse-jkube-sample-custom-enricher-app --- | ||
[WARNING] k8s: Cannot access cluster for detecting mode: No route to host (Host unreachable) | ||
[INFO] k8s: Running generator spring-boot | ||
[INFO] k8s: spring-boot: Using Docker image quay.io/jkube/jkube-java-binary-s2i:0.0.8 as base / builder | ||
[INFO] k8s: Using resource templates from /home/rohaan/work/repos/jkube/quickstarts/kit/custom-istio-enricher/app/src/main/jkube | ||
[INFO] k8s: jkube-service: Adding a default service 'eclipse-jkube-sample-custom-enricher-app' with ports [8080] | ||
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2 | ||
[INFO] k8s: istio-enricher: Added dummy networking.istio.io/v1alpha3 Gateway | ||
[INFO] k8s: istio-enricher: Exiting Istio Enricher | ||
[INFO] k8s: validating /home/rohaan/work/repos/jkube/quickstarts/kit/custom-istio-enricher/app/target/classes/META-INF/jkube/kubernetes/eclipse-jkube-sample-custom-enricher-app.yml resource | ||
[WARNING] k8s: Failed to validate resources: null | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] BUILD SUCCESS | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] Total time: 6.108 s | ||
[INFO] Finished at: 2020-10-30T22:25:51+05:30 | ||
[INFO] ------------------------------------------------------------------------ | ||
``` | ||
After running resource goal, you should be able to see a dummy `Gateway` manifest in target directory: | ||
``` | ||
app : $ cat target/classes/META-INF/jkube/kubernetes/eclipse-jkube-sample-custom-enricher-app.yml | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Gateway | ||
metadata: | ||
labels: | ||
app: eclipse-jkube-sample-custom-enricher-app | ||
provider: jkube | ||
version: 1.1.0-SNAPSHOT | ||
group: org.eclipse.jkube.quickstarts.kit | ||
name: eclipse-jkube-sample-custom-enricher-app | ||
spec: | ||
selector: | ||
app: test-app | ||
servers: | ||
- hosts: | ||
- uk.bookinfo.com | ||
- in.bookinfo.com | ||
port: | ||
name: http | ||
number: 80 | ||
protocol: HTTP | ||
tls: | ||
httpsRedirect: 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,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>eclipse-jkube-sample-custom-enricher-app</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.eclipse.jkube.quickstarts.kit</groupId> | ||
<artifactId>eclipse-jkube-sample-custom-enricher-parent</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<name>Eclipse JKube :: Quickstarts :: Kit :: Custom Enricher App</name> | ||
<description>Spring Boot example with a custom enricher</description> | ||
|
||
<dependencies> | ||
|
||
<!-- Boot generator --> | ||
<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> | ||
|
||
<plugin> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>kubernetes-maven-plugin</artifactId> | ||
<version>${jkube.version}</version> | ||
<configuration> | ||
<enricher> | ||
<includes> | ||
<!-- Include to standard profile --> | ||
<include>istio-enricher</include> | ||
</includes> | ||
<config> | ||
<istio-enricher> | ||
<name>${project.artifactId}</name> | ||
</istio-enricher> | ||
</config> | ||
</enricher> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>resource</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
|
||
<dependencies> | ||
<!-- Custom enricher as plugin dependency --> | ||
<dependency> | ||
<groupId>org.eclipse.jkube.quickstarts.kit</groupId> | ||
<artifactId>eclipse-jkube-sample-custom-enricher-istio</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
...nricher/app/src/main/java/org/eclipse/jkube/quickstarts/kit/enricher/app/Application.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,24 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.kit.enricher.app; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...her/app/src/main/java/org/eclipse/jkube/quickstarts/kit/enricher/app/HelloController.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,26 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.kit.enricher.app; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
@GetMapping("/") | ||
public String index() { | ||
return "Hello World!"; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
quickstarts/kit/custom-istio-enricher/istio-enricher/pom.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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>eclipse-jkube-sample-custom-enricher-istio</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.eclipse.jkube.quickstarts.kit</groupId> | ||
<artifactId>eclipse-jkube-sample-custom-enricher-parent</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<name>Eclipse JKube :: Quickstarts :: Kit :: Custom Istio Enricher</name> | ||
<description>Custom Istio Enricher which extends Eclipse JKube Enricher API and Fabric8 Istio Java Client to create Istio Gateway Manifest</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-enricher-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>me.snowdrop</groupId> | ||
<artifactId>istio-client</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
69 changes: 69 additions & 0 deletions
69
...enricher/src/main/java/org/eclipse/jkube/quickstart/kit/enricher/istio/IstioEnricher.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,69 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstart.kit.enricher.istio; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesListBuilder; | ||
import me.snowdrop.istio.api.networking.v1alpha3.GatewayBuilder; | ||
import org.eclipse.jkube.kit.common.Configs; | ||
import org.eclipse.jkube.kit.config.resource.PlatformMode; | ||
import org.eclipse.jkube.kit.enricher.api.BaseEnricher; | ||
import org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext; | ||
|
||
public class IstioEnricher extends BaseEnricher { | ||
|
||
public IstioEnricher(JKubeEnricherContext enricherContext) { | ||
super(enricherContext, "istio-enricher"); | ||
} | ||
|
||
// Available configuration keys | ||
private enum Config implements Configs.Config { | ||
// name of the gateway to create | ||
name; | ||
|
||
public String def() { return d; } protected String d; | ||
} | ||
|
||
@Override | ||
public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { | ||
log.info("Added dummy networking.istio.io/v1alpha3 Gateway"); | ||
builder.addToItems(createGatewayBuilder()); | ||
log.info("Exiting Istio Enricher"); | ||
} | ||
|
||
private GatewayBuilder createGatewayBuilder() { | ||
return new GatewayBuilder() | ||
.withNewMetadata() | ||
.withName(getGatewayName()) | ||
.endMetadata() | ||
.withNewSpec() | ||
.addToSelector("app", "test-app") | ||
.addNewServer() | ||
.withNewPort() | ||
.withNumber(80) | ||
.withName("http") | ||
.withProtocol("HTTP") | ||
.endPort() | ||
.addNewHost("uk.bookinfo.com") | ||
.addNewHost("in.bookinfo.com") | ||
.withNewTls() | ||
.withHttpsRedirect(true) | ||
.endTls() | ||
.endServer() | ||
.endSpec(); | ||
} | ||
|
||
private String getGatewayName() { | ||
return getConfig(Config.name); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...tarts/kit/custom-istio-enricher/istio-enricher/src/main/resources/META-INF/jkube/enricher
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 @@ | ||
org.eclipse.jkube.quickstart.kit.enricher.istio.IstioEnricher |
Oops, something went wrong.