Skip to content

Commit

Permalink
Helm Chart
Browse files Browse the repository at this point in the history
Add a Helm chart to simplify installation and distribution. Also include
release an install utilities.
  • Loading branch information
bcessa committed Dec 6, 2019
1 parent 1e20edb commit ce17075
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -15,5 +15,6 @@ vendor/**
!**/testdata/*.pem

# Artifacts
govanity
govanity_*
/govanity
/govanity_*
release-*
12 changes: 11 additions & 1 deletion Makefile
Expand Up @@ -24,6 +24,9 @@ ca-roots: ## Generate the list of valid CA certificates
@docker stop ca-roots

test: ## Run all tests excluding the vendor dependencies
# Lint helm charts available
helm lint helm/*

# Static analysis
golangci-lint run -v ./...
go-consistent -v ./...
Expand All @@ -35,7 +38,6 @@ clean: ## Download and compile all dependencies and intermediary products
@-rm -rf vendor
go mod tidy
go mod verify
go mod vendor

updates: ## List available updates for direct dependencies
# https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
Expand All @@ -59,3 +61,11 @@ docker: ## Build docker image
@-docker rmi $(DOCKER_IMAGE):$(VERSION_TAG)
@docker build --build-arg VERSION_TAG="$(VERSION_TAG)" --rm -t $(DOCKER_IMAGE):$(VERSION_TAG) .
@-rm $(BINARY_NAME)_$(VERSION_TAG)_linux_amd64 ca-roots.crt

release: ## Prepare the artifacts for a new release
@-rm -rf release-$(VERSION_TAG)
mkdir release-$(VERSION_TAG)
make build-for os=linux arch=amd64 dest=release-$(VERSION_TAG)/
make build-for os=darwin arch=amd64 dest=release-$(VERSION_TAG)/
make build-for os=windows arch=amd64 suffix=".exe" dest=release-$(VERSION_TAG)/
make build-for os=windows arch=386 suffix=".exe" dest=release-$(VERSION_TAG)/
22 changes: 22 additions & 0 deletions helm/govanity/.helmignore
@@ -0,0 +1,22 @@
# 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
.vscode/
7 changes: 7 additions & 0 deletions helm/govanity/Chart.yaml
@@ -0,0 +1,7 @@
apiVersion: v2
name: govanity
description: Go vanity URLs server
type: application
version: 0.1.0
appVersion: 0.1.0
home: https://github.com/bryk-io/go-vanity
21 changes: 21 additions & 0 deletions helm/govanity/templates/NOTES.txt
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "govanity.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "govanity.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "govanity.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "govanity.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
63 changes: 63 additions & 0 deletions helm/govanity/templates/_helpers.tpl
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "govanity.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 "govanity.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 "govanity.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "govanity.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "govanity.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
9 changes: 9 additions & 0 deletions helm/govanity/templates/configmap.yaml
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "govanity.fullname" . }}
labels:
{{- include "govanity.labels" . | nindent 4 }}
data:
config.yaml: |-
{{ toYaml .Values.configuration | indent 4 }}
67 changes: 67 additions & 0 deletions helm/govanity/templates/deployment.yaml
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "govanity.fullname" . }}
labels:
{{- include "govanity.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "govanity.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ toYaml .Values.configuration | sha256sum }}
labels:
{{- include "govanity.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "govanity.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: config
configMap:
name: {{ include "govanity.fullname" . }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "-config"
- "/tmp/config.yaml"
volumeMounts:
- name: config
mountPath: /tmp
ports:
- name: http
containerPort: 9090
protocol: TCP
livenessProbe:
httpGet:
path: /api/ping
port: http
readinessProbe:
httpGet:
path: /api/ping
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
41 changes: 41 additions & 0 deletions helm/govanity/templates/ingress.yaml
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "govanity.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "govanity.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions helm/govanity/templates/service.yaml
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "govanity.fullname" . }}
labels:
{{- include "govanity.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "govanity.selectorLabels" . | nindent 4 }}
8 changes: 8 additions & 0 deletions helm/govanity/templates/serviceaccount.yaml
@@ -0,0 +1,8 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "govanity.serviceAccountName" . }}
labels:
{{ include "govanity.labels" . | nindent 4 }}
{{- end -}}
58 changes: 58 additions & 0 deletions helm/govanity/values.yaml
@@ -0,0 +1,58 @@
configuration: ""
# Server YAML configuration

replicaCount: 1
nameOverride: ""
fullnameOverride: ""
imagePullSecrets: []
image:
repository: govanity
pullPolicy: IfNotPresent

serviceAccount:
create: true
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name:

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

resources: {}
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

0 comments on commit ce17075

Please sign in to comment.