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

Refactor to enable local storage #1313

Open
wants to merge 2 commits into
base: master
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
71 changes: 2 additions & 69 deletions assisted_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,76 +22,9 @@ ASSISTED_OPERATOR_INDEX="${ASSISTED_OPERATOR_INDEX:-quay.io/ocpmetal/assisted-se
ASSETS_DIR="${OCP_DIR}/saved-assets/assisted-installer-manifests"


function generate_local_storage() {
mkdir -p "${ASSETS_DIR}"

cat >"${ASSETS_DIR}/01-local-storage-operator.yaml" <<EOF
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: redhat-operators
sourceNamespace: openshift-marketplace
EOF

cat >"${ASSETS_DIR}/02-local-volume.yaml" <<EOCR
apiVersion: local.storage.openshift.io/v1
kind: LocalVolume
metadata:
name: assisted-service
namespace: openshift-local-storage
spec:
logLevel: Normal
managementState: Managed
storageClassDevices:
$(fill_local_storage)
storageClassName: assisted-service
volumeMode: Filesystem
EOCR
}


function fill_local_storage() {
if [ ! -z "${VM_EXTRADISKS_LIST}" ]; then
cat <<EOF
- devicePaths:
EOF
fi

for disk in ${VM_EXTRADISKS_LIST}; do
cat <<EOF
- /dev/$disk
EOF
done
}


function deploy_local_storage() {
oc adm new-project openshift-local-storage || true

oc annotate project openshift-local-storage openshift.io/node-selector=''

generate_local_storage

echo "Creating local storage operator group and subscription..."
oc apply -f "${ASSETS_DIR}/01-local-storage-operator.yaml"
wait_for_crd "localvolumes.local.storage.openshift.io"

echo "Creating local volume and storage class..."
oc apply -f "${ASSETS_DIR}/02-local-volume.yaml"
export STORAGE_CLASS_NAME="assisted-service"
${SCRIPTDIR}/enable_local_storage.sh
}


Expand Down
2 changes: 1 addition & 1 deletion common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export NUM_WORKERS=${NUM_WORKERS:-"2"}
export NUM_EXTRA_WORKERS=${NUM_EXTRA_WORKERS:-"0"}
export EXTRA_WORKERS_ONLINE_STATUS=${EXTRA_WORKERS_ONLINE_STATUS:-"true"}
export VM_EXTRADISKS=${VM_EXTRADISKS:-"false"}
export VM_EXTRADISKS_LIST=${VM_EXTRADISKS_LIST:-"vdb"}
export VM_EXTRADISKS_LIST=${VM_EXTRADISKS_LIST:-"vda"}
export VM_EXTRADISKS_SIZE=${VM_EXTRADISKS_SIZE:-"8G"}
export MASTER_HOSTNAME_FORMAT=${MASTER_HOSTNAME_FORMAT:-"master-%d"}
export WORKER_HOSTNAME_FORMAT=${WORKER_HOSTNAME_FORMAT:-"worker-%d"}
Expand Down
114 changes: 114 additions & 0 deletions enable_local_storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash
set -eux -o pipefail

source logging.sh
source common.sh
source utils.sh

ASSETS_DIR=${ASSETS_DIR:-"${OCP_DIR}/enable-local-storage"}
STORAGE_CLASS_NAME=${STORAGE_CLASS_NAME:-local-storage}


function generate_subscription() {
mkdir -p "${ASSETS_DIR}"

cat >"${ASSETS_DIR}/01-local-storage-operator.yaml" <<EOF
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: redhat-operators
sourceNamespace: openshift-marketplace
EOF
}

function generate_local_volume() {
mkdir -p "${ASSETS_DIR}"

cat >"${ASSETS_DIR}/02-local-volume.yaml" <<EOCR
apiVersion: local.storage.openshift.io/v1
kind: LocalVolume
metadata:
name: ${STORAGE_CLASS_NAME}
namespace: openshift-local-storage
spec:
logLevel: Normal
managementState: Managed
storageClassDevices:
$(fill_local_storage)
storageClassName: ${STORAGE_CLASS_NAME}
volumeMode: Filesystem
EOCR
}


function fill_local_storage() {
if [ ! -z "${VM_EXTRADISKS_LIST}" ]; then
cat <<EOF
- devicePaths:
EOF
fi

for disk in ${VM_EXTRADISKS_LIST}; do
cat <<EOF
- /dev/$disk
EOF
done
}


function deploy_local_storage() {
oc adm new-project openshift-local-storage || true

oc annotate --overwrite project openshift-local-storage openshift.io/node-selector=''

if [[ "$OPENSHIFT_RELEASE_TYPE" == "ga" ]]; then
generate_subscription
echo "Creating local storage operator group and subscription..."
oc apply -f "${ASSETS_DIR}/01-local-storage-operator.yaml"
else
oc project openshift-local-storage
LSO_PATH=${LOCAL_STORAGE_OPERATOR_PATH:-$GOPATH/src/github.com/openshift/local-storage-operator}
if [ ! -d $LSO_PATH ]; then
echo "Did not find $LSO_PATH" 1>&2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up idea: just clone or go get it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea, cloning when not present similar to other repos seems like the most consistent option

exit 1
fi
pushd ${LSO_PATH}
make build
# Run make deploy steps manually so we can override the default namespace
pushd config/manager
kustomize edit set image controller=controller:latest
popd
pushd config/default
kustomize edit set namespace openshift-local-storage
popd
kustomize build config/default | oc apply -f -
popd
fi
wait_for_crd "localvolumes.local.storage.openshift.io"

generate_local_volume
echo "Creating local volume and storage class..."
oc apply -f "${ASSETS_DIR}/02-local-volume.yaml"
}


if [ "${VM_EXTRADISKS}" != "false" ]; then
deploy_local_storage
else
echo "Cannot deploy local storage unless VM_EXTRADISKS is enabled"
hardys marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
2 changes: 1 addition & 1 deletion vm_setup_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ironic_prefix: "{{ ironic_prefix }}"
num_masters: 3
num_workers: 1
num_extraworkers: 0
extradisks_list: "{{ lookup('env', 'VM_EXTRADISKS_LIST').split(' ') | default(['vdb']) }}"
extradisks_list: "{{ lookup('env', 'VM_EXTRADISKS_LIST').split(' ') | default(['vda']) }}"
extradisks_size: "{{ lookup('env', 'VM_EXTRADISKS_SIZE') | default(['8G']) }}"
flavors:
master:
Expand Down