Skip to content

Commit

Permalink
additional chart testing (#3)
Browse files Browse the repository at this point in the history
* add kubeval

* bump version

* update readme

* kind testing

* kubeval ingress

* explicit cleanup
  • Loading branch information
Jordan Hoeft committed Feb 13, 2024
1 parent 63b32be commit 19978b6
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/inject-sensitive-values.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Directory containing values files
VALUES_DIR=$1

# Image repository and tag
REPO=$2
TAG=$3
PRIVATE_KEY=$4

# Loop through each values file in the directory
for VALUES_FILE in "$VALUES_DIR"/*.yaml; do
# Use sed to update the repository and tag
sed -i "s|repository:.*|repository: $REPO|g" "$VALUES_FILE"
sed -i "s|tag:.*|tag: \"$TAG\"|g" "$VALUES_FILE"
sed -i "s|PrivateKey = \".*\"|PrivateKey = \"$PRIVATE_KEY\"|g" "$VALUES_FILE"
done
39 changes: 39 additions & 0 deletions .github/kubeval.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

mkdir -p ./.bin
export PATH="./.bin:$PATH"

set -euxo pipefail

KUBEVAL_VERSION=v0.16.1

SEMVER_VERSION=v1.0.5

CHART_DIRS="$(git diff --find-renames --name-only "$(git rev-parse --abbrev-ref HEAD)" remotes/origin/main -- charts | cut -d '/' -f 2 | uniq)"
SCHEMA_LOCATION="https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/"

# install kubeval
curl --silent --show-error --fail --location --output /tmp/kubeval.tar.gz https://github.com/instrumenta/kubeval/releases/download/"${KUBEVAL_VERSION}"/kubeval-linux-amd64.tar.gz
tar -C .bin/ -xf /tmp/kubeval.tar.gz kubeval

# install semver compare
curl -sSfLo .bin/semver2 https://raw.githubusercontent.com/Ariel-Rodriguez/sh-semversion-2/${SEMVER_VERSION}/semver2.sh
chmod +x .bin/semver2

# Compute required kubernetes api versions
apis=()

# validate charts
for CHART_DIR in ${CHART_DIRS}; do
(cd "charts/${CHART_DIR}"; helm dependency build)
for VALUES_FILE in charts/"${CHART_DIR}"/ci/*.yaml; do
helm template \
"${apis[@]}" \
--values "${VALUES_FILE}" \
charts/"${CHART_DIR}" | kubeval \
--strict \
--ignore-missing-schemas \
--kubernetes-version "${KUBERNETES_VERSION#v}" \
--schema-location "${SCHEMA_LOCATION}"
done
done
126 changes: 126 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:

merge_group:
permissions:
id-token: write
contents: read

jobs:
lint-chart:
Expand Down Expand Up @@ -42,11 +45,124 @@ jobs:
- name: Run helm-docs
run: .github/helm-docs.sh

kubeval-chart:
runs-on: ubuntu-latest
needs:
- lint-chart
- lint-docs
strategy:
matrix:
k8s:
# from https://github.com/yannh/kubernetes-json-schema
- v1.26.12
- v1.27.9
- v1.28.5
- v1.29.0
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run kubeval
env:
KUBERNETES_VERSION: ${{ matrix.k8s }}
run: .github/kubeval.sh

install-chart:
name: install-chart
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login || !startsWith(github.event.pull_request.head.ref, 'renovate/') }}
needs:
- lint-chart
- lint-docs
- kubeval-chart
strategy:
matrix:
k8s:
# from https://hub.docker.com/r/kindest/node/tags
- v1.26.13
- v1.27.10
- v1.28.6
- v1.29.1
env:
ECR_REPO: "${{ secrets.ECR_REPO }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: assume base role
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
role-session-name: ${{ github.actor }}
mask-aws-account-id: true
aws-region: us-east-1
role-duration-seconds: 900

- name: assume ecr role
run: |
aws sts assume-role --role-arn ${{ secrets.ECR_ROLE }} --role-session-name ${{ github.actor }} --region us-east-1 --tags "Key=repo,Value=builder-vault-helm" > assume-role-output.json
AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' assume-role-output.json)
AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' assume-role-output.json)
AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' assume-role-output.json)
echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV
echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV
echo "::add-mask::$AWS_ACCESS_KEY_ID"
echo "::add-mask::$AWS_SECRET_ACCESS_KEY"
echo "::add-mask::$AWS_SESSION_TOKEN"
- name: Get appVersion from Chart.yaml
id: chart_version
run: |
APP_VERSION=$(grep 'appVersion:' charts/tsm-node/Chart.yaml | awk '{print $2}')
echo "IMAGE_TAG=$APP_VERSION" >> $GITHUB_ENV
- name: Pull image from ECR
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_REPO
IMAGE_TAG=$(echo ${{ env.IMAGE_TAG }} | tr -d '\r')
docker pull $ECR_REPO:$IMAGE_TAG
- name: Create kind ${{ matrix.k8s }} cluster
uses: helm/[email protected]
with:
node_image: kindest/node:${{ matrix.k8s }}
version: v0.21.0

- name: Load image into kind cluster
run: |
IMAGE_TAG=$(echo ${{ env.IMAGE_TAG }} | tr -d '\r')
kind load docker-image $ECR_REPO:$IMAGE_TAG -n chart-testing
- name: Inject ECR Repo and Image Tag into Values Files
run: |
IMAGE_TAG=$(echo ${{ env.IMAGE_TAG }} | tr -d '\r')
./.github/inject-sensitive-values.sh charts/tsm-node/ci $ECR_REPO $IMAGE_TAG ${{ secrets.PRIVATE_KEY }}
- name: Install chart-testing
uses: helm/[email protected]

- name: Run chart install
run: ct install --config .github/ct.yaml

- name: Cleanup AWS Credentials
if: always()
run: |
echo "AWS_ACCESS_KEY_ID=" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=" >> $GITHUB_ENV
echo "AWS_SESSION_TOKEN=" >> $GITHUB_ENV
# Catch-all required check for test matrix
test-success:
needs:
- lint-chart
- lint-docs
- kubeval-chart
- install-chart
runs-on: ubuntu-latest
timeout-minutes: 1
if: always()
Expand All @@ -61,3 +177,13 @@ jobs:
needs.lint-docs.result == 'failure' ||
needs.lint-docs.result == 'cancelled'
run: exit 1
- name: Fail for failed or cancelled kubeval-chart
if: |
needs.kubeval-chart.result == 'failure' ||
needs.kubeval-chart.result == 'cancelled'
run: exit 1
- name: Fail for failed or cancelled install-chart
if: |
needs.install-chart.result == 'failure' ||
needs.install-chart.result == 'cancelled'
run: exit 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.bin
2 changes: 1 addition & 1 deletion charts/tsm-node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ maintainers:
- name: Blockdaemon
email: [email protected]
type: application
version: 0.1.0
version: 0.1.1
appVersion: "61.0.2"
2 changes: 1 addition & 1 deletion charts/tsm-node/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tsm-node

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 61.0.2](https://img.shields.io/badge/AppVersion-61.0.2-informational?style=flat-square)
![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 61.0.2](https://img.shields.io/badge/AppVersion-61.0.2-informational?style=flat-square)

A Helm chart to deploy a Blockdaemon TSM node to kubernetes

Expand Down
35 changes: 35 additions & 0 deletions charts/tsm-node/ci/configFile-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
replicaCount: 1
index: 0

config:
configFile: |
[Player]
Index = 0
PrivateKey = "replace me"
[Database]
DriverName = "sqlite3"
DataSourceName = "/tmp/tsmdb"
EncryptorMasterPassword = "ENCRYPTION_KEY"
[SDKServer]
Port = 8080
image:
repository: <the name of the repository where tsm-node is stored>
pullPolicy: IfNotPresent
tag: "61.0.2"
sdkService:
type: NodePort
ports:
- port: 8080
name: sdk
targetPort: 8080
- port: 9000
name: mpc
targetPort: 9000

mpcService:
enabled: false

ingress:
enabled: false
46 changes: 46 additions & 0 deletions charts/tsm-node/ci/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
replicaCount: 1
index: 0

config:
configFile: |
[Player]
Index = 0
PrivateKey = "replace me"
[Database]
DriverName = "sqlite3"
DataSourceName = "/tmp/tsmdb"
EncryptorMasterPassword = "ENCRYPTION_KEY"
[SDKServer]
Port = 8080
image:
repository: <the name of the repository where tsm-node is stored>
pullPolicy: IfNotPresent
tag: "61.0.2"
sdkService:
type: NodePort
ports:
- port: 8080
name: sdk
targetPort: 8080
- port: 9000
name: mpc
targetPort: 9000

mpcService:
enabled: false

ingress:
enabled: true
className: "alb"
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/certificate-arn: <acm certificate arn>
alb.ingress.kubernetes.io/healthcheck-path: /ping
hosts:
- host: "tsm0-sdk.exmaple.com"
paths:
- path: /
pathType: Prefix
port: 8080
2 changes: 1 addition & 1 deletion charts/tsm-node/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
name: {{ .name }}
protocol: TCP
{{- end }}
livenessProbe: #TODO
livenessProbe:
httpGet:
path: /ping
port: sdk
Expand Down

0 comments on commit 19978b6

Please sign in to comment.