# _helpers.tpl
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "schema-registry-ui.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 "schema-registry-ui.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 "schema-registry-ui.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
 # deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "schema-registry-ui.fullname" . }}
  labels:
    app: {{ template "schema-registry-ui.name" . }}
    chart: {{ template "schema-registry-ui.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "schema-registry-ui.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "schema-registry-ui.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
          - name: SCHEMAREGISTRY_URL
            value: "{{ .Values.schemaRegistry.url }}:{{ .Values.schemaRegistry.port }}"
          - name: PROXY
            value: "{{ .Values.schemaRegistry.proxy }}"
          - name: ALLOW_GLOBAL
            value: "{{ .Values.schemaRegistry.allowGlobal }}"
          - name: ALLOW_TRANSITIVE
            value: "{{ .Values.schemaRegistry.allowTransitive }}"
          - name: ALLOW_DELETION
            value: "{{ .Values.schemaRegistry.allowDeletion }}"
          - name: READONLY_MODE
            value: "{{ .Values.schemaRegistry.readOnlyMode }}"
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
 # ingress.yaml
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "schema-registry-ui.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    app: {{ template "schema-registry-ui.name" . }}
    chart: {{ template "schema-registry-ui.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ . }}
      http:
        paths:
          - path: {{ $ingressPath }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: http
  {{- end }}
{{- end }}
 # service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ template "schema-registry-ui.fullname" . }}
  labels:
    app: {{ template "schema-registry-ui.name" . }}
    chart: {{ template "schema-registry-ui.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- range $key, $value := . }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
  {{- end }}
spec:
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
    {{- range $cidr := .Values.service.loadBalancerSourceRanges }}
    - {{ $cidr }}
    {{- end }}
  {{- end }}
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: {{ template "schema-registry-ui.name" . }}
    release: {{ .Release.Name }}

# Default values for schema-registry-ui.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: landoop/schema-registry-ui
  tag: 0.9.5
  pullPolicy: IfNotPresent

service:
  type: LoadBalancer
  port: 80
  annotations: {}
  ## Limit load balancer source ips to list of CIDRs (where available)
  # loadBalancerSourceRanges: []

schemaRegistry:
  url: "http://localhost"
  port: 8081
  proxy: false
  allowGlobal: false
  allowTransitive: false
  allowDeletion: false
  readOnlyMode: false

ingress:
  enabled: false
  annotations: {}
  path: /
  hosts:
    - schema-registry-ui.local
  tls: []

resources: {}

nodeSelector: {}

tolerations: []

affinity: {}
