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

Replace master with primary in all occurrences of scripts #1316

Merged
merged 3 commits into from
Sep 26, 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
10 changes: 5 additions & 5 deletions install/Docker/dockerfiles/Dockerfile.redis
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ RUN if [ -z "$ODIMRA_USER_ID" ] || [ -z "$ODIMRA_GROUP_ID" ]; then \

RUN apt-get -y update
RUN apt-get -y install openssl bash sed
RUN mkdir /redis-master /redis-slave
RUN mkdir /redis-primary /redis-secondary

COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-master.conf /redis-master/redis.conf
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-slave.conf /redis-slave/redis.conf
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-primary.conf /redis-primary/redis.conf
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-secondary.conf /redis-secondary/redis.conf
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-createschema.sh /createschema.sh
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-checkdb.sh /checkdb.sh
COPY --chown=odimra:odimra install/Docker/dockerfiles/scripts/redis-entrypointsetup.sh /entrypointsetup.sh

RUN chmod 0700 /entrypointsetup.sh /redis-master /redis-slave
RUN chown -R odimra:odimra /data /redis-master /redis-slave
RUN chmod 0700 /entrypointsetup.sh /redis-primary /redis-secondary
RUN chown -R odimra:odimra /data /redis-primary /redis-secondary

USER odimra:odimra

Expand Down
2 changes: 1 addition & 1 deletion install/Docker/dockerfiles/scripts/redis-checkdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
sleep 3
echo "Checking if default entries already present"
redis_password=$(openssl pkeyutl -decrypt -in cipher -inkey ${ODIMRA_RSA_PRIVATE_FILE} -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha512)
redis-cli -a ${redis_password} -h ${master} -p ${REDIS_HA_REDIS_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} <<HERE
redis-cli -a ${redis_password} -h ${primary} -p ${REDIS_HA_REDIS_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} <<HERE
exists "role:Administrator"
HERE
2 changes: 1 addition & 1 deletion install/Docker/dockerfiles/scripts/redis-createschema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RETURN=`/checkdb.sh | grep '0' > /dev/null`
if [ $? -eq 0 ]; then
echo "Updating the db with default entries"
redis_password=$(openssl pkeyutl -decrypt -in cipher -inkey ${ODIMRA_RSA_PRIVATE_FILE} -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha512)
redis-cli -a ${redis_password} -h ${master} -p ${REDIS_HA_REDIS_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} <<HERE
redis-cli -a ${redis_password} -h ${primary} -p ${REDIS_HA_REDIS_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} <<HERE
Set "registry:assignedprivileges" '{"List":["Login", "ConfigureManager", "ConfigureUsers", "ConfigureSelf", "ConfigureComponents"]}'
Set "roles:redfishdefined" '{"List":["Administrator", "Operator", "ReadOnly"]}'
Set "User:admin" '{"UserName":"admin","Password":"O01bKrP7Tzs7YoO3YvQt4pRa2J_R6HI34ZfP4MxbqNIYAVQVt2ewGXmhjvBfzMifM7bHFccXKGmdHvj3hY44Hw==","RoleId":"Administrator", "AccountTypes":["Redfish"]}'
Expand Down
123 changes: 61 additions & 62 deletions install/Docker/dockerfiles/scripts/redis-entrypointsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,25 @@
# EntrypointSetup script for deploying redis HA via Sentinel in a kubernetes cluster
# This script expects following environment variables to be set,
# 1. SENTINEL: true if this is sentinel instance, else false.
# 2. MASTER: true if this is master instance, this is helpful when starting the cluster for the first time.
# 2. PRIMARY: true if this is primary instance, this is helpful when starting the cluster for the first time.
# 3. REDIS_HA_SENTINEL_SERVICE_HOST: this is service name of sentinel, check the yaml.
# 4. REDIS_HA_SENTINEL_SERVICE_PORT: this is service port of sentinel.
# 5. REDIS_HA_REDIS_SERVICE_HOST: this is master's service name, this is needed when sentinel starts for the first time.
# 6. REDIS_HA_REDIS_SERVICE_PORT: this is master's port, is needed when sentinel starts for the first time.
# 5. REDIS_HA_REDIS_SERVICE_HOST: this is primary's service name, this is needed when sentinel starts for the first time.
# 6. REDIS_HA_REDIS_SERVICE_PORT: this is primary's port, is needed when sentinel starts for the first time.
# 7. REDIS_DEFAULT_PASSWORD: default password for Redis instances.

