Skip to content

Commit

Permalink
feat: tsuru-api
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrokiefer committed Apr 28, 2021
1 parent efcbc02 commit 756e16f
Show file tree
Hide file tree
Showing 11 changed files with 719 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/tsuru-api/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/tsuru-api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: tsuru-api
description: A Helm chart to install Tsuru API Server

# 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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.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. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.9.2"
62 changes: 62 additions & 0 deletions charts/tsuru-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "tsuru-api.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 "tsuru-api.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 "tsuru-api.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "tsuru-api.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "tsuru-api.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
157 changes: 157 additions & 0 deletions charts/tsuru-api/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "tsuru-api.fullname" . }}-config
labels:
{{- include "tsuru-api.labels" . | nindent 4 }}
data:
{{- with .Values.indexPageTemplate }}
index.tpl: |-
{{ . | indent 4 }}
{{- end }}
tsuru.conf: |-
listen: "{{ .Values.tsuruConfig.listen | default "0.0.0.0:8080" }}"
host: "{{ .Values.tsuruConfig.host }}"
{{- if .Values.tsuruConfig.useTLS }}
use-tls: true
tls:
cert-file: {{ .Values.tsuruConfig.TLS.certFilename }}
key-file: {{ .Values.tsuruConfig.TLS.certKeyFile }}
listen: {{ .Values.tsuruConfig.TLS.listen }}
{{- if .Values.tsuruConfig.TLS.autoreloadInterval }}
auto-reload:
interval: {{ .Values.tsuruConfig.TLS.autoreloadInterval }}
{{- end }}
{{- if .Values.tsuruConfig.TLS.validateCertificate }}
validate-certificate: {{ .Values.tsuruConfig.TLS.validateCertificate }}
{{- end }}
{{- end }}

disable-index-page: {{ .Values.tsuruConfig.disableIndexPage | default true }}
{{- if .Values.tsuruConfig.indexPageTemplate }}
index-page-template: /etc/tsuru/index.tpl
{{- end }}

database:
url: {{ .Values.tsuruConfig.database.mongodbURL | default "localhost:27017" }}
name: {{ .Values.tsuruConfig.database.databaseName | default "tsuru" }}

{{ if .Values.tsuruConfig.SMTP }}
smtp:
server: {{ .Values.tsuruConfig.SMTP.server }}
user: {{ .Values.tsuruConfig.SMTP.username }}
{{- with .Values.tsuruConfig.SMTP.password }}
password: {{.}}
{{- end }}
{{- end }}

auth:
scheme: {{ .Values.tsuruConfig.auth.scheme }}
user-registration: {{ .Values.tsuruConfig.auth.userRegistration }}
{{- with .Values.tsuruConfig.auth.maxSimultaneousSessions }}
max-simultaneous-sessions: {{.}}
{{- end }}
{{- if (eq .Values.tsuruConfig.auth.scheme "native") }}
token-expire-days: {{ .Values.tsuruConfig.auth.native.tokenExpire }}
hash-cost: {{ .Values.tsuruConfig.auth.native.hashCost }}
{{- else if (eq .Values.tsuruConfig.auth.scheme "oauth") }}
oauth:
client-id: {{ .Values.tsuruConfig.auth.oauth.clientID }}
client-secret: {{ .Values.tsuruConfig.auth.oauth.clientSecret }}
scope: {{ .Values.tsuruConfig.auth.oauth.scope }}
auth-url: {{ .Values.tsuruConfig.auth.oauth.authURL }}
token-url: {{ .Values.tsuruConfig.auth.oauth.tokenURL }}
info-url: {{ .Values.tsuruConfig.auth.oauth.infoURL }}
collection: {{ .Values.tsuruConfig.auth.oauth.collection }}
callback-port: {{ .Values.tsuruConfig.auth.oauth.callbackPort }}
{{- end }}

queue:
mongo-url: {{ .Values.tsuruConfig.queue.mongodbURL | default "localhost:27017" }}
mongo-database: {{ .Values.tsuruConfig.queue.databaseName | default "tsuru" }}

admin-team: {{ .Values.tsuruConfig.adminTeam }}

{{- if .Values.tsuruConfig.quota }}
quota:
apps-per-user: {{ .Values.tsuruConfig.quota.appsPerUser }}
units-per-app: {{ .Values.tsuruConfig.quota.unitsPerApp }}
{{- end }}

# - Router configuration
# http://docs.tsuru.io/en/stable/reference/config.html#config-routers
routers:
{{- toYaml .Values.tsuruConfig.routers | nindent 6}}

# - Events configuration
events:
suppress-sensitive-envs: {{ .Values.tsuruConfig.events.suppressSensitiveEnvs | default "true" }}

# - Provisioner configuration
# http://docs.tsuru.io/en/stable/reference/config.html#provisioner
provisioner: {{ .Values.tsuruConfig.provisioner }}
{{- if .Values.tsuruConfig.docker }}
docker:
{{- toYaml .Values.tsuruConfig.docker | nindent 6}}
{{- end }}
kubernetes:
{{- if .Values.tsuruConfig.kubernetes.deploySidecarImage }}
deploy-sidecar-image: {{ .Values.tsuruConfig.kubernetes.deploySidecarImage }}
{{- end }}
{{- if .Values.tsuruConfig.kubernetes.deployInspectImage }}
deploy-inspect-image: {{ .Values.tsuruConfig.kubernetes.deployInspectImage }}
{{- end }}
{{- if .Values.tsuruConfig.kubernetes.usePoolNamespaces }}
use-pool-namespaces: {{ .Values.tsuruConfig.kubernetes.usePoolNamespaces }}
{{- end }}
{{- if .Values.tsuruConfig.kubernetes.deploymentProgressTimeout }}
deployment-progress-timeout: {{ .Values.tsuruConfig.kubernetes.deploymentProgressTimeout }}
{{- end }}

