diff --git a/example/redisfailover/custom-shutdown.yaml b/example/redisfailover/custom-shutdown.yaml index 6b320102c..45bddcdcd 100644 --- a/example/redisfailover/custom-shutdown.yaml +++ b/example/redisfailover/custom-shutdown.yaml @@ -17,8 +17,8 @@ metadata: data: shutdown.sh: | echo "shutdown in progress..." - master=$(redis-cli -h ${RFS_REDIS_SERVICE_HOST} -p ${RFS_REDIS_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) + master=$(redis-cli -h ${RFS_REDISFAILOVER_SERVICE_HOST} -p ${RFS_REDISFAILOVER_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) redis-cli SAVE if [[ $master == $(hostname -i) ]]; then - redis-cli -h ${RFS_REDIS_SERVICE_HOST} -p ${RFS_REDIS_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster + redis-cli -h ${RFS_REDISFAILOVER_SERVICE_HOST} -p ${RFS_REDISFAILOVER_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster fi diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 68e9d9a54..cd763f359 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "strings" "bytes" @@ -161,13 +162,14 @@ func generateRedisConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string func generateRedisShutdownConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap { name := GetRedisShutdownConfigMapName(rf) namespace := rf.Namespace + rfName := strings.ToUpper(rf.Name) labels = util.MergeLabels(labels, generateSelectorLabels(redisRoleName, rf.Name)) - shutdownContent := `master=$(redis-cli -h ${RFS_REDIS_SERVICE_HOST} -p ${RFS_REDIS_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) + shutdownContent := fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) redis-cli SAVE if [ "$master" = "$(hostname -i)" ]; then - redis-cli -h ${RFS_REDIS_SERVICE_HOST} -p ${RFS_REDIS_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster -fi` + redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster +fi`, rfName) return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{