-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from all commits
e9745c8
4680b1d
e604855
8e044b2
42f5a78
2e37cab
153813a
896a4fd
8e5965d
18c10a9
8f3928b
a533fab
c74779b
58b6a83
a985d0d
0677c42
7cc04ab
e1ce7c8
e7d0973
2fe8ba4
f659772
7f3d807
952de06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
NGINX=$(kubectl get pod -n $ns -l lagoon.sh/service=nginx -o name | head -n1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
CLI=$(kubectl get pod -n $ns -l lagoon.sh/service=cli --no-headers | grep -v cronjob | grep Running | awk '{print $1}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kubectl exec -n $ns $NGINX -- tar cf - /app/web/sites/default/files | kubectl exec -i -n $ns $CLI -- tar xvfk - -C / || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
# 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"}}]}}}}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# Get pvc variable | ||
PV_NAME=$(kubectl get pv -n $NAMESPACE new-nginx | grep pvc | awk '{print $3}') || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
echo $PV_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if [ -z $PV_NAME ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
echo "skipping" | ||
continue | ||
fi | ||
echo $PV_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
# Delete old PVC from namespace | ||
kubectl delete pvc -n $NAMESPACE new-nginx --wait=false || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kubectl patch pvc -n $NAMESPACE new-nginx -p '{"metadata":{"finalizers":null}}' || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# 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" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
kubectl get pv $VOLUME_NAME -o yaml > "./pvAndPvcBackup/${NAMESPACE}_${VOLUME_NAME}" | ||||||||||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shellcheck (suggestion)] reported by reviewdog 🐶
Suggested change
|
||||||||||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shellcheck (suggestion)] reported by reviewdog 🐶
Suggested change
|
||||||||||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shellcheck (suggestion)] reported by reviewdog 🐶
Suggested change
|
||||||||||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# Get pvc variable | ||
SHARE_NAME=$(kubectl get pvc -n $ns tmp-nginx | grep pvc | awk '{print $3}' | cut -c 5- ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# echo $SHARE_NAME | ||
|
||
PROJECT_NAME=$(echo $ns | rev | cut -c 6- | rev) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# 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"}}]}}}}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kubectl patch deployments.apps -n $ns nginx -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "nginx"}}]}}}}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
done |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kubectl patch deployments.apps -n $ns nginx -p '{"spec":{"template":{"spec": {"volumes": [{"name": "nginx", "persistentVolumeClaim": { "claimName": "tmp-nginx"}}]}}}}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
kubectl patch -n $ns pvc nginx -p '{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"metadata": { | ||
"annotations": { | ||
"kubectl.kubernetes.io/last-applied-configuration": null | ||
} | ||
} | ||
}' || true | ||
done |
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 |
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" |
There was a problem hiding this comment.
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