Skip to content

Commit

Permalink
Add onyxia (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Donatien26 authored May 12, 2020
1 parent f36dfd1 commit 4da6e50
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.tgz
index.yaml
index.yaml
*/my-values.yml
23 changes: 23 additions & 0 deletions charts/onyxia/.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/
21 changes: 21 additions & 0 deletions charts/onyxia/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: onyxia
description: Onyxia is your datalab's hub.
icon: https://onyxia.lab.sspcloud.fr/onyxia.svg
# 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
7 changes: 7 additions & 0 deletions charts/onyxia/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

1. Enjoy Onyxia :)
{{- if .Values.ingress.enabled }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.hostname }}
{{ else }}
The application is running but not exposed by ingress
{{ end }}
124 changes: 124 additions & 0 deletions charts/onyxia/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "onyxia.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "onyxia.ui.name" -}}
{{- printf "%s-%s" (include "onyxia.name" .) .Values.ui.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}


{{- define "onyxia.api.name" -}}
{{- printf "%s-%s" (include "onyxia.name" .) .Values.api.name | 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 "onyxia.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 -}}

{{- define "onyxia.ui.fullname" -}}
{{- printf "%s-%s" (include "onyxia.fullname" .) .Values.ui.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}


{{- define "onyxia.api.fullname" -}}
{{- printf "%s-%s" (include "onyxia.fullname" .) .Values.api.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "onyxia.chart" -}}
{{- printf "onyxia" -}}
{{- end -}}

{{- define "onyxia.api.chart" -}}
{{- printf "onyxia-api" -}}
{{- end -}}

{{- define "onyxia.ui.chart" -}}
{{- printf "onyxia-ui" -}}
{{- end -}}


{{/*Common labels*/}}

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

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

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

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


{{- define "onyxia.api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "onyxia.api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "onyxia.ui.selectorLabels" -}}
app.kubernetes.io/name: {{ include "onyxia.ui.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*Create the name of the service account to use*/}}

{{- define "onyxia.api.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "onyxia.api.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{- define "onyxia.ui.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "onyxia.ui.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
16 changes: 16 additions & 0 deletions charts/onyxia/templates/cluster-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: {{ include "onyxia.fullname" . }}
labels:
{{- include "onyxia.api.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: {{ include "onyxia.api.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
64 changes: 64 additions & 0 deletions charts/onyxia/templates/deployment-onyxia-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "onyxia.api.fullname" . }}
labels:
{{- include "onyxia.api.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.api.replicaCount }}
selector:
matchLabels:
{{- include "onyxia.api.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "onyxia.api.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.api.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "onyxia.api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.api.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.api.securityContext | nindent 12 }}
image: "{{ .Values.api.image.name }}:{{ .Values.api.image.version }}"
env:
{{- range $key, $val := .Values.api.env }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end}}
{{- if .Values.api.regions }}
- name: regions
value: {{ .Values.api.regions | toJson | quote }}
{{- end}}
imagePullPolicy: {{ .Values.api.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /public/healthcheck
port: http
readinessProbe:
httpGet:
path: /public/healthcheck
port: http
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
{{- with .Values.api.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
69 changes: 69 additions & 0 deletions charts/onyxia/templates/deployment-onyxia-ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "onyxia.ui.fullname" . }}
labels:
{{- include "onyxia.ui.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.ui.replicaCount }}
selector:
matchLabels:
{{- include "onyxia.ui.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "onyxia.ui.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "onyxia.ui.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.ui.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.ui.securityContext | nindent 12 }}
image: "{{ .Values.ui.image.name }}:{{ .Values.ui.image.version }}"
imagePullPolicy: {{ .Values.ui.image.pullPolicy }}
env:
{{- if .Values.ingress.enabled }}
{{- if .Values.ingress.tls }}
- name: BASE_API_URL
value: {{ printf "https://%s/%s" .Values.ingress.hostname "api" | quote }}
{{- else }}
- name: BASE_API_URL
value: {{ printf "http://%s/%s" .Values.ingress.hostname "api" | quote }}
{{- end}}
{{- end}}
{{- range $key, $val := .Values.ui.env }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end}}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.ui.resources | nindent 12 }}
{{- with .Values.ui.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.ui.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.ui.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
41 changes: 41 additions & 0 deletions charts/onyxia/templates/ingress-onyxia.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullNameApi := include "onyxia.api.fullname" . -}}
{{- $fullNameUi := include "onyxia.ui.fullname" . -}}
{{- $fullName := include "onyxia.fullname" . -}}
{{- $svcPortApi := .Values.api.service.port -}}
{{- $svcPortUi := .Values.api.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "onyxia.labels" . | nindent 4 }}
annotations:
{{- with .Values.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
{{- if .Values.ingress.tls }}
tls:
- hosts:
- {{ .Values.ingress.hostname | quote }}
{{- end }}
rules:
- host: {{ .Values.ingress.hostname | quote }}
http:
paths:
- path: /api/(.*)
backend:
serviceName: {{ $fullNameApi }}
servicePort: {{ $svcPortApi }}
- path: /(.*)
backend:
serviceName: {{$fullNameUi}}
servicePort: {{$svcPortUi}}
{{- end }}
15 changes: 15 additions & 0 deletions charts/onyxia/templates/service-onyxia-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "onyxia.api.fullname" . }}
labels:
{{- include "onyxia.api.labels" . | nindent 4 }}
spec:
type: {{ .Values.api.service.type }}
ports:
- port: {{ .Values.api.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "onyxia.api.selectorLabels" . | nindent 4 }}
Loading

0 comments on commit 4da6e50

Please sign in to comment.