From bda3f9fcd0585966d8b59f4fdab5e40a81b1e8c7 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Tue, 27 Jun 2023 13:51:21 +1200 Subject: [PATCH 01/15] first passing testing of docker-compose for vols --- legacy/scripts/exec-gather-volumes.sh | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 legacy/scripts/exec-gather-volumes.sh diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh new file mode 100755 index 00000000..c481bc88 --- /dev/null +++ b/legacy/scripts/exec-gather-volumes.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# First step: Parse the docker-compose.yml for any volumes that have the label "lagoon.type: persistent" +DOCKER_COMPOSE_YAML="test/docker-compose.yml" +# Parse docker-compose.yml and extract volume names with "lagoon.type: persistent" label +volumes=$(yq e '.volumes | with_entries(select(.value.labels."lagoon.type" == "persistent")) | keys | .[]' "$DOCKER_COMPOSE_YAML") + +# Print the list of volume names +echo "Volumes:" +echo "$volumes" +echo + +# Create an array to store the volumes that need to be created +volumes_to_create=() + +# Iterate over the volumes +for volume in $volumes; do + echo "Volume: $volume" + + # Loop through the services and check if they reference the current volume + services=$(yq e '.services | to_entries | .[] | select(.value.labels | has("lagoon.volumes.'$volume'.path")) | .key' "$DOCKER_COMPOSE_YAML") + + # Print the services and their corresponding paths for the current volume + while IFS= read -r service; do + path=$(yq e '.services."'$service'".labels."lagoon.volumes.'$volume'.path"' "$DOCKER_COMPOSE_YAML") + echo "- Service: $service, Path: $path" + done <<< "$services" + + # If no services reference the volume, print a message indicating it is not used + if [[ -z "$services" ]]; then + echo "- Not used" + else + # Add the volume to the array of volumes that need to be created + volumes_to_create+=("$volume") + fi + + echo +done + +echo "Volumes to be created:" +echo "${volumes_to_create[@]}" From 912ab4ad9b99bdc408d7819a6d6a1a4209f8227e Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Tue, 27 Jun 2023 14:20:23 +1200 Subject: [PATCH 02/15] Further work on output --- legacy/scripts/exec-gather-volumes.sh | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index c481bc88..b2f4447f 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -12,6 +12,7 @@ echo # Create an array to store the volumes that need to be created volumes_to_create=() +EXTRA_VOLUMES_MOUNT_VALS="" #this will be output to our values file # Iterate over the volumes for volume in $volumes; do @@ -24,6 +25,13 @@ for volume in $volumes; do while IFS= read -r service; do path=$(yq e '.services."'$service'".labels."lagoon.volumes.'$volume'.path"' "$DOCKER_COMPOSE_YAML") echo "- Service: $service, Path: $path" + + if [[ "$service" != "" ]]; then + EXTRA_VOLUMES_MOUNT_VALS+="\ +customVolumeMount.$service.$volume: $path +" + fi + done <<< "$services" # If no services reference the volume, print a message indicating it is not used @@ -39,3 +47,25 @@ done echo "Volumes to be created:" echo "${volumes_to_create[@]}" + +EXTRA_VOLUMES_VALUES_YAML="" + + +# Check if volumes_to_create array is not empty before iterating +if [[ ${#volumes_to_create[@]} -gt 0 ]]; then + echo "Volumes to be created:" + EXTRA_VOLUMES_VALUES_YAML+="\ +customVolumes: +" + for volume in "${volumes_to_create[@]}"; do + echo "- $volume" + EXTRA_VOLUMES_VALUES_YAML+="\ + - $volume +" + done +else + echo "No volumes to create." +fi + +echo "$EXTRA_VOLUMES_VALUES_YAML" +echo "$EXTRA_VOLUMES_MOUNT_VALS" \ No newline at end of file From dcd8b2649d86a1ba8916f1d55ef47089a078d852 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 28 Jun 2023 10:24:14 +1200 Subject: [PATCH 03/15] Changes up format to make it easier to consume --- legacy/scripts/exec-gather-volumes.sh | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index b2f4447f..21e3ee82 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -1,34 +1,45 @@ #!/bin/bash -# First step: Parse the docker-compose.yml for any volumes that have the label "lagoon.type: persistent" -DOCKER_COMPOSE_YAML="test/docker-compose.yml" + +if [[ -z "$DOCKER_COMPOSE_YAML" ]]; then + echo "no docker compose file given" + exit +fi + +EXTRA_MOUNT_VALUES_FILE="${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" + + # Parse docker-compose.yml and extract volume names with "lagoon.type: persistent" label volumes=$(yq e '.volumes | with_entries(select(.value.labels."lagoon.type" == "persistent")) | keys | .[]' "$DOCKER_COMPOSE_YAML") # Print the list of volume names -echo "Volumes:" +echo "Extra volumes defined:" echo "$volumes" echo # Create an array to store the volumes that need to be created volumes_to_create=() -EXTRA_VOLUMES_MOUNT_VALS="" #this will be output to our values file +EXTRA_VOLUMES_MOUNT_VALS="\ +customVolumeMounts: +" #this will be output to our values file # Iterate over the volumes for volume in $volumes; do - echo "Volume: $volume" - +# echo "Volume: $volume" + EXTRA_VOLUMES_MOUNT_VALS+="\ + - $volume: +" # Loop through the services and check if they reference the current volume services=$(yq e '.services | to_entries | .[] | select(.value.labels | has("lagoon.volumes.'$volume'.path")) | .key' "$DOCKER_COMPOSE_YAML") # Print the services and their corresponding paths for the current volume while IFS= read -r service; do path=$(yq e '.services."'$service'".labels."lagoon.volumes.'$volume'.path"' "$DOCKER_COMPOSE_YAML") - echo "- Service: $service, Path: $path" +# echo "- Service: $service, Path: $path" if [[ "$service" != "" ]]; then EXTRA_VOLUMES_MOUNT_VALS+="\ -customVolumeMount.$service.$volume: $path + - $service: $path " fi @@ -68,4 +79,7 @@ else fi echo "$EXTRA_VOLUMES_VALUES_YAML" -echo "$EXTRA_VOLUMES_MOUNT_VALS" \ No newline at end of file +echo "$EXTRA_VOLUMES_MOUNT_VALS" + +echo "$EXTRA_VOLUMES_VALUES_YAML" > $EXTRA_MOUNT_VALUES_FILE +echo "$EXTRA_VOLUMES_MOUNT_VALS" >> $EXTRA_MOUNT_VALUES_FILE \ No newline at end of file From 922f77a26ac35cabc3d121d58a8da9b45f21b91d Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 5 Jul 2023 06:20:17 +1200 Subject: [PATCH 04/15] updates to exec-gather-volumes.sh --- legacy/scripts/exec-gather-volumes.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index 21e3ee82..9a5dacf9 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -7,7 +7,7 @@ if [[ -z "$DOCKER_COMPOSE_YAML" ]]; then fi EXTRA_MOUNT_VALUES_FILE="${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" - +CUSTOMVOLUME_PREFIX="lcv-" # we just use this to distinguish from any other volumes that might be created # Parse docker-compose.yml and extract volume names with "lagoon.type: persistent" label volumes=$(yq e '.volumes | with_entries(select(.value.labels."lagoon.type" == "persistent")) | keys | .[]' "$DOCKER_COMPOSE_YAML") @@ -27,7 +27,7 @@ customVolumeMounts: for volume in $volumes; do # echo "Volume: $volume" EXTRA_VOLUMES_MOUNT_VALS+="\ - - $volume: + - $CUSTOMVOLUME_PREFIX$volume: " # Loop through the services and check if they reference the current volume services=$(yq e '.services | to_entries | .[] | select(.value.labels | has("lagoon.volumes.'$volume'.path")) | .key' "$DOCKER_COMPOSE_YAML") @@ -69,7 +69,7 @@ if [[ ${#volumes_to_create[@]} -gt 0 ]]; then customVolumes: " for volume in "${volumes_to_create[@]}"; do - echo "- $volume" + echo "- $CUSTOMVOLUME_PREFIX$volume" EXTRA_VOLUMES_VALUES_YAML+="\ - $volume " From 570475528fe6463b66855e59a9b6a6e0f2cab192 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 5 Jul 2023 10:21:00 +1200 Subject: [PATCH 05/15] First commit of custom pvc --- legacy/helmcharts/custom-pvc/.helmignore | 22 +++++++ legacy/helmcharts/custom-pvc/Chart.yaml | 17 +++++ .../custom-pvc/templates/_helpers.tpl | 62 +++++++++++++++++++ .../helmcharts/custom-pvc/templates/pvcs.yaml | 23 +++++++ legacy/helmcharts/custom-pvc/values.yaml | 39 ++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 legacy/helmcharts/custom-pvc/.helmignore create mode 100644 legacy/helmcharts/custom-pvc/Chart.yaml create mode 100644 legacy/helmcharts/custom-pvc/templates/_helpers.tpl create mode 100644 legacy/helmcharts/custom-pvc/templates/pvcs.yaml create mode 100644 legacy/helmcharts/custom-pvc/values.yaml diff --git a/legacy/helmcharts/custom-pvc/.helmignore b/legacy/helmcharts/custom-pvc/.helmignore new file mode 100644 index 00000000..fbe01f88 --- /dev/null +++ b/legacy/helmcharts/custom-pvc/.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/ \ No newline at end of file diff --git a/legacy/helmcharts/custom-pvc/Chart.yaml b/legacy/helmcharts/custom-pvc/Chart.yaml new file mode 100644 index 00000000..65705cb2 --- /dev/null +++ b/legacy/helmcharts/custom-pvc/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +name: custom-pvc +description: A Helm chart for Kubernetes creating lagoon custom-pvc + +# 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: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl new file mode 100644 index 00000000..36aa7e1a --- /dev/null +++ b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* vim: set filetype=mustache: */}} +{{/* + +{{/* + Create chart name and version as used by the chart label. + */}} + {{- define "custom-pvc.chart" -}} + {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} + {{- end -}} + + +{{- define "custom-pvc.name" -}} +{{- printf "lcv-%s" .Values | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} + +{{- define "custom-pvc.labels" -}} +helm.sh/chart: {{ template "custom-pvc.chart" .Context }} +{{ include "custom-pvc.selectorLabels" . }} +app.kubernetes.io/managed-by: {{ .Context.Release.Service }} +{{ include "custom-pvc.lagoonLabels" .Context }} +{{- end -}} + +{{/* +Selector labels +*/}} + +{{- define "custom-pvc.selectorLabels" -}} +app.kubernetes.io/name: {{ include "custom-pvc.name" . }} +app.kubernetes.io/instance: {{ .Context.Release.Name }} +{{- end -}} + +{{/* +Lagoon Labels +*/}} +{{- define "custom-pvc.lagoonLabels" -}} +lagoon.sh/service: {{ .Values.Release.Name }} +lagoon.sh/service-type: {{ .Values.Chart.Name }} +lagoon.sh/project: {{ .Values.project }} +lagoon.sh/environment: {{ .Values.environment }} +lagoon.sh/environmentType: {{ .Values.environmentType }} +lagoon.sh/buildType: {{ .Values.buildType }} +{{- end -}} + + +{{/* +Annotations +*/}} +{{- define "custom-pvc.annotations" -}} +lagoon.sh/version: {{ .Values.lagoonVersion | quote }} +{{- if .Values.branch }} +lagoon.sh/branch: {{ .Values.branch | quote }} +{{- end }} +{{- if .Values.prNumber }} +lagoon.sh/prNumber: {{ .Values.prNumber | quote }} +lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} +lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} +{{- end }} +{{- end -}} diff --git a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml new file mode 100644 index 00000000..77030516 --- /dev/null +++ b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml @@ -0,0 +1,23 @@ +{{ $context := . }} +{{- range .Values.customVolumes }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "custom-pvc.name" (dict "Values" . "Context" $context ) }} + + labels: + {{- include "custom-pvc.labels" (dict "Values" . "Context" $context ) | nindent 4 }} +annotations: + k8up.syn.tools/backup: "true" + {{- include "custom-pvc.annotations" $context | nindent 4 }} +spec: + accessModes: + - ReadWriteMany + storageClassName: bulk + resources: + requests: + storage: {{ $context.Values.persistentStorage.size | quote }} + +{{- end }} + diff --git a/legacy/helmcharts/custom-pvc/values.yaml b/legacy/helmcharts/custom-pvc/values.yaml new file mode 100644 index 00000000..1158abb1 --- /dev/null +++ b/legacy/helmcharts/custom-pvc/values.yaml @@ -0,0 +1,39 @@ +# Default values for custom-pvc. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# fastly: +# apiToken: '' +# platformTLSConfiguration: '' + +--- +persistentStorage: + name: cli + +customVolumes: + - config + - files + +customVolumeMounts: + - config: + - cli: /config + - php: /config + - files: + - cli: /app/web/sites/default/files/ + - nginx: /app/web/sites/default/files/ + - php: /app/web/sites/default/files/ + - notused: + +Chart: + Name: chartname + Version: 0.0.1 + + +nameOverride: oiwjef + +project: oweifj + +persistentStorage.size: 5Gi + +lagoonVersion: 21 + From 0fecfdff4ae091355d46fcae8c9fd68699c87ed9 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 5 Jul 2023 10:50:51 +1200 Subject: [PATCH 06/15] Fixes annotations --- legacy/helmcharts/custom-pvc/templates/_helpers.tpl | 8 ++++---- legacy/helmcharts/custom-pvc/templates/pvcs.yaml | 5 ++--- legacy/helmcharts/custom-pvc/values.yaml | 5 ----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl index 36aa7e1a..1fe8705f 100644 --- a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl +++ b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl @@ -10,7 +10,7 @@ {{- define "custom-pvc.name" -}} -{{- printf "lcv-%s" .Values | trunc 63 | trimSuffix "-" -}} +{{- printf "lcv-%s" .IterationValues | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* @@ -37,8 +37,8 @@ app.kubernetes.io/instance: {{ .Context.Release.Name }} Lagoon Labels */}} {{- define "custom-pvc.lagoonLabels" -}} -lagoon.sh/service: {{ .Values.Release.Name }} -lagoon.sh/service-type: {{ .Values.Chart.Name }} +lagoon.sh/service: {{ .Release.Name }} +lagoon.sh/service-type: {{ .Chart.Name }} lagoon.sh/project: {{ .Values.project }} lagoon.sh/environment: {{ .Values.environment }} lagoon.sh/environmentType: {{ .Values.environmentType }} @@ -59,4 +59,4 @@ lagoon.sh/prNumber: {{ .Values.prNumber | quote }} lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} {{- end }} -{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml index 77030516..7ca83561 100644 --- a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml +++ b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml @@ -4,12 +4,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: {{ include "custom-pvc.name" (dict "Values" . "Context" $context ) }} + name: {{ template "custom-pvc.name" (dict "IterationValues" . "Context" $context ) }} labels: - {{- include "custom-pvc.labels" (dict "Values" . "Context" $context ) | nindent 4 }} + {{- include "custom-pvc.labels" (dict "IterationValues" . "Context" $context ) | nindent 4 }} annotations: - k8up.syn.tools/backup: "true" {{- include "custom-pvc.annotations" $context | nindent 4 }} spec: accessModes: diff --git a/legacy/helmcharts/custom-pvc/values.yaml b/legacy/helmcharts/custom-pvc/values.yaml index 1158abb1..205877cf 100644 --- a/legacy/helmcharts/custom-pvc/values.yaml +++ b/legacy/helmcharts/custom-pvc/values.yaml @@ -24,10 +24,6 @@ customVolumeMounts: - php: /app/web/sites/default/files/ - notused: -Chart: - Name: chartname - Version: 0.0.1 - nameOverride: oiwjef @@ -36,4 +32,3 @@ project: oweifj persistentStorage.size: 5Gi lagoonVersion: 21 - From cbc1b43ec50ce82646835502eaf5aa13af65292c Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 5 Jul 2023 10:52:53 +1200 Subject: [PATCH 07/15] Further work --- legacy/helmcharts/custom-pvc/templates/pvcs.yaml | 1 - legacy/helmcharts/custom-pvc/values.yaml | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml index 7ca83561..70aa837f 100644 --- a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml +++ b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml @@ -5,7 +5,6 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: name: {{ template "custom-pvc.name" (dict "IterationValues" . "Context" $context ) }} - labels: {{- include "custom-pvc.labels" (dict "IterationValues" . "Context" $context ) | nindent 4 }} annotations: diff --git a/legacy/helmcharts/custom-pvc/values.yaml b/legacy/helmcharts/custom-pvc/values.yaml index 205877cf..b7afb9b5 100644 --- a/legacy/helmcharts/custom-pvc/values.yaml +++ b/legacy/helmcharts/custom-pvc/values.yaml @@ -6,9 +6,9 @@ # apiToken: '' # platformTLSConfiguration: '' ---- +# this is the default persistentStorage size for PVCs persistentStorage: - name: cli + size: 5Gi customVolumes: - config @@ -29,6 +29,4 @@ nameOverride: oiwjef project: oweifj -persistentStorage.size: 5Gi - lagoonVersion: 21 From b94678e529053d1a71fee978927bb951f6ccd21f Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 5 Jul 2023 11:17:17 +1200 Subject: [PATCH 08/15] cli-persistent template update --- .../cli-persistent/templates/_helpers.tpl | 4 +++ .../cli-persistent/templates/deployment.yaml | 28 +++++++++++++++++++ legacy/scripts/exec-gather-volumes.sh | 4 ++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/legacy/helmcharts/cli-persistent/templates/_helpers.tpl b/legacy/helmcharts/cli-persistent/templates/_helpers.tpl index ddb0f7c5..389a51b2 100644 --- a/legacy/helmcharts/cli-persistent/templates/_helpers.tpl +++ b/legacy/helmcharts/cli-persistent/templates/_helpers.tpl @@ -96,3 +96,7 @@ Generate path for twig storage emptyDir {{- define "cli-persistent.twig-storage.path" -}} {{- printf "%s/php" .Values.persistentStorage.path }} {{- end -}} + +{{- define "custom-pvc.name" -}} +{{- printf "lcv-%s" . | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/legacy/helmcharts/cli-persistent/templates/deployment.yaml b/legacy/helmcharts/cli-persistent/templates/deployment.yaml index 86935666..334f2b48 100644 --- a/legacy/helmcharts/cli-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/cli-persistent/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- $topValues := .Values }} apiVersion: apps/v1 kind: Deployment metadata: @@ -40,6 +41,20 @@ spec: claimName: {{ .Values.persistentStorage.name }} - name: {{ include "cli-persistent.twig-storage.name" . | quote }} emptyDir: {} + {{/* we iterate over all the custom volumes and see if we can find our service */}} + {{- range .Values.customVolumeMounts }} + {{- range $volumeName, $value := . }} + {{- range $i, $servicePathMap := $value }} + {{- range $serviceName, $path := $servicePathMap }} + {{- if eq $serviceName $topValues.persistentStorage.name }} + - name: {{ template "custom-pvc.name" $volumeName }} + persistentVolumeClaim: + claimName: {{ template "custom-pvc.name" $volumeName }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} {{- if .Values.dynamicSecretVolumes }} {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} {{- end }} @@ -73,6 +88,19 @@ spec: mountPath: {{ .Values.persistentStorage.path | quote }} - name: {{ include "cli-persistent.twig-storage.name" . | quote }} mountPath: {{ include "cli-persistent.twig-storage.path" . | quote }} + {{- range .Values.customVolumeMounts }} + {{- range $volumeName, $value := . }} + {{- range $i, $servicePathMap := $value }} + {{- range $serviceName, $path := $servicePathMap }} + {{- if eq $serviceName $topValues.persistentStorage.name }} + - name: {{ template "custom-pvc.name" $volumeName }} + mountPath: {{ $path }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- if .Values.dynamicSecretMounts }} {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index 9a5dacf9..6072f25b 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -7,7 +7,9 @@ if [[ -z "$DOCKER_COMPOSE_YAML" ]]; then fi EXTRA_MOUNT_VALUES_FILE="${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" -CUSTOMVOLUME_PREFIX="lcv-" # we just use this to distinguish from any other volumes that might be created + +# The prefix below CAN be used, but this should be moved into the helm templates +CUSTOMVOLUME_PREFIX="" # we just use this to distinguish from any other volumes that might be created # Parse docker-compose.yml and extract volume names with "lagoon.type: persistent" label volumes=$(yq e '.volumes | with_entries(select(.value.labels."lagoon.type" == "persistent")) | keys | .[]' "$DOCKER_COMPOSE_YAML") From 3d633450bf0d0fdb6cceda861fee2c2647b8f154 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Thu, 6 Jul 2023 08:25:13 +1200 Subject: [PATCH 09/15] Adds mounts to appropriate pods for poc --- .../cli-persistent/templates/deployment.yaml | 1 - legacy/helmcharts/cli-persistent/values.yaml | 14 ++++++- .../templates/deployment.yaml | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/legacy/helmcharts/cli-persistent/templates/deployment.yaml b/legacy/helmcharts/cli-persistent/templates/deployment.yaml index 334f2b48..cd1fbbf7 100644 --- a/legacy/helmcharts/cli-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/cli-persistent/templates/deployment.yaml @@ -100,7 +100,6 @@ spec: {{- end }} {{- end }} {{- end }} - {{- if .Values.dynamicSecretMounts }} {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} diff --git a/legacy/helmcharts/cli-persistent/values.yaml b/legacy/helmcharts/cli-persistent/values.yaml index 1df2ddc6..6fffc587 100644 --- a/legacy/helmcharts/cli-persistent/values.yaml +++ b/legacy/helmcharts/cli-persistent/values.yaml @@ -11,7 +11,7 @@ gitSha: "" image: "" persistentStorage: - name: "" + name: "cli" imagePullPolicy: Always @@ -63,3 +63,15 @@ cronjobUseSpot: false dynamicSecretMounts: [] dynamicSecretVolumes: [] + + + +customVolumeMounts: + - config: + - cli: /config + - php: /config + - files: + - cli: /app/web/sites/default/files/ + - nginx: /app/web/sites/default/files/ + - php: /app/web/sites/default/files/ + - notused: diff --git a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml index 579f1158..88b4cda3 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml @@ -36,6 +36,20 @@ spec: claimName: {{ include "nginx-php-persistent.persistentStorageName" . }} - name: {{ include "nginx-php-persistent.twig-storage.name" . | quote }} emptyDir: {} + {{/* we iterate over all the custom volumes and see if we can find our service */}} + {{- range .Values.customVolumeMounts }} + {{- range $volumeName, $value := . }} + {{- range $i, $servicePathMap := $value }} + {{- range $serviceName, $path := $servicePathMap }} + {{- if eq $serviceName $topValues.persistentStorage.name }} + - name: {{ template "custom-pvc.name" $volumeName }} + persistentVolumeClaim: + claimName: {{ template "custom-pvc.name" $volumeName }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} {{- if .Values.dynamicSecretVolumes }} {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} {{- end }} @@ -105,6 +119,18 @@ spec: volumeMounts: - name: {{ include "nginx-php-persistent.persistentStorageName" . }} mountPath: {{ .Values.persistentStorage.path | quote }} + {{- range .Values.customVolumeMounts }} + {{- range $volumeName, $value := . }} + {{- range $i, $servicePathMap := $value }} + {{- range $serviceName, $path := $servicePathMap }} + {{- if eq $serviceName $topValues.persistentStorage.name }} + - name: {{ template "custom-pvc.name" $volumeName }} + mountPath: {{ $path }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} {{- if .Values.dynamicSecretMounts }} {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} @@ -142,6 +168,18 @@ spec: mountPath: {{ .Values.persistentStorage.path | quote }} - name: {{ include "nginx-php-persistent.twig-storage.name" . | quote }} mountPath: {{ include "nginx-php-persistent.twig-storage.path" . | quote }} + {{- range .Values.customVolumeMounts }} + {{- range $volumeName, $value := . }} + {{- range $i, $servicePathMap := $value }} + {{- range $serviceName, $path := $servicePathMap }} + {{- if eq $serviceName $topValues.persistentStorage.name }} + - name: {{ template "custom-pvc.name" $volumeName }} + mountPath: {{ $path }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} {{- if .Values.dynamicSecretMounts }} {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} From 0956743110b92d46dccbc3444d539ac4ab66ec77 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Thu, 6 Jul 2023 08:46:57 +1200 Subject: [PATCH 10/15] Updating some of helm details --- legacy/helmcharts/cli-persistent/templates/deployment.yaml | 1 - .../helmcharts/nginx-php-persistent/templates/deployment.yaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/legacy/helmcharts/cli-persistent/templates/deployment.yaml b/legacy/helmcharts/cli-persistent/templates/deployment.yaml index cd1fbbf7..e2412322 100644 --- a/legacy/helmcharts/cli-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/cli-persistent/templates/deployment.yaml @@ -41,7 +41,6 @@ spec: claimName: {{ .Values.persistentStorage.name }} - name: {{ include "cli-persistent.twig-storage.name" . | quote }} emptyDir: {} - {{/* we iterate over all the custom volumes and see if we can find our service */}} {{- range .Values.customVolumeMounts }} {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} diff --git a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml index 88b4cda3..a3e0911c 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- $topValues := .Values }} apiVersion: apps/v1 kind: Deployment metadata: @@ -36,7 +37,6 @@ spec: claimName: {{ include "nginx-php-persistent.persistentStorageName" . }} - name: {{ include "nginx-php-persistent.twig-storage.name" . | quote }} emptyDir: {} - {{/* we iterate over all the custom volumes and see if we can find our service */}} {{- range .Values.customVolumeMounts }} {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} From 06c3c43729782bb718292dc27feaee7432f1f4c2 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Thu, 6 Jul 2023 13:43:22 +1200 Subject: [PATCH 11/15] Sets up helm value files --- legacy/build-deploy-docker-compose.sh | 3 ++ .../nginx-php-persistent/values.yaml | 1 + legacy/scripts/exec-gather-volumes.sh | 5 ++- .../exec-kubectl-resources-with-images.sh | 6 +-- .../extravolumes-values.yaml | 14 +++++++ legacy/scripts/test/docker-compose.yml | 42 +++++++++++++++++++ 6 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml create mode 100644 legacy/scripts/test/docker-compose.yml diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 60191587..b29fe98d 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1391,6 +1391,9 @@ set -x YAML_FOLDER="/kubectl-build-deploy/lagoon/deploymentconfigs-pvcs-cronjobs-backups" mkdir -p $YAML_FOLDER +# handle multiple pvc +. /kubectl-build-deploy/scripts/exec-gather-volumes.sh + for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}" do IFS=':' read -ra SERVICE_TYPES_ENTRY_SPLIT <<< "$SERVICE_TYPES_ENTRY" diff --git a/legacy/helmcharts/nginx-php-persistent/values.yaml b/legacy/helmcharts/nginx-php-persistent/values.yaml index 6ee09e5b..c7ef9660 100644 --- a/legacy/helmcharts/nginx-php-persistent/values.yaml +++ b/legacy/helmcharts/nginx-php-persistent/values.yaml @@ -81,3 +81,4 @@ cronjobUseSpot: false dynamicSecretMounts: [] dynamicSecretVolumes: [] + diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index 6072f25b..78bd2ee2 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -7,6 +7,7 @@ if [[ -z "$DOCKER_COMPOSE_YAML" ]]; then fi EXTRA_MOUNT_VALUES_FILE="${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" +touch ${EXTRA_MOUNT_VALUES_FILE} # The prefix below CAN be used, but this should be moved into the helm templates CUSTOMVOLUME_PREFIX="" # we just use this to distinguish from any other volumes that might be created @@ -84,4 +85,6 @@ echo "$EXTRA_VOLUMES_VALUES_YAML" echo "$EXTRA_VOLUMES_MOUNT_VALS" echo "$EXTRA_VOLUMES_VALUES_YAML" > $EXTRA_MOUNT_VALUES_FILE -echo "$EXTRA_VOLUMES_MOUNT_VALS" >> $EXTRA_MOUNT_VALUES_FILE \ No newline at end of file +echo "$EXTRA_VOLUMES_MOUNT_VALS" >> $EXTRA_MOUNT_VALUES_FILE + +helm template custom-pvc /kubectl-build-deploy/helmcharts/custom-pvc -f $EXTRA_MOUNT_VALUES_FILE > $YAML_FOLDER/pvc.yaml \ No newline at end of file diff --git a/legacy/scripts/exec-kubectl-resources-with-images.sh b/legacy/scripts/exec-kubectl-resources-with-images.sh index 669026d5..8c30f77d 100755 --- a/legacy/scripts/exec-kubectl-resources-with-images.sh +++ b/legacy/scripts/exec-kubectl-resources-with-images.sh @@ -16,15 +16,15 @@ if [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep # Add the Image Hash as Parameter of "[SERVICETYPE]_SERVICE_IMAGE" HELM_SET_VALUES+=(--set "images.${line}=${DEPLOYMENT_SERVICETYPE_IMAGE_NAME_HASH}") done < <(cat /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/values.yaml | shyaml keys images) - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml --set service_name="${SERVICE_NAME}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml --set service_name="${SERVICE_NAME}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml # check if we need a single image to inject elif [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep image) ]]; then SERVICE_NAME_IMAGE="${MAP_SERVICE_NAME_TO_IMAGENAME[${SERVICE_NAME}]}" SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${SERVICE_NAME_IMAGE}]}" cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml --set image="${SERVICE_NAME_IMAGE_HASH}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml --set image="${SERVICE_NAME_IMAGE_HASH}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml elif [ -d /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} ]; then cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml fi diff --git a/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml b/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml new file mode 100644 index 00000000..00103b9f --- /dev/null +++ b/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml @@ -0,0 +1,14 @@ +customVolumes: + - config + - files + +customVolumeMounts: + - config: + - cli: /config + - php: /config + - files: + - cli: /app/web/sites/default/files/ + - nginx: /app/web/sites/default/files/ + - php: /app/web/sites/default/files/ + - notused: + diff --git a/legacy/scripts/test/docker-compose.yml b/legacy/scripts/test/docker-compose.yml new file mode 100644 index 00000000..855e612f --- /dev/null +++ b/legacy/scripts/test/docker-compose.yml @@ -0,0 +1,42 @@ +volumes: + config: + labels: + lagoon.type: persistent + files: + labels: + lagoon.type: persistent + db: + labels: + lagoon.type: none ## not technically needed, but explicit + notused: + labels: + lagoon.type: persistent ## not technically needed, but explicit + logs: + {} + +services: + + cli: + labels: + lagoon.type: cli-persistent + lagoon.volumes.files.path: /app/web/sites/default/files/ + lagoon.volumes.config.path: /config + + nginx: + labels: + lagoon.type: nginx-php-persistent + lagoon.volumes.files.path: /app/web/sites/default/files/ + + php: + labels: + lagoon.type: nginx-php-persistent + lagoon.volumes.files.path: /app/web/sites/default/files/ + lagoon.volumes.config.path: /config + + mariadb: + image: uselagoon/mariadb-10.5-drupal:latest + labels: + lagoon.type: mariadb + lando.type: mariadb-drupal + volumes: + - db:/var/lib/mysql \ No newline at end of file From 5da6d66f11cdb6a6216c1d3b6119dd93b8c35b2b Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Thu, 6 Jul 2023 15:19:08 +1200 Subject: [PATCH 12/15] Removing and changing data --- legacy/helmcharts/cli-persistent/values.yaml | 12 ------ legacy/helmcharts/custom-pvc/values.yaml | 23 +--------- legacy/scripts/exec-gather-volumes.sh | 9 +++- .../exec-kubectl-resources-with-images.sh | 6 +-- .../extravolumes-values.yaml | 14 ------- legacy/scripts/test/docker-compose.yml | 42 ------------------- 6 files changed, 11 insertions(+), 95 deletions(-) delete mode 100644 legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml delete mode 100644 legacy/scripts/test/docker-compose.yml diff --git a/legacy/helmcharts/cli-persistent/values.yaml b/legacy/helmcharts/cli-persistent/values.yaml index 6fffc587..480eefdc 100644 --- a/legacy/helmcharts/cli-persistent/values.yaml +++ b/legacy/helmcharts/cli-persistent/values.yaml @@ -63,15 +63,3 @@ cronjobUseSpot: false dynamicSecretMounts: [] dynamicSecretVolumes: [] - - - -customVolumeMounts: - - config: - - cli: /config - - php: /config - - files: - - cli: /app/web/sites/default/files/ - - nginx: /app/web/sites/default/files/ - - php: /app/web/sites/default/files/ - - notused: diff --git a/legacy/helmcharts/custom-pvc/values.yaml b/legacy/helmcharts/custom-pvc/values.yaml index b7afb9b5..c8b86a5e 100644 --- a/legacy/helmcharts/custom-pvc/values.yaml +++ b/legacy/helmcharts/custom-pvc/values.yaml @@ -8,25 +8,4 @@ # this is the default persistentStorage size for PVCs persistentStorage: - size: 5Gi - -customVolumes: - - config - - files - -customVolumeMounts: - - config: - - cli: /config - - php: /config - - files: - - cli: /app/web/sites/default/files/ - - nginx: /app/web/sites/default/files/ - - php: /app/web/sites/default/files/ - - notused: - - -nameOverride: oiwjef - -project: oweifj - -lagoonVersion: 21 + size: 5Gi \ No newline at end of file diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index 78bd2ee2..5b6f8b8d 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -6,7 +6,7 @@ if [[ -z "$DOCKER_COMPOSE_YAML" ]]; then exit fi -EXTRA_MOUNT_VALUES_FILE="${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" +EXTRA_MOUNT_VALUES_FILE="/${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/extravolumes-values.yaml" touch ${EXTRA_MOUNT_VALUES_FILE} # The prefix below CAN be used, but this should be moved into the helm templates @@ -87,4 +87,9 @@ echo "$EXTRA_VOLUMES_MOUNT_VALS" echo "$EXTRA_VOLUMES_VALUES_YAML" > $EXTRA_MOUNT_VALUES_FILE echo "$EXTRA_VOLUMES_MOUNT_VALS" >> $EXTRA_MOUNT_VALUES_FILE -helm template custom-pvc /kubectl-build-deploy/helmcharts/custom-pvc -f $EXTRA_MOUNT_VALUES_FILE > $YAML_FOLDER/pvc.yaml \ No newline at end of file + +helm template custom-pvc /kubectl-build-deploy/helmcharts/custom-pvc -f $EXTRA_MOUNT_VALUES_FILE > $YAML_FOLDER/pvc.yaml + +echo "********** OUTPUT pvc.yaml *********" +cat $YAML_FOLDER/pvc.yaml +echo "********** END pvc.yaml *********" \ No newline at end of file diff --git a/legacy/scripts/exec-kubectl-resources-with-images.sh b/legacy/scripts/exec-kubectl-resources-with-images.sh index 8c30f77d..4e714d6b 100755 --- a/legacy/scripts/exec-kubectl-resources-with-images.sh +++ b/legacy/scripts/exec-kubectl-resources-with-images.sh @@ -16,15 +16,15 @@ if [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep # Add the Image Hash as Parameter of "[SERVICETYPE]_SERVICE_IMAGE" HELM_SET_VALUES+=(--set "images.${line}=${DEPLOYMENT_SERVICETYPE_IMAGE_NAME_HASH}") done < <(cat /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/values.yaml | shyaml keys images) - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml --set service_name="${SERVICE_NAME}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/extravolumes-values.yaml --set service_name="${SERVICE_NAME}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml # check if we need a single image to inject elif [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep image) ]]; then SERVICE_NAME_IMAGE="${MAP_SERVICE_NAME_TO_IMAGENAME[${SERVICE_NAME}]}" SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${SERVICE_NAME_IMAGE}]}" cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml --set image="${SERVICE_NAME_IMAGE_HASH}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/extravolumes-values.yaml --set image="${SERVICE_NAME_IMAGE_HASH}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml elif [ -d /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} ]; then cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/pvc.yaml "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml + helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml -f /kubectl-build-deploy/extravolumes-values.yaml "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml fi diff --git a/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml b/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml deleted file mode 100644 index 00103b9f..00000000 --- a/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml +++ /dev/null @@ -1,14 +0,0 @@ -customVolumes: - - config - - files - -customVolumeMounts: - - config: - - cli: /config - - php: /config - - files: - - cli: /app/web/sites/default/files/ - - nginx: /app/web/sites/default/files/ - - php: /app/web/sites/default/files/ - - notused: - diff --git a/legacy/scripts/test/docker-compose.yml b/legacy/scripts/test/docker-compose.yml deleted file mode 100644 index 855e612f..00000000 --- a/legacy/scripts/test/docker-compose.yml +++ /dev/null @@ -1,42 +0,0 @@ -volumes: - config: - labels: - lagoon.type: persistent - files: - labels: - lagoon.type: persistent - db: - labels: - lagoon.type: none ## not technically needed, but explicit - notused: - labels: - lagoon.type: persistent ## not technically needed, but explicit - logs: - {} - -services: - - cli: - labels: - lagoon.type: cli-persistent - lagoon.volumes.files.path: /app/web/sites/default/files/ - lagoon.volumes.config.path: /config - - nginx: - labels: - lagoon.type: nginx-php-persistent - lagoon.volumes.files.path: /app/web/sites/default/files/ - - php: - labels: - lagoon.type: nginx-php-persistent - lagoon.volumes.files.path: /app/web/sites/default/files/ - lagoon.volumes.config.path: /config - - mariadb: - image: uselagoon/mariadb-10.5-drupal:latest - labels: - lagoon.type: mariadb - lando.type: mariadb-drupal - volumes: - - db:/var/lib/mysql \ No newline at end of file From d494be7d08dd1187065b33efd6a8cb4b3e812e12 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Tue, 11 Jul 2023 13:29:53 +1200 Subject: [PATCH 13/15] Hashes out some annotations --- legacy/helmcharts/custom-pvc/templates/_helpers.tpl | 2 ++ legacy/helmcharts/custom-pvc/templates/pvcs.yaml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl index 1fe8705f..6cfcaeb8 100644 --- a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl +++ b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl @@ -39,10 +39,12 @@ Lagoon Labels {{- define "custom-pvc.lagoonLabels" -}} lagoon.sh/service: {{ .Release.Name }} lagoon.sh/service-type: {{ .Chart.Name }} +{{/* Get these sorted lagoon.sh/project: {{ .Values.project }} lagoon.sh/environment: {{ .Values.environment }} lagoon.sh/environmentType: {{ .Values.environmentType }} lagoon.sh/buildType: {{ .Values.buildType }} +*/}} {{- end -}} diff --git a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml index 70aa837f..0cca784f 100644 --- a/legacy/helmcharts/custom-pvc/templates/pvcs.yaml +++ b/legacy/helmcharts/custom-pvc/templates/pvcs.yaml @@ -7,8 +7,10 @@ metadata: name: {{ template "custom-pvc.name" (dict "IterationValues" . "Context" $context ) }} labels: {{- include "custom-pvc.labels" (dict "IterationValues" . "Context" $context ) | nindent 4 }} -annotations: - {{- include "custom-pvc.annotations" $context | nindent 4 }} +{{/* + annotations: + { { - include "custom-pvc.annotations" $context | nindent 4 } } +*/}} spec: accessModes: - ReadWriteMany From c59e9194c00299010b33e46975658d1cebe5bc38 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 12 Jul 2023 09:04:17 +1200 Subject: [PATCH 14/15] Further work on templating --- legacy/helmcharts/cli-persistent/templates/deployment.yaml | 4 ++-- .../helmcharts/nginx-php-persistent/templates/_helpers.tpl | 5 +++++ .../nginx-php-persistent/templates/deployment.yaml | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/legacy/helmcharts/cli-persistent/templates/deployment.yaml b/legacy/helmcharts/cli-persistent/templates/deployment.yaml index e2412322..a42d1047 100644 --- a/legacy/helmcharts/cli-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/cli-persistent/templates/deployment.yaml @@ -45,7 +45,7 @@ spec: {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} {{- range $serviceName, $path := $servicePathMap }} - {{- if eq $serviceName $topValues.persistentStorage.name }} + {{- if eq $serviceName $.Release.Name }} - name: {{ template "custom-pvc.name" $volumeName }} persistentVolumeClaim: claimName: {{ template "custom-pvc.name" $volumeName }} @@ -91,7 +91,7 @@ spec: {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} {{- range $serviceName, $path := $servicePathMap }} - {{- if eq $serviceName $topValues.persistentStorage.name }} + {{- if eq $serviceName $.Release.Name }} - name: {{ template "custom-pvc.name" $volumeName }} mountPath: {{ $path }} {{- end }} diff --git a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl b/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl index 0d290874..5a1e103c 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl +++ b/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl @@ -135,3 +135,8 @@ Generate path for twig storage emptyDir {{- define "nginx-php-persistent.twig-storage.path" -}} {{- printf "%s/php" .Values.persistentStorage.path }} {{- end -}} + + +{{- define "custom-pvc.name" -}} +{{- printf "lcv-%s" . | trunc 63 | trimSuffix "-" -}} +{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml index a3e0911c..df4cb967 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml @@ -41,7 +41,7 @@ spec: {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} {{- range $serviceName, $path := $servicePathMap }} - {{- if eq $serviceName $topValues.persistentStorage.name }} + {{- if eq $serviceName $.Release.Name }} - name: {{ template "custom-pvc.name" $volumeName }} persistentVolumeClaim: claimName: {{ template "custom-pvc.name" $volumeName }} @@ -123,7 +123,7 @@ spec: {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} {{- range $serviceName, $path := $servicePathMap }} - {{- if eq $serviceName $topValues.persistentStorage.name }} + {{- if eq $serviceName $.Release.Name }} - name: {{ template "custom-pvc.name" $volumeName }} mountPath: {{ $path }} {{- end }} @@ -172,7 +172,7 @@ spec: {{- range $volumeName, $value := . }} {{- range $i, $servicePathMap := $value }} {{- range $serviceName, $path := $servicePathMap }} - {{- if eq $serviceName $topValues.persistentStorage.name }} + {{- if eq $serviceName $.Release.Name }} - name: {{ template "custom-pvc.name" $volumeName }} mountPath: {{ $path }} {{- end }} From b6699182211020322b3dac0db864daf605ebcbe4 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Wed, 12 Jul 2023 09:16:46 +1200 Subject: [PATCH 15/15] Adds custom more labels --- legacy/helmcharts/custom-pvc/templates/_helpers.tpl | 2 -- legacy/scripts/exec-gather-volumes.sh | 6 +----- .../scripts/kubectl-build-deploy/extravolumes-values.yaml | 8 ++++++++ 3 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml diff --git a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl index 6cfcaeb8..1fe8705f 100644 --- a/legacy/helmcharts/custom-pvc/templates/_helpers.tpl +++ b/legacy/helmcharts/custom-pvc/templates/_helpers.tpl @@ -39,12 +39,10 @@ Lagoon Labels {{- define "custom-pvc.lagoonLabels" -}} lagoon.sh/service: {{ .Release.Name }} lagoon.sh/service-type: {{ .Chart.Name }} -{{/* Get these sorted lagoon.sh/project: {{ .Values.project }} lagoon.sh/environment: {{ .Values.environment }} lagoon.sh/environmentType: {{ .Values.environmentType }} lagoon.sh/buildType: {{ .Values.buildType }} -*/}} {{- end -}} diff --git a/legacy/scripts/exec-gather-volumes.sh b/legacy/scripts/exec-gather-volumes.sh index 5b6f8b8d..83493442 100755 --- a/legacy/scripts/exec-gather-volumes.sh +++ b/legacy/scripts/exec-gather-volumes.sh @@ -88,8 +88,4 @@ echo "$EXTRA_VOLUMES_VALUES_YAML" > $EXTRA_MOUNT_VALUES_FILE echo "$EXTRA_VOLUMES_MOUNT_VALS" >> $EXTRA_MOUNT_VALUES_FILE -helm template custom-pvc /kubectl-build-deploy/helmcharts/custom-pvc -f $EXTRA_MOUNT_VALUES_FILE > $YAML_FOLDER/pvc.yaml - -echo "********** OUTPUT pvc.yaml *********" -cat $YAML_FOLDER/pvc.yaml -echo "********** END pvc.yaml *********" \ No newline at end of file +helm template custom-pvc /kubectl-build-deploy/helmcharts/custom-pvc -f $EXTRA_MOUNT_VALUES_FILE -f /kubectl-build-deploy/values.yaml > $YAML_FOLDER/pvc.yaml \ No newline at end of file diff --git a/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml b/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml new file mode 100644 index 00000000..02a2aebb --- /dev/null +++ b/legacy/scripts/kubectl-build-deploy/extravolumes-values.yaml @@ -0,0 +1,8 @@ + + +customVolumes: + - testmount + +customVolumeMounts: + - testmount: + - cli: /testmount/ \ No newline at end of file