Skip to content

Commit

Permalink
feat: new CI/Test process and secret creation bug fix (#42)
Browse files Browse the repository at this point in the history
fixes #34 and fixes #40

chore: update gitignore with files from VSCode

test: update test script

fix: ci refactor + fixes #34, fixes #40

chore: test more kube versions
  • Loading branch information
patrickleet authored Oct 26, 2020
1 parent 28f9ee4 commit 7264e21
Show file tree
Hide file tree
Showing 29 changed files with 377 additions and 204 deletions.
13 changes: 13 additions & 0 deletions .github/ci.docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# build docker image and push it to kind nodes

set -o errexit

DOCKER_TAG="keycloak-controller:local"

echo -e "\n##### create docker image with tag $DOCKER_TAG #####\n"
docker build -t "$DOCKER_TAG" ./target

echo -e "\n##### push docker image to kind nodes #####\n"
kind --name chart-testing load docker-image "$DOCKER_TAG"
23 changes: 23 additions & 0 deletions .github/ci.example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

NAMESPACE="keycloak"

echo -e "\n##### install keycloak-controller examples #####\n"
while IFS= read -r KEYCLOAK_EXAMPLE; do
kubectl -n "$NAMESPACE" apply -f "${KEYCLOAK_EXAMPLE}"
done < <(find examples -type f)

echo -e "\n##### show keycloak-controller examples #####\n"
kubectl -n "$NAMESPACE" get keycloaks.k8s.kiwigrid.com
echo ""
kubectl -n "$NAMESPACE" get keycloakrealms.k8s.kiwigrid.com
echo ""
kubectl -n "$NAMESPACE" get keycloakclients.k8s.kiwigrid.com
echo ""
kubectl -n "$NAMESPACE" get keycloakclientscopes.k8s.kiwigrid.com
echo ""
14 changes: 14 additions & 0 deletions .github/ci.helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

echo -e "\n##### add helm repos #####\n"
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add codecentric https://codecentric.github.io/helm-charts
helm repo add kiwigrid https://kiwigrid.github.io

echo -e "\n##### update helm repos #####\n"
helm repo update
28 changes: 28 additions & 0 deletions .github/ci.keycloak-controller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

KEYCLOAK_CONTROLLER_CHART_VERSION="${1}"
NAMESPACE="keycloak"

echo -e "\n##### install keycloak-controller crds #####\n"
while IFS= read -r CRD; do
kubectl apply -f "${CRD}"
done < <(find src/main/k8s -type f)

echo -e "\n##### test controller crds #####\n"
kubectl -n "$NAMESPACE" wait --for condition=established --timeout=15s crd/keycloakclients.k8s.kiwigrid.com
kubectl -n "$NAMESPACE" wait --for condition=established --timeout=15s crd/keycloakclientscopes.k8s.kiwigrid.com
kubectl -n "$NAMESPACE" wait --for condition=established --timeout=15s crd/keycloakrealms.k8s.kiwigrid.com
kubectl -n "$NAMESPACE" wait --for condition=established --timeout=15s crd/keycloaks.k8s.kiwigrid.com

echo -e "\n##### install keycloak-controller #####\n"
helm upgrade -i keycloak-controller kiwigrid/keycloak-controller \
--wait \
--namespace keycloak \
--version "$KEYCLOAK_CONTROLLER_CHART_VERSION" \
--set image.repository=keycloak-controller \
--set image.tag=local
24 changes: 24 additions & 0 deletions .github/ci.keycloak.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

KEYCLOAK_CHART_VERSION="${1}"
NAMESPACE="keycloak"

echo -e "\n##### create keycloak namespace #####\n"
kubectl create namespace $NAMESPACE

echo -e "\n##### install keycloak #####\n"
kubectl create secret generic keycloak-auth \
--namespace $NAMESPACE \
--from-literal=username=keycloak \
--from-literal=password=keycloak

helm upgrade -i keycloak codecentric/keycloak \
--wait \
--namespace $NAMESPACE \
--version "${KEYCLOAK_CHART_VERSION}" \
--values .github/keycloak-values.yaml
10 changes: 10 additions & 0 deletions .github/ci.maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

mvn clean && mvn package
12 changes: 12 additions & 0 deletions .github/ci.provision.helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -o errexit

HELM_VERSION="${1}"

echo -e "\n##### install helm #####\n"
curl --silent --show-error --fail --location --output get_helm.sh https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get
chmod 700 get_helm.sh
./get_helm.sh --version "${HELM_VERSION}"

helm version
10 changes: 10 additions & 0 deletions .github/ci.provision.kubernetes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -o errexit

K8S_VERSION="${1}"

echo -e "\n##### install kubectl #####\n"
curl --silent --show-error --fail --location --output kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
9 changes: 9 additions & 0 deletions .github/ci.provision.maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -o errexit

echo -e "\n##### install mvn & java #####\n"
sudo apt-get update && sudo apt-get install -y maven openjdk-11-jdk
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

mvn --version
16 changes: 16 additions & 0 deletions .github/ci.verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -o errexit

NAMESPACE="keycloak"

echo -e "\n##### check for errors in keycloak-controller logs #####\n"
sleep 60
if kubectl -n "${NAMESPACE}" logs -l app.kubernetes.io/name=keycloak-controller | grep -q ERROR; then
echo "errors found in logs :("
kubectl -n "${NAMESPACE}" logs -l app.kubernetes.io/name=keycloak-controller
exit 1
else
echo "no errors found in logs :)"
kubectl -n "${NAMESPACE}" logs -l app.kubernetes.io/name=keycloak-controller
fi
13 changes: 0 additions & 13 deletions .github/docker-build.sh

This file was deleted.

82 changes: 0 additions & 82 deletions .github/k8s-install.sh

This file was deleted.

15 changes: 15 additions & 0 deletions .github/keycloak-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extraEnv: |
- name: KEYCLOAK_USER_FILE
value: /secrets/keycloak-auth/username
- name: KEYCLOAK_PASSWORD_FILE
value: /secrets/keycloak-auth/password
- name: PROXY_ADDRESS_FORWARDING
value: "true"
extraVolumeMounts: |
- name: keycloak-auth
mountPath: /secrets/keycloak-auth
readOnly: true
extraVolumes: |
- name: keycloak-auth
secret:
secretName: keycloak-auth
4 changes: 2 additions & 2 deletions .github/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
# the control plane node config
- role: control-plane
# the 2 workers
- role: worker
- role: worker
- role: worker
8 changes: 8 additions & 0 deletions .github/local.kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

kind create cluster --config .github/kind-config.yaml --name chart-testing
8 changes: 8 additions & 0 deletions .github/local.maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# ci for keycloak-controller
#

set -o errexit

mvn clean && mvn package
11 changes: 0 additions & 11 deletions .github/mvn-build.sh

This file was deleted.

43 changes: 26 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,46 @@ jobs:
needs:
- lint-bash-scripts
env:
HELM_VERSION: v3.2.4
HELM_VERSION: v3.3.4
strategy:
matrix:
k8s-version:
- v1.14.10
- v1.15.7
- v1.16.9
- v1.17.5
- v1.18.6
- v1.15.12
- v1.16.15
- v1.17.11
- v1.18.8
- v1.19.1
keycloak-chart:
# keycloak 9.0.0
- 7.7.1
# keycloak 10.0.0
- 8.3.0
# keycloak 11.0.0
- 9.0.1
keycloak-controller-chart:
- 0.6.1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Fetch history
run: git fetch --prune --unshallow
- name: provision
run: |
.github/ci.provision.kubernetes.sh ${{ matrix.k8s-version }} & \
.github/ci.provision.helm.sh $HELM_VERSION & \
.github/ci.provision.maven.sh & \
wait
- name: maven
run: .github/ci.maven.sh
- name: Create kind ${{ matrix.k8s-version }} cluster
uses: helm/kind-action@master
with:
config: .github/kind-config.yaml
node_image: kindest/node:${{ matrix.k8s-version }}
- name: mvn build
run: .github/mvn-build.sh
- name: build docker image & push to kind nodes
run: .github/docker-build.sh
- name: test keycloak-controller
run: .github/k8s-install.sh ${{ matrix.keycloak-chart }} ${{ matrix.keycloak-controller-chart }} ${{ matrix.k8s-version }}
run: .github/ci.docker-build.sh
- name: helm
run: .github/ci.helm.sh
- name: keycloak and keycloak controller
run: |
.github/ci.keycloak.sh ${{ matrix.keycloak-chart }} & \
.github/ci.keycloak-controller.sh ${{ matrix.keycloak-controller-chart }} & \
wait
- name: examples
run: .github/ci.example.sh
- name: verify
run: .github/ci.verify.sh
Loading

0 comments on commit 7264e21

Please sign in to comment.