From 55f52de6fc0d5b579d78fcfc9885325cf1f2a378 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Thu, 15 Jul 2021 15:13:18 -0400 Subject: [PATCH 1/8] adding new scripts and auto genreating vd* --- README.md | 2 + configure_crcssh.sh | 3 ++ deploy_odf.sh | 56 ++++++++++------------ generate_volumes.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++ uninstall_odf.sh | 21 +++++--- 5 files changed, 158 insertions(+), 38 deletions(-) create mode 100755 configure_crcssh.sh create mode 100755 generate_volumes.sh diff --git a/README.md b/README.md index 573ffb2..892f750 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ At this time `odf-nano` does not support MacOS. If you know how to create and at ### CRC / OC Binaries - Download CRC and OC binaries from [cloud.redhat.com]((https://cloud.redhat.com/openshift/create/local) - Create CRC directlry `mkdir ~/.crc` +- configure crcssh `./configure_crcssh.sh` - Also get CRC pull secret from [cloud.redhat.com]((https://cloud.redhat.com/openshift/create/local) and save it as `~/.crc/pull-secret.txt` ## Step -1 :: Deploy CRC ### Watch Demo Video [here](https://www.youtube.com/watch?v=mae0tiLkQag) @@ -55,6 +56,7 @@ crc console --credentials > crc-creds.txt ### Prerequisites - SSH into the host machine running CRC VM - Create a few raw devices that `ODF-Nano` will use +- You can also run `./generate_volumes.sh` ``` ## Don't worry this is thin provisioned sudo -S qemu-img create -f raw ~/.crc/vdb 100G diff --git a/configure_crcssh.sh b/configure_crcssh.sh new file mode 100755 index 0000000..4b55653 --- /dev/null +++ b/configure_crcssh.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa -o StrictHostKeyChecking=no core@`crc ip`'" >> ~/.bash_aliases \ No newline at end of file diff --git a/deploy_odf.sh b/deploy_odf.sh index ac56681..1c3c42f 100755 --- a/deploy_odf.sh +++ b/deploy_odf.sh @@ -6,6 +6,7 @@ #!/bin/bash set +x echo "Setting up environment for ODF - this will take a few minutes" +VOLUME_COUNT="$(ls ~/.crc/vd* | wc -l)" oc label "$(oc get no -o name)" cluster.ocs.openshift.io/openshift-storage='' --overwrite >/dev/null @@ -82,44 +83,32 @@ apiVersion: storage.k8s.io/v1 metadata: name: localblock provisioner: kubernetes.io/no-provisioner +EOF + + +for vdisk in ~/.crc/vd* +do + virtual_disk="${vdisk##*/}" + virtual_drive="${virtual_disk%.*}" + + echo "Create local-pv-${virtual_drive} for ODF-Nano" + disk_size=$(ls -lath ~/.crc/${virtual_drive} | grep -oE [0-9]{3}G) +cat </dev/null --- apiVersion: v1 kind: PersistentVolume metadata: - name: local-pv-vdb -spec: - capacity: - storage: 100Gi - volumeMode: Block - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Delete - storageClassName: localblock - local: - path: /dev/vdb - nodeAffinity: - required: - nodeSelectorTerms: - - matchExpressions: - - key: node.openshift.io/os_id - operator: In - values: - - rhcos ---- -apiVersion: v1 -kind: PersistentVolume -metadata: - name: local-pv-vdc + name: local-pv-${virtual_drive} spec: capacity: - storage: 100Gi + storage: ${disk_size}i volumeMode: Block accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: localblock local: - path: /dev/vdc + path: /dev/${virtual_drive} nodeAffinity: required: nodeSelectorTerms: @@ -129,6 +118,8 @@ spec: values: - rhcos EOF +sleep 2s +done seq 20 30 | xargs -n1 -P0 -I {} oc patch pv/pv00{} -p '{"metadata":{"annotations":{"volume.beta.kubernetes.io/storage-class": "localfile"}}}' >/dev/null @@ -153,7 +144,7 @@ data: mon_osd_nearfull_ratio = .75 mon_max_pg_per_osd = 600 osd_pool_default_min_size = 1 - osd_pool_default_size = 2 + osd_pool_default_size = ${VOLUME_COUNT} [osd] osd_memory_target_cgroup_limit_ratio = 0.5 kind: ConfigMap @@ -221,7 +212,7 @@ spec: manageNodes: false monDataDirHostPath: /var/lib/rook storageDeviceSets: - - count: 2 + - count: ${VOLUME_COUNT} dataPVCTemplate: spec: accessModes: @@ -336,7 +327,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} metadataPool: compressionMode: "" crushRoot: "" @@ -349,7 +340,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} metadataServer: activeCount: 1 activeStandby: false @@ -444,7 +435,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} gateway: allNodes: false instances: 1 @@ -462,7 +453,7 @@ spec: dataChunks: 0 failureDomain: osd replicated: - size: 2 + size: ${VOLUME_COUNT} requireSafeReplicaSize: false EOF @@ -506,3 +497,4 @@ spec: EOF echo "ODF is installed now" + diff --git a/generate_volumes.sh b/generate_volumes.sh new file mode 100755 index 0000000..3bd74b3 --- /dev/null +++ b/generate_volumes.sh @@ -0,0 +1,114 @@ +#!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases + +read -p "Enter volume count Example: 2 > " VOLUME_COUNT +read -p "Enter volume size Example: 100 > " VOLUME_SIZE + +if [ ${VOLUME_COUNT} -gt 5 ]; +then + echo "Volume count of ${VOLUME_COUNT} is too high" + echo "A max of five volumes may be added." + exit 1 +fi + + +if [ ${VOLUME_COUNT} -lt 2 ]; +then + echo "setting default volume count to 2" + VOLUME_COUNT=2 +fi + +if [ ${VOLUME_SIZE} -lt 100 ] +then + echo "setting default volume size to 100" + VOLUME_SIZE=100 +fi + +virtual_drive[1]="vdb" +virtual_drive[2]="vdc" +virtual_drive[3]="vdd" +virtual_drive[4]="vde" +virtual_drive[5]="vdf" + +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo "Create ${virtual_drive[$i]} for ODF-Nano" + sudo -S qemu-img create -f raw ~/.crc/${virtual_drive[$i]} ${VOLUME_SIZE}G +done + +CRC_STATUS=$(crc status | grep "CRC VM:" | awk '{print $3}') +if [ $CRC_STATUS == "Running" ]; +then + echo "crc stop" + crc stop +fi +sudo virsh list --all +sudo virsh dumpxml crc > ~/crc.xml + +BUS=$(grep -o '0x03' ~/crc.xml| egrep -o '.{1}$') + +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo "Checking that ${virtual_drive[$i]} exists on crc" + if grep '/home/admin/.crc/'${virtual_drive[$i]}'' ~/crc.xml > /dev/null + then + echo "$HOME/.crc/${virtual_drive[$i]} already exists in ~/crc.xml" + exit 1 + fi +done + +if [ ${BUS} -ne 3 ]; +then + echo "Incorrect address bus for drive" + exit 1 +fi + +if [ -f ~/crc-patch.xml ]; +then + rm ~/crc-patch.xml + touch ~/crc-patch.xml +else + touch ~/crc-patch.xml +fi + +echo ' ' > ~/crc-patch.xml +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo ${virtual_drive[$i]} + address_bus=$(($BUS + $i + 1)) + +sudo tee -a ~/crc-patch.xml > /dev/null < + + + + + +
+ +EOT +done + +cp ~/crc.xml ~/crc-backup.xml + +line=$(grep -n '' ~/crc.xml | cut -d ":" -f 1) +line=$(grep -n '' ~/crc.xml | cut -d ":" -f 1) +{ head -n $(($line-1)) ~/crc.xml; cat ~/crc-patch.xml; tail -n +$(($line+1)) ~/crc.xml; } > ~/crc-mod.xml +cat ~/crc-mod.xml +sed -i "s|~|$HOME|g" ~/crc-mod.xml +sudo virsh define ~/crc-mod.xml || exit $? + +read -p "Would you like to start CRC? (y/n)" -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + crc start +fi + +echo "Block creation validation" +crcssh lsblk + +echo "To restore configutation run the following." +echo "$ sudo virsh define ~/crc-backup.xml" +echo "$ crc start " \ No newline at end of file diff --git a/uninstall_odf.sh b/uninstall_odf.sh index 81e913d..9d4920e 100644 --- a/uninstall_odf.sh +++ b/uninstall_odf.sh @@ -1,4 +1,6 @@ #!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases oc annotate storagecluster ocs-storagecluster uninstall.ocs.openshift.io/cleanup-policy="delete" --overwrite oc annotate storagecluster ocs-storagecluster uninstall.ocs.openshift.io/mode="forced" --overwrite @@ -31,9 +33,16 @@ oc project default for i in $(oc get node -l cluster.ocs.openshift.io/openshift-storage= -o jsonpath='{ .items[*].metadata.name }'); do oc debug node/${i} -- chroot /host rm -rfv /mnt/local-storage/${SC}/; done oc delete localvolumediscovery.local.storage.openshift.io/auto-discover-devices -n openshift-local-storage -alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa core@"$(crc ip)"' -for i in vdb vdc ; do crcssh sudo wipefs -af /dev/$i ; done -for i in vdb vdc ; do crcssh sudo sgdisk --zap-all /dev/$i ; done -for i in vdb vdc ; do crcssh sudo dd if=/dev/zero of=/dev/$i bs=1M count=100 oflag=direct,dsync ; done -for i in vdb vdc ; do crcssh sudo blkdiscard /dev/$i ; done - +for vdisk in ~/.crc/vd* +do + virtual_disk="${vdisk##*/}" + virtual_drive="${virtual_disk%.*}" + echo "Wiping $virtual_drive" + crcssh sudo wipefs -af /dev/$vdisk ; + sleep 2s + crcssh sudo sgdisk --zap-all /dev/$vdisk + sleep 2s + crcssh sudo dd if=/dev/zero of=/dev/$vdisk bs=1M count=100 oflag=direct,dsync ; + sleep 2s + crcssh sudo blkdiscard /dev/$vdisk ; +done \ No newline at end of file From 88fb963257fe0f621949eed2f0b07fee8deef60f Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Thu, 15 Jul 2021 15:29:26 -0400 Subject: [PATCH 2/8] changing unintall_odf permissions --- uninstall_odf.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 uninstall_odf.sh diff --git a/uninstall_odf.sh b/uninstall_odf.sh old mode 100644 new mode 100755 From 2c74157c210574a6db2e80a6094ecb77aeaf8925 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Thu, 15 Jul 2021 15:30:54 -0400 Subject: [PATCH 3/8] correcting variable in uninstall script --- uninstall_odf.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uninstall_odf.sh b/uninstall_odf.sh index 9d4920e..5f82a24 100755 --- a/uninstall_odf.sh +++ b/uninstall_odf.sh @@ -38,11 +38,11 @@ do virtual_disk="${vdisk##*/}" virtual_drive="${virtual_disk%.*}" echo "Wiping $virtual_drive" - crcssh sudo wipefs -af /dev/$vdisk ; + crcssh sudo wipefs -af /dev/$virtual_drive ; sleep 2s - crcssh sudo sgdisk --zap-all /dev/$vdisk + crcssh sudo sgdisk --zap-all /dev/$virtual_drive sleep 2s - crcssh sudo dd if=/dev/zero of=/dev/$vdisk bs=1M count=100 oflag=direct,dsync ; + crcssh sudo dd if=/dev/zero of=/dev/$virtual_drive bs=1M count=100 oflag=direct,dsync ; sleep 2s - crcssh sudo blkdiscard /dev/$vdisk ; + crcssh sudo blkdiscard /dev/$virtual_drive ; done \ No newline at end of file From c3306129b1476f4fd79b15ac57664bf37199af53 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Thu, 15 Jul 2021 15:31:27 -0400 Subject: [PATCH 4/8] correcting variable in uninstall script --- uninstall_odf.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/uninstall_odf.sh b/uninstall_odf.sh index 5f82a24..84cec80 100755 --- a/uninstall_odf.sh +++ b/uninstall_odf.sh @@ -38,6 +38,7 @@ do virtual_disk="${vdisk##*/}" virtual_drive="${virtual_disk%.*}" echo "Wiping $virtual_drive" + echo "*********************" crcssh sudo wipefs -af /dev/$virtual_drive ; sleep 2s crcssh sudo sgdisk --zap-all /dev/$virtual_drive From e701de763ccb55c452588f33045d544c845ebea0 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Fri, 16 Jul 2021 12:24:19 -0400 Subject: [PATCH 5/8] adding default storage class command --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 892f750..d7a18ea 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,11 @@ oc get sc ``` - You now have File/Block/Object Persistent Storage Classes from ODF. Deploy and Test your app locally, like you do in production (OCP & ODF) +- Optional: Define default storage class +``` + oc patch storageclass ocs-storagecluster-ceph-rbd -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}} +``` + ![ODF Storage Classes](assets/odf-sc.png) # Miscelleanous From f4eca16724e3f5bfb43ef28e5868283810b30434 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 20 Jul 2021 09:17:16 -0400 Subject: [PATCH 6/8] updating crcssh --- configure_crcssh.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure_crcssh.sh b/configure_crcssh.sh index 4b55653..bf8ec01 100755 --- a/configure_crcssh.sh +++ b/configure_crcssh.sh @@ -1,3 +1,8 @@ #!/bin/bash -echo "alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa -o StrictHostKeyChecking=no core@`crc ip`'" >> ~/.bash_aliases \ No newline at end of file +if grep -q "crcssh=" ~/.bash_aliases +then + echo "crcssh already exists in ~/.bash_aliases " +else + echo "alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa -o StrictHostKeyChecking=no core@`crc ip`'" >> ~/.bash_aliases +fi From d308a3e53aae9b1b4a886ca3edef548277ca8f96 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 20 Jul 2021 09:34:33 -0400 Subject: [PATCH 7/8] adding reconfigure_sizing.sh --- generate_volumes.sh | 12 ++++++------ reconfigure_sizing.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100755 reconfigure_sizing.sh diff --git a/generate_volumes.sh b/generate_volumes.sh index 3bd74b3..cbb1413 100755 --- a/generate_volumes.sh +++ b/generate_volumes.sh @@ -104,11 +104,11 @@ echo if [[ $REPLY =~ ^[Yy]$ ]] then crc start -fi + echo "Block creation validation" + crcssh lsblk -echo "Block creation validation" -crcssh lsblk + echo "To restore configutation run the following." + echo "$ sudo virsh define ~/crc-backup.xml" + echo "$ crc start " +fi -echo "To restore configutation run the following." -echo "$ sudo virsh define ~/crc-backup.xml" -echo "$ crc start " \ No newline at end of file diff --git a/reconfigure_sizing.sh b/reconfigure_sizing.sh new file mode 100755 index 0000000..6c7a8fb --- /dev/null +++ b/reconfigure_sizing.sh @@ -0,0 +1,39 @@ +#!/bin/bash +function configure_crc(){ + crc config set consent-telemetry no + crc config set enable-cluster-monitoring true + crc config set cpus ${1} + crc config set memory ${2} + crc config view +} + +read -p "Reconfigure CPUs Example: 15 > " CPU_COUNT +read -p "Reconfigure Memory size in MB Example: 60000 > " VOLUME_SIZE + + + +CRC_STATUS=$(crc status | grep "CRC VM:" | awk '{print $3}') + +if [ ${CRC_STATUS} == "Running" ]; +then + crc stop + configure_crc ${CPU_COUNT} ${VOLUME_SIZE} +else + configure_crc ${CPU_COUNT} ${VOLUME_SIZE} +fi + + +read -p "Would you like to start CRC? (y/n)" -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + crc start + echo "Block creation validation" + crcssh lsblk + + echo "To restore configutation run the following." + echo "$ sudo virsh define ~/crc-backup.xml" + echo "$ crc start " +fi + + From 092e75e14d27660014ef8bdc6e458dbe7bc02cf6 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 20 Jul 2021 09:37:57 -0400 Subject: [PATCH 8/8] adding reconfigure_sizing.sh --- reconfigure_sizing.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/reconfigure_sizing.sh b/reconfigure_sizing.sh index 6c7a8fb..901fe24 100755 --- a/reconfigure_sizing.sh +++ b/reconfigure_sizing.sh @@ -1,4 +1,7 @@ #!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases + function configure_crc(){ crc config set consent-telemetry no crc config set enable-cluster-monitoring true