11#! /bin/bash
22
33# Generate a random filename
4- RANDOM_FILE =" /tmp/cmo_monitoring_csv_ $( date +%s%N) .yaml"
4+ MONITORING_FILE =" /tmp/monitoring_csv_ $( date +%s%N) .yaml"
55
6- CMO_CSV_NAME =$( oc get deployment --kubeconfig " ${KUBECONFIG} " --namespace=" ${MP_NAMESPACE} " | grep " cluster- monitoring-operator " | awk ' {print $1}' )
6+ MONITORING_CSV_NAME =$( oc get deployment --kubeconfig " ${KUBECONFIG} " --namespace=" ${MP_NAMESPACE} " | grep " monitoring-plugin " | awk ' {print $1}' )
77
88oc project --namespace=" ${MP_NAMESPACE} "
99
10- oc get deployment " ${CMO_CSV_NAME } " -n " ${MP_NAMESPACE} " -o yaml > " ${RANDOM_FILE } " --kubeconfig " ${KUBECONFIG} "
10+ oc get deployment " ${MONITORING_CSV_NAME } " -n " ${MP_NAMESPACE} " -o yaml > " ${MONITORING_FILE } " --kubeconfig " ${KUBECONFIG} "
1111
1212# Patch the deployment file related images
13- sed -i " s#value: .*monitoring-plugin.*#value: ${MP_IMAGE} #g" " ${RANDOM_FILE} "
14- sed -i " s#^\([[:space:]]*- -images=monitoring-plugin=\).*#\1${MP_IMAGE} #g" " ${RANDOM_FILE} "
13+ sed -i " s#^\([[:space:]]*image: \).*#\1${MP_IMAGE} #g" " ${MONITORING_FILE} "
1514
16- oc replace -f " ${RANDOM_FILE } " --kubeconfig " ${KUBECONFIG} "
15+ oc replace -f " ${MONITORING_FILE } " --kubeconfig " ${KUBECONFIG} "
1716
18- # Scale down
17+ # Scale down the cluster-monitoring-operator as "manager" pod is responsible for the monitoring-plugin
1918oc patch clusterversion version --type json -p " $( cat disable-monitoring.yaml) "
2019
2120oc scale --replicas=0 -n " ${MP_NAMESPACE} " deployment/cluster-monitoring-operator
2221
23- oc scale --replicas=0 -n " ${MP_NAMESPACE} " deployment/monitoring-plugin
24-
2522# Apply the patched deployment resource file
26- oc replace -f " ${RANDOM_FILE} " --kubeconfig " ${KUBECONFIG} "
27-
28- # Scale up the Monitoring-plugin
29- oc scale --replicas=1 -n " ${MP_NAMESPACE} " deployment/cluster-monitoring-operator
23+ oc replace -f " ${MONITORING_FILE} " --kubeconfig " ${KUBECONFIG} "
3024
25+ # Scale up the monitoring-plugin with new image, leaving the cluster-monitoring-operator at 0 replicas to not revert the change
3126oc scale --replicas=1 -n " ${MP_NAMESPACE} " deployment/monitoring-plugin
3227
3328# Wait for the operator to reconcile the change and make sure all the pods are running.
3429sleep 30
3530OUTPUT=` oc wait --for=condition=Ready pods --selector=app.kubernetes.io/part-of=monitoring-plugin -n " ${MP_NAMESPACE} " --timeout=60s`
36- echo " ${OUTPUT} "
37- OUTPUT=` oc wait --for=condition=ready pods -l app.kubernetes.io/name=cluster-monitoring-operator -n " ${MP_NAMESPACE} " --timeout=60s --kubeconfig " ${KUBECONFIG} " `
3831echo " ${OUTPUT} "
0 commit comments