Skip to content

Commit

Permalink
deploy commander using helm (#550)
Browse files Browse the repository at this point in the history
* deploy commander using helm

* teardown commanders using helm, fix status

* stop scenario faster

* stop warnet faster

* fix scenarios_test

User proper scenarios delete function
  • Loading branch information
willcl-ark authored Sep 10, 2024
1 parent 4fff537 commit 65fa357
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 109 deletions.
23 changes: 23 additions & 0 deletions resources/charts/commander/.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/
24 changes: 24 additions & 0 deletions resources/charts/commander/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: commander
description: A Helm chart for a commander

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: 0.1.0
1 change: 1 addition & 0 deletions resources/charts/commander/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Commander beginning their mission.
60 changes: 60 additions & 0 deletions resources/charts/commander/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "commander.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 "commander.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

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

{{/*
Common labels
*/}}
{{- define "commander.labels" -}}
helm.sh/chart: {{ include "commander.chart" . }}
{{ include "commander.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.podLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

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

{{/*
Create the name of the service account to use
*/}}
{{- define "commander.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "commander.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions resources/charts/commander/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "commander.fullname" . }}-scenario
labels:
{{- include "commander.labels" . | nindent 4 }}
binaryData:
scenario.py: {{ .Values.scenario }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "commander.fullname" . }}-warnet
labels:
{{- include "commander.labels" . | nindent 4 }}
binaryData:
warnet.json: {{ .Values.warnet }}
32 changes: 32 additions & 0 deletions resources/charts/commander/templates/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Pod
metadata:
name: {{ include "commander.fullname" . }}
labels:
{{- include "commander.labels" . | nindent 4 }}
app: {{ include "commander.name" . }}
mission: commander
spec:
restartPolicy: {{ .Values.restartPolicy }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/bin/sh", "-c"]
args:
- |
python3 /scenario.py {{ .Values.args }}
volumeMounts:
- name: scenario
mountPath: /scenario.py
subPath: scenario.py
- name: warnet
mountPath: /warnet.json
subPath: warnet.json
volumes:
- name: scenario
configMap:
name: {{ include "commander.fullname" . }}-scenario
- name: warnet
configMap:
name: {{ include "commander.fullname" . }}-warnet
78 changes: 78 additions & 0 deletions resources/charts/commander/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Default values for commander.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
namespace: warnet

restartPolicy: Never

image:
repository: bitcoindevproject/warnet-commander
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podLabels:
app: "warnet"
mission: "commander"

podSecurityContext: {}

securityContext: {}

service:
type: ClusterIP

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# livenessProbe:
# exec:
# command:
# - pidof
# - commander
# failureThreshold: 3
# initialDelaySeconds: 5
# periodSeconds: 5
# successThreshold: 1
# timeoutSeconds: 1
# readinessProbe:
# failureThreshold: 1
# periodSeconds: 1
# successThreshold: 1
# tcpSocket:
# port: 2323
# timeoutSeconds: 1

# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
# secret:
# secretName: mysecret
# optional: false

# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true

port:

scenario: ""

warnet: ""

args: ""
1 change: 1 addition & 0 deletions src/warnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Helm charts
BITCOIN_CHART_LOCATION = str(CHARTS_DIR.joinpath("bitcoincore"))
FORK_OBSERVER_CHART = str(CHARTS_DIR.joinpath("fork-observer"))
COMMANDER_CHART = str(CHARTS_DIR.joinpath("commander"))
NAMESPACES_CHART_LOCATION = CHARTS_DIR.joinpath("namespaces")
DEFAULT_NETWORK = Path("6_node_bitcoin")
DEFAULT_NAMESPACES = Path("two_namespaces_two_users")
Expand Down
Loading

0 comments on commit 65fa357

Please sign in to comment.