Skip to content

Commit

Permalink
refactor(main): add test helm chart example
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu committed Jul 13, 2023
1 parent 714d45f commit f9689ea
Show file tree
Hide file tree
Showing 16 changed files with 1,042 additions and 0 deletions.
490 changes: 490 additions & 0 deletions tests/user-yaml/deploy.yaml

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions tests/zot/.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/
6 changes: 6 additions & 0 deletions tests/zot/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
appVersion: VERSION
description: A Helm chart for Kubernetes
name: zot
type: application
version: 0.1.22
15 changes: 15 additions & 0 deletions tests/zot/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Get the application URL by running these commands:
export ZOT_PORT=$(kubectl get --namespace zot -o jsonpath="{.spec.ports[0].port}" services zot)
export ZOT_IP=$(kubectl get --namespace zot -o jsonpath="{.spec.clusterIP}" services zot)
echo "https://$ZOT_IP:$ZOT_PORT"
You can now access your application using helm.

helm registry login $ZOT_IP:$ZOT_PORT --insecure -u user -p user
helm push zot-0.1.22.tgz oci://$ZOT_IP:$ZOT_PORT --insecure-skip-tls-verify
helm pull oci://$ZOT_IP:$ZOT_PORT/zot --version 0.1.22 --insecure-skip-tls-verify=true

Using svc address: helm registry login {{ include "zot.fullname" . }}.{{.Release.Namespace}}.svc.cluster.local:{{.Values.service.port}} --insecure -u user -p user

You can push your all helm chart for your zot registry.

sealos run labring/zot-upload:main -f
62 changes: 62 additions & 0 deletions tests/zot/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "zot.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 "zot.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 "zot.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "zot.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "zot.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions tests/zot/templates/check-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-cert-manager-check"
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}-cert-manager-check"
labels:
app: "{{ .Chart.Name }}"
release: "{{ .Release.Name }}"
spec:
restartPolicy: Never
containers:
- name: cert-manager-check
image: busybox:latest
command: ["sh", "-c", "until echo exit | telnet cert-manager-webhook.cert-manager.svc 443; do echo waiting for cert-manager; sleep 10; done;"]
55 changes: 55 additions & 0 deletions tests/zot/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
config.json: |-
{
"storage": {
"rootDirectory": "/var/lib/registry",
"gc": true,
"gcDelay": "1h",
"gcInterval": "24h",
"storageDriver": {{ toJson .Values.s3 }}
},
"http": {
"address": "0.0.0.0",
"port": "5000",
{{if .Values.tlsEnable}}
"tls": {
"cert":"/tmp/serving-certs/tls.crt",
"key":"/tmp/serving-certs/tls.key",
"caCert":"/tmp/serving-certs/ca.crt"
},
{{end}}
"realm":"zot",
"auth":{
"htpasswd":{
"path":"/etc/zot/htpasswd"
},
"failDelay":1
},
"accessControl": {{ toJson .Values.accessControl }}
},
"log": { "level": "debug" },
"extensions": {
{{if .Values.prometheusEnable}}
"metrics": {
"enable": true,
"prometheus": {
"path": "/metrics"
}
},
{{end}}
"search": {
"enable": true,
"cve": {
"updateInterval": "2h"
}
},
"scrub": {
"enable": true,
"interval": "24h"
}
}
}
94 changes: 94 additions & 0 deletions tests/zot/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "zot.fullname" . }}
labels:
{{- include "zot.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "zot.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "zot.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "zot.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: zot
containerPort: 5000
protocol: TCP
volumeMounts:
- mountPath: /tmp/serving-certs
name: cert
readOnly: true
- mountPath: '/etc/zot/htpasswd'
name: {{ .Release.Name }}-secret
subPath: htpasswd
- mountPath: '/etc/zot/config.json'
name: {{ .Release.Name }}-config
subPath: config.json
- mountPath: '/var/lib/registry'
name: {{ .Release.Name }}-volume
livenessProbe:
httpGet:
path: /v2/
port: 5000
scheme: HTTPS
httpHeaders:
- name: Authorization
value: Basic {{ printf "%s:%s" .Values.authHeaderUser .Values.authHeaderPassword | b64enc }}
readinessProbe:
httpGet:
path: /v2/
port: 5000
scheme: HTTPS
httpHeaders:
- name: Authorization
value: Basic {{ printf "%s:%s" .Values.authHeaderUser .Values.authHeaderPassword | b64enc }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: cert
secret:
defaultMode: 420
secretName: {{.Values.tlsSecretName}}
- name: {{ .Release.Name }}-config
configMap:
name: {{ .Release.Name }}-config
- name: {{ .Release.Name }}-secret
secret:
secretName: {{ .Release.Name }}-secret
- name: {{ .Release.Name }}-volume
persistentVolumeClaim:
claimName: {{ .Values.pvc.name | default (printf "%s-pvc" .Release.Name) }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
26 changes: 26 additions & 0 deletions tests/zot/templates/monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{if .Values.prometheusEnable }}
# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "zot.fullname" . }}
labels:
{{- include "zot.labels" . | nindent 4 }}
spec:
endpoints:
- path: /metrics
port: zot
scheme: https
basicAuth:
password:
name: {{ .Release.Name }}-secret-user
key: username
username:
name: {{ .Release.Name }}-secret-user
key: password
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
{{- include "zot.labels" . | nindent 4 }}
{{end}}
13 changes: 13 additions & 0 deletions tests/zot/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.pvc.name | default (printf "%s-pvc" .Release.Name) }}
spec:
accessModes:
- {{ .Values.pvc.accessMode | default "ReadWriteOnce" }}
resources:
requests:
storage: {{ .Values.pvc.storage | default "8Gi" }}
{{- if .Values.pvc.storageClassName }}
storageClassName: {{ .Values.pvc.storageClassName }}
{{- end }}
8 changes: 8 additions & 0 deletions tests/zot/templates/secret-user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-secret-user
type: Opaque
data:
username: {{ .Values.authHeaderUser | b64enc }}
password: {{ .Values.authHeaderPassword | b64enc }}
9 changes: 9 additions & 0 deletions tests/zot/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-secret
type: Opaque
data:
{{- range $key, $val := .Values.secretFiles }}
{{ $key }}: {{ $val | b64enc }}
{{- end }}
15 changes: 15 additions & 0 deletions tests/zot/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "zot.fullname" . }}
labels:
{{- include "zot.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: zot
protocol: TCP
name: zot
selector:
{{- include "zot.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions tests/zot/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "zot.serviceAccountName" . }}
labels:
{{- include "zot.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
26 changes: 26 additions & 0 deletions tests/zot/templates/tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ include "zot.fullname" . }}
labels:
{{- include "zot.labels" . | nindent 4 }}
spec:
dnsNames:
- {{ include "zot.fullname" . }}.{{.Release.Namespace}}.svc
- {{ include "zot.fullname" . }}.{{.Release.Namespace}}.svc.cluster.local
{{- range .Values.extraDNSNames }}
- {{ . }}
{{- end }}
issuerRef:
kind: Issuer
name: zot-selfsigned-issuer
secretName: {{.Values.tlsSecretName}}
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: zot-selfsigned-issuer
labels:
{{- include "zot.labels" . | nindent 4 }}
spec:
selfSigned: {}
Loading

0 comments on commit f9689ea

Please sign in to comment.