Skip to content

Commit

Permalink
Merge pull request #135 from IBM/fk-misc
Browse files Browse the repository at this point in the history
Miscellaneous changes
  • Loading branch information
arthurlaimbock authored Sep 15, 2022
2 parents acbaf75 + a6719b9 commit 244023f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,30 @@ for c in $(echo $cartridges | jq -r '.[].name');do
fi
done

if [ $exit_code -ne 0 ];then
#
log "Log status of pods in project ${project} to file ${status_dir}/log/${project}-pods.out"
oc get po -n ${project} > ${status_dir}/log/${project}-pods.out

# Check if there are any pods in Pending state for > 15 minutes
CURRENT_TIME=$(date +%s)
while read -r line;do
if [ ! -z "${line}" ];then
read -r POD_NAME POD_START POD_STATE <<< "${line}"
POD_START_EPOCH=$(date -d "${POD_START}" +%s)
TIME_DIFF=$((CURRENT_TIME-POD_START_EPOCH))
if [ ${TIME_DIFF} -gt 900 ];then
log "Pod ${POD_NAME} in project ${project} has been Pending for more than 15 minutes"
exit_code=4
fi
fi
done <<< $(oc get po -n ${project} -o jsonpath='{range .items[?(@.status.phase=="Pending")]}{.metadata.name}{"\t"}{.metadata.creationTimestamp}{"\t"}{.status.phase}{"\n"}{end}')

if [ "${exit_code}" == "4" ];then
log "Pods have been in Pending state for more than 15 minutes. Most-likely the OpenShift cluster does not have enough capacity for all selected services."
fi

if [ "${exit_code}" != "0" ];then
log "Exiting because of error."
exit $exit_code
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- block:
- debug:
var: current_cp4d_cluster
var: _p_current_cp4d_cluster

- name: Prepare yaml file for network policy
template:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- block:
- debug:
var: _p_current_cp4d_cluster

- name: Prepare yaml file for Watson Knowledge Studio CR
template:
src: watson-ks-cr-45.j2
dest: "{{ status_dir }}/cp4d/watson-ks-cr-45-{{ _p_current_cp4d_cluster.project }}.yml"

- name: Create Watson Knowledge Studio CR
shell: |
oc apply -f {{ status_dir }}/cp4d/watson-ks-cr-45-{{ _p_current_cp4d_cluster.project }}.yml
when: _p_current_cp4d_cluster.cp4d_version >= "4.5.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-v \
--cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \
--components={% for c in _cartridges_to_install -%}
{%- if (c.state | default('installed')) == 'installed' -%}
{%- if (c.state | default('installed')) == 'installed' and c.name != 'watson-ks' -%}
{%- if not loop.first -%},{% endif -%}
{{ c.olm_utils_name }}
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: knowledgestudio.watson.ibm.com/v1
kind: KnowledgeStudio
metadata:
name: wks
namespace: {{ _p_current_cp4d_cluster.project }}
spec:
license:
accept: {{ _cpd_accept_licenses | default(False) }}
global:
storageClassName: {{ ocp_storage_class_block }}
size: {{ _current_cp4d_cartridge.size }}
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ cartridge_cr:
cr_file_prefix: watson-ks
olm_utils_name: watson_ks
cartridge_label: operators.coreos.com/ibm-watson-ks-operator.ibm-common-services
cr_preprocessing_script: cp4d-pre-wks-45.yml
inventory: wksOperatorSetup
search_string: ibm-watson-ks
package_manifest: ibm-watson-ks-operator
Expand Down
13 changes: 10 additions & 3 deletions docker-scripts/run_automation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ if [[ error -ne 0 ]];then
exit 1
fi

echo ""
echo "Starting Automation script..."
echo ""
# Change to base directory
cd ${SCRIPT_DIR}/..

# Ensure /tmp/work exists
mkdir -p /tmp/work

# Retrieve version by checking the git log
DEPLOYER_VERSION_INFO=$(git log -n1 --pretty='format:%h %cd |%s' --date=format:'%Y-%m-%dT%H:%M:%S' 2> /dev/null)
COMMIT_HASH=$(echo $DEPLOYER_VERSION_INFO | awk '{print $1}')
COMMIT_TIMESTAMP=$(echo $DEPLOYER_VERSION_INFO | awk '{print $2}')
COMMIT_MESSAGE=$(echo $DEPLOYER_VERSION_INFO | cut -d'|' -f2)

