OT-CONTAINER-KIT / redis-operator

A golang based redis operator that will make/oversee Redis standalone/cluster/replication/sentinel mode setup on top of the Kubernetes.
https://ot-redis-operator.netlify.app/
Apache License 2.0
752 stars 209 forks source link

Dynamically GetMasterIP(replication) methods without restarting sentinel #436

Open muicoder opened 1 year ago

muicoder commented 1 year ago

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Describe alternatives you've considered

What version of redis-operator are you using?

redis-operator version: v0.14.0

Additional context

https://github.com/spotahome/redis-operator/blob/fe8090ac7291ee53ac30e534fa1cc03e5759fd10/operator/redisfailover/service/check.go#L266

muicoder commented 1 year ago

Use script to get MasterIP method

if [ -s "$REDIS_TLS_CA_KEY" ]; then
  readonly REDIS_CLI="redis-cli --tls --cacert $REDIS_TLS_CA_KEY"
else
  readonly REDIS_CLI="redis-cli"
fi

readonly REPLSVC="${REPLICATION:-repl}"

until $REDIS_CLI -h "$MASTER_HOST" -p "$MASTER_PORT" info Keyspace 2>/dev/null; do
  eval "$($REDIS_CLI -h "$REPLSVC" info Replication 2>/dev/null | grep "master_[hp]o[rs]t:" | awk -F: '{sub("\r$", "");printf("%s=%s\n"),toupper($1),$2}')"
  sleep 1
done

echo "sentinel monitor ${MASTER_GROUP_NAME:-myMaster} ${IP:-$MASTER_HOST} ${PORT:-$MASTER_PORT} ${QUORUM:-2}"

https://github.com/muicoder/redis-operator/blob/action/chart/files/entrypoint.sh#L99

Tested for Chart

https://github.com/muicoder/redis-operator/compare/master...action

muicoder commented 1 year ago

After the master-slave switchover, the env(IP) address change triggers the pod to restart.