Skip to content

Commit

Permalink
script to apply ORM files (#2301)
Browse files Browse the repository at this point in the history
* added label to ORM files for clean up

Signed-off-by: Henry Li <[email protected]>

* renamed ORM files to use .yaml instead of .yml

Signed-off-by: Henry Li <[email protected]>

* added script to update namespace of ORM files

Signed-off-by: Henry Li <[email protected]>

* updated script to accommodate services namespace instead of operator namespace and added cert-manager namespace handling

Signed-off-by: Henry Li <[email protected]>

---------

Signed-off-by: Henry Li <[email protected]>
  • Loading branch information
bitscuit authored Nov 18, 2024
1 parent 465c427 commit 96dcfd4
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 5 deletions.
191 changes: 191 additions & 0 deletions turbonomic/install_orm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env bash

# Licensed Materials - Property of IBM
# Copyright IBM Corporation 2024. All Rights Reserved
# US Government Users Restricted Rights -
# Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# This is an internal component, bundled with an official IBM product.
# Please refer to that particular license for additional information.

# ---------- Command variables ----------

# script base directory
BASE_DIR=$(cd $(dirname "$0")/$(dirname "$(readlink $0)") && pwd -P)

# services namespace
SERVICES_NAMESPACE=

# cert-manager namespace
CERT_NAMESPACE="ibm-cert-manager"

# is uninstall flag?
UNINSTALL=

IFS='
'


# counter to keep track of installation steps
STEP=0

# ---------- Main functions ----------

function msg() {
printf '%b\n' "$1"
}

function info() {
msg "[INFO] ${1}"
}

function success() {
msg "\33[32m[✔] ${1}\33[0m"
}

function warning() {
msg "\33[33m[✗] ${1}\33[0m"
}

function error() {
msg "\33[31m[✘] ${1}\33[0m"
exit 1
}

function title() {
msg "\33[34m# ${1}\33[0m"
}

function translate_step() {
local step=$1
echo "${step}" | tr '[1-9]' '[a-i]'
}

function main() {
parse_arguments "$@"
install_orms
}

function install_orms() {
check_prereqs

if [[ -z ${UNINSTALL} ]]; then
install_orm
fi
if [[ ${UNINSTALL} == "true" ]]; then
delete_orm
fi

msg "-----------------------------------------------------------------------"
success "IBM Cloud Pak foundational services OperatorResourceMapping installation or removal completed at $(date) ."
exit 0
}

function print_usage() {
script_name=`basename ${0}`
echo "Usage: ${script_name} [OPTIONS]..."
echo ""
echo "Install IBM Cloud Pak foundational services OperatorResourceMapping"
echo ""
echo "Options:"
echo " -n, --namespace string IBM Cloud Pak foundational services namespace. Default is same namespace as IBM Cloud Pak foundational services"
echo " -u, --uninstall Uninstall IBM Cloud Pak foundational services OperatorResourceMapping"
echo " -h, --help Print usage information"
echo ""
}

function parse_arguments() {
# process options
while [[ "$1" != "" ]]; do
case "$1" in
-n | --namespace)
shift
SERVICES_NAMESPACE=$1
;;
-c | --cert-manager-namespace)
shift
CERT_NAMESPACE=$1
;;
-u | --uninstall)
shift
UNINSTALL=true
;;
-h | --help)
print_usage
exit 1
;;
*)
;;
esac
shift
done
}

# ---------- Supporting functions ----------

function check_prereqs() {
title "[$(translate_step ${STEP})] Checking prerequisites ..."
msg "-----------------------------------------------------------------------"

# checking oc command
if [[ -z "$(command -v oc 2> /dev/null)" ]]; then
error "oc command not available"
else
success "oc command available"
fi

# checking oc command logged in
user=$(oc whoami 2> /dev/null)
if [ $? -ne 0 ]; then
error "You must be logged into the OpenShift Cluster from the oc command line"
else
success "oc command logged in as ${user}"
fi

# checking for SERVICES_NAMESPACE
if [[ -z "${SERVICES_NAMESPACE}" ]]; then
SERVICES_NAMESPACE=$(oc project -q)
fi

# checking for OperandRegistry in SERVICES_NAMESPACE
if [[ -z "$(oc -n ${SERVICES_NAMESPACE} get operandregistry common-service --ignore-not-found)" ]]; then
info "Missing OperandRegistry, likely IBM Cloud Pak foundational services are not installed in namespace ${SERVICES_NAMESPACE}"
else
success "Found OperandRegistry common-service in namespace ${SERVICES_NAMESPACE}"
fi

}

function install_orm() {
title "[$(translate_step ${STEP})] Installing IBM Cloud Pak foundational services OperatorResourceMapping ..."
msg "-----------------------------------------------------------------------"

info "Using IBM Cloud Pak foundational services namespace: ${SERVICES_NAMESPACE}"

local dir="${BASE_DIR}/operands"

for file in `ls -1 ${dir}/*.yaml`; do
info "Installing `basename ${file}` ..."
cat ${file} | sed -e "s/{{ placeholder_namespace }}/${SERVICES_NAMESPACE}/g" \
| sed -e "s/{{ placeholder_cert_namespace }}/${CERT_NAMESPACE}/g" \
| oc apply -f -
done

}

function delete_orm() {
title "[$(translate_step ${STEP})] Removing IBM Cloud Pak foundational services OperatorResourceMapping ..."
msg "-----------------------------------------------------------------------"

oc delete operatorresourcemapping -n ${SERVICES_NAMESPACE} --selector=component=cpfs

local is_cert_orm=$(oc get operatorresourcemapping -n ${CERT_NAMESPACE} --ignore-not-found | grep "cert-manager")
if [ ! -z ${is_cert_orm} ]; then
warning "Must manually delete OperatorResourceMapping for ibm-cert-manager because other tenants could be using it"
fi
}

# --- Run ---

main $*

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
apiVersion: devops.turbonomic.io/v1alpha1
kind: OperatorResourceMapping
metadata:
name: cert-manager-orm
namespace: $namespace
name: cert-manager-config-orm
namespace: {{ placeholder_cert_namespace }}
labels:
component: cpfs
spec:
mappings:
patterns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apiVersion: devops.turbonomic.io/v1alpha1
kind: OperatorResourceMapping
metadata:
name: auth-service-orm
namespace: $namespace
namespace: {{ placeholder_namespace }}
labels:
component: cpfs
spec:
mappings:
patterns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apiVersion: devops.turbonomic.io/v1alpha1
kind: OperatorResourceMapping
metadata:
name: management-orm
namespace: $namespace
namespace: {{ placeholder_namespace }}
labels:
component: cpfs
spec:
mappings:
patterns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apiVersion: devops.turbonomic.io/v1alpha1
kind: OperatorResourceMapping
metadata:
name: provider-orm
namespace: $namespace
namespace: {{ placeholder_namespace }}
labels:
component: cpfs
spec:
mappings:
patterns:
Expand Down
3 changes: 3 additions & 0 deletions turbonomic/operands/orm-common-web-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: devops.turbonomic.io/v1alpha1
kind: OperatorResourceMapping
metadata:
name: common-web-ui-orm
namespace: {{ placeholder_namespace }}
labels:
component: cpfs
spec:
owner: # target same namespace by default
apiVersion: operators.ibm.com/v1alpha1
Expand Down

0 comments on commit 96dcfd4

Please sign in to comment.