From 70f08bea0cfef874dce3057abdd97ee036ff8fe5 Mon Sep 17 00:00:00 2001 From: Marin Date: Mon, 27 Sep 2021 14:12:52 -0700 Subject: [PATCH] add terminationGracePeriodSeconds option --- api/redisfailover/v1/types.go | 43 +++++++++++---------- operator/redisfailover/service/generator.go | 27 ++++++++----- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/api/redisfailover/v1/types.go b/api/redisfailover/v1/types.go index 9005eff81..20072a843 100644 --- a/api/redisfailover/v1/types.go +++ b/api/redisfailover/v1/types.go @@ -32,27 +32,28 @@ type RedisCommandRename struct { // RedisSettings defines the specification of the redis cluster type RedisSettings struct { - Image string `json:"image,omitempty"` - ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` - Replicas int32 `json:"replicas,omitempty"` - Resources corev1.ResourceRequirements `json:"resources,omitempty"` - CustomConfig []string `json:"customConfig,omitempty"` - CustomCommandRenames []RedisCommandRename `json:"customCommandRenames,omitempty"` - Command []string `json:"command,omitempty"` - ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"` - Storage RedisStorage `json:"storage,omitempty"` - Exporter RedisExporter `json:"exporter,omitempty"` - Affinity *corev1.Affinity `json:"affinity,omitempty"` - SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` - ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` - PodAnnotations map[string]string `json:"podAnnotations,omitempty"` - ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"` - HostNetwork bool `json:"hostNetwork,omitempty"` - DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"` - PriorityClassName string `json:"priorityClassName,omitempty"` - ServiceAccountName string `json:"serviceAccountName,omitempty"` + Image string `json:"image,omitempty"` + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + Replicas int32 `json:"replicas,omitempty"` + Resources corev1.ResourceRequirements `json:"resources,omitempty"` + CustomConfig []string `json:"customConfig,omitempty"` + CustomCommandRenames []RedisCommandRename `json:"customCommandRenames,omitempty"` + Command []string `json:"command,omitempty"` + ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"` + Storage RedisStorage `json:"storage,omitempty"` + Exporter RedisExporter `json:"exporter,omitempty"` + Affinity *corev1.Affinity `json:"affinity,omitempty"` + SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + PodAnnotations map[string]string `json:"podAnnotations,omitempty"` + ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"` + HostNetwork bool `json:"hostNetwork,omitempty"` + DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"` + PriorityClassName string `json:"priorityClassName,omitempty"` + ServiceAccountName string `json:"serviceAccountName,omitempty"` + TerminationGracePeriodSeconds int64 `json:"terminationGracePeriod,omitempty"` } // SentinelSettings defines the specification of the sentinel cluster diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 1c90656d8..644cc212e 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -244,6 +244,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri labels = util.MergeLabels(labels, selectorLabels) volumeMounts := getRedisVolumeMounts(rf) volumes := getRedisVolumes(rf) + terminationGracePeriodSeconds := getTerminationGracePeriodSeconds(rf) ss := &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ @@ -268,15 +269,16 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri Annotations: rf.Spec.Redis.PodAnnotations, }, Spec: corev1.PodSpec{ - Affinity: getAffinity(rf.Spec.Redis.Affinity, labels), - Tolerations: rf.Spec.Redis.Tolerations, - NodeSelector: rf.Spec.Redis.NodeSelector, - SecurityContext: getSecurityContext(rf.Spec.Redis.SecurityContext), - HostNetwork: rf.Spec.Redis.HostNetwork, - DNSPolicy: getDnsPolicy(rf.Spec.Redis.DNSPolicy), - ImagePullSecrets: rf.Spec.Redis.ImagePullSecrets, - PriorityClassName: rf.Spec.Redis.PriorityClassName, - ServiceAccountName: rf.Spec.Redis.ServiceAccountName, + Affinity: getAffinity(rf.Spec.Redis.Affinity, labels), + Tolerations: rf.Spec.Redis.Tolerations, + NodeSelector: rf.Spec.Redis.NodeSelector, + SecurityContext: getSecurityContext(rf.Spec.Redis.SecurityContext), + HostNetwork: rf.Spec.Redis.HostNetwork, + DNSPolicy: getDnsPolicy(rf.Spec.Redis.DNSPolicy), + ImagePullSecrets: rf.Spec.Redis.ImagePullSecrets, + PriorityClassName: rf.Spec.Redis.PriorityClassName, + ServiceAccountName: rf.Spec.Redis.ServiceAccountName, + TerminationGracePeriodSeconds: &terminationGracePeriodSeconds, Containers: []corev1.Container{ { Name: "redis", @@ -799,3 +801,10 @@ func pullPolicy(specPolicy corev1.PullPolicy) corev1.PullPolicy { } return specPolicy } + +func getTerminationGracePeriodSeconds(rf *redisfailoverv1.RedisFailover) int64 { + if rf.Spec.Redis.TerminationGracePeriodSeconds > 0 { + return rf.Spec.Redis.TerminationGracePeriodSeconds + } + return 30 +}