diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..eaa3705 --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,15 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{ define "testapp.name" }}{{ default "testapp" .Values.nameOverride | trunc 63 }}{{ 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). +*/}} +{{ define "testapp.fullname" }} +{{- $name := default "testapp" .Values.nameOverride -}} +{{ printf "%s-%s" .Release.Name $name | trunc 63 -}} +{{ end }} diff --git a/chart/templates/deploymant-db.yaml b/chart/templates/deploymant-db.yaml index dd3b4b3..df8e023 100644 --- a/chart/templates/deploymant-db.yaml +++ b/chart/templates/deploymant-db.yaml @@ -10,6 +10,11 @@ metadata: component: db spec: replicas: {{ .Values.db.replicas }} + selector: + matchLabels: + app: {{ template "testapp.name" . }}-db + release: "{{ .Release.Name }}" + component: db template: metadata: annotations: diff --git a/chart/templates/deploymant-srv.yaml b/chart/templates/deploymant-srv.yaml index fd44fc2..dafbc80 100644 --- a/chart/templates/deploymant-srv.yaml +++ b/chart/templates/deploymant-srv.yaml @@ -10,6 +10,11 @@ metadata: component: srv spec: replicas: {{ .Values.srv.replicas }} + selector: + matchLabels: + app: {{ template "testapp.name" . }}-srv + release: "{{ .Release.Name }}" + component: srv template: metadata: annotations: @@ -42,7 +47,7 @@ spec: protocol: TCP env: - name: DB_HOST - value: {{ template "testapp.fullname" . }}-db.{{ Release.Namespace }}.svc + value: {{ template "testapp.fullname" . }}-db.{{ .Release.Namespace }}.svc {{- range $key, $value := .Values.srv.env }} - name: {{ $key }} value: {{ $value | quote }} diff --git a/chart/templates/service-db.yaml b/chart/templates/service-db.yaml index 1b6188b..6491a43 100644 --- a/chart/templates/service-db.yaml +++ b/chart/templates/service-db.yaml @@ -1,25 +1,25 @@ apiVersion: v1 kind: Service metadata: - name: {{ template "drone.fullname" . }}-db + name: {{ template "testapp.fullname" . }}-db annotations: - {{- range $key, $value := .Values.Db.service.annotations }} + {{- range $key, $value := .Values.service.db.annotations }} {{ $key }}: {{ $value | quote }} {{- end }} labels: - app: {{ template "drone.name" . }}-db + app: {{ template "testapp.name" . }}-db chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" spec: - type: {{ .Values.Db.service.type }} + type: {{ .Values.service.db.type }} ports: - name: http - port: {{ .Values.Db.service.httpPort }} + port: {{ .Values.service.db.httpPort }} targetPort: 8080 -{{- if hasKey .Values.Db.service "nodePort" }} - nodePort: {{ .Values.Db.service.nodePort }} +{{- if hasKey .Values.service.db "nodePort" }} + nodePort: {{ .Values.service.db.nodePort }} {{- end }} selector: - app: {{ template "drone.name" . }}-db + app: {{ template "testapp.name" . }}-db release: {{ .Release.Name | quote }} diff --git a/chart/templates/service-srv.yaml b/chart/templates/service-srv.yaml index 57e6542..bfa4b68 100644 --- a/chart/templates/service-srv.yaml +++ b/chart/templates/service-srv.yaml @@ -11,7 +11,7 @@ metadata: host: "^{{ .Values.srv.host }}.*$" host_regex: true prefix: / - service: {{ template "testapp.fullname" . }}-srv.{{ Release.Namespace }}.svc:8080 + service: {{ template "testapp.fullname" . }}-srv.{{ .Release.Namespace }}.svc:8080 {{- range $key, $value := .Values.service.srv.annotations }} {{ $key }}: {{ $value | quote }} {{- end }} diff --git a/db.go b/db.go index fef60ed..5faf2d2 100644 --- a/db.go +++ b/db.go @@ -11,6 +11,9 @@ import ( var version string func main() { + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL) h, err := os.Hostname() diff --git a/srv.go b/srv.go index eb83467..1260c67 100644 --- a/srv.go +++ b/srv.go @@ -15,6 +15,9 @@ import ( var version string func main() { + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL) h, err := os.Hostname()