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

Switch from in tree to csi #448

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e9745c8
add a staging site for the DDF people to test on and give canary back…
Aug 19, 2024
4680b1d
Intermediary SC for the new CSI pluging
Aug 22, 2024
e604855
new PV for using with CSI
Aug 22, 2024
8e044b2
new PVC for using with CSI
Aug 22, 2024
42f5a78
script that creates new PV and PVC, using CSI, for a namespace and pa…
Aug 22, 2024
2e37cab
patch the deployment to use the new PVC
Aug 22, 2024
153813a
check that the namespace exists before doing anything
Aug 22, 2024
896a4fd
clean up the old pvc and pv
Aug 22, 2024
8e5965d
make a backup before deletion
Aug 23, 2024
18c10a9
sharename was wrong
Aug 23, 2024
8f3928b
needed to be split as the names are not the same
Aug 26, 2024
a533fab
point to the new one - we're done testing for now
Aug 26, 2024
c74779b
backups from sites the script has been run on
Aug 26, 2024
58b6a83
update name of the new csi, so lagoon can find and use it
Aug 28, 2024
a985d0d
point to the new SC as the provider
Aug 28, 2024
0677c42
changes after having run scripts
Aug 28, 2024
7cc04ab
we wont need this anymore
Aug 28, 2024
e1ce7c8
script to copy files from nginx to cli pod in a namespace
Aug 28, 2024
e7d0973
script to delete obsolote pv's and pvc's
Aug 28, 2024
2fe8ba4
script to make temporary pv and pvc's for namespace
Aug 28, 2024
f659772
script to patch the nginx's in a namespace so they use the right storage
Aug 28, 2024
7f3d807
script to patch the metadata so lagoon will recognize the pvc's
Aug 28, 2024
952de06
clean up the infrastruture folder
Aug 28, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Start a KK Shell session
#
# Syntax:
# dplsh [-p profile-name] [additional shell args]
#
set -euo pipefail

NAMESPACES=$(kubectl get ns -l lagoon.sh/controller=lagoon --no-headers | awk '{print $1}' | grep herning)

for ns in $NAMESPACES; do
echo $ns
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

NGINX=$(kubectl get pod -n $ns -l lagoon.sh/service=nginx -o name | head -n1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

CLI=$(kubectl get pod -n $ns -l lagoon.sh/service=cli --no-headers | grep -v cronjob | grep Running | awk '{print $1}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl exec -n $ns $NGINX -- tar cf - /app/web/sites/default/files | kubectl exec -i -n $ns $CLI -- tar xvfk - -C / || true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

done
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
#
# This script creates new PersistentVolumeClaims and PersistentVolumes for a namespace
#

set -euo pipefail

source ./deleteOldPvAndPvc.sh

# Test the entered namespace for good measure
kubectl get ns $1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086


echo "Adding new PVC and PV to $1"

#Get the volume name of the PV
VOLUME_NAME=$(kubectl get pvc -n $1 nginx | grep pvc | awk '{print $3}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# Change it's name slighty so we can recognize it from the old ones
NEW="new-"
NEW_VOLUME_NAME=${NEW}${VOLUME_NAME}
echo $NEW_VOLUME_NAME
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086


# Set the PVC's volumeName to the new volume name
volumeName=$NEW_VOLUME_NAME yq -i '.spec.volumeName = strenv(volumeName)' pvc.yaml
namespace=$1 yq -i '.metadata.namespace = strenv(namespace)' pvc.yaml

# Set the PV's name to the new volume name
volumeName=$NEW_VOLUME_NAME yq -i '.metadata.name = strenv(volumeName)' pv.yaml
# The sharename is the same as we are doing a logical deletion and not a real one
shareName=$VOLUME_NAME yq -i '.spec.csi.volumeAttributes.shareName = strenv(shareName)' pv.yaml

# Apply the new PV and PVC to the cluster
kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml

# Switch the nginx deployments nginx volume to use the new PVC
kubectl patch deployments.apps -n $1 nginx -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "new-nginx"}}]}}}}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086


echo "$1 is now using the intermediary SC via it's new PVC and PV. The Nginx has been patched and new pods spun up"

echo "Proceeding to remove the now obsolete PV and PVC from the namespace $1"

backupAndDeleteOldPvAndPvc $1 $VOLUME_NAME "nginx"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086


echo ######## Done ########
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
#
# This script creates new PersistentVolumeClaims and PersistentVolumes for a namespace
#

set -euo pipefail

NAMESPACES=$(kubectl get ns -l lagoon.sh/controller=lagoon --no-headers | awk '{print $1}')
for NAMESPACE in $NAMESPACES; do
echo $NAMESPACE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# Get pvc variable
PV_NAME=$(kubectl get pv -n $NAMESPACE new-nginx | grep pvc | awk '{print $3}') || true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

