Skip to content

Commit

Permalink
feat: add Kubernetes configuration files for Besu
Browse files Browse the repository at this point in the history
   This commit introduces Kubernetes configuration files for deploying Besu nodes. Key additions include:

   - Helm charts for Besu genesis and node deployment
   - Kubernetes manifests for Besu network setup
   - Configuration files for Besu node operations in a Kubernetes environment
  • Loading branch information
謝明華 authored and a7351220 committed Aug 28, 2024
1 parent a35f528 commit 57a57d3
Show file tree
Hide file tree
Showing 35 changed files with 1,836 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/eth/command/backup/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const command = 'export'

export const desc = '匯出現有的 Eth Network'


interface OptType {
interactive: boolean
}
Expand Down
8 changes: 3 additions & 5 deletions src/eth/command/cluster/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { WalletType } from '../../../wallet/model/type/wallet.type'
import { defaultNetworkConfig } from '../../model/defaultNetworkConfig'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices } from '../../config/network.type'
import { NetworkType } from '../../config/network.type'

import { getNetworkTypeChoices, NetworkType } from '../../config/network.type'
export const command = 'apply'

export const desc = '產生 Network Cluster 所需的相關設定檔案並建立網路'
Expand Down Expand Up @@ -44,13 +42,13 @@ export const handler = async (argv: Arguments<OptType>) => {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: `⚠️ Detecting ${networkType} cluster already exists. The following processes will remove all existing files. Continue?`,
message: '⚠️ Detecting cluster already exists. The following processes will remove all existing files. Continue?',
initial: false,
}, { onCancel })).value
if (confirmDelete) {
const spinner = ora(`${networkType} Cluster Delete ...`).start()
cluster.removeHelmChartFiles()
spinner.succeed(`Remove all existing files!`)
spinner.succeed('Remove all existing files!')
}
return confirmDelete
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/eth/command/cluster/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { defaultNetworkConfig } from '../../model/defaultNetworkConfig'
import { onCancel } from '../../../util/error'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices } from '../../config/network.type'
import { NetworkType } from '../../config/network.type'
import { getNetworkTypeChoices, NetworkType } from '../../config/network.type'

export const command = 'generate'