{{ if .Values.tsuruConfig.volumePlans }}
# - Volume Plans
# https://docs.tsuru.io/stable/managing/volumes.html#volume-plans
volume-plans:
{{- .Values.tsuruConfig.volumePlans | toYaml | nindent 6 }}
{{- end }}

{{- if .Values.tsuruConfig.iaas }}
# - Iaas configuration
# http://docs.tsuru.io/en/stable/reference/config.html#iaas-configuration
iaas:
default: {{ .Values.tsuruConfig.iaas.iaas_default | default "ec2" }}
{{- if .Values.tsuruConfig.iaas.cloudstack }}
{{ .Values.tsuruConfig.iaas.cloudstack | indent 6 }}
{{- end }}
{{- if .Values.tsuruConfig.iaas.ec2 }}
{{ .Values.tsuruConfig.iaas.ec2 | indent 6 }}
{{- end }}
{{- if .Values.tsuruConfig.iaas.customIaaS }}
custom:
{{ .Values.tsuruConfig.iaas.customIaaS | indent 8 }}
{{- end }}
node-protocol: {{ .Values.tsuruConfig.iaas.nodeProtocol | default "http" }}
node-port: {{ .Values.tsuruConfig.iaas.nodePort | default "2375" }}
{{- end }}

# - Debug configuration
# http://docs.tsuru.io/en/stable/reference/config.html#log-level
debug: {{ .Values.tsuruConfig.debug | default "false" }}
log:
{{- if .Values.tsuruConfig.log.file }}
file: {{ .Values.tsuruConfig.log.file }}
{{- end }}
disable-syslog: {{ .Values.tsuruConfig.log.disableSyslog | default "false" }}
syslog-tag: {{ .Values.tsuruConfig.log.syslogTag | default "tsurud" }}
use-stderr: {{ .Values.tsuruConfig.log.useStdErr | default "false" }}
app-log-service: "memory"
app-log-memory-buffer-bytes: {{ .Values.tsuruConfig.log.appLogBufferBytes | default "1048576"}}


{{ if .Values.tsuruConfig.eventThrottling }}
# - Event throttling configuration
# https://docs.tsuru.io/master/reference/config.html#event-throttling-configuration
event:
throttling:
{{ .Values.tsuruConfig.eventThrottling | toYaml | indent 6 }}
{{- end }}
119 changes: 119 additions & 0 deletions charts/tsuru-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "tsuru-api.fullname" . }}
labels:
{{- include "tsuru-api.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- if .Values.strategy }}
strategy:
{{- toYaml .Values.strategy | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "tsuru-api.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "tsuru-api.selectorLabels" . | nindent 8 }}
spec:
terminationGracePeriodSeconds: 600
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "tsuru-api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.targetHTTPPort }}
protocol: TCP
- name: https
containerPort: {{ .Values.service.targetHTTPSPort }}
protocol: TCP
livenessProbe:
httpGet:
path: /healthcheck
port: {{ .Values.service.targetHTTPPort }}
initialDelaySeconds: 90
timeoutSeconds: 20
failureThreshold: 10
readinessProbe:
httpGet:
path: /healthcheck
port: {{ .Values.service.targetHTTPPort }}
timeoutSeconds: 10
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
{{- range $secret := .Values.secretKeys }}
- name: {{ $secret | upper }}
valueFrom:
secretKeyRef:
name: {{ $.Values.secretName }}
key: {{ $secret }}
{{- end }}
{{- if .Values.tracing.enabled }}
- name: JAEGER_AGENT_HOST
value: {{ .Values.tracing.agentHost }}
- name: JAEGER_SAMPLER_TYPE
value: {{ .Values.tracing.sampler.type }}
{{- if .Values.tracing.sampler.param }}
- name: JAEGER_SAMPLER_PARAM
value: {{ .Values.tracing.sampler.param | quote }}
{{- end }}
{{- end }}
volumeMounts:
- name: tsuru-api-config
mountPath: /etc/tsuru
{{- if .Values.tlsSecretName }}
- name: tls
mountPath: /mnt/tls
readOnly: true
{{- end }}
{{- if .Values.hostCertBundleFile }}
- name: host-cert-bundle
mountPath: {{ .Values.hostCertBundleFile }}
{{- end }}
restartPolicy: Always
volumes:
- name: tsuru-api-config
configMap:
name: {{ include "tsuru-api.fullname" . }}-config
{{- if .Values.tlsSecretName }}
- name: tls
secret:
secretName: {{ .Values.tlsSecretName }}
{{- end }}
{{- if .Values.hostCertBundleFile }}
- name: host-cert-bundle
hostPath:
path: {{ .Values.hostCertBundleFile }}
type: File
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading

0 comments on commit 756e16f

Please sign in to comment.