Skip to content

Commit dc35cf0

Browse files
committed
Helm charts
1 parent 4dcdaba commit dc35cf0

23 files changed

+679
-15
lines changed

Makefile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.PHONY: all deps docker docker-cgo clean docs test test-race fmt lint install deploy-docs
2+
3+
TAGS =
4+
5+
INSTALL_DIR = $(GOPATH)/bin
6+
DEST_DIR = ./target
7+
PATHINSTBIN = $(DEST_DIR)/bin
8+
PATHINSTDOCKER = $(DEST_DIR)/docker
9+
10+
VERSION := $(shell git describe --tags || echo "v0.0.0")
11+
VER_CUT := $(shell echo $(VERSION) | cut -c2-)
12+
VER_MAJOR := $(shell echo $(VER_CUT) | cut -f1 -d.)
13+
VER_MINOR := $(shell echo $(VER_CUT) | cut -f2 -d.)
14+
VER_PATCH := $(shell echo $(VER_CUT) | cut -f3 -d.)
15+
VER_RC := $(shell echo $(VER_PATCH) | cut -f2 -d-)
16+
DATE := $(shell date +"%Y-%m-%dT%H:%M:%SZ")
17+
18+
LD_FLAGS = -w -s
19+
GO_FLAGS =
20+
DOCS_FLAGS =
21+
22+
APPS = contract-event-processor
23+
all: $(APPS)
24+
25+
install: $(APPS)
26+
@mkdir -p bin
27+
@cp $(PATHINSTBIN)/contract-event-processor ./bin/
28+
29+
deps:
30+
@go mod tidy
31+
@go mod vendor
32+
33+
SOURCE_FILES = $(shell find lib internal -type f -name "*.go")
34+
35+
36+
$(PATHINSTBIN)/%: $(SOURCE_FILES)
37+
@go build $(GO_FLAGS) -tags "$(TAGS)" -ldflags "$(LD_FLAGS) " -o $@ ./cmd/$*
38+
39+
$(APPS): %: $(PATHINSTBIN)/%
40+
41+
docker-tags:
42+
@echo "latest,$(VER_CUT),$(VER_MAJOR).$(VER_MINOR),$(VER_MAJOR)" > .tags
43+
44+
docker-rc-tags:
45+
@echo "latest,$(VER_CUT),$(VER_MAJOR)-$(VER_RC)" > .tags
46+
47+
docker-cgo-tags:
48+
@echo "latest-cgo,$(VER_CUT)-cgo,$(VER_MAJOR).$(VER_MINOR)-cgo,$(VER_MAJOR)-cgo" > .tags
49+
50+
docker: deps
51+
@docker build -f ./resources/docker/Dockerfile . -t dimozone/contract-event-processor:$(VER_CUT)
52+
@docker tag dimozone/contract-event-processor:$(VER_CUT) dimozone/contract-event-processor:latest
53+
54+
docker-cgo: deps
55+
@docker build -f ./resources/docker/Dockerfile.cgo . -t dimozone/contract-event-processor:$(VER_CUT)-cgo
56+
@docker tag dimozone/contract-event-processor:$(VER_CUT)-cgo dimozone/contract-event-processor:latest-cgo
57+
58+
fmt:
59+
@go list -f {{.Dir}} ./... | xargs -I{} gofmt -w -s {}
60+
@go mod tidy
61+
62+
lint:
63+
@go vet $(GO_FLAGS) ./...
64+
65+
test: $(APPS)
66+
@go test $(GO_FLAGS) -timeout 3m -race ./...
67+
@$(PATHINSTBIN)/contract-event-processor test ./config/test/...
68+
69+
clean:
70+
rm -rf $(PATHINSTBIN)
71+
rm -rf $(DEST_DIR)/dist
72+
rm -rf $(PATHINSTDOCKER)
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: contract-event-processor
3+
description: A Helm chart for Kubernetes
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: "1.16.0"
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 "contract-event-processor.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 "contract-event-processor.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "contract-event-processor.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 "contract-event-processor.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 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "contract-event-processor.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 "contract-event-processor.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 "contract-event-processor.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "contract-event-processor.labels" -}}
37+
helm.sh/chart: {{ include "contract-event-processor.chart" . }}
38+
{{ include "contract-event-processor.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 "contract-event-processor.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "contract-event-processor.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 "contract-event-processor.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "contract-event-processor.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{- if .Values.cronJob.enabled }}
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: {{ include "contract-event-processor.fullname" . }}-load-dd
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "contract-event-processor.labels" . | nindent 4 }}
9+
spec:
10+
schedule: {{ .Values.cronJob.schedule | quote}}
11+
concurrencyPolicy: "Forbid"
12+
jobTemplate:
13+
spec:
14+
template:
15+
metadata:
16+
annotations:
17+
{{- with .Values.podAnnotations }}
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "contract-event-processor.selectorLabels" . | nindent 12 }}
22+
spec:
23+
containers: []
24+
restartPolicy: OnFailure
25+
{{ end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "contract-event-processor.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "contract-event-processor.labels" . | nindent 4 }}
8+
spec:
9+
{{- if not .Values.autoscaling.enabled }}
10+
replicas: {{ .Values.replicaCount }}
11+
{{- end }}
12+
selector:
13+
matchLabels:
14+
{{- include "contract-event-processor.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
annotations:
18+
checksum/config: {{ include (print $.Template.BasePath "/envconfigmap.yaml") . | sha256sum }}
19+
{{- with .Values.podAnnotations }}
20+
{{- toYaml . | nindent 8 }}
21+
{{- end }}
22+
labels:
23+
{{- include "contract-event-processor.selectorLabels" . | nindent 8 }}
24+
spec:
25+
topologySpreadConstraints:
26+
- maxSkew: 1
27+
topologyKey: topology.kubernetes.io/zone
28+
whenUnsatisfiable: ScheduleAnyway
29+
labelSelector:
30+
matchLabels:
31+
{{- include "contract-event-processor.selectorLabels" . | nindent 12 }}
32+
{{- with .Values.imagePullSecrets }}
33+
imagePullSecrets:
34+
{{- toYaml . | nindent 8 }}
35+
{{- end }}
36+
serviceAccountName: {{ include "contract-event-processor.serviceAccountName" . }}
37+
securityContext:
38+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
39+
initContainers:
40+
- name: migrate
41+
securityContext:
42+
{{- toYaml .Values.securityContext | nindent 12 }}
43+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
44+
command: ['sh', '-c', "/contract-event-processor migrate"]
45+
envFrom:
46+
- configMapRef:
47+
name: {{ include "contract-event-processor.fullname" . }}-config
48+
- secretRef:
49+
name: {{ include "contract-event-processor.fullname" . }}-secret
50+
containers:
51+
- name: {{ .Chart.Name }}
52+
securityContext:
53+
{{- toYaml .Values.securityContext | nindent 12 }}
54+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
55+
imagePullPolicy: {{ .Values.image.pullPolicy }}
56+
envFrom:
57+
- configMapRef:
58+
name: {{ include "contract-event-processor.fullname" . }}-config
59+
- secretRef:
60+
name: {{ include "contract-event-processor.fullname" . }}-secret
61+
ports:
62+
{{ toYaml .Values.ports | indent 12 }}
63+
livenessProbe:
64+
httpGet:
65+
path: /
66+
port: mon-http
67+
readinessProbe:
68+
httpGet:
69+
path: /
70+
port: mon-http
71+
resources:
72+
{{- toYaml .Values.resources | nindent 12 }}
73+
{{- with .Values.nodeSelector }}
74+
nodeSelector:
75+
{{- toYaml . | nindent 8 }}
76+
{{- end }}
77+
{{- with .Values.affinity }}
78+
affinity:
79+
{{- toYaml . | nindent 8 }}
80+
{{- end }}
81+
{{- with .Values.tolerations }}
82+
tolerations:
83+
{{- toYaml . | nindent 8 }}
84+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "contract-event-processor.fullname" . }}-config
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "contract-event-processor.labels" . | nindent 4 }}
8+
data:
9+
{{- range $key, $val := .Values.env }}
10+
{{ $key }} : {{ $val | quote}}
11+
{{- end}}
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 "contract-event-processor.fullname" . }}
6+
labels:
7+
{{- include "contract-event-processor.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "contract-event-processor.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 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "contract-event-processor.fullname" . -}}
3+
{{- $svcPort := .Values.service.port -}}
4+
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
5+
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
6+
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
7+
{{- end }}
8+
{{- end }}
9+
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
10+
apiVersion: networking.k8s.io/v1
11+
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
12+
apiVersion: networking.k8s.io/v1beta1
13+
{{- else -}}
14+
apiVersion: extensions/v1beta1
15+
{{- end }}
16+
kind: Ingress
17+
metadata:
18+
name: {{ $fullName }}
19+
labels:
20+
{{- include "contract-event-processor.labels" . | nindent 4 }}
21+
{{- with .Values.ingress.annotations }}
22+
annotations:
23+
{{- toYaml . | nindent 4 }}
24+
{{- end }}
25+
spec:
26+
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
27+
ingressClassName: {{ .Values.ingress.className }}
28+
{{- end }}
29+
{{- if .Values.ingress.tls }}
30+
tls:
31+
{{- range .Values.ingress.tls }}
32+
- hosts:
33+
{{- range .hosts }}
34+
- {{ . | quote }}
35+
{{- end }}
36+
secretName: {{ .secretName }}
37+
{{- end }}
38+
{{- end }}
39+
rules:
40+
{{- range .Values.ingress.hosts }}
41+
- host: {{ .host | quote }}
42+
http:
43+
paths:
44+
{{- range .paths }}
45+
- path: {{ .path }}
46+
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
47+
pathType: {{ .pathType }}
48+
{{- end }}
49+
backend:
50+
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
51+
service:
52+
name: {{ $fullName }}
53+
port:
54+
number: 8080
55+
{{- else }}
56+
serviceName: {{ $fullName }}
57+
servicePort: {{ $svcPort }}
58+
{{- end }}
59+
{{- end }}
60+
{{- end }}
61+
{{- end }}

0 commit comments

Comments
 (0)