-
Notifications
You must be signed in to change notification settings - Fork 368
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
Elect a new master on sigterm #70
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ import ( | |
) | ||
|
||
const ( | ||
redisConfigurationVolumeName = "redis-config" | ||
redisStorageVolumeName = "redis-data" | ||
redisConfigurationVolumeName = "redis-config" | ||
redisShutdownConfigurationVolumeName = "redis-shutdown-config" | ||
redisStorageVolumeName = "redis-data" | ||
) | ||
|
||
func generateSentinelService(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.Service { | ||
|
@@ -122,6 +123,28 @@ tcp-keepalive 60`, | |
} | ||
} | ||
|
||
func generateRedisShutdownConfigMap(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap { | ||
name := GetRedisShutdownConfigMapName(rf) | ||
namespace := rf.Namespace | ||
|
||
labels = util.MergeLabels(labels, generateLabels(redisRoleName, rf.Name)) | ||
|
||
return &corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Namespace: namespace, | ||
Labels: labels, | ||
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) | ||
if [[ $master == $(hostname -i) ]]; then | ||
redis-cli -h ${RFS_REDIS_SERVICE_HOST} -p ${RFS_REDIS_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster | ||
fi`, | ||
}, | ||
} | ||
} | ||
|
||
func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *appsv1beta2.StatefulSet { | ||
name := GetRedisName(rf) | ||
namespace := rf.Namespace | ||
|
@@ -202,6 +225,13 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma | |
}, | ||
}, | ||
Resources: resources, | ||
Lifecycle: &corev1.Lifecycle{ | ||
PreStop: &corev1.Handler{ | ||
Exec: &corev1.ExecAction{ | ||
Command: []string{"/bin/sh", "-c", "/redis-shutdown/shutdown.sh"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Volumes: volumes, | ||
|
@@ -541,6 +571,10 @@ func getRedisVolumeMounts(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volu | |
Name: redisConfigurationVolumeName, | ||
MountPath: "/redis", | ||
}, | ||
{ | ||
Name: redisShutdownConfigurationVolumeName, | ||
MountPath: "/redis-shutdown", | ||
}, | ||
{ | ||
Name: getRedisDataVolumeName(rf), | ||
MountPath: "/data", | ||
|
@@ -552,7 +586,9 @@ func getRedisVolumeMounts(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volu | |
|
||
func getRedisVolumes(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volume { | ||
configMapName := GetRedisConfigMapName(rf) | ||
shutdownConfigMapName := GetRedisShutdownConfigMapName(rf) | ||
|
||
defaultMode := int32(0744) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the mounting mode by default. I'd change this to "executionMode" |
||
volumes := []corev1.Volume{ | ||
{ | ||
Name: redisConfigurationVolumeName, | ||
|
@@ -564,6 +600,17 @@ func getRedisVolumes(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volume { | |
}, | ||
}, | ||
}, | ||
{ | ||
Name: redisShutdownConfigurationVolumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: shutdownConfigMapName, | ||
}, | ||
DefaultMode: &defaultMode, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
dataVolume := getRedisDataVolume(rf) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,24 @@ func GetRedisConfigMapName(rf *redisfailoverv1alpha2.RedisFailover) string { | |
return GetRedisName(rf) | ||
} | ||
|
||
// GetRedisShutdownConfigMapName returns the name for redis configmap | ||
func GetRedisShutdownConfigMapName(rf *redisfailoverv1alpha2.RedisFailover) string { | ||
if rf.Spec.Redis.ShutdownConfigMap != "" { | ||
return rf.Spec.Redis.ShutdownConfigMap | ||
} | ||
return GetRedisShowDownName(rf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
} | ||
|
||
// GetRedisName returns the name for redis resources | ||
func GetRedisName(rf *redisfailoverv1alpha2.RedisFailover) string { | ||
return generateName(redisName, rf.Name) | ||
} | ||
// GetRedisName returns the name for redis resources | ||
func GetRedisShowDownName(rf *redisfailoverv1alpha2.RedisFailover) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
return generateName(redisShutdownName, rf.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would create "rfshutdown-rfname". Do you think it's explanatory or it should be in other way? |
||
} | ||
|
||
|
||
|
||
// GetSentinelConfigMapName returns the name for sentinel configmap | ||
func GetSentinelConfigMapName(rf *redisfailoverv1alpha2.RedisFailover) string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why checking the ConfigMap if the Esure is for the ShutdownConfigMap?