Skip to content

Commit 4645935

Browse files
authored
Add Helm chart (#1)
1 parent d7a1930 commit 4645935

16 files changed

+539
-0
lines changed

.github/workflows/helm.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: lint/helm
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "helm/**"
9+
- ".github/workflows/helm.yaml"
10+
pull_request:
11+
paths:
12+
- "helm/**"
13+
- ".github/workflows/helm.yaml"
14+
workflow_dispatch:
15+
16+
# Cancel in-progress runs for pull requests when developers push
17+
# additional changes
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
21+
22+
jobs:
23+
lint:
24+
timeout-minutes: 5
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: azure/[email protected]
29+
with:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
- run: helm lint --strict ./helm

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The marketplace is a single binary. Deployment involves running the binary,
1414
pointing it to a directory of extensions, and exposing the binary's bound
1515
address in some way.
1616

17+
### Kubernetes
18+
19+
If deploying with Kubernetes see the [Helm directory](./helm) otherwise read on.
20+
1721
### Getting the binary
1822

1923
The binary can be downloaded from GitHub releases. For example here is a way to

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
go_1_19
1414
golangci-lint
1515
gotestsum
16+
kubernetes-helm
1617
];
1718
};
1819
}

helm/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/Chart.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: code-marketplace
3+
description: Open source extension marketplace for VS Code.
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "v1.1.0"

helm/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Code Extension Marketplace Helm Chart
2+
3+
This directory contains the Helm chart used to deploy the marketplace onto a
4+
Kubernetes cluster.
5+
6+
## Quickstart
7+
8+
```console
9+
$ git clone --depth 1 https://github.com/coder/code-marketplace
10+
$ helm upgrade --install code-marketplace ./code-marketplace/helm
11+
```
12+
13+
This deploys the marketplace on the default Kubernetes cluster.
14+
15+
## Ingress
16+
17+
You will need to configure `ingress` in [values.yaml](./values.yaml) to expose the
18+
marketplace on an external domain or change `service.type` to get yourself an
19+
external IP address.
20+
21+
It is recommended to configure `ingress` with TLS or put the external IP behind
22+
a TLS-terminating reverse proxy because code-server will refuse to connect to
23+
the marketplace if it is not behind HTTPS.
24+
25+
More information can be found at these links:
26+
27+
https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
28+
https://kubernetes.io/docs/concepts/services-networking/ingress/
29+
30+
## Adding/removing extensions
31+
32+
One way to get extensions added or removed is to exec into the pod and use the
33+
marketplace binary to add and remove them.
34+
35+
```
36+
export POD_NAME=$(kubectl get pods -l "app.kubernetes.io/name=code-marketplace,app.kubernetes.io/instance=code-marketplace" -o jsonpath="{.items[0].metadata.name}")
37+
$ kubectl exec -it "$POD_NAME" -- /opt/code-marketplace add https://github.com/VSCodeVim/Vim/releases/download/v1.24.1/vim-1.24.1.vsix --extensions-dir /extensions
38+
```
39+
40+
In the future it will be possible to use Artifactory for storing and retrieving
41+
extensions instead of a persistent volume.
42+
43+
## Uninstall
44+
45+
To uninstall/delete the marketplace deployment:
46+
47+
```console
48+
$ helm delete code-marketplace
49+
```
50+
51+
This removes all the Kubernetes components associated with the chart (including
52+
the persistent volume) and deletes the release.
53+
54+
## Configuration
55+
56+
Please refer to [values.yaml](./values.yaml) for available Helm values and their
57+
defaults.
58+
59+
Specify values using `--set`:
60+
61+
```console
62+
$ helm upgrade --install code-marketplace ./helm-chart \
63+
--set persistence.size=10Gi
64+
```
65+
66+
Or edit and use the YAML file:
67+
68+
```console
69+
$ helm upgrade --install code-marketplace ./helm-chart -f values.yaml
70+
```

helm/templates/NOTES.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "code-marketplace.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "code-marketplace.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "code-marketplace.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "code-marketplace.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}

helm/templates/_helpers.tpl

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "code-marketplace.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "code-marketplace.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "code-marketplace.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "code-marketplace.labels" -}}
37+
helm.sh/chart: {{ include "code-marketplace.chart" . }}
38+
{{ include "code-marketplace.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "code-marketplace.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "code-marketplace.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "code-marketplace.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "code-marketplace.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

helm/templates/deployment.yaml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "code-marketplace.fullname" . }}
5+
labels:
6+
{{- include "code-marketplace.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "code-marketplace.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "code-marketplace.selectorLabels" . | nindent 8 }}
22+
spec:
23+
{{- with .Values.imagePullSecrets }}
24+
imagePullSecrets:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
serviceAccountName: {{ include "code-marketplace.serviceAccountName" . }}
28+
volumes:
29+
- name: extensions
30+
persistentVolumeClaim:
31+
claimName: {{ include "code-marketplace.fullname" . }}
32+
securityContext:
33+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
34+
containers:
35+
- name: {{ .Chart.Name }}
36+
securityContext:
37+
{{- toYaml .Values.securityContext | nindent 12 }}
38+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
39+
imagePullPolicy: {{ .Values.image.pullPolicy }}
40+
ports:
41+
- name: http
42+
containerPort: 80
43+
protocol: TCP
44+
args:
45+
- --address
46+
- 0.0.0.0:80
47+
- --extensions-dir
48+
- /extensions
49+
volumeMounts:
50+
- name: extensions
51+
mountPath: /extensions
52+
livenessProbe:
53+
httpGet:
54+
path: /healthz
55+
port: http
56+
readinessProbe:
57+
httpGet:
58+
path: /healthz
59+
port: http
60+
resources:
61+
{{- toYaml .Values.resources | nindent 12 }}
62+
{{- with .Values.nodeSelector }}
63+
nodeSelector:
64+
{{- toYaml . | nindent 8 }}
65+
{{- end }}
66+
{{- with .Values.affinity }}
67+
affinity:
68+
{{- toYaml . | nindent 8 }}
69+
{{- end }}
70+
{{- with .Values.tolerations }}
71+
tolerations:
72+
{{- toYaml . | nindent 8 }}
73+
{{- end }}

helm/templates/hpa.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2beta1
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "code-marketplace.fullname" . }}
6+
labels:
7+
{{- include "code-marketplace.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "code-marketplace.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
21+
{{- end }}
22+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
23+
- type: Resource
24+
resource:
25+
name: memory
26+
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
27+
{{- end }}
28+
{{- end }}

0 commit comments

Comments
 (0)