Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a nginx as an option #117

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charts/operator-wandb/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ dependencies:
version: "*.*.*"
repository: file://charts/flat-run-fields-updater
condition: flat-run-fields-updater.install
- name: nginx
version: "*.*.*"
repository: file://charts/nginx
condition: nginx.install
23 changes: 23 additions & 0 deletions charts/operator-wandb/charts/nginx/.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/
15 changes: 15 additions & 0 deletions charts/operator-wandb/charts/nginx/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: nginx
type: application
description: A Helm chart for Kubernetes

version: 0.1.0
appVersion: "0.33.0"

home: https://wandb.ai
icon: https://wandb.ai/logo.svg

maintainers:
- name: wandb
email: [email protected]
url: https://wandb.com
1 change: 1 addition & 0 deletions charts/operator-wandb/charts/nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# nginx
129 changes: 129 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Expand the name of the chart.
*/}}
{{- define "nginx.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified nginx 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 "nginx.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 "nginx.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "nginx.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "nginx.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Returns the extraEnv keys and values to inject into containers.

Global values will override any chart-specific values.
*/}}
{{- define "nginx.extraEnv" -}}
{{- $allExtraEnv := merge (default (dict) .local.extraEnv) .global.extraEnv -}}
{{- range $key, $value := $allExtraEnv }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end -}}
{{- end -}}

{{/*
Returns a list of _common_ labels to be shared across all
app deployments and other shared objects.
*/}}
{{- define "nginx.commonLabels" -}}
{{- $commonLabels := default (dict) .Values.common.labels -}}
{{- if $commonLabels }}
{{- range $key, $value := $commonLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end -}}
{{- end -}}

{{/*
Returns a list of _pod_ labels to be shared across all
nginx deployments.
*/}}
{{- define "nginx.podLabels" -}}
{{- range $key, $value := .Values.pod.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end -}}

{{- define "nginx.redis" -}}
{{- $cs := include "wandb.redis.connectionString" . }}
{{- $ca := include "wandb.redis.caCert" . }}
{{- if $ca }}
{{- printf "%s?tls=true&caCertPath=/etc/ssl/certs/redis_ca.pem&ttlInSeconds=604800" $cs -}}
{{- else }}
{{- print $cs -}}
{{- end }}
{{- end }}

{{- define "nginx.bucket" -}}
{{- $bucket := "" -}}
{{- if eq .Values.global.bucket.provider "az" -}}
{{- $bucket = printf "az://%s/%s" .Values.global.bucket.name .Values.global.bucket.path -}}
{{- end -}}
{{- if eq .Values.global.bucket.provider "gcs" -}}
{{- $bucket = printf "gs://%s" .Values.global.bucket.name -}}
{{- end -}}
{{- if eq .Values.global.bucket.provider "s3" -}}
{{- if and .Values.global.bucket.accessKey .Values.global.bucket.secretKey -}}
{{- $bucket = printf "s3://%s:%s@%s/%s" .Values.global.bucket.accessKey .Values.global.bucket.secretKey .Values.global.bucket.name .Values.global.bucket.path -}}
{{- else -}}
{{- $bucket = printf "s3://%s/%s" .Values.global.bucket.name .Values.global.bucket.path -}}
{{- end -}}
{{- end -}}
{{- trimSuffix "/" $bucket -}}
{{- end -}}
39 changes: 39 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "nginx.fullname" . }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "nginx.commonLabels" . | nindent 4 }}
{{- include "nginx.labels" . | nindent 4 }}
{{- if .Values.configMap.labels -}}
{{- toYaml .Values.configMap.labels | nindent 4 }}
{{- end }}
annotations:
{{- if .Values.configMap.annotations -}}
{{- toYaml .Values.configMap.annotations | nindent 4 }}
{{- end }}
data:
nginx.conf: |
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
server {
listen 80;

location / {
proxy_pass http://{{ .Release.Name }}-app;
}

location /console {
proxy_pass http://{{ .Release.Name }}-console;
}
}
}
69 changes: 69 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- if .Values.enabled }}
{{- $imageCfg := dict "global" $.Values.global.image "local" $.Values.image -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nginx.fullname" . }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "nginx.commonLabels" . | nindent 4 }}
{{- include "nginx.labels" . | nindent 4 }}
{{- if .Values.deployment.labels -}}
{{- toYaml .Values.deployment.labels | nindent 4 }}
{{- end }}
annotations:
{{- include "wandb.deploymentAnnotations" $ | nindent 4 }}
{{- if .Values.deployment.annotations -}}
{{- toYaml .Values.deployment.annotations | nindent 4 }}
{{- end }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "wandb.selectorLabels" $ | nindent 6 }}
{{- include "nginx.labels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "wandb.podLabels" . | nindent 8 }}
{{- include "nginx.commonLabels" . | nindent 8 }}
{{- include "nginx.podLabels" . | nindent 8 }}
{{- include "nginx.labels" . | nindent 8 }}
annotations:
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if .Values.pod.annotations -}}
{{- toYaml .Values.pod.annotations | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "app.serviceAccountName" . }}
{{- if .tolerations }}
tolerations:
{{- toYaml .tolerations | nindent 8 }}
{{- end }}
{{- include "wandb.nodeSelector" . | nindent 6 }}
{{- include "wandb.priorityClassName" . | nindent 6 }}
{{- include "wandb.podSecurityContext" .Values.pod.securityContext | nindent 6 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
volumeMounts:
{{- if ne (include "wandb.redis.caCert" .) "" }}
- name: {{ include "nginx.fullname" . }}-redis-ca
mountPath: /etc/ssl/certs/redis_ca.pem
subPath: redis_ca.pem
{{- end }}
ports:
- containerPort: 80
{{- include "nginx.extraEnv" (dict "global" $.Values.global "local" .Values) | nindent 12 }}
{{- include "wandb.extraEnvFrom" (dict "root" $ "local" .) | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: config-volume
configMap:
name: {{ include "nginx.fullname" . }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "nginx.fullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "nginx.commonLabels" . | nindent 4 }}
{{- include "nginx.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "nginx.fullname" . }}
minReplicas: 1
maxReplicas: 1
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
23 changes: 23 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "app.fullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "app.commonLabels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.role.labels -}}
{{- toYaml .Values.role.labels | nindent 4 }}
{{- end }}
annotations:
{{- if .Values.role.annotations -}}
{{- toYaml .Values.role.annotations | nindent 4 }}
{{- end }}
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "create", "update", "delete"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]
23 changes: 23 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "app.commonLabels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.role.labels -}}
{{- toYaml .Values.role.labels | nindent 4 }}
{{- end }}
annotations:
{{- if .Values.role.annotations -}}
{{- toYaml .Values.role.annotations | nindent 4 }}
{{- end }}
roleRef:
kind: ClusterRole
apiGroup: rbac.authorization.k8s.io
name: {{ include "app.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "app.fullname" . }}
namespace: {{ .Release.Namespace }}
23 changes: 23 additions & 0 deletions charts/operator-wandb/charts/nginx/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "nginx.fullname" . }}
labels:
{{- include "wandb.commonLabels" . | nindent 4 }}
{{- include "nginx.labels" . | nindent 4 }}
{{- include "nginx.commonLabels" . | nindent 4 }}
{{- if .Values.service.labels -}}
{{- toYaml .Values.service.labels | nindent 4 }}
{{- end }}
annotations:
{{- if .Values.service.annotations -}}
{{- toYaml .Values.service.annotations | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- protocol: TCP
port: 80
targetPort: 80
selector:
{{- include "nginx.labels" . | nindent 4 }}
Loading
Loading