Skip to content

Commit 9c5fb9d

Browse files
author
Steven Hardy
committed
Refactor to enable local storage
Refactor code from assisted_deployment.sh to enable_local_storage.sh so that the local-storage operator can be enabled for deployed clusters independent of the other assisted dependencies. Note this currently only works for ga builds (not nightly/ci)
1 parent 918da5c commit 9c5fb9d

File tree

2 files changed

+92
-69
lines changed

2 files changed

+92
-69
lines changed

assisted_deployment.sh

+2-69
Original file line numberDiff line numberDiff line change
@@ -22,76 +22,9 @@ ASSISTED_OPERATOR_INDEX="${ASSISTED_OPERATOR_INDEX:-quay.io/ocpmetal/assisted-se
2222
ASSETS_DIR="${OCP_DIR}/saved-assets/assisted-installer-manifests"
2323

2424

25-
function generate_local_storage() {
26-
mkdir -p "${ASSETS_DIR}"
27-
28-
cat >"${ASSETS_DIR}/01-local-storage-operator.yaml" <<EOF
29-
apiVersion: operators.coreos.com/v1alpha2
30-
kind: OperatorGroup
31-
metadata:
32-
name: local-operator-group
33-
namespace: openshift-local-storage
34-
spec:
35-
targetNamespaces:
36-
- openshift-local-storage
37-
---
38-
apiVersion: operators.coreos.com/v1alpha1
39-
kind: Subscription
40-
metadata:
41-
name: local-storage-operator
42-
namespace: openshift-local-storage
43-
spec:
44-
installPlanApproval: Automatic
45-
name: local-storage-operator
46-
source: redhat-operators
47-
sourceNamespace: openshift-marketplace
48-
EOF
49-
50-
cat >"${ASSETS_DIR}/02-local-volume.yaml" <<EOCR
51-
apiVersion: local.storage.openshift.io/v1
52-
kind: LocalVolume
53-
metadata:
54-
name: assisted-service
55-
namespace: openshift-local-storage
56-
spec:
57-
logLevel: Normal
58-
managementState: Managed
59-
storageClassDevices:
60-
$(fill_local_storage)
61-
storageClassName: assisted-service
62-
volumeMode: Filesystem
63-
EOCR
64-
}
65-
66-
67-
function fill_local_storage() {
68-
if [ ! -z "${VM_EXTRADISKS_LIST}" ]; then
69-
cat <<EOF
70-
- devicePaths:
71-
EOF
72-
fi
73-
74-
for disk in ${VM_EXTRADISKS_LIST}; do
75-
cat <<EOF
76-
- /dev/$disk
77-
EOF
78-
done
79-
}
80-
81-
8225
function deploy_local_storage() {
83-
oc adm new-project openshift-local-storage || true
84-
85-
oc annotate project openshift-local-storage openshift.io/node-selector=''
86-
87-
generate_local_storage
88-
89-
echo "Creating local storage operator group and subscription..."
90-
oc apply -f "${ASSETS_DIR}/01-local-storage-operator.yaml"
91-
wait_for_crd "localvolumes.local.storage.openshift.io"
92-
93-
echo "Creating local volume and storage class..."
94-
oc apply -f "${ASSETS_DIR}/02-local-volume.yaml"
26+
export STORAGE_CLASS_NAME="assisted-service"
27+
${SCRIPTDIR}/enable_local_storage.sh
9528
}
9629

9730

enable_local_storage.sh

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
source logging.sh
5+
source common.sh
6+
source utils.sh
7+
8+
ASSETS_DIR=${ASSETS_DIR:-"${OCP_DIR}/enable-local-storage"}
9+
STORAGE_CLASS_NAME=${STORAGE_CLASS_NAME:-local-storage}
10+
11+
12+
function generate_local_storage() {
13+
mkdir -p "${ASSETS_DIR}"
14+
15+
cat >"${ASSETS_DIR}/01-local-storage-operator.yaml" <<EOF
16+
apiVersion: operators.coreos.com/v1alpha2
17+
kind: OperatorGroup
18+
metadata:
19+
name: local-operator-group
20+
namespace: openshift-local-storage
21+
spec:
22+
targetNamespaces:
23+
- openshift-local-storage
24+
---
25+
apiVersion: operators.coreos.com/v1alpha1
26+
kind: Subscription
27+
metadata:
28+
name: local-storage-operator
29+
namespace: openshift-local-storage
30+
spec:
31+
installPlanApproval: Automatic
32+
name: local-storage-operator
33+
source: redhat-operators
34+
sourceNamespace: openshift-marketplace
35+
EOF
36+
37+
cat >"${ASSETS_DIR}/02-local-volume.yaml" <<EOCR
38+
apiVersion: local.storage.openshift.io/v1
39+
kind: LocalVolume
40+
metadata:
41+
name: ${STORAGE_CLASS_NAME}
42+
namespace: openshift-local-storage
43+
spec:
44+
logLevel: Normal
45+
managementState: Managed
46+
storageClassDevices:
47+
$(fill_local_storage)
48+
storageClassName: ${STORAGE_CLASS_NAME}
49+
volumeMode: Filesystem
50+
EOCR
51+
}
52+
53+
54+
function fill_local_storage() {
55+
if [ ! -z "${VM_EXTRADISKS_LIST}" ]; then
56+
cat <<EOF
57+
- devicePaths:
58+
EOF
59+
fi
60+
61+
for disk in ${VM_EXTRADISKS_LIST}; do
62+
cat <<EOF
63+
- /dev/$disk
64+
EOF
65+
done
66+
}
67+
68+
69+
function deploy_local_storage() {
70+
oc adm new-project openshift-local-storage || true
71+
72+
oc annotate --overwrite project openshift-local-storage openshift.io/node-selector=''
73+
74+
generate_local_storage
75+
76+
echo "Creating local storage operator group and subscription..."
77+
oc apply -f "${ASSETS_DIR}/01-local-storage-operator.yaml"
78+
wait_for_crd "localvolumes.local.storage.openshift.io"
79+
80+
echo "Creating local volume and storage class..."
81+
oc apply -f "${ASSETS_DIR}/02-local-volume.yaml"
82+
}
83+
84+
85+
if [ "${VM_EXTRADISKS}" != "false" ]; then
86+
deploy_local_storage
87+
else
88+
echo "Cannot deploy local storage unless VM_EXTRADISKS is enabled"
89+
exit 1
90+
fi

0 commit comments

Comments
 (0)