Skip to content

Commit f7b0b62

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. This also now works for pre-release builds by installing LSO from source.
1 parent bacf996 commit f7b0b62

File tree

2 files changed

+116
-69
lines changed

2 files changed

+116
-69
lines changed

assisted_deployment.sh

Lines changed: 2 additions & 69 deletions
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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env bash
2+
set -eux -o pipefail
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_subscription() {
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+
38+
function generate_local_volume() {
39+
mkdir -p "${ASSETS_DIR}"
40+
41+
cat >"${ASSETS_DIR}/02-local-volume.yaml" <<EOCR
42+
apiVersion: local.storage.openshift.io/v1
43+
kind: LocalVolume
44+
metadata:
45+
name: ${STORAGE_CLASS_NAME}
46+
namespace: openshift-local-storage
47+
spec:
48+
logLevel: Normal
49+
managementState: Managed
50+
storageClassDevices:
51+
$(fill_local_storage)
52+
storageClassName: ${STORAGE_CLASS_NAME}
53+
volumeMode: Filesystem
54+
EOCR
55+
}
56+
57+
58+
function fill_local_storage() {
59+
if [ ! -z "${VM_EXTRADISKS_LIST}" ]; then
60+
cat <<EOF
61+
- devicePaths:
62+
EOF
63+
fi
64+
65+
for disk in ${VM_EXTRADISKS_LIST}; do
66+
cat <<EOF
67+
- /dev/$disk
68+
EOF
69+
done
70+
}
71+
72+
73+
function deploy_local_storage() {
74+
oc adm new-project openshift-local-storage || true
75+
76+
oc annotate --overwrite project openshift-local-storage openshift.io/node-selector=''
77+
78+
if [[ "$OPENSHIFT_RELEASE_TYPE" == "ga" ]]; then
79+
generate_subscription
80+
echo "Creating local storage operator group and subscription..."
81+
oc apply -f "${ASSETS_DIR}/01-local-storage-operator.yaml"
82+
else
83+
oc project openshift-local-storage
84+
LSO_PATH=${LOCAL_STORAGE_OPERATOR_PATH:-$GOPATH/src/github.com/openshift/local-storage-operator}
85+
if [ ! -d $LSO_PATH ]; then
86+
echo "Did not find $LSO_PATH" 1>&2
87+
exit 1
88+
fi
89+
pushd ${LSO_PATH}
90+
make build
91+
# Run make deploy steps manually so we can override the default namespace
92+
pushd config/manager
93+
kustomize edit set image controller=controller:latest
94+
popd
95+
pushd config/default
96+
kustomize edit set namespace openshift-local-storage
97+
popd
98+
kustomize build config/default | oc apply -f -
99+
popd
100+
fi
101+
wait_for_crd "localvolumes.local.storage.openshift.io"
102+
103+
generate_local_volume
104+
echo "Creating local volume and storage class..."
105+
oc apply -f "${ASSETS_DIR}/02-local-volume.yaml"
106+
}
107+
108+
109+
if [ "${VM_EXTRADISKS}" != "false" ]; then
110+
deploy_local_storage
111+
else
112+
echo "Cannot deploy local storage unless VM_EXTRADISKS is enabled"
113+
exit 1
114+
fi

0 commit comments

Comments
 (0)