Skip to content

Commit

Permalink
redis-ha: add redis source to restore options
Browse files Browse the repository at this point in the history
  • Loading branch information
hawwwdi committed Sep 11, 2024
1 parent 4d03a7e commit 67bf680
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
22 changes: 11 additions & 11 deletions charts/redis-ha/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ apiVersion: v2
name: redis-ha
home: http://redis.io/
keywords:
- redis
- keyvalue
- database
version: 4.27.6
- redis
- keyvalue
- database
version: 4.27.7
appVersion: 7.2.4
description: This Helm chart provides a highly available Redis implementation with a master/slave configuration and uses Sentinel sidecars for failover management
icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png
maintainers:
- email: [email protected]
name: ssalaues
- email: [email protected]
name: dandydeveloper
- email: [email protected]
name: ssalaues
- email: [email protected]
name: dandydeveloper
sources:
- https://redis.io/download
- https://github.com/DandyDeveloper/charts/blob/master/charts/redis-ha
- https://github.com/oliver006/redis_exporter
- https://redis.io/download
- https://github.com/DandyDeveloper/charts/blob/master/charts/redis-ha
- https://github.com/oliver006/redis_exporter
2 changes: 2 additions & 0 deletions charts/redis-ha/templates/redis-ha-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

{{- $regexRestoreS3 := "^s3://.+|^S3://.+" -}}
{{- $regexRestoreSSH := "^.+@.+:.+" -}}
{{- $regexRestoreRedis := "^redis://(?:[A-Za-z0-9_]+(?::[^@]+)?@)?[A-Za-z0-9.-]+(?::\\d{1,5})?(?:/\\d+)?$" -}}


{{- if or (regexFind $regexRestoreSSH (toString .Values.restore.ssh.source)) (regexFind $regexRestoreS3 (toString .Values.restore.s3.source)) }}
apiVersion: v1
Expand Down
28 changes: 28 additions & 0 deletions charts/redis-ha/templates/redis-ha-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- $regexRestoreS3 := "^s3://.+|^S3://.+" -}}
{{- $regexRestoreSSH := "^.+@.+:.+" -}}
{{- $regexRestoreRedis := "^redis://(?:[A-Za-z0-9_]+(?::[^@]+)?@)?[A-Za-z0-9.-]+(?::\\d{1,5})?(?:/\\d+)?$" -}}


apiVersion: apps/v1
kind: StatefulSet
Expand Down Expand Up @@ -243,6 +245,32 @@ spec:
- name: data
mountPath: /data
{{- end }}
{{ if regexFind $regexRestoreRedis (toString .Values.restore.redis.source) }}
- name: restore-redis
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{ toYaml .Values.init.resources | indent 10 }}
command:
- sh
args:
- "-c"
- "test ! -s /data/dump.rdb \
&& timeout {{ .Values.restore.timeout }} \
redis-cli -u {{ .Values.restore.redis.source }} --rdb /data/dump.rdb_ \
&& test -s /data/dump.rdb_ \
&& if test -s /data/dump.rdb; \
then cp -v /data/dump.rdb /data/dump.rdb_orig; fi \
&& mv -v /data/dump.rdb_ /data/dump.rdb"
{{- if .Values.restore.existingSecret }}
envFrom:
- secretRef:
name: {{ .Values.existingSecret }}
{{- end }}
volumeMounts:
- name: data
mountPath: /data
{{- end }}
{{- if .Values.extraInitContainers }}
{{- toYaml .Values.extraInitContainers | nindent 6 }}
{{- end }}
Expand Down
41 changes: 25 additions & 16 deletions charts/redis-ha/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ haproxy:
## Pod Disruption Budget
## ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/
##
podDisruptionBudget: {}
podDisruptionBudget:
{}
# Use only one of the two
# maxUnavailable: 1
# minAvailable: 1
Expand Down Expand Up @@ -187,7 +188,7 @@ haproxy:
type: RuntimeDefault
capabilities:
drop:
- ALL
- ALL

## Whether the haproxy pods should be forced to run on separate nodes.
hardAntiAffinity: true
Expand All @@ -201,10 +202,10 @@ haproxy:
## Custom config-haproxy.cfg files used to override default settings. If this file is
## specified then the config-haproxy.cfg above will be ignored.
# customConfig: |-
# Define configuration here
# Define configuration here
## Place any additional configuration section to add to the default config-haproxy.cfg
# extraConfig: |-
# Define configuration here
# Define configuration here