# This method launches redis instance which assumes it self as master
function launchmaster() {
echo "Starting Redis instance as Master.."
# This method launches redis instance which assumes it self as primary
function launchprimary() {
echo "Starting Redis instance as Primary.."
redis_password=$(openssl pkeyutl -decrypt -in cipher -inkey ${ODIMRA_RSA_PRIVATE_FILE} -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha512)
echo "while true; do sleep 2; export master=\$(hostname -I | cut -d ' ' -f 1); echo \"Master IP is Me : \${master}\"; echo \"Setting STARTUP_MASTER_IP in redis\"; redis-cli -a '${redis_password}' -h \${master} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} set STARTUP_MASTER_IP \${master}; if [ \$? == \"0\" ]; then echo \"Successfully set STARTUP_MASTER_IP\"; if [ \${REDIS_ONDISK_DB} == \"true\" ]; then bash \/createschema.sh; fi; break; fi; echo \"Connecting to master \${master} failed. Waiting...\"; sleep 5; done" > insert_master_ip_and_default_entries.sh
bash insert_master_ip_and_default_entries.sh &
sed -i "s/REDIS_DEFAULT_PASSWORD/${redis_password}/" /redis-master/redis.conf

echo "while true; do sleep 2; export primary=\$(hostname -I | cut -d ' ' -f 1); echo \"Primary IP is Me : \${primary}\"; echo \"Setting STARTUP_PRIMARY_IP in redis\"; redis-cli -a '${redis_password}' -h \${primary} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} set STARTUP_PRIMARY_IP \${primary}; if [ \$? == \"0\" ]; then echo \"Successfully set STARTUP_PRIMARY_IP\"; if [ \${REDIS_ONDISK_DB} == \"true\" ]; then bash \/createschema.sh; fi; break; fi; echo \"Connecting to primary \${primary} failed. Waiting...\"; sleep 5; done" > insert_primary_ip_and_default_entries.sh
bash insert_primary_ip_and_default_entries.sh &
sed -i "s/REDIS_DEFAULT_PASSWORD/${redis_password}/" /redis-primary/redis.conf
hostname=$(hostname -f)
sed -i "s/%replica-announce-ip%/${hostname}/" /redis-master/redis.conf
sed -i "s/%master-port%/${REDIS_HA_REDIS_SERVICE_PORT}/" /redis-master/redis.conf
sed -i "s/%replica-announce-ip%/${hostname}/" /redis-primary/redis.conf
sed -i "s/%primary-port%/${REDIS_HA_REDIS_SERVICE_PORT}/" /redis-primary/redis.conf

redis-server /redis-master/redis.conf --protected-mode no
redis-server /redis-primary/redis.conf --protected-mode no
}

# This method launches sentinels
Expand All @@ -50,10 +49,10 @@ function launchsentinel() {
x=1
while [ $x -le 5 ]
do
master=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-master-addr-by-name ${REDIS_MASTER_SET} | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
echo "Connected to Sentinel Service and retrieved Redis Master hostname as ${master}"
master="${master//\"}"
primary=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-primary-addr-by-name ${REDIS_PRIMARY_SET} | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${primary} ]]; then
echo "Connected to Sentinel Service and retrieved Redis Primary hostname as ${primary}"
primary="${primary//\"}"
break
else
echo "Unable to connect to sentinel, retrying..."
Expand All @@ -62,17 +61,17 @@ function launchsentinel() {
x=$(( $x + 1 ))
done

if ! [[ -n ${master} ]]; then
echo "Unable to connect to Sentinel Service, probably because I am first Sentinel to start. I will use default master hostname ${MASTER_HOST_NAME} to connect to sentinel"
master=${MASTER_HOST_NAME}
if ! [[ -n ${primary} ]]; then
echo "Unable to connect to Sentinel Service, probably because I am first Sentinel to start. I will use default primary hostname ${PRIMARY_HOST_NAME} to connect to sentinel"
primary=${PRIMARY_HOST_NAME}
fi

while true; do
redis-cli -a ${redis_password} -h ${master} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} INFO
redis-cli -a ${redis_password} -h ${primary} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
echo "Connecting to primary failed. Waiting..."
sleep 10
done

