Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a chart for YOURLS function #117

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions charts/function/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj

# OWNERS file for Kubernetes
OWNERS
# example production yaml
values-production.yaml
# ci files
ci/
9 changes: 9 additions & 0 deletions charts/function/Chart.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions charts/function/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v2
version: 0.0.1
name: function
description: Serverless Function
appVersion: "1.0.0"
type: application
keywords:
- shortener
- url
- bitly
home: https://yourls.org
icon: https://yourls.org/images/yourls-logo.png
sources:
- https://github.com/YOURLS/function
- https://github.com/YOURLS/charts
maintainers:
- name: YOURLS
email: [email protected]
- name: LeoColomb
email: [email protected]
kubeVersion: ">=1.20.0-0"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
version: ^1.11.1
tags:
- bitnami-common
- condition: redis.enabled
name: redis
repository: https://charts.bitnami.com/bitnami
version: ^16.4.0
tags:
- function-database
annotations:
artifacthub.io/license: MIT
artifacthub.io/links: |
- name: Upstream Project
url: https://github.com/YOURLS/function
artifacthub.io/signKey: |
fingerprint: 6FCD850E18E4A4FF76DD1184A3A42A61961E423F
url: https://yourls.org/.well-known/openpgpkey/hu/6e4gbtp15q1znf3unweeducn7urty4mr
artifacthub.io/changes: |
- kind: added
description: First version
Empty file added charts/function/README.md
Empty file.
102 changes: 102 additions & 0 deletions charts/function/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{{/* vim: set filetype=mustache: */}}

{{/*
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).
*/}}
{{- define "function.redis.fullname" -}}
{{- include "common.names.dependency.fullname" (dict "chartName" "redis" "chartValues" .Values.redis "context" $) -}}
{{- end -}}

{{/*
Return the proper YOURLS image name
*/}}
{{- define "function.image" -}}
{{- $imageRoot := .Values.image -}}
{{- if not .Values.image.tag }}
{{- $tag := (dict "tag" .Chart.AppVersion) -}}
{{- $imageRoot := merge .Values.image $tag -}}
{{- end -}}
{{- include "common.images.image" (dict "imageRoot" $imageRoot "global" .Values.global) -}}
{{- end -}}

{{/*
Return the Function Secret Name
*/}}
{{- define "function.secretName" -}}
{{- if .Values.function.existingSecret }}
{{- printf "%s" .Values.function.existingSecret -}}
{{- else -}}
{{- printf "%s" (include "common.names.fullname" .) -}}
{{- end -}}
{{- end -}}

{{/*
Return the Redis™ hostname
*/}}
{{- define "function.redisHost" -}}
{{- if .Values.redis.enabled }}
{{- printf "%s-master" (include "function.redis.fullname" .) -}}
{{- else -}}
{{- printf "%s" .Values.externalDatabase.host -}}
{{- end -}}
{{- end -}}

{{/*
Return the Redis™ port
*/}}
{{- define "function.redisPort" -}}
{{- if .Values.redis.enabled }}
{{- printf "6379" | quote -}}
{{- else -}}
{{- .Values.externalDatabase.port | quote -}}
{{- end -}}
{{- end -}}

{{/*
Return true if a secret object for Redis™ should be created
*/}}
{{- define "function.redis.createSecret" -}}
{{- if and (not .Values.redis.enabled) (not .Values.externalDatabase.existingSecret) .Values.externalDatabase.password }}
{{- true -}}
{{- end -}}
{{- end -}}

{{/*
Return the Redis™ secret name
*/}}
{{- define "function.redis.secretName" -}}
{{- if .Values.redis.enabled }}
{{- if .Values.redis.auth.existingSecret }}
{{- printf "%s" .Values.redis.auth.existingSecret -}}
{{- else -}}
{{- printf "%s" (include "function.redis.fullname" .) -}}
{{- end -}}
{{- else if .Values.externalDatabase.existingSecret }}
{{- printf "%s" .Values.externalDatabase.existingSecret -}}
{{- else -}}
{{- printf "%s-redis" (include "common.names.fullname" .) -}}
{{- end -}}
{{- end -}}

{{/*
Return the Redis™ secret key
*/}}
{{- define "function.redis.secretPasswordKey" -}}
{{- if and .Values.redis.enabled .Values.redis.auth.existingSecret }}
{{- required "You need to provide existingSecretPasswordKey when an existingSecret is specified in redis" .Values.redis.auth.existingSecretPasswordKey | printf "%s" }}
{{- else if and (not .Values.redis.enabled) .Values.externalDatabase.existingSecret }}
{{- required "You need to provide existingSecretPasswordKey when an existingSecret is specified in redis" .Values.externalDatabase.existingSecretPasswordKey | printf "%s" }}
{{- else -}}
{{- printf "redis-password" -}}
{{- end -}}
{{- end -}}

{{/*
Return whether Redis™ uses password authentication or not
*/}}
{{- define "function.redis.auth.enabled" -}}
{{- if or (and .Values.redis.enabled .Values.redis.auth.enabled) (and (not .Values.redis.enabled) (or .Values.externalDatabase.password .Values.externalDatabase.existingSecret)) }}
{{- true -}}
{{- end -}}
{{- end -}}
14 changes: 14 additions & 0 deletions charts/function/templates/configmaps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "common.names.fullname" . }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
data:
REDIS_HOST: {{ template "function.redisHost" . }}
REDIS_PORT_NUMBER: {{ template "function.redisPort" . }}
16 changes: 16 additions & 0 deletions charts/function/templates/externaldb-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if (include "function.redis.createSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "common.names.fullname" . }}-redis
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
type: Opaque
data:
redis-password: {{ .Values.externalDatabase.password | b64enc | quote }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/function/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if not .Values.function.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
type: Opaque
data:
endpoint: {{ .Values.function.endpoint | b64enc | quote }}
token: {{ .Values.function.token | b64enc | quote }}
{{- end }}
50 changes: 50 additions & 0 deletions charts/function/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
template:
metadata:
labels: {{- include "common.labels.standard" . | nindent 8 }}
{{- if .Values.podLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
{{- end }}
{{- if or .Values.podAnnotations }}
annotations:
{{- if .Values.podAnnotations }}
{{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
{{- end }}
{{- end }}
spec:
containers:
- name: function
image: {{ template "function.image" . }}
env:
{{- if (include "function.redis.auth.enabled" .) }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "function.redis.secretName" . }}
key: {{ include "function.redis.secretPasswordKey" . }}
{{- end }}
- name: YOURLS_ENDPOINT
valueFrom:
secretKeyRef:
name: {{ include "function.secretName" . }}
key: endpoint
- name: YOURLS_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "function.secretName" . }}
key: token
envFrom:
- configMapRef:
name: {{ include "common.names.fullname" . }}
Loading
Loading