Skip to content

Commit

Permalink
Support Helm in K8s / OCP
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Feb 8, 2022
1 parent 4090fe2 commit 7c4d9df
Show file tree
Hide file tree
Showing 20 changed files with 404 additions and 103 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ jobs:
- name: Build Project using Helm
run: |
oc new-project helm
./run_tests_with_helm.sh "${{ github.event.pull_request.head.repo.owner.html_url }}/${{ github.event.pull_request.head.repo.name }}" ${{ github.head_ref }}
./run_tests_with_helm_in_ocp.sh "${{ github.event.pull_request.head.repo.owner.html_url }}/${{ github.event.pull_request.head.repo.name }}" ${{ github.head_ref }}
- name: Delete Project using Helm
run: oc delete project helm
linux-build-kubernetes:
name: PR - Linux - JVM ${{ matrix.java }} - Kubernetes
needs: linux-build-local
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8 ]
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Java
uses: actions/[email protected]
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
cache: 'maven'
- name: Kubernetes KinD Cluster
uses: container-tools/kind-action@v1
with:
version: v0.11.1
registry: true
- name: Build Project using Helm
run: |
kubectl create namespace helm
./run_tests_with_helm_in_k8s.sh $KIND_REGISTRY helm
- name: Delete Project using Helm
run: kubectl delete namespace helm
# - name: Build Project using Dekorate
# run: |
# kubectl create namespace k8s
# ./mvnw -s .github/mvn-settings.xml clean verify -Pkubernetes,kubernetes-it -Ddekorate.docker.registry=kind-registry:5000 -Dkubernetes.namespace=k8s -Ddekorate.push=true
40 changes: 40 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Push Images"
on:
workflow_dispatch:
push:
branches:
- sb-2.5.x
jobs:
push:
name: Push Images to Quay.io
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11 ]
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Java
uses: actions/[email protected]
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
cache: 'maven'
- name: Quay.io Login
run: docker login quay.io -u="${{secrets.QUAY_USER}}" -p="${{secrets.QUAY_TOKEN}}"
- name: Build
run: ./mvnw -s .github/mvn-settings.xml clean package
- name: Push Image to Quay.io
run: |
CONTAINER_REGISTRY=quay.io/snowdrop
## Cute name service:
NAME_IMAGE=spring-boot-cb-name-example:2.5.8
docker build ./name-service -t $NAME_IMAGE
docker tag $NAME_IMAGE $CONTAINER_REGISTRY/$NAME_IMAGE
docker push $CONTAINER_REGISTRY/$NAME_IMAGE
## Greeting service:
GREETING_IMAGE=spring-boot-cb-greeting-example:2.5.8
docker build ./greeting-service -t $GREETING_IMAGE
docker tag $GREETING_IMAGE $CONTAINER_REGISTRY/$GREETING_IMAGE
docker push $CONTAINER_REGISTRY/$GREETING_IMAGE
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
* [Introduction](#introduction)
* [Deploying application on OpenShift using Dekorate](#deploying-application-on-openshift-using-dekorate)
* [Deploying application on OpenShift using Helm](#deploying-application-on-openshift-using-helm)
* [Deploying application on Kubernetes using Helm](#deploying-application-on-kubernetes-using-helm)
* [Running Tests on OpenShift using Dekorate](#running-tests-on-openshift-using-dekorate)
* [Running Tests on OpenShift using S2i from Source](#running-tests-on-openshift-using-s2i-from-source)
* [Running Tests on OpenShift using Helm](#running-tests-on-openshift-using-helm)
* [Running Tests on Kubernetes with Helm](#running-tests-on-kubernetes-using-helm)
* [Test the service](#test-the-service)
* [Maven Test](#maven-test)
* [Manual Test](#manual-test)
Expand Down Expand Up @@ -36,7 +38,7 @@ First, make sure you have installed [the Helm command line](https://helm.sh/docs
Then, you need to install the example by doing:

```
helm install circuit-breaker ./helm --set name-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set name-service.s2i.source.ref=<branch-to-use> --set greeting-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set greeting-service.s2i.source.ref=<branch-to-use>
helm install circuit-breaker ./helm --set name-service.route.expose=true --set name-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set name-service.s2i.source.ref=<branch-to-use> --set greeting-service.route.expose=true --set greeting-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set greeting-service.s2i.source.ref=<branch-to-use>
```

**note**: Replace `<branch-to-use>` with one branch from `https://github.com/snowdrop/circuit-breaker-example/branches/all`.
Expand All @@ -47,6 +49,24 @@ And to uninstall the chart, execute:
helm uninstall circuit-breaker
```

## Deploying application on Kubernetes using Helm

Requirements:
- Have installed [the Helm command line](https://helm.sh/docs/intro/install/)
- Have connected/logged to a kubernetes cluster

You need to install the example by doing:

```
helm install circuit-breaker ./helm -n <k8s namespace> --set name-service.ingress.host=<your k8s domain> --set greeting-service.ingress.host=<your k8s domain>
```

And to uninstall the chart, execute:

```
helm uninstall circuit-breaker
```

## Running Tests on OpenShift using Dekorate

```
Expand All @@ -68,13 +88,32 @@ This script can take 2 parameters referring to the repository and the branch to
## Running Tests on OpenShift using Helm

```
./run_tests_with_helm.sh
./run_tests_with_helm_in_ocp.sh
```

This script can take 2 parameters referring to the repository and the branch to use to source the images from.

```bash
./run_tests_with_helm.sh "https://github.com/snowdrop/circuit-breaker-example" branch-to-test
./run_tests_with_helm_in_ocp.sh "https://github.com/snowdrop/circuit-breaker-example" branch-to-test
```

## Running Tests on Kubernetes using Helm

First, you need to create the k8s namespace:

```
kubectl create namespace <the k8s namespace>
```

Then, run the tests by specifying the container registry and the kubernetes namespace:
```
./run_tests_with_helm_in_k8s.sh <your container registry: for example "quay.io/user"> <the k8s namespace>
```

For example:

```
./run_tests_with_helm_in_k8s.sh "quay.io/user" "myNamespace"
```

## Test the service
Expand Down
9 changes: 9 additions & 0 deletions greeting-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,14 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>kubernetes</id>
<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>kubernetes-spring-starter</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NameService {
@Autowired
private CircuitBreakerRegistry circuitBreakerRegistry;

@Value("${name.host:http://spring-boot-circuit-breaker-name:80}")
@Value("${name.host:http://spring-boot-circuit-breaker-name:8080}")
private String nameHost;

public NameService() {
Expand Down
3 changes: 3 additions & 0 deletions greeting-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ resilience4j.circuitbreaker:
dekorate:
openshift:
expose: true
env-vars:
- name: name.host
value: http://spring-boot-circuit-breaker-name:80
s2i:
builder-image: registry.access.redhat.com/ubi8/openjdk-8:1.3
12 changes: 6 additions & 6 deletions helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies:
- name: spring-boot-example-app
repository: http://snowdrop.github.io/helm
version: 0.0.3
repository: http://localhost:8080
version: 0.0.4
- name: spring-boot-example-app
repository: http://snowdrop.github.io/helm
version: 0.0.3
digest: sha256:98c5ec3240851e09e5a003744cd2abd671e08bf1a30fdf603a0ac3ff856707d4
generated: "2022-02-02T09:57:36.524763302+01:00"
repository: http://localhost:8080
version: 0.0.4
digest: sha256:06c0f8c009ddf8f601ab43dd9c956e5a25e642f9a04211f54bc801ce41629c92
generated: "2022-02-08T14:34:54.264266543+01:00"
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ icon: https://avatars.githubusercontent.com/u/558276?s=400&u=19efc68c74844b2e092
dependencies:
- alias: name-service
name: spring-boot-example-app
version: 0.0.3
version: 0.0.4
repository: http://snowdrop.github.io/helm
- alias: greeting-service
name: spring-boot-example-app
version: 0.0.3
version: 0.0.4
repository: http://snowdrop.github.io/helm
Binary file removed helm/charts/spring-boot-example-app-0.0.3.tgz
Binary file not shown.
Binary file added helm/charts/spring-boot-example-app-0.0.4.tgz
Binary file not shown.
18 changes: 7 additions & 11 deletions helm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name-service:
name: spring-boot-circuit-breaker-name
version: 2.5.8-1-SNAPSHOT
docker:
image: quay.io/snowdrop/spring-boot-cb-name-example:2.5.8
s2i:
# Default s2i source repository
source:
repo: https://github.com/snowdrop/circuit-breaker-example
ref: sb-2.5.x
env:
- name: MAVEN_ARGS_APPEND
value: "-pl name-service"
Expand All @@ -14,16 +12,14 @@ name-service:
greeting-service:
name: spring-boot-circuit-breaker-greeting
version: 2.5.8-1-SNAPSHOT
docker:
image: quay.io/snowdrop/spring-boot-cb-greeting-example:2.5.8
env:
- name: name.host
value: http://spring-boot-circuit-breaker-name:8080
s2i:
# Default s2i source repository
source:
repo: https://github.com/snowdrop/circuit-breaker-example
ref: sb-2.5.x
env:
- name: MAVEN_ARGS_APPEND
value: "-pl greeting-service"
- name: ARTIFACT_DIR
value: "greeting-service/target"
env:
- name: name.host
value: http://spring-boot-circuit-breaker-name:8080
9 changes: 9 additions & 0 deletions name-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,14 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>kubernetes</id>
<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>kubernetes-spring-starter</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
</license>
</licenses>
<repositories>
<repository>
<id>maven-central</id>
<name>Public Maven Central Repository</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>redhat-ga</id>
<name>Red Hat GA Repository</name>
Expand All @@ -61,6 +66,11 @@
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-central</id>
<name>Public Maven Central Repository</name>
<url>https://repo.maven.apache.org/maven2/</url>
</pluginRepository>
<pluginRepository>
<id>redhat-ga</id>
<name>Red Hat GA Repository</name>
Expand Down
4 changes: 2 additions & 2 deletions run_tests_with_dekorate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
source scripts/waitFor.sh

# 1.- Deploy Name Service
./mvnw -s .github/mvn-settings.xml verify -pl name-service -Popenshift -Ddekorate.deploy=true
./mvnw -s .github/mvn-settings.xml clean verify -pl name-service -Popenshift -Ddekorate.deploy=true
if [[ $(waitFor "spring-boot-circuit-breaker-name" "app.kubernetes.io/name") -eq 1 ]] ; then
echo "Name service failed to deploy. Aborting"
exit 1
fi

# 2.- Deploy Greeting Service
./mvnw -s .github/mvn-settings.xml verify -pl greeting-service -Popenshift -Ddekorate.deploy=true
./mvnw -s .github/mvn-settings.xml clean verify -pl greeting-service -Popenshift -Ddekorate.deploy=true
if [[ $(waitFor "spring-boot-circuit-breaker-greeting" "app.kubernetes.io/name") -eq 1 ]] ; then
echo "Greeting service failed to deploy. Aborting"
exit 1
Expand Down
31 changes: 31 additions & 0 deletions run_tests_with_helm_in_k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
CONTAINER_REGISTRY=${1:-localhost:5000}
K8S_NAMESPACE=${2:-helm}

source scripts/waitFor.sh
oc project $K8S_NAMESPACE

# Build
./mvnw -s .github/mvn-settings.xml clean package

# Create docker image and tag it in registry
## Name service:
NAME_IMAGE=circuit-breaker-name:latest
docker build ./name-service -t $NAME_IMAGE
docker tag $NAME_IMAGE $CONTAINER_REGISTRY/$NAME_IMAGE
docker push $CONTAINER_REGISTRY/$NAME_IMAGE

## Greeting service:
GREETING_IMAGE=circuit-breaker-greeting:latest
docker build ./greeting-service -t $GREETING_IMAGE
docker tag $GREETING_IMAGE $CONTAINER_REGISTRY/$GREETING_IMAGE
docker push $CONTAINER_REGISTRY/$GREETING_IMAGE

helm install circuit-breaker ./helm -n $K8S_NAMESPACE --set name-service.docker.image=$CONTAINER_REGISTRY/$NAME_IMAGE --set greeting-service.docker.image=$CONTAINER_REGISTRY/$GREETING_IMAGE
if [[ $(waitFor "spring-boot-circuit-breaker-greeting" "app") -eq 1 ]] ; then
echo "Application failed to deploy. Aborting"
exit 1
fi

# Run OpenShift Tests
./mvnw -s .github/mvn-settings.xml clean verify -Pkubernetes-it -Dkubernetes.namespace=$K8S_NAMESPACE
2 changes: 1 addition & 1 deletion run_tests_with_helm.sh → run_tests_with_helm_in_ocp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SOURCE_REPOSITORY_REF=${2:-sb-2.5.x}

source scripts/waitFor.sh

helm install circuit-breaker ./helm --set name-service.s2i.source.repo=$SOURCE_REPOSITORY_URL --set name-service.s2i.source.ref=$SOURCE_REPOSITORY_REF --set greeting-service.s2i.source.repo=$SOURCE_REPOSITORY_URL --set greeting-service.s2i.source.ref=$SOURCE_REPOSITORY_REF
helm install circuit-breaker ./helm --set name-service.route.expose=true --set name-service.s2i.source.repo=$SOURCE_REPOSITORY_URL --set name-service.s2i.source.ref=$SOURCE_REPOSITORY_REF --set greeting-service.route.expose=true --set greeting-service.s2i.source.repo=$SOURCE_REPOSITORY_URL --set greeting-service.s2i.source.ref=$SOURCE_REPOSITORY_REF
if [[ $(waitFor "spring-boot-circuit-breaker-greeting" "app") -eq 1 ]] ; then
echo "Application failed to deploy. Aborting"
exit 1
Expand Down
Loading

0 comments on commit 7c4d9df

Please sign in to comment.