echo $PV_NAME
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

if [ -z $PV_NAME ]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

echo "skipping"
continue
fi
echo $PV_NAME
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086


# Delete old PVC from namespace
kubectl delete pvc -n $NAMESPACE new-nginx --wait=false || true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl patch pvc -n $NAMESPACE new-nginx -p '{"metadata":{"finalizers":null}}' || true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# Mark old PV as up for deletion
# kubectl delete pv $PV_NAME --grace-period=0 --wait=false || true
# kubectl patch pv $PV_NAME -p '{"metadata":{"finalizers":null}}' || true

done
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# This script creates new PersistentVolumeClaims and PersistentVolumes for a namespace
#

set -euo pipefail

function backupAndDeleteOldPvAndPvc() {
local NAMESPACE=$1
local VOLUME_NAME=$2
local PVC_NAME=$3

# Backup the the old PVC and PV before deleting them
kubectl get pvc -n $NAMESPACE $PVC_NAME -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${PVC_NAME}.yaml"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl get pv $VOLUME_NAME -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${VOLUME_NAME}"
Comment on lines +14 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
kubectl get pvc -n $NAMESPACE $PVC_NAME -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${PVC_NAME}.yaml"
kubectl get pv $VOLUME_NAME -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${VOLUME_NAME}"
kubectl get pvc -n "$NAMESPACE" "$PVC_NAME" -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${PVC_NAME}.yaml"
kubectl get pv "$VOLUME_NAME" -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${VOLUME_NAME}"

# Delete old PVC from namespace
kubectl delete pvc -n $NAMESPACE $PVC_NAME --wait=false
kubectl patch pvc -n $NAMESPACE $PVC_NAME -p '{"metadata":{"finalizers":null}}'
Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
kubectl delete pvc -n $NAMESPACE $PVC_NAME --wait=false
kubectl patch pvc -n $NAMESPACE $PVC_NAME -p '{"metadata":{"finalizers":null}}'
kubectl delete pvc -n "$NAMESPACE" "$PVC_NAME" --wait=false
kubectl patch pvc -n "$NAMESPACE" "$PVC_NAME" -p '{"metadata":{"finalizers":null}}'

# Mark old PV as up for deletion
kubectl delete pv $VOLUME_NAME --grace-period=0 --wait=false
kubectl patch pv $VOLUME_NAME -p '{"metadata":{"finalizers":null}}'
Comment on lines +20 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
kubectl delete pv $VOLUME_NAME --grace-period=0 --wait=false
kubectl patch pv $VOLUME_NAME -p '{"metadata":{"finalizers":null}}'
kubectl delete pv "$VOLUME_NAME" --grace-period=0 --wait=false
kubectl patch pv "$VOLUME_NAME" -p '{"metadata":{"finalizers":null}}'

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
#
# Start a KK Shell session
#
# Syntax:
# dplsh [-p profile-name] [additional shell args]
#
set -euo pipefail

NAMESPACES=$(kubectl get ns -l lagoon.sh/controller=lagoon --no-headers | awk '{print $1}' | grep main)
VOLUMEHANDLE_PREFIX="/subscriptions/8ac8a259-5bb3-4799-bd1e-455145b12550/resourceGroups/rg-env-dplplat01/providers/Microsoft.Storage/storageAccounts/stdpldplplat01585708af/"
for ns in $NAMESPACES; do
echo $ns
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# Get pvc variable
SHARE_NAME=$(kubectl get pvc -n $ns tmp-nginx | grep pvc | awk '{print $3}' | cut -c 5- )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# echo $SHARE_NAME

PROJECT_NAME=$(echo $ns | rev | cut -c 6- | rev)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

# echo $PROJECT_NAME
# Set the PV's name to the new sharename
volumeName="$SHARE_NAME" yq -i '.metadata.name = strenv(volumeName)' pv.yaml
# The sharename is the same as we are doing a logical deletion and not a real one
shareName=$SHARE_NAME yq -i '.spec.csi.volumeAttributes.shareName = strenv(shareName)' pv.yaml

volumeHandle="$VOLUMEHANDLE_PREFIX$SHARE_NAME" yq -i '.spec.csi.volumeHandle = strenv(volumeHandle)' pv.yaml
namespace=$ns yq -i '.metadata.namespace = strenv(namespace)' pv.yaml
namespace=$ns yq -i '.spec.csi.nodeStageSecretRef.namespace = strenv(namespace)' pv.yaml
# cat pv.yaml

namespace=$ns yq -i '.metadata.namespace = strenv(namespace)' pvc.yaml
volumeName="$SHARE_NAME" yq -i '.spec.volumeName = strenv(volumeName)' pvc.yaml
projectName=$PROJECT_NAME yq -i '.metadata.labels."lagoon.sh/project" = strenv(projectName)' pvc.yaml
# cat pvc.yaml
kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml

kubectl patch deployments.apps -n $ns cli -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "nginx"}}]}}}}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl patch deployments.apps -n $ns nginx -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "nginx"}}]}}}}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

