diff --git a/deploy/helm/.gitignore b/deploy/helm/.gitignore new file mode 100644 index 000000000..1e033a05a --- /dev/null +++ b/deploy/helm/.gitignore @@ -0,0 +1,6 @@ +*.tgz +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deploy/helm/.helmignore b/deploy/helm/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deploy/helm/.helmignore @@ -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/ diff --git a/deploy/helm/Chart.lock b/deploy/helm/Chart.lock new file mode 100644 index 000000000..ae02b3730 --- /dev/null +++ b/deploy/helm/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 10.2.0 +digest: sha256:ffc74acdb2350c12e199b3cf080130440bb1e137d1cf10dec1fbdbe597d40510 +generated: "2021-01-27T22:09:53.941520746+01:00" diff --git a/deploy/helm/Chart.yaml b/deploy/helm/Chart.yaml new file mode 100644 index 000000000..28c69e4d5 --- /dev/null +++ b/deploy/helm/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: nebraska +description: Nebraska is an update manager for Flatcar Container Linux. +type: application +keywords: + - nebraska + - kinvolk + - CoreOS + - update manager + - updates + - Omaha protocol + - flatcar + - Flatcar Container Linux +version: 0.1.0 +appVersion: "2.3.0" + +dependencies: +- name: postgresql + version: 10.2.6 + repository: https://charts.bitnami.com/bitnami + condition: postgresql.enabled diff --git a/deploy/helm/templates/NOTES.txt b/deploy/helm/templates/NOTES.txt new file mode 100644 index 000000000..b8dfd8a9e --- /dev/null +++ b/deploy/helm/templates/NOTES.txt @@ -0,0 +1,20 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "nebraska.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nebraska.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nebraska.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "nebraska.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deploy/helm/templates/_helpers.tpl b/deploy/helm/templates/_helpers.tpl new file mode 100644 index 000000000..c31403a96 --- /dev/null +++ b/deploy/helm/templates/_helpers.tpl @@ -0,0 +1,75 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "nebraska.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 "nebraska.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 "nebraska.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "nebraska.labels" -}} +helm.sh/chart: {{ include "nebraska.chart" . }} +{{ include "nebraska.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "nebraska.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nebraska.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "nebraska.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "nebraska.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Create a default fully qualified postgresql name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "nebraska.postgresql.fullname" -}} +{{- $name := default "postgresql" .Values.postgresql.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "nebraska.ingressScheme" -}} +http{{ if $.Values.ingress.tls }}s{{ end }} +{{- end -}} diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml new file mode 100644 index 000000000..768b31b4d --- /dev/null +++ b/deploy/helm/templates/deployment.yaml @@ -0,0 +1,161 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "nebraska.fullname" . }} + labels: + {{- include "nebraska.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "nebraska.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nebraska.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "nebraska.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - "/nebraska/nebraska" + args: + {{- /* General settings */}} + {{- if .Values.config.app.title }} + - "-client-title={{ .Values.config.app.title }}" + {{- end }} + {{- if .Values.config.app.logoPath }} + - "-client-logo={{ .Values.config.app.logoPath }}" + {{- end }} + {{- if .Values.config.app.headerStyle }} + - "-client-header-style={{ .Values.config.app.headerStyle }}" + {{- end }} + {{- if .Values.config.app.httpStaticDir }} + - "-http-static-dir={{ .Values.config.app.httpStaticDir }}" + {{- end }} + + {{- /* Syncer settings */}} + {{- if .Values.config.syncer.enabled }} + - "-enable-syncer" + {{- if .Values.config.syncer.interval }} + - "-sync-interval={{ .Values.config.syncer.interval }}" + {{- end }} + {{- if .Values.config.syncer.updateURL }} + - "-sync-update-url={{ .Values.config.syncer.updateURL }}" + {{- end }} + {{- end }} + + {{- /* Host packages settings */}} + {{- if .Values.config.hostFlatcarPackages.enabled }} + - "-host-flatcar-packages" + - "-flatcar-packages-path={{ required "A valid 'packagesPath' is required when hosting Flatcar packages." .Values.config.hostFlatcarPackages.packagesPath }}" + {{- if .Values.ingress.enabled }} + - "-nebraska-url={{ printf "%s://%s" (include "nebraska.ingressScheme" .) (index .Values.ingress.hosts 0) }}" + {{- else if .Values.config.hostFlatcarPackages.nebraskaURL }} + - "-nebraska-url={{ .Values.config.hostFlatcarPackages.nebraskaURL }}" + {{- end }} + {{- end }} + + {{- /* Auth settings */}} + {{- if .Values.config.auth.mode }} + - "-auth-mode={{ .Values.config.auth.mode }}" + {{- end }} + {{- if and .Values.config.auth.github.readWriteTeams (not (eq .Values.config.auth.mode "noop")) }} + - "-gh-rw-teams={{ .Values.config.auth.github.readWriteTeams }}" + {{- end }} + {{- if and .Values.config.auth.github.readOnlyTeams (not (eq .Values.config.auth.mode "noop")) }} + - "-gh-ro-teams={{ .Values.config.auth.github.readOnlyTeams }}" + {{- end }} + env: + - name: NEBRASKA_DB_URL + valueFrom: + secretKeyRef: + name: {{ include "nebraska.fullname" . }} + key: dbURL + {{- if or (eq .Values.config.auth.mode "github") (not .Values.config.auth.mode) }} + - name: "NEBRASKA_GITHUB_OAUTH_CLIENT_ID" + value: "{{ .Values.config.auth.github.clientID }}" + - name: "NEBRASKA_GITHUB_OAUTH_CLIENT_SECRET" + valueFrom: + secretKeyRef: + name: {{ include "nebraska.fullname" . }} + key: ghClientSecret + - name: "NEBRASKA_GITHUB_SESSION_SECRET" + valueFrom: + secretKeyRef: + name: {{ include "nebraska.fullname" . }} + key: ghSessionAuthKey + - name: "NEBRASKA_GITHUB_SESSION_CRYPT_KEY" + valueFrom: + secretKeyRef: + name: {{ include "nebraska.fullname" . }} + key: ghSessionCryptKey + - name: "NEBRASKA_GITHUB_WEBHOOK_SECRET" + valueFrom: + secretKeyRef: + name: {{ include "nebraska.fullname" . }} + key: ghWebhookSecret + {{- if .Values.config.auth.github.enterpriseURL }} + - name: "NEBRASKA_GITHUB_ENTERPRISE_URL" + value: "{{ .Values.config.auth.github.enterpriseURL }}" + {{- end }} + {{- end }} + {{- range $key, $value := .Values.env }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- if .Values.config.hostFlatcarPackages.enabled }} + volumeMounts: + - mountPath: {{ .Values.config.hostFlatcarPackages.packagesPath }} + name: packages + {{- end }} + ports: + - name: http + containerPort: {{ .Values.env.PORT | default 8000 }} + protocol: TCP + {{- if .Values.livenessProbe.enabled }} + livenessProbe: + {{- omit .Values.livenessProbe "enabled" | toYaml | nindent 12 }} + {{- end }} + {{- if .Values.readinessProbe.enabled }} + readinessProbe: + {{- omit .Values.readinessProbe "enabled" | toYaml | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- if .Values.config.hostFlatcarPackages.enabled }} + volumes: + - name: packages + {{- if .Values.config.hostFlatcarPackages.persistence.enabled}} + persistentVolumeClaim: + claimName: {{ include "nebraska.fullname" . }}-packages + {{- else }} + emptyDir: {} + {{- end }} + {{- 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 }} diff --git a/deploy/helm/templates/ingress.yaml b/deploy/helm/templates/ingress.yaml new file mode 100644 index 000000000..a77367cd3 --- /dev/null +++ b/deploy/helm/templates/ingress.yaml @@ -0,0 +1,50 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "nebraska.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- $kubeGitVersion := .Capabilities.KubeVersion.GitVersion -}} +{{- if semverCompare ">=1.19-0" $kubeGitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" $kubeGitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "nebraska.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: / + backend: + {{- if semverCompare ">=1.19-0" $kubeGitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + pathType: ImplementationSpecific + {{- else -}} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} diff --git a/deploy/helm/templates/pvc.yaml b/deploy/helm/templates/pvc.yaml new file mode 100644 index 000000000..9c00098d6 --- /dev/null +++ b/deploy/helm/templates/pvc.yaml @@ -0,0 +1,16 @@ +{{- if .Values.config.hostFlatcarPackages.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "nebraska.fullname" . }}-packages + labels: + {{- include "nebraska.labels" . | nindent 4 }} +spec: + accessModes: {{ .Values.config.hostFlatcarPackages.persistence.accessModes }} + resources: + requests: + storage: {{ .Values.config.hostFlatcarPackages.persistence.size }} + {{- if .Values.config.hostFlatcarPackages.persistence.storageClass }} + storageClassName: {{ .Values.config.hostFlatcarPackages.persistence.storageClass }} + {{- end }} +{{- end }} diff --git a/deploy/helm/templates/secrets.yaml b/deploy/helm/templates/secrets.yaml new file mode 100644 index 000000000..c2abb26c5 --- /dev/null +++ b/deploy/helm/templates/secrets.yaml @@ -0,0 +1,19 @@ +{{- $user := .Values.postgresql.postgresqlUsername }} +{{- $pass := .Values.postgresql.postgresqlPassword }} +{{- $db := .Values.postgresql.postgresqlDatabase }} +{{- $host := include "nebraska.postgresql.fullname" . }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "nebraska.fullname" . }} + labels: + {{- include "nebraska.labels" . | nindent 4 }} +type: Opaque +data: + dbURL: {{ printf "postgres://%s:%s@%s:5432/%s?sslmode=disable&connect_timeout=10" $user $pass $host $db | b64enc }} + {{- if or (eq .Values.config.auth.mode "github") (not .Values.config.auth.mode) }} + ghClientSecret: {{ required "A valid 'clientSecret' is required when using github authentication." .Values.config.auth.github.clientSecret | toString | b64enc }} + ghSessionAuthKey: {{ required "A valid 'sessionAuthKey' is required when using github authentication." .Values.config.auth.github.sessionAuthKey | toString | b64enc }} + ghSessionCryptKey: {{ required "A valid 'sessionCryptKey' is required when using github authentication." .Values.config.auth.github.sessionCryptKey | toString | b64enc }} + ghWebhookSecret: {{ required "A valid 'webhookSecret' is required when using github authentication." .Values.config.auth.github.webhookSecret | toString | b64enc }} + {{- end }} diff --git a/deploy/helm/templates/service.yaml b/deploy/helm/templates/service.yaml new file mode 100644 index 000000000..d5a3bb238 --- /dev/null +++ b/deploy/helm/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nebraska.fullname" . }} + labels: + {{- include "nebraska.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "nebraska.selectorLabels" . | nindent 4 }} diff --git a/deploy/helm/templates/serviceaccount.yaml b/deploy/helm/templates/serviceaccount.yaml new file mode 100644 index 000000000..5fdb66747 --- /dev/null +++ b/deploy/helm/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "nebraska.serviceAccountName" . }} + labels: + {{- include "nebraska.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml new file mode 100644 index 000000000..d025a55c4 --- /dev/null +++ b/deploy/helm/values.yaml @@ -0,0 +1,148 @@ +# Default values for nebraska. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + registry: quay.io + repository: flatcar/nebraska + # Overrides the image tag whose default is the chart appVersion. + tag: "" + pullPolicy: IfNotPresent + +imagePullSecrets: [] + # - name: myregistrykey +nameOverride: "" +fullnameOverride: "" + +config: + app: + logoPath: /nebraska/assets/kinvolk-logo.svg + title: Kinvolk Update Service + headerStyle: dark + httpStaticDir: /nebraska/static + + syncer: + enabled: true + # interval: 1h + # updateURL: "https://public.update.flatcar-linux.net/v1/update/" + + hostFlatcarPackages: + enabled: false + packagesPath: /mnt/packages + # nebraskaURL: http://flatcar.example.com + persistence: + enabled: false + storageClass: + accessModes: + - ReadWriteOnce + size: 10Gi + + auth: + mode: noop + github: + clientID: + clientSecret: + sessionAuthKey: + sessionCryptKey: + webhookSecret: + readWriteTeams: + readOnlyTeams: + enterpriseURL: + + +extraArgs: [] + # - "-http-log" + # - "-api-endpoint-suffix=mysecret" + +env: + TZ: UTC + # PORT: 8080 + # GIN_MODE: release + # LOGXI: "*=DBG" + # LOGXI_FORMAT: "LTSV" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: true + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - flatcar.example.com + tls: [] + # - secretName: chart-example-tls + # hosts: + # - flatcar.example.com + +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: {} + +livenessProbe: + enabled: true + httpGet: + path: / + port: http + +readinessProbe: + enabled: true + httpGet: + path: / + port: http + +# Configuration values for the postgresql dependency. +# ... for more options see https://github.com/bitnami/charts/tree/master/bitnami/postgresql +postgresql: + enabled: true + postgresqlUsername: postgres + postgresqlPassword: changeIt + postgresqlDatabase: nebraska + image: + tag: 12.5.0-debian-10-r76 + persistence: + enabled: false + storageClass: + accessModes: + - ReadWriteOnce + size: 1Gi