From 730958c07d13b555b2004c730416423309b6a89a Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 15:45:06 +0000 Subject: [PATCH 1/10] add spaces between services For readability sake - we want to easily distinguish each service. Atm this can't be achieved unless you fold the code. Resolves: Related: Signed-off-by: Daniel Andrei Minca --- diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index 885eace..8cd3a87 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -20,6 +20,7 @@ services: - GL_USER=root - PYTHONPATH=/code - PAGURE_CONFIG=/code/dev/openshift.cfg + worker: build: context: ./containers @@ -35,6 +36,7 @@ services: environment: - PYTHONPATH=/code - PAGURE_CONFIG=/code/dev/openshift.cfg + logcom: build: context: ./containers @@ -50,6 +52,7 @@ services: environment: - PYTHONPATH=. - PAGURE_CONFIG=/code/dev/openshift.cfg + ev: build: context: ./containers @@ -64,8 +67,10 @@ services: environment: - PYTHONPATH=. - PAGURE_CONFIG=/code/dev/openshift.cfg + redis: image: redis + postgresql: image: postgres environment: From 9021f3bdd8b4c13bacfaf25ce57127281583c3e6 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 15:45:06 +0000 Subject: [PATCH 2/10] generate the scaffold code for the Helm Chart - we need a starting point; generate scaffold Resolves: Related: Signed-off-by: Daniel Andrei Minca --- diff --git a/helm/pagure/.helmignore b/helm/pagure/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/helm/pagure/.helmignore @@ -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/ diff --git a/helm/pagure/Chart.yaml b/helm/pagure/Chart.yaml new file mode 100644 index 0000000..4e44833 --- /dev/null +++ b/helm/pagure/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: pagure +version: 0.1.0 diff --git a/helm/pagure/templates/NOTES.txt b/helm/pagure/templates/NOTES.txt new file mode 100644 index 0000000..ecc2e24 --- /dev/null +++ b/helm/pagure/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range $.Values.ingress.paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host }}{{ . }} + {{- 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 "pagure.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 svc -w {{ include "pagure.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pagure.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + 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 "pagure.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/helm/pagure/templates/_helpers.tpl b/helm/pagure/templates/_helpers.tpl new file mode 100644 index 0000000..c3db5db --- /dev/null +++ b/helm/pagure/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "pagure.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 "pagure.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 "pagure.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm/pagure/templates/deployment.yaml b/helm/pagure/templates/deployment.yaml new file mode 100644 index 0000000..d2f31b7 --- /dev/null +++ b/helm/pagure/templates/deployment.yaml @@ -0,0 +1,51 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "pagure.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + helm.sh/chart: {{ include "pagure.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/helm/pagure/templates/ingress.yaml b/helm/pagure/templates/ingress.yaml new file mode 100644 index 0000000..4923380 --- /dev/null +++ b/helm/pagure/templates/ingress.yaml @@ -0,0 +1,40 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "pagure.fullname" . -}} +{{- $ingressPaths := .Values.ingress.paths -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + helm.sh/chart: {{ include "pagure.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- 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: + {{- range $ingressPaths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} + {{- end }} +{{- end }} diff --git a/helm/pagure/templates/service.yaml b/helm/pagure/templates/service.yaml new file mode 100644 index 0000000..85d3153 --- /dev/null +++ b/helm/pagure/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "pagure.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + helm.sh/chart: {{ include "pagure.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "pagure.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/helm/pagure/templates/tests/test-connection.yaml b/helm/pagure/templates/tests/test-connection.yaml new file mode 100644 index 0000000..0ee17bf --- /dev/null +++ b/helm/pagure/templates/tests/test-connection.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "pagure.fullname" . }}-test-connection" + labels: + app.kubernetes.io/name: {{ include "pagure.name" . }} + helm.sh/chart: {{ include "pagure.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "pagure.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/helm/pagure/values.yaml b/helm/pagure/values.yaml new file mode 100644 index 0000000..c053776 --- /dev/null +++ b/helm/pagure/values.yaml @@ -0,0 +1,48 @@ +# Default values for pagure. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + tag: stable + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + paths: [] + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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: {} From 9462f2b459bf1039dae73dcf1a363d080150ffca Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 15:45:07 +0000 Subject: [PATCH 3/10] add README for describing what we're doing here Resolves: Related: Signed-off-by: Daniel Andrei Minca --- diff --git a/helm/pagure/README.md b/helm/pagure/README.md new file mode 100644 index 0000000..a4cda4f --- /dev/null +++ b/helm/pagure/README.md @@ -0,0 +1,17 @@ +# pagure Helm Chart +> Deploys fully-fledged pagure.io on your Kubernetes cluster + +## TL;DR; + +```sh +helm install --name pagure helm/pagure +``` + +## Configuration + +The table lists the configurable parameters of the pagure chart and their default values. + +Parameter | Description | Default +--- | --- | --- +`foo.bar` | name of the foobar component | `foobar` + From 6e9714023eff84c3172eb3f7d9a2abdd68e281e0 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 15:45:07 +0000 Subject: [PATCH 4/10] fix markdown table markdown broke my table >.< Resolves: Related: Signed-off-by: Daniel Andrei Minca --- diff --git a/helm/pagure/README.md b/helm/pagure/README.md index a4cda4f..9f737a5 100644 --- a/helm/pagure/README.md +++ b/helm/pagure/README.md @@ -10,7 +10,9 @@ helm install --name pagure helm/pagure ## Configuration The table lists the configurable parameters of the pagure chart and their default values. + + Parameter | Description | Default --- | --- | --- `foo.bar` | name of the foobar component | `foobar` From 628603a287426f4683d53a76a60072f528f51b55 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 17:41:39 +0000 Subject: [PATCH 5/10] replace old syntax --- diff --git a/helm/pagure/templates/deployment.yaml b/helm/pagure/templates/deployment.yaml index d2f31b7..1302dd7 100644 --- a/helm/pagure/templates/deployment.yaml +++ b/helm/pagure/templates/deployment.yaml @@ -21,8 +21,8 @@ spec: spec: containers: - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + image: "{{ .Values.image }}" + imagePullPolicy: {{ .Values.pullPolicy }} ports: - name: http containerPort: 80 diff --git a/helm/pagure/values.yaml b/helm/pagure/values.yaml index c053776..0d509da 100644 --- a/helm/pagure/values.yaml +++ b/helm/pagure/values.yaml @@ -4,10 +4,8 @@ replicaCount: 1 -image: - repository: nginx - tag: stable - pullPolicy: IfNotPresent +image: "" # TODO: add official pagure.io image from Registry +pullPolicy: IfNotPresent nameOverride: "" fullnameOverride: "" From b00b725ee18927afb215b9973215a46e0d016d35 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 17:42:15 +0000 Subject: [PATCH 6/10] make it compatible with k8s version >=1.14 --- diff --git a/helm/pagure/templates/ingress.yaml b/helm/pagure/templates/ingress.yaml index 4923380..7177a16 100644 --- a/helm/pagure/templates/ingress.yaml +++ b/helm/pagure/templates/ingress.yaml @@ -1,7 +1,11 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "pagure.fullname" . -}} {{- $ingressPaths := .Values.ingress.paths -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} apiVersion: extensions/v1beta1 +{{- end }} kind: Ingress metadata: name: {{ $fullName }} From 8cde20d994b050430f5f7048d023e8f06c4ab5ec Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 18:40:13 +0000 Subject: [PATCH 7/10] add instructions for hacking on kubernetes --- diff --git a/helm/README.md b/helm/README.md new file mode 100644 index 0000000..873ea5f --- /dev/null +++ b/helm/README.md @@ -0,0 +1,35 @@ +# Developing with the Helm Chart +> This docu provides you detailed instructions for easily developing +> this Helm Chart (ie. testing, deploying the app et. al.) + +## Prerequisites + +In order to start hacking locally without hassle, you're gonna need to install +* [k3d][1] - installation instructions in readme +* [kubectl][2] - for running commands in the Kubernetes cluster + +## Spinning up a mini Kubernetes cluster locally +Helm Charts run on Kubernetes, therefore a Kubernetes cluster is a requirement, this is +how you can spin up your tiny Kubernetes cluster locally with [k3d][1] + +```bash +# create the cluster +k3d create + +# authenticate to execute commands in cluster +export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')" + +# check if you have the cluster ready +kubectl get nodes -owide +``` + +## Start hacking + +Install the helm chart in your local Kubernetes cluster now + +```bash +helm install --name pagure helm/pagure +``` + +[1]: https://github.com/rancher/k3d +[2]: https://kubernetes.io/docs/tasks/tools/install-kubectl/ \ No newline at end of file From 3c357332b682c812de8fd23bb411f333d1cc9c72 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 18:53:56 +0000 Subject: [PATCH 8/10] add instructions for hacking on kubernetes --- diff --git a/helm/README.md b/helm/README.md index 873ea5f..6f1e120 100644 --- a/helm/README.md +++ b/helm/README.md @@ -31,5 +31,13 @@ Install the helm chart in your local Kubernetes cluster now helm install --name pagure helm/pagure ``` +## Teardown + +If you decide to call it a day, just destroy the local Kubernetes cluster + +```bash +k3d delete +``` + [1]: https://github.com/rancher/k3d [2]: https://kubernetes.io/docs/tasks/tools/install-kubectl/ \ No newline at end of file From ef3a256a7f1898e208040d0b8d4d3ccf45539dbc Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 19:34:39 +0000 Subject: [PATCH 9/10] try a first spin * just run the frontend first & make it scream a little for whatever it needs to function --- diff --git a/helm/pagure/values.yaml b/helm/pagure/values.yaml index 0d509da..643789a 100644 --- a/helm/pagure/values.yaml +++ b/helm/pagure/values.yaml @@ -4,7 +4,7 @@ replicaCount: 1 -image: "" # TODO: add official pagure.io image from Registry +image: "dminca/pagure-web:latest" # TODO: replace with official image pullPolicy: IfNotPresent nameOverride: "" From 135de66d4a165bbbe4ca25f0b9b2035e650c33b1 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Minca Date: Apr 08 2020 20:12:20 +0000 Subject: [PATCH 10/10] fix indentation * loops & control statements are easier to spot this way --- diff --git a/helm/pagure/templates/deployment.yaml b/helm/pagure/templates/deployment.yaml index 1302dd7..2c35bc1 100644 --- a/helm/pagure/templates/deployment.yaml +++ b/helm/pagure/templates/deployment.yaml @@ -37,15 +37,15 @@ spec: port: http resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} +{{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} +{{- end }} +{{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} +{{- end }} +{{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} - {{- end }} +{{- end }} diff --git a/helm/pagure/templates/ingress.yaml b/helm/pagure/templates/ingress.yaml index 7177a16..1569705 100644 --- a/helm/pagure/templates/ingress.yaml +++ b/helm/pagure/templates/ingress.yaml @@ -14,31 +14,31 @@ metadata: helm.sh/chart: {{ include "pagure.chart" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} - {{- with .Values.ingress.annotations }} +{{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} - {{- end }} +{{- end }} spec: {{- if .Values.ingress.tls }} tls: - {{- range .Values.ingress.tls }} +{{- range .Values.ingress.tls }} - hosts: - {{- range .hosts }} +{{- range .hosts }} - {{ . | quote }} - {{- end }} +{{- end }} secretName: {{ .secretName }} - {{- end }} +{{- end }} {{- end }} rules: - {{- range .Values.ingress.hosts }} +{{- range .Values.ingress.hosts }} - host: {{ . | quote }} http: paths: - {{- range $ingressPaths }} +{{- range $ingressPaths }} - path: {{ . }} backend: serviceName: {{ $fullName }} servicePort: http - {{- end }} - {{- end }} +{{- end }} +{{- end }} {{- end }}