Expand All @@ -84,12 +83,12 @@ function launchsentinel() {
echo "sentinel announce-hostnames yes" >> ${sentinel_conf}
echo "sentinel announce-ip ${hostname}" >> ${sentinel_conf}
echo "sentinel announce-port ${REDIS_HA_SENTINEL_SERVICE_PORT}" >> ${sentinel_conf}
echo "sentinel monitor ${REDIS_MASTER_SET} ${master} ${REDIS_HA_REDIS_SERVICE_PORT} ${SENTINEL_QUORUM}" >> ${sentinel_conf}
echo "sentinel auth-pass ${REDIS_MASTER_SET} ${redis_password}" >> ${sentinel_conf}
echo "sentinel monitor ${REDIS_PRIMARY_SET} ${primary} ${REDIS_HA_REDIS_SERVICE_PORT} ${SENTINEL_QUORUM}" >> ${sentinel_conf}
echo "sentinel auth-pass ${REDIS_PRIMARY_SET} ${redis_password}" >> ${sentinel_conf}
echo "requirepass ${redis_password}" >> ${sentinel_conf}
echo "sentinel down-after-milliseconds ${REDIS_MASTER_SET} ${DOWN_AFTER_MILLISECONDS}" >> ${sentinel_conf}
echo "sentinel failover-timeout ${REDIS_MASTER_SET} ${FAILOVER_TIMEOUT}" >> ${sentinel_conf}
echo "sentinel parallel-syncs ${REDIS_MASTER_SET} ${PARALLEL_SYNCS}" >> ${sentinel_conf}
echo "sentinel down-after-milliseconds ${REDIS_PRIMARY_SET} ${DOWN_AFTER_MILLISECONDS}" >> ${sentinel_conf}
echo "sentinel failover-timeout ${REDIS_PRIMARY_SET} ${FAILOVER_TIMEOUT}" >> ${sentinel_conf}
echo "sentinel parallel-syncs ${REDIS_PRIMARY_SET} ${PARALLEL_SYNCS}" >> ${sentinel_conf}
echo "bind 0.0.0.0" >> ${sentinel_conf}
echo "port 0" >> ${sentinel_conf}
echo "tls-port 26379" >> ${sentinel_conf}
Expand All @@ -102,42 +101,42 @@ function launchsentinel() {
redis-sentinel ${sentinel_conf} --protected-mode no
}

# This method launches slave instances
function launchslave() {
echo "Starting Redis instance as Slave , Master IP $1"
# This method launches secondry instances
function launchsecondry() {
echo "Starting Redis instance as Secondry , Primary IP $1"

redis_password=$(openssl pkeyutl -decrypt -in cipher -inkey ${ODIMRA_RSA_PRIVATE_FILE} -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha512)
while true; do
echo "Trying to retrieve the Master IP again, in case of failover master ip would have changed."
master=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-master-addr-by-name ${REDIS_MASTER_SET} | tr ',' ' ' | cut -d' ' -f1)
echo "Trying to retrieve the Primary IP again, in case of failover primary ip would have changed."
Primary=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-primary-addr-by-name ${REDIS_PRIMARY_SET} | tr ',' ' ' | cut -d' ' -f1)

if [[ -n ${master} ]]; then
master="${master//\"}"
if [[ -n ${primary} ]]; then
primary="${primary//\"}"
else
echo "Failed to find master."
echo "Failed to find primary."
sleep 60
continue
fi
redis-cli -a ${redis_password} -h ${master} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} INFO
redis-cli -a ${redis_password} -h ${primary} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
echo "Connecting to primary failed. Waiting..."
sleep 10
done

hostname=$(hostname -f)
sed -i "s/%master-ip%/${master}/" /redis-slave/redis.conf
sed -i "s/%master-port%/${REDIS_HA_REDIS_SERVICE_PORT}/" /redis-slave/redis.conf
sed -i "s/REDIS_DEFAULT_PASSWORD/${redis_password}/" /redis-slave/redis.conf
sed -i "s/%replica-announce-ip%/${hostname}/" /redis-slave/redis.conf
sed -i "s/%replicaof%/${master}/" /redis-slave/redis.conf
sed -i "s/%primary-ip%/${primary}/" /redis-secondry/redis.conf
sed -i "s/%primary-port%/${REDIS_HA_REDIS_SERVICE_PORT}/" /redis-secondry/redis.conf
sed -i "s/REDIS_DEFAULT_PASSWORD/${redis_password}/" /redis-secondry/redis.conf
sed -i "s/%replica-announce-ip%/${hostname}/" /redis-secondry/redis.conf
sed -i "s/%replicaof%/${primary}/" /redis-secondry/redis.conf

