feat: Add polymorphic-app chart (#14)

main
Rakshit Menpara 2022-03-08 15:30:24 +05:30 committed by GitHub
parent 5358c5ec7f
commit 32a6c98856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 1124 additions and 7 deletions

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# 2 space indentation
[*.{yml,yaml}]
indent_style = space
indent_size = 2

2
.gitignore vendored
View File

@ -14,3 +14,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/
tmp-*
.DS_Store

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020 Improwised Technologies Pvt. Ltd.
Copyright (c) 2022 Improwised Technologies Pvt. Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -12,17 +12,17 @@ helm repo add improwised https://improwised.github.io/charts/
1. Package the chart, this will create `chartname-semver.tgz` file.
```bash
helm package <chart-directory-name>
```
```bash
helm package <chart-directory-name>
```
2. Checkout `gh-pages` branch of this repo and move `chart-name-semver.tgz` to `charts` directory.
3. Index added chart
```bash
helm repo index --url https://improwised.github.io/charts .
```
```bash
helm repo index --url https://improwised.github.io/charts .
```
4. Add appropriate commit message and push it

View File

@ -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/

View File

@ -0,0 +1,21 @@
apiVersion: v2
name: polymorphic-app
description: A Helm chart for deploying any custom applications, specifically polymorphic applications.
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 1.0.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.0.0

View File

@ -0,0 +1,14 @@
# Polymorphic Application Chart
This chart provides an abstraction layer over Kubernetes resources to easily represent wide ranges of different cloud-native applications. It is designed to be very flexible and can be used to various configurations. The primary aim for this chart is to make it easy to deploy and maintain cloud native applications on top of Kubernetes.
This chart is ideal for deploying applications that support polymorphic container pattern. A polymorphic container has multiple entrypoints and behaves differently depending on the entrypoint. This is particularly useful in creating event-driven monolithic applications, where some of the codebase (interfaces etc.) is shared, and the application needs to have multiple, independently scalable "workers" that process these events.
## Features
* Supports the following kind of deployments:
* API: Consists of a kubernetes `Deployment`, `Service`, and optionally `Ingress` and `HorizontalPodAutoscaler`. Typically used to deploy REST/gRPC API services.
* Worker: Consists of a kubernetes `Deployment` and optionally a `HorizontalPodAutoscaler`. Typically used to deploy long-running services that are not consumed through a TCP/HTTP server. e.g. Queue Workers and Stream Processors
* Jobs: Typically used to run one-off jobs, mostly helm hooks, to be run when installing/uninstalling/upgrading the helm deployment. Used to run database migrations by default. Backed by Kubernetes `Job`.
* CronJobs: Typically used to run scheduled jobs. Used for triggering events and batch processing jobs at a regular interval. Backed by Kubernetes `CronJob`.
* Designed to be used with [Flux Helm Controller](https://github.com/fluxcd/helm-controller), [Helmfile](https://github.com/roboll/helmfile), and any other mechanism that is backed by helm values-file override.

View File

@ -0,0 +1,174 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "polymorphic-app.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 "polymorphic-app.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 "polymorphic-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "polymorphic-app.labels" -}}
helm.sh/chart: {{ include "polymorphic-app.chart" . }}
{{ include "polymorphic-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "polymorphic-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "polymorphic-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "polymorphic-app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "polymorphic-app.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{/*
Files that would be mounted inside all of the components
{{- define "polymorphic-app.filesAsSecrets" -}}
{{- if .Values.certificate.enabled }}
{{- range $key, $value := .Values.certificate.files }}
{{ $key }}: {{ $value | b64enc }}
{{- end }}
{{- end }}
{{- end -}}
*/}}
{{/*
Root Env secrets name
{{- define "polymorphic-app.rootEnvSecrets" -}}
{{- $root := . -}}
{{- range $key, $value := .Values.envSecrets.name }}
envFrom:
- secretRef:
name: {{ $value }}
{{- end }}
{{- end -}}
*/}}
{{/*
WorkerTemplate Env secrets name
{{- define "polymorphic-app.workerTemplateEnvSecrets" -}}
{{- $root := . -}}
{{- range $key, $value := .Values.workerTemplate.envSecrets }}
envFrom:
- secretRef:
name: {{ $value }}
{{- end }}
{{- end -}}
*/}}
{{/*
Individual Workers Env secrets name
{{- define "polymorphic-app.workerEnvSecrets" -}}
{{- $root := .Values -}}
{{- range $root.workers.envSecrets }}
envFrom:
- secretRef:
name: {{ $.Values.workers.name }}
{{- end }}
{{- end -}}
*/}}
{{/*
Return the appropriate apiVersion for deployment.
*/}}
{{- define "deployment.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.Version -}}
{{- print "extensions/v1beta1" -}}
{{- else -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}
{{/*
Return the appropriate apiVersion for ingress.
*/}}
{{- define "ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.Version -}}
{{- print "extensions/v1beta1" -}}
{{- else if semverCompare "<1.19-0" .Capabilities.KubeVersion.Version -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "networking.k8s.io/v1" -}}
{{- end -}}
{{- end -}}
{{- define "ingress.backend" -}}
{{- $apiVersion := (include "ingress.apiVersion" .context) -}}
{{- if or (eq $apiVersion "extensions/v1beta1") (eq $apiVersion "networking.k8s.io/v1beta1") -}}
serviceName: {{ .serviceName }}
servicePort: {{ .servicePort }}
{{- else -}}
service:
name: {{ .serviceName }}
port:
{{- if typeIs "string" .servicePort }}
name: {{ .servicePort }}
{{- else if or (typeIs "int" .servicePort) (typeIs "float64" .servicePort) }}
number: {{ .servicePort | int }}
{{- end }}
{{- end -}}
{{- end -}}
{{- define "ingress.pathtype" -}}
{{- $apiVersion := (include "ingress.apiVersion" .) -}}
{{- if (eq $apiVersion "networking.k8s.io/v1") -}}
pathType: ImplementationSpecific
{{- end -}}
{{- end -}}
{{/*
Return the appropriate apiVersion for cronjob.
*/}}
{{- define "cronjob.apiVersion" -}}
{{- if semverCompare "<1.21-0" .Capabilities.KubeVersion.Version -}}
{{- print "batch/v1beta1" -}}
{{- else -}}
{{- print "batch/v1" -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,95 @@
{{- range .Values.cronJobs }}
---
apiVersion: {{ include "cronjob.apiVersion" $ }}
kind: CronJob
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.cronJobTemplate.name }}"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.cronJobTemplate.name }}
annotations:
linkerd.io/inject: disabled
{{- with .annotations | default $.Values.cronJobTemplate.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
schedule: {{ .schedule | quote }}
suspend: {{ .suspend | default false }}
jobTemplate:
spec:
template:
spec:
{{- if $.Values.cronJobTemplate.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 12 }}
{{- else if .imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 12 }}
{{- else }}
{{- if $.Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml $.Values.imagePullSecrets | indent 12 }}
{{- end }}
{{- end }}
restartPolicy: Never
containers:
- name: "{{ $.Release.Name }}-{{ .name | default $.Values.cronJobTemplate.name }}"
{{- if .image }}
image: "{{ .image.repository }}:{{ .image.tag }}"
{{- else }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
{{- end }}
env:
{{- if .env }}
{{ toYaml .env | indent 14 }}
{{- end }}
{{- if $.Values.env }}
{{ toYaml $.Values.env | indent 14 }}
{{- end }}
{{- if $.Values.cronJobTemplate.env }}
{{ toYaml $.Values.cronJobTemplate.env | indent 14 }}
{{- end }}
envFrom:
{{- if .envFrom }}
{{ toYaml .envFrom | indent 14 }}
{{- end }}
{{- if $.Values.envFrom }}
{{ toYaml $.Values.envFrom | indent 14 }}
{{- end }}
{{- if $.Values.cronJobTemplate.envFrom }}
{{ toYaml $.Values.cronJobTemplate.envFrom | indent 14 }}
{{- end }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- if .command }}
{{- with .command | default $.Values.cronJobTemplate.command }}
command:
{{ toYaml . | indent 14 }}
{{- end }}
{{- end }}
{{- if .args }}
{{- with .args | default $.Values.cronJobTemplate.args }}
args:
{{ toYaml . | indent 14 }}
{{- end }}
{{- end }}
volumeMounts:
{{- if .volumeMounts }}
{{ toYaml .volumeMounts | indent 12 }}
{{- end }}
{{- if $.Values.volumeMounts }}
{{ toYaml $.Values.volumeMounts | indent 12 }}
{{- end }}
{{- if $.Values.cronJobTemplate.volumeMounts }}
{{ toYaml $.Values.cronJobTemplate.volumeMounts | indent 12 }}
{{- end }}
volumes:
{{- if .volumes }}
{{ toYaml .volumes | indent 12 }}
{{- end }}
{{- if $.Values.volumes }}
{{ toYaml $.Values.volumes | indent 12 }}
{{- end }}
{{- if $.Values.cronJobTemplate.volumes }}
{{ toYaml $.Values.cronJobTemplate.volumes | indent 12 }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,95 @@
{{- range .Values.jobs }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.jobTemplate.name }}"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.jobTemplate.name }}
annotations:
linkerd.io/inject: disabled
{{- with .annotations | default $.Values.jobTemplate.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
template:
metadata:
labels:
{{- include "polymorphic-app.labels" $ | nindent 8 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.jobTemplate.name }}
spec:
{{- if $.Values.jobTemplate.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else if .imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else }}
{{- if $.Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml $.Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- end }}
restartPolicy: Never
containers:
- name: "{{ $.Release.Name }}-{{ .name | default $.Values.jobTemplate.name }}"
{{- if .image }}
image: "{{ .image.repository }}:{{ .image.tag }}"
{{- else }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
{{- end }}
env:
{{- if .env }}
{{ toYaml .env | indent 12 }}
{{- end }}
{{- if $.Values.env }}
{{ toYaml $.Values.env | indent 12 }}
{{- end }}
{{- if $.Values.jobTemplate.env }}
{{ toYaml $.Values.jobTemplate.env | indent 12 }}
{{- end }}
envFrom:
{{- if .envFrom }}
{{ toYaml .envFrom | indent 12 }}
{{- end }}
{{- if $.Values.envFrom }}
{{ toYaml $.Values.envFrom | indent 12 }}
{{- end }}
{{- if $.Values.jobTemplate.envFrom }}
{{ toYaml $.Values.jobTemplate.envFrom | indent 12 }}
{{- end }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- if .command }}
{{- with .command | default $.Values.jobTemplate.command }}
command:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
{{- if .args }}
{{- with .args | default $.Values.jobTemplate.args }}
args:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
volumeMounts:
{{- if .volumeMounts }}
{{ toYaml .volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.volumeMounts }}
{{ toYaml $.Values.volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.jobTemplate.volumeMounts }}
{{ toYaml $.Values.jobTemplate.volumeMounts | indent 10 }}
{{- end }}
volumes:
{{- if .volumes }}
{{ toYaml .volumes | indent 8 }}
{{- end }}
{{- if $.Values.volumes }}
{{ toYaml $.Values.volumes | indent 8 }}
{{- end }}
{{- if $.Values.jobTemplate.volumes }}
{{ toYaml $.Values.jobTemplate.volumes | indent 8 }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,247 @@
{{- range .Values.services }}
---
apiVersion: {{ include "deployment.apiVersion" $ }}
kind: Deployment
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc
{{- with .annotations | default $.Values.serviceTemplate.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 50%
maxSurge: 100%
replicas: {{ .minReplicaCount | default $.Values.serviceTemplate.minReplicaCount }}
selector:
matchLabels:
{{- include "polymorphic-app.selectorLabels" $ | nindent 6 }}
app.kubernetes.io/component: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
template:
metadata:
labels:
{{- include "polymorphic-app.labels" $ | nindent 8 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc
spec:
{{- if $.Values.serviceTemplate.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else if .imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else }}
{{- if $.Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml $.Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- end }}
terminationGracePeriodSeconds: {{ .terminationGracePeriodSeconds | default $.Values.serviceTemplate.terminationGracePeriodSeconds }}
containers:
- name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}"
{{- if .image }}
image: "{{ .image.repository }}:{{ .image.tag }}"
{{- else }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
{{- end }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
{{- if .env }}
{{ toYaml .env | indent 12 }}
{{- end }}
{{- if $.Values.env }}
{{ toYaml $.Values.env | indent 12 }}
{{- end }}
{{- if $.Values.serviceTemplate.env }}
{{ toYaml $.Values.serviceTemplate.env | indent 12 }}
{{- end }}
envFrom:
{{- if .envFrom }}
{{ toYaml .envFrom | indent 12 }}
{{- end }}
{{- if $.Values.envFrom }}
{{ toYaml $.Values.envFrom | indent 12 }}
{{- end }}
{{- if $.Values.serviceTemplate.envFrom }}
{{ toYaml $.Values.serviceTemplate.envFrom | indent 12 }}
{{- end }}
{{- if .command }}
{{- with .command | default $.Values.serviceTemplate.command }}
command:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
{{- if .args }}
{{- with .args | default $.Values.serviceTemplate.args }}
args:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
{{- with .ports | default $.Values.serviceTemplate.ports }}
ports:
{{ toYaml . | indent 12 }}
{{- end }}
{{- with .resources | default $.Values.serviceTemplate.resources }}
resources:
{{ toYaml . | indent 12 }}
{{- end }}
volumeMounts:
{{- if .volumeMounts }}
{{ toYaml .volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.volumeMounts }}
{{ toYaml $.Values.volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.serviceTemplate.volumeMounts }}
{{ toYaml $.Values.serviceTemplate.volumeMounts | indent 10 }}
{{- end }}
lifecycle:
preStop:
exec:
command: ["bash","-c","sleep 120"]
{{- if or ($.Values.serviceTemplate.healthcheck) (.healthcheck) }}
{{- if and (or (eq .healthcheck.type "httpGet") (eq $.Values.serviceTemplate.healthcheck.type "httpGet")) (or .healthcheck.path $.Values.serviceTemplate.healthcheck.path) }}
livenessProbe:
httpGet:
path: {{ .healthcheck.path | default $.Values.serviceTemplate.healthcheck.path }}
port: http
timeoutSeconds: 7
readinessProbe:
httpGet:
path: {{ .healthcheck.path | default $.Values.serviceTemplate.healthcheck.path }}
port: http
timeoutSeconds: 7
{{- end }}
{{- end }}
volumes:
{{- if .volumes }}
{{ toYaml .volumes | indent 8 }}
{{- end }}
{{- if $.Values.volumes }}
{{ toYaml $.Values.volumes | indent 8 }}
{{- end }}
{{- if $.Values.serviceTemplate.volumes }}
{{ toYaml $.Values.serviceTemplate.volumes | indent 8 }}
{{- end }}
{{- with .nodeSelector | default $.Values.serviceTemplate.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: kubernetes.io/hostname
labelSelector:
matchLabels:
{{- include "polymorphic-app.labels" $ | nindent 18 }}
app.kubernetes.io/component: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
{{- with .affinity | default $.Values.serviceTemplate.affinity }}
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .tolerations | default $.Values.serviceTemplate.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
{{- if .autoscaling | default $.Values.serviceTemplate.autoscaling }}
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
minReplicas: {{ .minReplicaCount | default $.Values.serviceTemplate.minReplicaCount }}
maxReplicas: {{ .maxReplicaCount | default $.Values.serviceTemplate.maxReplicaCount }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
# - type: Resource
# resource:
# name: memory
# target:
# type: AverageValue
# averageValue: 100Mi
{{- end }}
{{- if and .service (.service.enabled | default $.Values.serviceTemplate.service.enabled) }}
---
apiVersion: v1
kind: Service
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc
{{- with (.service.annotations | default $.Values.serviceTemplate.service.annotations) }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .service.type | default $.Values.serviceTemplate.service.type }}
ports:
{{- with (.service.ports | default $.Values.serviceTemplate.service.ports) }}
{{ toYaml . | nindent 4 }}
{{- end }}
selector:
{{- include "polymorphic-app.selectorLabels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc
{{- end }}
{{- if and .ingress (.ingress.enabled | default $.Values.serviceTemplate.ingress.enabled) }}
{{- $fullName := printf "%s-%s-svc" $.Release.Name (.name | default $.Values.serviceTemplate.name) -}}
---
apiVersion: {{ include "ingress.apiVersion" $ }}
kind: Ingress
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.serviceTemplate.name }}-svc"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
{{- with (.ingress.annotations | default $.Values.serviceTemplate.ingress.annotations) }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if gt (len (.ingress.tls | default $.Values.serviceTemplate.ingress.tls)) 0 }}
tls:
{{- range (.ingress.tls | default $.Values.serviceTemplate.ingress.tls) }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range (.ingress.hosts | default $.Values.serviceTemplate.ingress.hosts) }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend: {{- include "ingress.backend" (dict "serviceName" $fullName "servicePort" .servicePort "context" $) | nindent 14 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,189 @@
{{- range .Values.workers }}
---
apiVersion: {{ include "deployment.apiVersion" $ }}
kind: Deployment
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 50%
maxSurge: 100%
replicas: {{ .minReplicaCount | default $.Values.workerTemplate.minReplicaCount }}
selector:
matchLabels:
{{- include "polymorphic-app.selectorLabels" $ | nindent 6 }}
app.kubernetes.io/component: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
template:
metadata:
labels:
{{- include "polymorphic-app.labels" $ | nindent 8 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}
spec:
{{- if $.Values.workerTemplate.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else if .imagePullSecrets }}
imagePullSecrets:
{{ toYaml .imagePullSecrets | indent 8 }}
{{- else }}
{{- if $.Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml $.Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- end }}
terminationGracePeriodSeconds: {{ .terminationGracePeriodSeconds | default $.Values.workerTemplate.terminationGracePeriodSeconds }}
containers:
- name: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
{{- if .image }}
image: "{{ .image.repository }}:{{ .image.tag }}"
{{- else }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
{{- end }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
{{- if .env }}
{{ toYaml .env | indent 12 }}
{{- end }}
{{- if $.Values.env }}
{{ toYaml $.Values.env | indent 12 }}
{{- end }}
{{- if $.Values.workerTemplate.env }}
{{ toYaml $.Values.workerTemplate.env | indent 12 }}
{{- end }}
envFrom:
{{- if .envFrom }}
{{ toYaml .envFrom | indent 12 }}
{{- end }}
{{- if $.Values.envFrom }}
{{ toYaml $.Values.envFrom | indent 12 }}
{{- end }}
{{- if $.Values.workerTemplate.envFrom }}
{{ toYaml $.Values.workerTemplate.envFrom | indent 12 }}
{{- end }}
{{- if .command }}
{{- with .command | default $.Values.workerTemplate.command }}
command:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
{{- if .args }}
{{- with .args | default $.Values.workerTemplate.args }}
args:
{{ toYaml . | indent 12 }}
{{- end }}
{{- end }}
{{- with .resources | default $.Values.workerTemplate.resources }}
resources:
{{ toYaml . | indent 12 }}
{{- end }}
volumeMounts:
{{- if .volumeMounts }}
{{ toYaml .volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.volumeMounts }}
{{ toYaml $.Values.volumeMounts | indent 10 }}
{{- end }}
{{- if $.Values.workerTemplate.volumeMounts }}
{{ toYaml $.Values.workerTemplate.volumeMounts | indent 10 }}
{{- end }}
{{- if or ($.Values.workerTemplate.probe) (.probe) }}
livenessProbe:
exec:
{{- if $.Values.workerTemplate.probe }}
{{- with $.Values.workerTemplate.probe.aliveCommand }}
command:
{{ toYaml . | indent 14 }}
{{- end }}
{{- else }}
{{- with .probe.aliveCommand }}
command:
{{ toYaml . | indent 14 }}
{{- end }}
{{- end }}
initialDelaySeconds: 10
periodSeconds: 20
{{- if $.Values.workerTemplate.probe }}
timeoutSeconds: {{ $.Values.workerTemplate.probe.timeoutSeconds }}
{{- else }}
timeoutSeconds: {{ .probe.timeoutSeconds }}
{{- end }}
successThreshold: 1
readinessProbe:
exec:
{{- if $.Values.workerTemplate.probe }}
{{- with $.Values.workerTemplate.probe.aliveCommand }}
command:
{{ toYaml . | indent 14 }}
{{- end }}
{{- else }}
{{- with .probe.aliveCommand }}
command:
{{ toYaml . | indent 14 }}
{{- end }}
{{- end }}
initialDelaySeconds: 10
periodSeconds: 20
{{- if $.Values.workerTemplate.probe }}
timeoutSeconds: {{ $.Values.workerTemplate.probe.timeoutSeconds }}
{{- else }}
timeoutSeconds: {{ .probe.timeoutSeconds }}
{{- end }}
successThreshold: 1
{{- end }}
volumes:
{{- if .volumes }}
{{ toYaml .volumes | indent 8 }}
{{- end }}
{{- if $.Values.volumes }}
{{ toYaml $.Values.volumes | indent 8 }}
{{- end }}
{{- if $.Values.workerTemplate.volumes }}
{{ toYaml $.Values.workerTemplate.volumes | indent 8 }}
{{- end }}
{{- with .nodeSelector | default $.Values.workerTemplate.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .affinity | default $.Values.workerTemplate.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .tolerations | default $.Values.workerTemplate.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
{{- if .autoscaling | default $.Values.workerTemplate.autoscaling }}
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
labels:
{{- include "polymorphic-app.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}
spec:
scaleTargetRef:
apiVersion: apps/v1beta2
kind: Deployment
name: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
minReplicas: {{ .minReplicaCount | default $.Values.workerTemplate.minReplicaCount }}
maxReplicas: {{ .maxReplicaCount | default $.Values.workerTemplate.maxReplicaCount }}
metrics:
- type: Object
object:
{{- if or (.metricName) ($.Values.workerTemplate.metricName) }}
metricName: {{ .metricName | default $.Values.workerTemplate.metricName }}
{{- end }}
target:
apiVersion: apps/v1
kind: Deployment
name: "{{ $.Release.Name }}-{{ .name | default $.Values.workerTemplate.name }}"
targetValue: 100
{{- end }}
{{- end }}

View File

@ -0,0 +1,245 @@
# Default values for polymorphic-app.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
nameOverride: ""
fullnameOverride: ""
image:
repository:
tag:
pullPolicy: IfNotPresent
imagePullSecrets: []
volumeMounts: []
volumes: []
env: []
envFrom: []
# service template
serviceTemplate:
name: svc
image:
healthcheck:
enabled: false
type: httpGet
path: /healthz
autoscaling: false
minReplicaCount: 1
maxReplicaCount: 1
env: []
envFrom: []
ports:
- name: http
containerPort: 80
protocol: TCP
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
annotations: {}
nodeSelector: {}
tolerations: []
affinity: {}
volumeMounts: []
volumes: []
service:
enabled: true
type: ClusterIP
ports:
- name: http
port: 80
targetPort: http
protocol: TCP
annotations: {}
ingress:
enabled: false
annotations: {}
hosts:
- host: app.example.com
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
services: []
# worker template
workerTemplate:
name: worker
image:
autoscaling: false
minReplicaCount: 1
maxReplicaCount: 1
terminationGracePeriodSeconds: 30
secret:
enabled: false
env: []
envFrom: []
volumeMounts: []
volumes: []
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
workers:
#######################################
# pulsar-billing-service
#######################################
# - name: pulsar-billing-service
# image:
# repository:
# tag:
# # args: ["-template", "/var/www/.env.staging:/var/www/.env", "-poll", "php", "artisan", "queue:work"]
# env: []
# envFrom: []
# # - name: zxcv
# # value: uiop
# # certificates & keys will be mounted as a volume from secret
# autoscaling: false
# minReplicaCount: 1
# maxReplicaCount: 0
# # envSecrets:
# # name: uiop
# # name: zxcv
# # name: hjkl
# volumeMounts: []
# # - name: vol1
# # mountPath: /etc/vol1
# # - name: vol2
# # mountPath: /etc/vol2
# # - name: vol3
# # mountPath: /etc/vol3
# volumes: []
# # - name: vol1
# # secret:
# # secretName: secret1
# # - name: vol2
# # secret:
# # secretName: secret2
# # - name: vol3
# # secret:
# # secretName: secret3
# probe: []
# aliveCommand: ["/app/worker", "alive"]
# timeoutSeconds: 10
# resources:
# # # We usually recommend not to specify default resources and to leave this as a conscious
# # # choice for the user. This also increases chances charts run on environments with little
# # # resources, such as Minikube. If you do want to specify resources, uncomment the following
# # # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
# # nodeSelector: {}
# # tolerations: []
# # affinity: {}
cronJobTemplate:
name: cronjob
image:
tag:
repository:
suspend: true
env: []
envFrom: []
volumeMounts: []
annotations: {}
volumes: []
cronJobs:
# - name: update-status
# image:
# repository:
# tag:
# suspend: true
# env: []
# envFrom: []
# annotations: {}
# schedule: "0 5 * * *"
# # The `template` below places `.env.staging` to `.env`.
# args: ["-template", "/var/www/.env.staging:/var/www/.env", "php", "artisan", "listings:update-statuses"]
# volumeMounts: []
# # - name: vol1
# # mountPath: /etc/vol1
# # - name: vol2
# # mountPath: /etc/vol2
# # - name: vol3
# # mountPath: /etc/vol3
# volumes: []
# # - name: vol1
# # secret:
# # secretName: secret1
# # - name: vol2
# # secret:
# # secretName: secret2
# # - name: vol3
# # secret:
# # secretName: secret3
jobTemplate:
name: job
image:
repository:
tag:
env: []
envFrom: []
command:
annotations: []
volumeMounts: []
volumes: []
jobs:
# - name: migrate
# env:
# - name: TZ
# value: Asia/Kolkata
# # To keep the container running
# command: [ "/bin/sh", "-c", "--" ]
# args: [ "while true; do sleep 30; done;" ]
# command: ["migrate"]
# args: ["migrate", "-database", "${MIGRATION_URL}", "-path", "/app/db_migrations", "up"]