done
12 changes: 12 additions & 0 deletions infrastructure/dpladm/bin/csi-migration-scripts/new-bulk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: bulk
provisioner: file.csi.azure.com
reclaimPolicy: Retain
volumeBindingMode: Immediate
allowVolumeExpansion: true
parameters:
resourcegroup: rg-env-dplplat01
skuName: Standard_LRS
storageAccount: stdpldplplat01585708af
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
#
# Start a KK Shell session
#
# Syntax:
# dplsh [-p profile-name] [additional shell args]
#
set -euo pipefail

NAMESPACES=$(kubectl get ns -l lagoon.sh/controller=lagoon --no-headers | awk '{print $1}' )

for ns in $NAMESPACES; do
echo $ns
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl patch deployments.apps -n $ns nginx -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "tmp-nginx"}}]}}}}'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

done
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Start a KK Shell session
#
# Syntax:
# dplsh [-p profile-name] [additional shell args]
#
set -euo pipefail

NAMESPACES=$(kubectl get ns -l lagoon.sh/controller=lagoon --no-headers | awk '{print $1}')
for ns in $NAMESPACES; do
echo $ns
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

kubectl patch -n $ns pvc nginx -p '{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": null
}
}
}' || true
done
32 changes: 32 additions & 0 deletions infrastructure/dpladm/bin/csi-migration-scripts/pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: PersistentVolume
metadata:
annotations:
pv.kubernetes.io/provisioned-by: file.csi.azure.com
name: pvc-5e5d8491-5ed5-4f92-ad51-598e507a9826
namespace: vordingborg-main
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: bulk
csi:
driver: file.csi.azure.com
readOnly: false
volumeHandle: /subscriptions/8ac8a259-5bb3-4799-bd1e-455145b12550/resourceGroups/rg-env-dplplat01/providers/Microsoft.Storage/storageAccounts/stdpldplplat01585708af/pvc-5e5d8491-5ed5-4f92-ad51-598e507a9826 # make sure volumeid is unique for every identical share in the cluster
volumeAttributes:
resourceGroup: rg-env-dplplat01 # optional, only set this when storage account is not in the same resource group as the cluster nodes
shareName: pvc-5e5d8491-5ed5-4f92-ad51-598e507a9826
nodeStageSecretRef:
name: azure-storage-account-stdpldplplat01585708af-secret
namespace: vordingborg-main
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=0
- gid=0
- mfsymlinks
- nosharesock
- nobrl # disable sending byte range lock requests to the server and for applications which have challenges with posix locks
31 changes: 31 additions & 0 deletions infrastructure/dpladm/bin/csi-migration-scripts/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
k8up.syn.tools/backup: "true"
lagoon.sh/branch: main
lagoon.sh/version: 23.12.0
finalizers:
- kubernetes.io/pvc-protection
labels:
app.kubernetes.io/instance: nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: nginx-php-persistent
helm.sh/chart: nginx-php-persistent-0.1.0
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: vordingborg
lagoon.sh/service: nginx
lagoon.sh/service-type: nginx-php-persistent
name: nginx
namespace: "vordingborg-main"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: bulk
volumeMode: Filesystem
volumeName: "pvc-5e5d8491-5ed5-4f92-ad51-598e507a9826"
10 changes: 9 additions & 1 deletion infrastructure/environments/dplplat01/sites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ sites:
# Testing and instructional sites
canary:
name: "Canary"
description: "A site to test new releases on"
description: "A site for developers and operators to test on"
releaseImageRepository: ghcr.io/danskernesdigitalebibliotek
releaseImageName: dpl-cms-source
dpl-cms-release: "2024.36.0"
plan: webmaster
moduletest-dpl-cms-release: "2024.36.0"
deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIhuA0K7CNvRoe+Xx7RaXG4+a8KcSpzuWn+G4sUPzNWx"
staging:
name: "Staging"
description: "A site to test new releases on"
releaseImageRepository: ghcr.io/danskernesdigitalebibliotek
releaseImageName: dpl-cms-source
dpl-cms-release: "2024.33.0"
plan: webmaster
deploy_key:
cms-school:
name: "CMS-skole"
description: "Et site til undervisning i CMSet"
Expand Down
Loading