## Container lifecycle hooks
## Ref: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
Expand All @@ -225,7 +226,8 @@ haproxy:
labels: {}
## user defines ingress rules that Haproxy should permit into
## uses the format defined in https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
ingressRules: []
ingressRules:
[]
# - selectors:
# - namespaceSelector:
# matchLabels:
Expand Down Expand Up @@ -271,7 +273,7 @@ sysctlImage:
## Redis specific configuration options
redis:
port: 6379
masterGroupName: "mymaster" # must match ^[\\w-\\.]+$) and can be templated
masterGroupName: "mymaster" # must match ^[\\w-\\.]+$) and can be templated

customCommand: []
# - bash
Expand Down Expand Up @@ -318,9 +320,9 @@ redis:
## Additional redis conf options can be added below
## For all available options see http://download.redis.io/redis-stable/redis.conf
min-replicas-to-write: 1
min-replicas-max-lag: 5 # Value in seconds
maxmemory: "0" # Max memory to use for each redis instance. Default is unlimited.
maxmemory-policy: "volatile-lru" # Max memory policy to use for each redis instance. Default is volatile-lru.
min-replicas-max-lag: 5 # Value in seconds
maxmemory: "0" # Max memory to use for each redis instance. Default is unlimited.
maxmemory-policy: "volatile-lru" # Max memory policy to use for each redis instance. Default is volatile-lru.
# Determines if scheduled RDB backups are created. Default is false.
# Please note that local (on-disk) RDBs will still be created when re-syncing with a new slave. The only way to prevent this is to enable diskless replication.
save: "900 1"
Expand All @@ -332,7 +334,7 @@ redis:
## Custom redis.conf files used to override default settings. If this file is
## specified then the redis.config above will be ignored.
# customConfig: |-
# Define configuration here
# Define configuration here

resources: {}
# requests:
Expand Down Expand Up @@ -422,7 +424,7 @@ sentinel:
## Custom sentinel.conf files used to override default settings. If this file is
## specified then the sentinel.config above will be ignored.
# customConfig: |-
# Define configuration here
# Define configuration here

resources: {}
# requests:
Expand Down Expand Up @@ -453,7 +455,7 @@ containerSecurityContext:
type: RuntimeDefault
capabilities:
drop:
- ALL
- ALL

## Assuming your kubelet allows it, you can the following instructions to configure
## specific sysctl parameters
Expand Down Expand Up @@ -606,7 +608,8 @@ exporter:
periodSeconds: 15
successThreshold: 2

podDisruptionBudget: {}
podDisruptionBudget:
{}
# Use only one of the two
# maxUnavailable: 1
# minAvailable: 1
Expand Down Expand Up @@ -669,14 +672,16 @@ tls:
## Name of CA certificate file
caCertFile: ca.crt

# restore init container is executed if restore.[s3|ssh].source is not false
# restore init container is executed if restore.[s3|ssh|redis].source is not false
# restore init container creates /data/dump.rdb_ from original if exists
# restore init container overrides /data/dump.rdb
# secrets are stored into environment of init container - stored encoded on k8s
# REQUIRED for s3 restore: AWS 'access_key' and 'secret_key' or stored in existingSecret
# EXAMPLE source for s3 restore: 's3://bucket/dump.rdb'
# REQUIRED for ssh restore: 'key' should be in one line including CR i.e. '-----BEGIN RSA PRIVATE KEY-----\n...\n...\n...\n-----END RSA PRIVATE KEY-----'
# EXAMPLE source for ssh restore: 'user@server:/path/dump.rdb'
# REQUIRED for redis restore: 'source' should be in form of redis connection uri: 'redis://[username:password@]host:port[/db]'
# EXAMPLE source for redis restore: 'redis://username:password@localhost:6379'
restore:
timeout: 600
# Set existingSecret to true to use secret specified in existingSecret above
Expand All @@ -693,6 +698,8 @@ restore:
ssh:
source: false
key: ""
redis:
source: false

## Custom PrometheusRule to be defined
## The value is evaluated as a template, so, for example, the value can depend on .Release or .Chart
Expand All @@ -707,7 +714,8 @@ prometheusRule:
# prometheusRule.interval -- How often rules in the group are evaluated (falls back to `global.evaluation_interval` if not set).
interval: 10s
# prometheusRule.rules -- Rules spec template (see https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#rule).
rules: []
rules:
[]
# Example:
# - alert: RedisPodDown
# expr: |
Expand Down Expand Up @@ -740,7 +748,8 @@ networkPolicy:
labels: {}
## user defines ingress rules that Redis should permit into
## uses the format defined in https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
ingressRules: []
ingressRules:
[]
# - selectors:
# - namespaceSelector:
# matchLabels:
Expand Down

0 comments on commit 67bf680

Please sign in to comment.