/
setup_lso.sh
executable file
·92 lines (77 loc) · 2.52 KB
/
setup_lso.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source ${__dir}/utils.sh
source ${__dir}/mirror_utils.sh
OC_VERSION=$(oc version -o json | jq --raw-output '.openshiftVersion' | cut -d'.' -f1-2)
STORAGE_CLASS_NAME="${STORAGE_CLASS_NAME:-assisted-service}"
INDEX_TAG="${INDEX_TAG:-v$OC_VERSION}"
DISCONNECTED="${DISCONNECTED:-false}"
function print_help() {
ALL_FUNCS="install_lso|create_local_volume|print_help"
if [ "${DISCONNECTED}" == "true" ]; then
echo "Usage: DISKS=\$(echo sd{b..f}) DISCONNECTED=true LOCAL_REGISTRY=... AUTHFILE=... bash ${0} (${ALL_FUNCS})"
else
echo "Usage: DISKS=\$(echo sd{b..f}) bash ${0} (${ALL_FUNCS})"
fi
}
function install_lso() {
oc adm new-project openshift-local-storage || true
retry -- oc annotate namespace openshift-local-storage openshift.io/node-selector='' --overwrite=true
catalog_source_name="redhat-operators"
if [ "${DISCONNECTED}" = true ]; then
if ! which opm; then
install_opm
fi
disable_default_indexes
index_image="registry.redhat.io/redhat/redhat-operator-index:${INDEX_TAG}"
catalog_source_name="mirror-catalog-for-local-storage-operator"
mirror_package "local-storage-operator" \
"${index_image}" "${LOCAL_REGISTRY}" "${AUTHFILE}" "${catalog_source_name}"
fi
tee >(oc apply -f -) <<EOCR
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: local-operator-group
namespace: openshift-local-storage
spec:
targetNamespaces:
- openshift-local-storage
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: local-storage-operator
namespace: openshift-local-storage
spec:
installPlanApproval: Automatic
name: local-storage-operator
source: ${catalog_source_name}
sourceNamespace: openshift-marketplace
EOCR
wait_for_operator "local-storage-operator" "openshift-local-storage"
echo "Done installing local-storage-operator!"
}
function create_local_volume() {
wait_for_crd "localvolumes.local.storage.openshift.io" "openshift-local-storage"
tee >(oc apply -f -) <<EOCR
apiVersion: local.storage.openshift.io/v1
kind: LocalVolume
metadata:
name: assisted-service
namespace: openshift-local-storage
spec:
logLevel: Normal
managementState: Managed
storageClassDevices:
- devicePaths:
$(printf ' - /dev/disk/by-id/wwn-%s\n' $(for disk in ${DISKS}; do disk_to_wwn ${disk}; done))
storageClassName: ${STORAGE_CLASS_NAME}
volumeMode: Filesystem
EOCR
echo "Done creating local volume for assisted-service!"
}
if [ -z "$@" ] || ! declare -F "$@"; then
print_help
exit 1
fi
"$@"