# Check that subcommand is valid
export SUBCOMMAND=${SUBCOMMAND,,}
export ACTION=${ACTION,,}
Expand Down Expand Up @@ -97,6 +101,9 @@ env|environment)
mkdir -p ${STATUS_DIR}/log
echo "===========================================================================" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
echo "Starting deployer" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
echo " Commit ID : ${COMMIT_HASH}" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
echo " Commit timestamp: ${COMMIT_TIMESTAMP}" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
echo " Commit message : ${COMMIT_MESSAGE}" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
echo "===========================================================================" | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log
run_cmd+=" 2>&1 | tee -a ${STATUS_DIR}/log/cloud-pak-deployer.log"
echo "$run_cmd" >> /tmp/deployer_run_cmd.log
Expand Down
28 changes: 14 additions & 14 deletions scripts/cp4d/cp4d-delete-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ while read -r line;do
;;
*)
log "Deleting $CR $CR_NAME"
oc delete -n ${CP4D_PROJECT} ${CR} ${CR_NAME} --wait=false
oc patch -n ${CP4D_PROJECT} ${CR}/${CR_NAME} --type=merge -p '{"metadata": {"finalizers":null}}'
oc delete -n ${CP4D_PROJECT} ${CR} ${CR_NAME} --wait=false --ignore-not-found
oc patch -n ${CP4D_PROJECT} ${CR}/${CR_NAME} --type=merge -p '{"metadata": {"finalizers":null}}' 2> /dev/null
resource_deleted=true
;;
esac
Expand All @@ -60,8 +60,8 @@ while read -r line;do
case $CR in
Ibmcpd|CommonService|OperandRequest)
log "Deleting $CR $CR_NAME"
oc delete -n ${CP4D_PROJECT} ${CR} ${CR_NAME} --wait=false
oc patch -n ${CP4D_PROJECT} ${CR}/${CR_NAME} --type=merge -p '{"metadata": {"finalizers":null}}'
oc delete -n ${CP4D_PROJECT} ${CR} ${CR_NAME} --wait=false --ignore-not-found
oc patch -n ${CP4D_PROJECT} ${CR}/${CR_NAME} --type=merge -p '{"metadata": {"finalizers":null}}' 2> /dev/null
resource_deleted=true
;;
*)
Expand All @@ -79,27 +79,27 @@ oc delete ns ${CP4D_PROJECT}

log "Deleting everything in the ibm-common-services project"
oc project ibm-common-services
oc delete CommonService -n ibm-common-services common-service
oc delete sub -n ibm-common-services -l operators.coreos.com/ibm-common-service-operator.ibm-common-services
oc delete csv -n ibm-common-services -l operators.coreos.com/ibm-common-service-operator.ibm-common-services
oc delete CommonService -n ibm-common-services common-service --ignore-not-found
oc delete sub -n ibm-common-services -l operators.coreos.com/ibm-common-service-operator.ibm-common-services --ignore-not-found
oc delete csv -n ibm-common-services -l operators.coreos.com/ibm-common-service-operator.ibm-common-services --ignore-not-found

oc delete operandrequest -n ibm-common-services --all
oc delete operandrequest -n ibm-common-services --all --ignore-not-found

oc delete operandconfig -n ibm-common-services --all
oc delete operandconfig -n ibm-common-services --all --ignore-not-found

oc delete operandregistry -n ibm-common-services --all
oc delete operandregistry -n ibm-common-services --all --ignore-not-found

oc delete nss -n ibm-common-services --all
oc delete nss -n ibm-common-services --all --ignore-not-found

oc delete sub -n ibm-common-services --all
oc delete csv -n ibm-common-services --all
oc delete sub -n ibm-common-services --all --ignore-not-found
oc delete csv -n ibm-common-services --all --ignore-not-found

log "Deleting ibm-common-services project"
oc delete ns ibm-common-services

log "Deleting IBM catalog sources"
oc delete catsrc -n openshift-marketplace \
$(oc get catsrc -n openshift-marketplace \
--no-headers | grep -E 'IBM|MANTA' | awk '{print $1}')
--no-headers | grep -E 'IBM|MANTA' | awk '{print $1}') --ignore-not-found

exit 0

0 comments on commit 244023f

Please sign in to comment.