Skip to content

Commit

Permalink
feat: Helm Chart (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 authored Jul 31, 2024
1 parent 312cad5 commit 926b34c
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/helm-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
##
# Copyright (C) 2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
name: Lint and Test Charts

on: pull_request

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: Azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
with:
version: v3.14.4

- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.x'
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992 # v2.6.1

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --config ct.yaml

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --config ct.yaml
2 changes: 2 additions & 0 deletions charts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/out
out
23 changes: 23 additions & 0 deletions charts/hedera-block-node/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
16 changes: 16 additions & 0 deletions charts/hedera-block-node/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
appVersion: "0.1.0-SNAPSHOT"
description: A Helm chart for Hedera Block Node
home: https://github.com/hashgraph/hedera-block-node
keywords:
- blocknode
- dlt
- hedera
- hashgraph
maintainers:
- name: Hedera Block Node Team
email: [email protected]
name: hedera-block-node
sources:
- https://github.com/hashgraph/hedera-block-node
version: 0.1.0-SNAPSHOT
75 changes: 75 additions & 0 deletions charts/hedera-block-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Helm Chart
Installs the Hedera Block Node on a Kubernetes cluster.

## Prerequisites
- Helm 3+
- Kubernetes 1.29+

Set environment variables that will be used for the remainder of the document:

```bash
export RELEASE="bn1"
```

## Template
To generate the K8 manifest files without installing the chart:
```bash
helm template --name-template my-bn hedera-block-node/ --dry-run --output-dir out
```

## Install
To install the chart:
```bash
helm repo add hedera-block-node https://hashgraph.github.io/hedera-block-node/charts
helm install "${RELEASE}" hedera-block-node/hedera-block-node -f <path-to-custom-values-file>
```
*Note:* If using the chart directly after cloning the github repo, there is no need to add the repo. and install can be directly.
Assuming you are at the root folder of the repo.
```bash
helm install "${RELEASE}" charts/hedera-block-node -f <path-to-custom-values-file>
```

## Configure

There are several ways to configure the Hedera Block Node. The following is the most common and recommended way to configure the Hedera Block Node.

1. Create an override values file, `values.yaml`:
2. Add the necessary environment configuration variables to the following section:
```yaml
blockNode:
config:
# Add any additional env configuration here
# key: value
BLOCKNODE_STORAGE_ROOT_PATH: "/app/storage"

```
3. Secrets should be set at the following structure:
```yaml
blockNode:
secret:
PRIVATE_KEY: "<Secret>"
```
or passed at the command line:
```bash
helm install "${RELEASE}" hedera-block-node/hedera-block-node --set blockNode.secret.PRIVATE_KEY="<Secret>"
```

## Using
Follow the `NOTES` instructions after installing the chart to perform `port-forward` to the Hedera Block Node and be able to use it.

## Uninstall
To uninstall the chart:
```bash
helm uninstall "${RELEASE}"
```

## Upgrade
To upgrade the chart:
```bash
# update the helm repo
helm repo update
# save current user supplied values
helm get values "${RELEASE}" > user-values.yaml
# upgrade the chart
helm upgrade "${RELEASE}" hedera-block-node/hedera-block-node -f user-values.yaml
```
22 changes: 22 additions & 0 deletions charts/hedera-block-node/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "hedera-block-node.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "hedera-block-node.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "hedera-block-node.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "hedera-block-node.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
80 changes: 80 additions & 0 deletions charts/hedera-block-node/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "hedera-block-node.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "hedera-block-node.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "hedera-block-node.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "hedera-block-node.labels" -}}
helm.sh/chart: {{ include "hedera-block-node.chart" . }}
{{ include "hedera-block-node.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "hedera-block-node.selectorLabels" -}}
app.kubernetes.io/name: {{ include "hedera-block-node.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "hedera-block-node.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "hedera-block-node.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
This function returns the image tag from the values.yaml file if provided.
If the tag is not provided, it defaults to the AppVersion specified in the Chart.yaml file.
Usage: {{ include "image.AppVersion" . }}
*/}}
{{- define "hedera-block-node.image.tag" -}}
{{- default .Chart.AppVersion .Values.image.tag -}}
{{- end -}}

{{/*
This function returns the image tag from the values.yaml file if provided.
If the tag is not provided, it defaults to the AppVersion specified in the Chart.yaml file.
Usage: {{ include "hedera-block-node.app.version" . }}
*/}}
{{- define "hedera-block-node.appVersion" -}}
{{- default .Chart.AppVersion .Values.blockNode.version -}}
{{- end -}}
9 changes: 9 additions & 0 deletions charts/hedera-block-node/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "hedera-block-node.fullname" . }}-config
data:
VERSION: {{ include "hedera-block-node.appVersion" . | quote }}
{{- range $key, $value := .Values.blockNode.config }}
{{ $key }}: {{ $value | quote }}
{{- end }}
65 changes: 65 additions & 0 deletions charts/hedera-block-node/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hedera-block-node.fullname" . }}
labels:
{{- include "hedera-block-node.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "hedera-block-node.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hedera-block-node.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hedera-block-node.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
envFrom:
- configMapRef:
name: {{ include "hedera-block-node.fullname" . }}-config
- secretRef:
name: {{ include "hedera-block-node.fullname" . }}-secret

# TODO: Uncomment them once we have the health and readiness probes in our application
#livenessProbe:
# httpGet:
# path: /health # we need to define this in our application
# port: 8080 # will be the same as server port?
#readinessProbe:
# httpGet:
# path: /ready # we need to define this in our application
# port: 8080 # will be the same as server port?
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

Loading

0 comments on commit 926b34c

Please sign in to comment.