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

Add config content variables for readability. #113

Merged
merged 1 commit into from
Feb 18, 2019
Merged
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
29 changes: 16 additions & 13 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func generateSentinelConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels m
namespace := rf.Namespace

labels = util.MergeLabels(labels, generateLabels(sentinelRoleName, rf.Name))
sentinelConfigFileContent := `sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 3000
sentinel parallel-syncs mymaster 2`

return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -97,10 +101,7 @@ func generateSentinelConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels m
OwnerReferences: ownerRefs,
},
Data: map[string]string{
sentinelConfigFileName: `sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 3000
sentinel parallel-syncs mymaster 2`,
sentinelConfigFileName: sentinelConfigFileContent,
},
}
}
Expand All @@ -110,6 +111,10 @@ func generateRedisConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[
namespace := rf.Namespace

labels = util.MergeLabels(labels, generateLabels(redisRoleName, rf.Name))
redisConfigFileContent := `slaveof 127.0.0.1 6379
tcp-keepalive 60
save 900 1
save 300 10`

return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -119,10 +124,7 @@ func generateRedisConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[
OwnerReferences: ownerRefs,
},
Data: map[string]string{
redisConfigFileName: `slaveof 127.0.0.1 6379
tcp-keepalive 60
save 900 1
save 300 10`,
redisConfigFileName: redisConfigFileContent,
},
}
}
Expand All @@ -132,6 +134,11 @@ func generateRedisShutdownConfigMap(rf *redisfailoverv1alpha2.RedisFailover, lab
namespace := rf.Namespace

labels = util.MergeLabels(labels, generateLabels(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)
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`

return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -141,11 +148,7 @@ func generateRedisShutdownConfigMap(rf *redisfailoverv1alpha2.RedisFailover, lab
OwnerReferences: ownerRefs,
},
Data: map[string]string{
"shutdown.sh": `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)
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`,
"shutdown.sh": shutdownContent,
},
}
}
Expand Down