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

Script Enhancements #20

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tldr; Watch introduction & Demo Video [here](https://www.youtube.com/watch?v=mae
### 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 - Linux
### Watch Demo Video [here](https://www.youtube.com/watch?v=mae0tiLkQag)
Expand Down Expand Up @@ -54,6 +55,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
Expand Down Expand Up @@ -200,6 +202,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

Expand Down
8 changes: 8 additions & 0 deletions configure_crcssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

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
56 changes: 24 additions & 32 deletions deploy_odf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <<EOF | oc create -f - >/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:
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -221,7 +212,7 @@ spec:
manageNodes: false
monDataDirHostPath: /var/lib/rook
storageDeviceSets:
- count: 2
- count: ${VOLUME_COUNT}
dataPVCTemplate:
spec:
accessModes:
Expand Down Expand Up @@ -336,7 +327,7 @@ spec:
failureDomain: osd
replicated:
requireSafeReplicaSize: false
size: 2
size: ${VOLUME_COUNT}
metadataPool:
compressionMode: ""
crushRoot: ""
Expand All @@ -349,7 +340,7 @@ spec:
failureDomain: osd
replicated:
requireSafeReplicaSize: false
size: 2
size: ${VOLUME_COUNT}
metadataServer:
activeCount: 1
activeStandby: false
Expand Down Expand Up @@ -444,7 +435,7 @@ spec:
failureDomain: osd
replicated:
requireSafeReplicaSize: false
size: 2
size: ${VOLUME_COUNT}
gateway:
allNodes: false
instances: 1
Expand All @@ -462,7 +453,7 @@ spec:
dataChunks: 0
failureDomain: osd
replicated:
size: 2
size: ${VOLUME_COUNT}
requireSafeReplicaSize: false
EOF

Expand Down Expand Up @@ -506,3 +497,4 @@ spec:
EOF

echo "ODF is installed now"

114 changes: 114 additions & 0 deletions generate_volumes.sh
Original file line number Diff line number Diff line change
@@ -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 ' </disk>' > ~/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
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='$HOME/.crc/${virtual_drive[$i]}' index='$i'/>
<backingStore/>
<target dev='${virtual_drive[$i]}' bus='virtio'/>
<alias name='virtio-disk$i'/>
<address type='pci' domain='0x0000' bus='0x0${address_bus}' slot='0x00' function='0x0'/>
</disk>
EOT
done

cp ~/crc.xml ~/crc-backup.xml

line=$(grep -n '</disk>' ~/crc.xml | cut -d ":" -f 1)
line=$(grep -n '</disk>' ~/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
echo "Block creation validation"
crcssh lsblk

echo "To restore configutation run the following."
echo "$ sudo virsh define ~/crc-backup.xml"
echo "$ crc start "
fi

42 changes: 42 additions & 0 deletions reconfigure_sizing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/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
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


22 changes: 16 additions & 6 deletions uninstall_odf.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,9 +33,17 @@ 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"
echo "*********************"
crcssh sudo wipefs -af /dev/$virtual_drive ;
sleep 2s
crcssh sudo sgdisk --zap-all /dev/$virtual_drive
sleep 2s
crcssh sudo dd if=/dev/zero of=/dev/$virtual_drive bs=1M count=100 oflag=direct,dsync ;
sleep 2s
crcssh sudo blkdiscard /dev/$virtual_drive ;
done