redis-server /redis-slave/redis.conf --protected-mode no
redis-server /redis-secondry/redis.conf --protected-mode no
}


# This method launches either slave or master based on some parameters
# This method launches either secondry or primary based on some parameters
function launchredis() {
echo "Launching Redis instance"

Expand All @@ -149,35 +148,35 @@ function launchredis() {
sentinel_down_time=10
sleep ${sentinel_down_time}

# Loop till I am able to launch slave or master
# Loop till I am able to launch secondry or primary
while true; do
# I will check if sentinel is up or not by connecting to it.
echo "Trying to connect to sentinel, to retireve master's ip"
master=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-master-addr-by-name ${REDIS_MASTER_SET} | tr ',' ' ' | cut -d' ' -f1)
# Is this instance marked as MASTER, it will matter only when the cluster is starting up for first time.
if [[ "${MASTER}" == "true" ]]; then
echo "MASTER is set to true"
# If I am able get master ip, then i will connect to the master, else i will asume the role of master
if [[ -n ${master} ]]; then
echo "Connected to Sentinel, this means it is not first time start, hence will start as a slave"
echo "Trying to connect to sentinel, to retireve primary's ip"
primary=$(redis-cli -a ${redis_password} -h ${REDIS_HA_SENTINEL_SERVICE_HOST} -p ${REDIS_HA_SENTINEL_SERVICE_PORT} --tls --cert ${TLS_CERT_FILE} --key ${TLS_KEY_FILE} --cacert ${TLS_CA_CERT_FILE} --csv SENTINEL get-primary-addr-by-name ${REDIS_PRIMARY_SET} | tr ',' ' ' | cut -d' ' -f1)
# Is this instance marked as PRIMARY, it will matter only when the cluster is starting up for first time.
if [[ "${PRIMARY}" == "true" ]]; then
echo "PRIMARY is set to true"
# If I am able get primary ip, then i will connect to the primary, else i will asume the role of primary
if [[ -n ${primary} ]]; then
echo "Connected to Sentinel, this means it is not first time start, hence will start as a secondry"
currenthost=$(hostname -f | cut -d ' ' -f 1)
master=`echo $master |tr -d '"'`
if [[ "${currenthost}" == "${master}" ]]; then
launchmaster
primary=`echo $primary |tr -d '"'`
if [[ "${currenthost}" == "${primary}" ]]; then
launchprimary
exit 0
fi
launchslave ${master}
launchsecondry ${primary}
exit 0
else
launchmaster
launchprimary
exit 0
fi
fi

# If I am not master, then i am definitely slave.
if [[ -n ${master} ]]; then
echo "Connected to Sentinel and Retrieved Master IP ${master}"
launchslave ${master}
# If I am not primary, then i am definitely secondry.
if [[ -n ${primary} ]]; then
echo "Connected to Sentinel and Retrieved Primary IP ${primary}"
launchsecondry ${primary}
exit 0
else
echo "Connecting to sentinel failed, Waiting..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,5 +893,5 @@ tls-cluster yes
# and ROLE will report those values.
#
replica-announce-ip %replica-announce-ip%
replica-announce-port %master-port%
replica-announce-port %primary-port%
#
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ dir /redis-data
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
slaveof %master-ip% %master-port%
slaveof %primary-ip% %primary-port%

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
Expand Down Expand Up @@ -893,7 +893,7 @@ tls-cluster yes
# and ROLE will report those values.
#
replica-announce-ip %replica-announce-ip%
replica-announce-port %master-port%
replica-announce-port %primary-port%
# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
Expand All @@ -913,5 +913,5 @@ replica-announce-port %master-port%
# network partition replicas automatically try to reconnect to masters
# and resynchronize with them.
#
replicaof %replicaof% %master-port%
replicaof %replicaof% %primary-port%
#
4 changes: 2 additions & 2 deletions lib-persistence-manager/persistencemgr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ type Config struct {
Host string
SentinelHost string
SentinelPort string
MasterSet string
PrimarySet string
Password string
}

// ConnPool is the established connection
type ConnPool struct {
ReadPool *redis.Client
WritePool *redis.Client
MasterIP string
PrimaryIP string
Mux sync.Mutex
}
Loading
Loading