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

Review changes from scripts-dev to scripts-adopter #1355

Merged
merged 3 commits into from
Jul 13, 2023
Merged
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
1 change: 1 addition & 0 deletions cp3pt0-deployment/common/authorize-namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

function help() {
echo "authorize-namespace.sh - Authorize a namespace to be manageable from another namespace through the NamespaceScope operator"
echo "See https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.0?topic=co-authorizing-foundational-services-perform-operations-workloads-in-namespace for more information."
echo "SYNTAX:"
echo "authorize-namespace.sh [namespace | default current namespace] [-to namespace | default ibm-common-services] [-delete]"
echo "WHERE:"
Expand Down
4 changes: 2 additions & 2 deletions cp3pt0-deployment/common/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ function cleanup_OperandBindInfo() {

function cleanup_NamespaceScope() {
local namespace=$1
${OC} delete namespacescope odlm-scope-managedby-odlm nss-odlm-scope nss-managedby-odlm -n ${namespace} --ignore-not-found
${OC} delete namespacescope odlm-scope-managedby-odlm nss-odlm-scope nss-managedby-odlm common-service -n ${namespace} --ignore-not-found
}

function cleanup_OperandRequest() {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ function delete_operand_finalizer() {
local ns=$2
for crd in ${crds}; do
if [ "${crd}" != "packagemanifests.packages.operators.coreos.com" ] && [ "${crd}" != "events" ] && [ "${crd}" != "events.events.k8s.io" ]; then
crs=$(${OC} get ${crd} --no-headers --ignore-not-found -n ${ns} 2>/dev/null | awk '{print $1}')
crs=$(${OC} get "${crd}" --no-headers --ignore-not-found -n "${ns}" 2>/dev/null | awk '{print $1}')
for cr in ${crs}; do
msg "Removing the finalizers for resource: ${crd}/${cr}"
${OC} patch ${crd} ${cr} -n ${ns} --type="json" -p '[{"op": "remove", "path":"/metadata/finalizers"}]' 2>/dev/null
Expand Down
27 changes: 14 additions & 13 deletions cp3pt0-deployment/migrate_tenant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,24 @@ function print_usage() {
script_name=`basename ${0}`
echo "Usage: ${script_name} --license-accept --operator-namespace <foundational-services-namespace> [OPTIONS]..."
echo ""
echo "Migrate Cloud Pak 2.0 Foundational services to in Cloud Pak 3.0 Foundational services"
echo "Migrate Cloud Pak 2.0 Foundational services to Cloud Pak 3.0 Foundational services"
echo "The --license-accept and --operator-namespace <operator-namespace> must be provided."
echo "See https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.0?topic=4x-in-place-migration for more information."
echo ""
echo "Options:"
echo " --oc string File path to oc CLI. Default uses oc in your PATH"
echo " --yq string File path to yq CLI. Default uses yq in your PATH"
echo " --oc string Optional. File path to oc CLI. Default uses oc in your PATH"
echo " --yq string Optional. File path to yq CLI. Default uses yq in your PATH"
echo " --operator-namespace string Required. Namespace to migrate Foundational services operator"
echo " --services-namespace Namespace to migrate operands of Foundational services, i.e. 'dataplane'. Default is the same as operator-namespace"
echo " --cert-manager-source string CatalogSource name of ibm-cert-manager-operator. This assumes your CatalogSource is already created. Default is ibm-cert-manager-catalog"
echo " --licensing-source string CatalogSource name of ibm-licensing. This assumes your CatalogSource is already created. Default is ibm-licensing-catalog"
echo " --enable-licensing Set this flag to migrate ibm-licensing-operator"
echo " --enable-private-catalog Set this flag to use namespace scoped CatalogSource. Default is in openshift-marketplace namespace"
echo " --license-accept Set this flag to accept the license agreement."
echo " -c, --channel string Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -s, --source string CatalogSource name. This assumes your CatalogSource is already created. Default is opencloud-operators"
echo " -v, --debug integer Verbosity of logs. Default is 0. Set to 1 for debug logs."
echo " --services-namespace Optional. Namespace to migrate operands of Foundational services, i.e. 'dataplane'. Default is the same as operator-namespace"
echo " --cert-manager-source string Optional. CatalogSource name of ibm-cert-manager-operator. This assumes your CatalogSource is already created. Default is ibm-cert-manager-catalog"
echo " --licensing-source string Optional. CatalogSource name of ibm-licensing. This assumes your CatalogSource is already created. Default is ibm-licensing-catalog"
echo " --enable-licensing Optional. Set this flag to migrate ibm-licensing-operator"
echo " --enable-private-catalog Optional. Set this flag to use namespace scoped CatalogSource. Default is in openshift-marketplace namespace"
echo " --license-accept Required. Set this flag to accept the license agreement."
echo " -c, --channel string Optional. Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string Optional. InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -s, --source string Optional. CatalogSource name. This assumes your CatalogSource is already created. Default is opencloud-operators"
echo " -v, --debug integer Optional. Verbosity of logs. Default is 0. Set to 1 for debug logs."
echo " -h, --help Print usage information"
echo ""
}
Expand Down
27 changes: 14 additions & 13 deletions cp3pt0-deployment/setup_singleton.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,22 @@ function print_usage() {
echo "The ibm-cert-manager-operator will be installed in namespace ibm-cert-manager"
echo "The ibm-licensing-operator will be installed in namespace ibm-licensing"
echo "The --license-accept must be provided."
echo "See https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.0?topic=manager-installing-cert-licensing-by-script for more information."
echo ""
echo "Options:"
echo " --oc string File path to oc CLI. Default uses oc in your PATH"
echo " --yq string File path to yq CLI. Default uses yq in your PATH"
echo " --operator-namespace string Namespace to migrate Cloud Pak 2 Foundational services"
echo " --enable-licensing Set this flag to install ibm-licensing-operator"
echo " --enable-private-catalog Set this flag to use namespace scoped CatalogSource. Default is in openshift-marketplace namespace"
echo " --cert-manager-source string CatalogSource name of ibm-cert-manager-operator. This assumes your CatalogSource is already created. Default is ibm-cert-manager-catalog"
echo " --licensing-source string CatalogSource name of ibm-licensing. This assumes your CatalogSource is already created. Default is ibm-licensing-catalog"
echo " -cmNs, --cert-manager-namespace string Set custom namespace for ibm-cert-manager-operator. Default is ibm-cert-manager"
echo " -licensingNs, --licensing-namespace string Set custom namespace for ibm-licensing-operator. Default is ibm-licensing"
echo " --license-accept Set this flag to accept the license agreement."
echo " -c, --channel string Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -v, --debug integer Verbosity of logs. Default is 0. Set to 1 for debug logs"
echo " --oc string Optional. File path to oc CLI. Default uses oc in your PATH"
echo " --yq string Optional. File path to yq CLI. Default uses yq in your PATH"
echo " --operator-namespace string Optional. Namespace to migrate Cloud Pak 2 Foundational services"
echo " --enable-licensing Optional. Set this flag to install ibm-licensing-operator"
echo " --enable-private-catalog Optional. Set this flag to use namespace scoped CatalogSource. Default is in openshift-marketplace namespace"
echo " --cert-manager-source string Optional. CatalogSource name of ibm-cert-manager-operator. This assumes your CatalogSource is already created. Default is ibm-cert-manager-catalog"
echo " --licensing-source string Optional. CatalogSource name of ibm-licensing. This assumes your CatalogSource is already created. Default is ibm-licensing-catalog"
echo " -cmNs, --cert-manager-namespace string Optional. Set custom namespace for ibm-cert-manager-operator. Default is ibm-cert-manager"
echo " -licensingNs, --licensing-namespace string Optional. Set custom namespace for ibm-licensing-operator. Default is ibm-licensing"
echo " --license-accept Required. Set this flag to accept the license agreement."
echo " -c, --channel string Optional. Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string Optional. InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -v, --debug integer Optional. Verbosity of logs. Default is 0. Set to 1 for debug logs"
echo " -h, --help Print usage information"
echo ""
}
Expand Down
90 changes: 64 additions & 26 deletions cp3pt0-deployment/setup_tenant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ OPERATOR_NS=""
SERVICES_NS=""
TETHERED_NS=""
EXCLUDED_NS=""
SIZE_PROFILE="starterset"
SIZE_PROFILE=""
INSTALL_MODE="Automatic"
PREVIEW_MODE=0
OC_CMD="oc"
DEBUG=0
LICENSE_ACCEPT=0
RETRY_CONFIG_CSCR=0
IS_UPGRADE=0

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

Expand Down Expand Up @@ -138,24 +139,25 @@ function print_usage() {
echo ""
echo "Set up an advanced topology tenant for Cloud Pak 3.0 Foundational services."
echo "The --license-accept and --operator-namespace must be provided."
echo "See https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.0?topic=online-installing-foundational-services-by-using-script for more information."
echo ""
echo "Options:"
echo " --oc string File path to oc CLI. Default uses oc in your PATH"
echo " --yq string File path to yq CLI. Default uses yq in your PATH"
echo " --enable-licensing Set this flag to install ibm-licensing-operator"
echo " --oc string Optional. File path to oc CLI. Default uses oc in your PATH"
echo " --yq string Optional. File path to yq CLI. Default uses yq in your PATH"
echo " --enable-licensing Optional. Set this flag to install ibm-licensing-operator"
echo " --operator-namespace string Required. Namespace to install Foundational services operator"
echo " --services-namespace Namespace to install operands of Foundational services, i.e. 'dataplane'. Default is the same as operator-namespace"
echo " --tethered-namespaces string Add namespaces to this tenant, comma-delimited, e.g. 'ns1,ns2'"
echo " --excluded-namespaces string Remove namespaces from this tenant, comma-delimited, e.g. 'ns1,ns2'"
echo " --license-accept Set this flag to accept the license agreement"
echo " -c, --channel string Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -s, --source string CatalogSource name. This assumes your CatalogSource is already created. Default is opencloud-operators"
echo " -n, --namespace string Namespace of CatalogSource. Default is openshift-marketplace"
echo " --preview Enable preview mode (dry run)"
echo " -v, --debug integer Verbosity of logs. Default is 0. Set to 1 for debug logs"
echo " --services-namespace Optional. Namespace to install operands of Foundational services, i.e. 'dataplane'. Default is the same as operator-namespace"
echo " --tethered-namespaces string Optional. Add namespaces to this tenant, comma-delimited, e.g. 'ns1,ns2'"
echo " --excluded-namespaces string Optional. Remove namespaces from this tenant, comma-delimited, e.g. 'ns1,ns2'"
echo " --license-accept Required. Set this flag to accept the license agreement"
echo " -c, --channel string Optional. Channel for Subscription(s). Default is v4.0"
echo " -i, --install-mode string Optional. InstallPlan Approval Mode. Default is Automatic. Set to Manual for manual approval mode"
echo " -s, --source string Optional. CatalogSource name. This assumes your CatalogSource is already created. Default is opencloud-operators"
echo " -n, --namespace string Optional. Namespace of CatalogSource. Default is openshift-marketplace"
echo " --preview Optional. Enable preview mode (dry run)"
echo " -v, --debug integer Optional. Verbosity of logs. Default is 0. Set to 1 for debug logs"
echo " -h, --help Print usage information"
echo " -p, --size-profile The default profile is starterset. Change the profile to starter, small, medium, or large, if required"
echo " -p, --size-profile Optional. The default profile is starterset. Change the profile to starter, small, medium, or large, if required"
echo ""
}

Expand All @@ -180,10 +182,6 @@ function pre_req() {
else
success "oc command logged in as ${user}"
fi

if [ $? -ne 0 ]; then
error "Cert-manager is not found or having more than one\n"
fi

if [ $LICENSE_ACCEPT -ne 1 ]; then
error "License not accepted. Rerun script with --license-accept flag set. See https://ibm.biz/integration-licenses for more details"
Expand All @@ -206,11 +204,18 @@ function pre_req() {
error "Channel is not semantic vx.y"
fi

# Check original configurations in main CommonService CR
default_arguments

# Check profile size
case "$SIZE_PROFILE" in
"starterset"|"starter"|"small"|"medium"|"large")
success "Profile size is valid."
;;
"")
SIZE_PROFILE="starterset"
success "Profile size is not specified. Use default value: $SIZE_PROFILE"
;;
*)
error " '$SIZE_PROFILE' is not a valid value for profile. Allowed values are 'starterset', 'starter', 'small', 'medium', and 'large'."
;;
Expand All @@ -220,11 +225,11 @@ function pre_req() {
error "Must provide operator namespace, please specify argument --operator-namespace"
fi

if [[ "$SERVICES_NS" == "" && "$TETHERED_NS" == "" && "$EXCLUDED_NS" == "" ]]; then
if [[ "$SERVICES_NS" == "" && "$TETHERED_NS" == "" && "$EXCLUDED_NS" == "" && $IS_UPGRADE -eq 0 ]]; then
error "Must provide additional namespaces, either --services-namespace, --tethered-namespaces, or --excluded-namespaces"
fi

if [[ "$SERVICES_NS" == "$OPERATOR_NS" && "$TETHERED_NS" == "" && "$EXCLUDED_NS" == "" ]]; then
if [[ "$SERVICES_NS" == "$OPERATOR_NS" && "$TETHERED_NS" == "" && "$EXCLUDED_NS" == "" && $IS_UPGRADE -eq 0 ]]; then
error "Must provide additional namespaces for --tethered-namespaces or --excluded-namespaces when services-namespace is the same as operator-namespace"
fi

Expand All @@ -234,6 +239,37 @@ function pre_req() {
echo ""
}

function default_arguments() {
# check if CommonService CRD exists in cluster
local is_CS_CRD_exist=$((${OC} get commonservice -n ${OPERATOR_NS} --ignore-not-found > /dev/null && echo exists) || echo fail)
if [[ "$is_CS_CRD_exist" == "exists" ]]; then
result=$("${OC}" get commonservice common-service -n ${OPERATOR_NS} -o yaml --ignore-not-found)
if [[ ! -z "$result" ]]; then

tmp_services_ns=$("${YQ}" eval '.spec.servicesNamespace' - <<< "$result")
tmp_size_profile=$("${YQ}" eval '.spec.size' - <<< "$result")

if [[ "$SERVICES_NS" == "" ]] && [[ "$tmp_services_ns" != "" ]] && [[ "$tmp_services_ns" != "null" ]]; then
SERVICES_NS=$("${YQ}" eval '.spec.servicesNamespace' - <<< "$result")
fi
if [[ "$SIZE_PROFILE" == "" ]] && [[ "$tmp_size_profile" != "" ]] && [[ "$tmp_size_profile" != "null" ]]; then
SIZE_PROFILE=$("${YQ}" eval '.spec.size' - <<< "$result")
fi
# if main CommonService CR exists, then defaulting from it, and it is a upgrade scenario, simple topology will be accepted
IS_UPGRADE=1
else
info "CommonService CRD exists but main CommonService CR does not exist, skipping defaulting from original CommonService CR\n"
fi
else
info "CommonService CRD does not exist, skipping defaulting from original CommonService CR\n"
fi

# Assign default values when not specified
if [[ "$SERVICES_NS" == "" ]]; then
SERVICES_NS=$OPERATOR_NS
fi
}

function create_ns_list() {
for ns in $OPERATOR_NS $SERVICES_NS ${TETHERED_NS//,/ }; do
create_namespace $ns
Expand Down Expand Up @@ -495,13 +531,14 @@ function configure_cs_kind() {
local delay=30

title "Configuring CommonService CR in $OPERATOR_NS..."
if [[ $($OC get CommonService common-service -n $OPERATOR_NS 2>/dev/null) != "" ]];then
info "CommonService CR is already deployed in $OPERATOR_NS\n"
result=$("${OC}" get commonservice common-service -n ${OPERATOR_NS} -o yaml --ignore-not-found)
if [[ ! -z "${result}" ]]; then
info "Configuring CommonService CR common-service in $OPERATOR_NS\n"
${OC} get commonservice common-service -n "${OPERATOR_NS}" -o yaml | ${YQ} eval '.spec += {"operatorNamespace": "'${OPERATOR_NS}'", "servicesNamespace": "'${SERVICES_NS}'", "size": "'${SIZE_PROFILE}'"}' > ${PREVIEW_DIR}/commonservice.yaml
${YQ} -i eval 'select(.kind == "CommonService") | del(.metadata.resourceVersion) | del(.metadata.uid) | del(.metadata.creationTimestamp) | del(.metadata.generation)' ${PREVIEW_DIR}/commonservice.yaml
else
info "Creating the CommonService object:\n"
fi

cat <<EOF > ${PREVIEW_DIR}/commonservice.yaml
cat <<EOF > ${PREVIEW_DIR}/commonservice.yaml
apiVersion: operator.ibm.com/v3
kind: CommonService
metadata:
Expand All @@ -512,6 +549,7 @@ spec:
servicesNamespace: $SERVICES_NS
size: $SIZE_PROFILE
EOF
fi

cat ${PREVIEW_DIR}/commonservice.yaml
echo ""
Expand Down
Loading
Loading