Expand Down Expand Up @@ -44,7 +43,7 @@ export const handler = async (argv: Arguments<OptType>) => {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: `⚠️ Detecting ${networkType} cluster already exists. The following processes will remove all existing files. Continue?`,
message: '⚠️ Detecting cluster already exists. The following processes will remove all existing files. Continue?',
initial: false,
}, { onCancel })).value
if (confirmDelete) {
Expand Down
2 changes: 1 addition & 1 deletion src/eth/config/besu/besuMemberConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const besuConfig: NetworkConfigType = {
networks: [NetworkType.BESU],
entrypoint: (chainId, peerPort, bootnode, nodeEncode) => [
'/bin/sh', '-c',
`besu --data-path=/data \
`besu --data-path=/data \
--genesis-file=/data/genesis.json \
--network-id=${chainId} \
${(bootnode) ? '--bootnodes '.concat(nodeEncode) : ''}\
Expand Down
4 changes: 2 additions & 2 deletions src/eth/config/networkConfigLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import quorumGenesisConfig from './quorum/quorumGenesisConfig'
import besuGenesisConfig from './besu/besuGenesisConfig'
import { NodeTypeEnum } from '../model/type/config.type'

const networkConfigs: { [key in NetworkType]: { member: NetworkConfigType; validator: NetworkConfigType; genesisJson: GenesisJsonType, ethereumJsonRpcVariant: String } } = {
const networkConfigs: { [key in NetworkType]: { member: NetworkConfigType; validator: NetworkConfigType; genesisJson: GenesisJsonType; ethereumJsonRpcVariant: string } } = {
[NetworkType.BESU]: {
member: besuMemberConfig,
validator: besuValidatorConfig,
Expand Down Expand Up @@ -38,7 +38,7 @@ export const getGenesisJson = (networkType: NetworkType): GenesisJsonType => {
}
return genesisJson
}
export const getEthereumJsonRpcVariant = (networkType: NetworkType): String => {
export const getEthereumJsonRpcVariant = (networkType: NetworkType): string => {
const ethereumJsonRpcVariant = networkConfigs[networkType].ethereumJsonRpcVariant
if (!ethereumJsonRpcVariant) {
throw new Error(`Unsupported network type: ${networkType}`)
Expand Down
1 change: 1 addition & 0 deletions src/eth/instance/bdkFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export default class BdkFile {
this.checkHelmChartPath()
return `${this.helmPath}/goquorum-genesis`
}

public getBesuGenesisChartPath (): string {
this.checkHelmChartPath()
return `${this.helmPath}/besu-genesis`
Expand Down
23 changes: 23 additions & 0 deletions src/eth/instance/infra/kubernetes/charts/besu-genesis/.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
*~
generated_config/
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
20 changes: 20 additions & 0 deletions src/eth/instance/infra/kubernetes/charts/besu-genesis/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
version: 0.1.0
appVersion: latest
name: besu-genesis
description: Besu Genesis generator with Helm chart in Kubernetes
keywords:
- ethereum
- besu
- hyperledger
- enterprise
- blockchain
- pegasys
- consensys
home: https://besu.hyperledger.org
sources:
- https://github.com/hyperledger/besu
maintainers:
- name: Joshua Fernandes
email: [email protected]
icon: http://besu.hyperledger.org/en/latest/favicon.ico
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "besu-genesis.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 "besu-genesis.fullname" -}}
{{- $name := default .Chart.Name -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" $name .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}


{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "besu-genesis.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "besu-genesis.name" . }}-cleanup
labels:
{{- if and (eq .Values.cluster.provider "azure") (.Values.cluster.cloudNativeServices) }}
azure.workload.identity/use: "true"
{{- end }}
app.kubernetes.io/name: besu-genesis-job-cleanup
app.kubernetes.io/component: genesis-job-cleanup
app.kubernetes.io/part-of: {{ include "besu-genesis.fullname" . }}
app.kubernetes.io/namespace: {{ .Release.Namespace }}
app.kubernetes.io/managed-by: helm
namespace: {{ .Release.Namespace }}
annotations:
helm.sh/hook-weight: "0"
helm.sh/hook: "pre-delete"
helm.sh/hook-delete-policy: "hook-succeeded"
spec:
backoffLimit: 3
completions: 1
template:
metadata:
labels:
{{- if and (eq .Values.cluster.provider "azure") (.Values.cluster.cloudNativeServices) }}
azure.workload.identity/use: "true"
{{- end}}
app.kubernetes.io/name: besu-genesis-job-cleanup
app.kubernetes.io/component: genesis-job-cleanup
app.kubernetes.io/part-of: {{ include "besu-genesis.fullname" . }}
app.kubernetes.io/namespace: {{ .Release.Namespace }}
app.kubernetes.io/managed-by: helm
spec:
{{- if and (eq .Values.cluster.provider "azure") (.Values.cluster.cloudNativeServices) }}
serviceAccountName: {{ .Values.azure.serviceAccountName }}
{{- else if and (eq .Values.cluster.provider "aws") (.Values.cluster.cloudNativeServices) }}
serviceAccountName: {{ .Values.aws.serviceAccountName }}
{{- else }}
serviceAccountName: {{ include "besu-genesis.name" . }}-sa
{{- end }}
restartPolicy: "Never"
containers:
- name: delete-genesis
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
securityContext:
runAsUser: 0
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -c
args:
- |
{{- if .Values.quorumFlags.removeGenesisOnDelete }}

echo "Deleting genesis configmap in k8s ..."
kubectl delete configmap --namespace {{ .Release.Namespace }} besu-genesis

echo "Deleting node-enodes configmap in k8s ..."
kubectl delete configmap --namespace {{ .Release.Namespace }} besu-peers

{{- end}}
Loading

0 comments on commit 57a57d3

Please sign in to comment.