#!/bin/bash
#
# https://quay.io/repository/ceph/ceph?tab=tags
#
#NEW_CEPH_IMAGE="ceph/ceph:v14.2.2-20190722"
#NEW_CEPH_IMAGE="ceph/ceph:v14.2.8-20200305"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.0-20200324"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.1-20200410"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.2-20200519"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.3-20200530"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.4-20200630"
#NEW_CEPH_IMAGE="ceph/ceph:v15.2.5-20200916"
##NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.4-20210514"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.5-20210708"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.6-20210926"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.6-20210927"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.7"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.7-20220303"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.7-20220317"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v17.1.0-20220317"
# cluster.yaml
   # Whether to allow unsupported versions of Ceph. Currently `octopus` and `pacific` are supported.
   # Future versions such as `pacific` would require this to be set to `true`.
   # Do not set to true in production.
#  allowUnsupported: false
# NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.7-20220317"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v16.2.10"
#NEW_CEPH_IMAGE="quay.io/ceph/ceph:v17.2.6-20230410"
NEW_CEPH_IMAGE="quay.io/ceph/ceph:v18.2.0-20230912"

export ROOK_SYSTEM_NAMESPACE="rook-ceph-system"
export ROOK_SYSTEM_NAMESPACE="rook-ceph"
export ROOK_NAMESPACE="rook-ceph"
CLUSTER_NAME="$ROOK_NAMESPACE"  # change if your cluster name is not the Rook namespace

RUNNER=""
[ "$1" == "-w" ] && RUNNER="watch" && shift
if [ "$1" == "update" ] ; then 
   [ -z "$RUNNER" ] && RUNNER="watch"
   kubectl -n $ROOK_NAMESPACE patch CephCluster $CLUSTER_NAME --type=merge \
     -p "{\"spec\": {\"cephVersion\": {\"image\": \"$NEW_CEPH_IMAGE\"}}}"
fi

CMD='kubectl -n $ROOK_NAMESPACE describe pods | grep "Image:.*ceph/ceph" | sort | uniq -c'
#CMD='kubectl -n $ROOK_NAMESPACE describe pods | grep "Image:.*ceph/ceph" '

if [ -z "$RUNNER" ] ; then 
   eval $CMD
else
   $RUNNER $CMD
fi
