Skip to content

Commit

Permalink
chore: support redis host network (#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Nov 28, 2024
1 parent e546f72 commit 0c8329a
Show file tree
Hide file tree
Showing 24 changed files with 645 additions and 163 deletions.
51 changes: 46 additions & 5 deletions addons-cluster/redis-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ Define redis cluster shardingSpec with ComponentDefinition.
name: redis
componentDef: redis-cluster-7
replicas: {{ .Values.replicas }}
{{- if .Values.nodePortEnabled }}
{{- if and .Values.nodePortEnabled (not .Values.fixedPodIPEnabled) (not .Values.hostNetworkEnabled) }}
services:
- name: redis-advertised
serviceType: NodePort
podService: true
{{- end }}
{{- if and .Values.fixedPodIPEnabled (not .Values.nodePortEnabled) (not .Values.hostNetworkEnabled) }}
env:
- name: FIXED_POD_IP_ENABLED
value: "true"
{{- end }}
{{- if and .Values.hostNetworkEnabled (not .Values.nodePortEnabled) (not .Values.fixedPodIPEnabled) }}
env:
- name: HOST_NETWORK_ENABLED
value: "true"
{{- end }}
systemAccounts:
- name: default
passwordConfig:
Expand Down Expand Up @@ -45,7 +55,7 @@ Define redis ComponentSpec with ComponentDefinition.
{{- define "redis-cluster.componentSpec" }}
- name: redis
{{- include "redis-cluster.replicaCount" . | indent 2 }}
{{- if .Values.nodePortEnabled }}
{{- if and .Values.nodePortEnabled (not .Values.fixedPodIPEnabled) (not .Values.hostNetworkEnabled) }}
services:
- name: redis-advertised
serviceType: NodePort
Expand All @@ -54,10 +64,14 @@ Define redis ComponentSpec with ComponentDefinition.
env:
- name: CUSTOM_SENTINEL_MASTER_NAME
value: {{ .Values.sentinel.customMasterName | default "" }}
{{- if .Values.fixedPodIPEnabled }}
{{- if and .Values.fixedPodIPEnabled (not .Values.nodePortEnabled) (not .Values.hostNetworkEnabled) }}
- name: FIXED_POD_IP_ENABLED
value: "true"
{{- end }}
{{- if and .Values.hostNetworkEnabled (not .Values.nodePortEnabled) (not .Values.fixedPodIPEnabled) }}
- name: HOST_NETWORK_ENABLED
value: "true"
{{- end }}
enabledLogs:
- running
serviceAccountName: {{ include "kblib.serviceAccountName" . }}
Expand All @@ -73,17 +87,22 @@ Define redis sentinel ComponentSpec with ComponentDefinition.
{{- define "redis-cluster.sentinelComponentSpec" }}
- name: redis-sentinel
replicas: {{ .Values.sentinel.replicas }}
{{- if .Values.nodePortEnabled }}
{{- if and .Values.nodePortEnabled (not .Values.fixedPodIPEnabled) (not .Values.hostNetworkEnabled) }}
services:
- name: sentinel-advertised
serviceType: NodePort
podService: true
{{- end }}
{{- if .Values.fixedPodIPEnabled }}
{{- if and .Values.fixedPodIPEnabled (not .Values.nodePortEnabled) (not .Values.hostNetworkEnabled) }}
env:
- name: FIXED_POD_IP_ENABLED
value: "true"
{{- end }}
{{- if and .Values.hostNetworkEnabled (not .Values.nodePortEnabled) (not .Values.fixedPodIPEnabled) }}
env:
- name: HOST_NETWORK_ENABLED
value: "true"
{{- end }}
resources:
limits:
cpu: {{ .Values.sentinel.cpu | quote }}
Expand Down Expand Up @@ -205,3 +224,25 @@ Define redis cluster sharding count.
{{- define "redis-cluster.shards" }}
shards: {{ max .Values.redisCluster.shardCount 3 }}
{{- end }}

{{/*
Define common fileds of cluster object
*/}}
{{- define "redis-cluster.clusterCommon" }}
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: {{ include "kblib.clusterName" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "kblib.clusterLabels" . | nindent 4 }}
{{- if and .Values.hostNetworkEnabled (eq .Values.mode "cluster") }}
annotations:
kubeblocks.io/host-network: "shard"
{{- else if .Values.hostNetworkEnabled }}
annotations:
kubeblocks.io/host-network: "redis,redis-sentinel"
{{- end }}
spec:
terminationPolicy: {{ .Values.extra.terminationPolicy }}
{{- include "kblib.affinity" . | indent 2 }}
{{- end }}
4 changes: 2 additions & 2 deletions addons-cluster/redis-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
{{- include "redis-cluster.legacyComponentSpec" . | indent 2 }}
{{- else if eq .Values.mode "cluster" }}
{{- /* TODO: when clusterDefinition topology supports sharding, migrate the cluster mode to topology as well */ -}}
{{- include "kblib.clusterCommon" . }}
{{- include "redis-cluster.clusterCommon" . }}
shardingSpecs:
{{- include "redis-cluster.shardingSpec" . | indent 2 }}
{{- else }}
{{- include "kblib.clusterCommon" . }}
{{- include "redis-cluster.clusterCommon" . }}
clusterDefinitionRef: redis
topology: {{ .Values.mode }}
componentSpecs:
Expand Down
8 changes: 6 additions & 2 deletions addons-cluster/redis-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ twemproxy:
memory: 0.2

## @param nodePortEnabled if true, the redis will use nodePort as the announce IP
## This option is mutually exclusive with fixedPodIPEnabled. When both nodePortEnabled and fixedPodIPEnabled are false, the default announce IP will be a headless service.
## This option is mutually exclusive with fixedPodIPEnabled and hostNetworkEnabled. When all hostNetworkEnabled, fixedPodIPEnabled, nodePortEnabled are false, the default announce IP will be a headless service.
nodePortEnabled: false

## If the K8s environment supports immutable pod IPs (usually requiring additional CNI plugins or other methods),
## you can set fixedPodIPEnabled to true. When fixedPodIPEnabled is true, the Redis will use the pod IP as the announce IP to meet network requirements in certain scenarios.
## This option is mutually exclusive with nodePortEnabled. When both nodePortEnabled and fixedPodIPEnabled are false, the default announce IP will be a headless service.
## This option is mutually exclusive with nodePortEnabled and hostNetworkEnabled. When all hostNetworkEnabled, fixedPodIPEnabled, nodePortEnabled are false, the default announce IP will be a headless service.
fixedPodIPEnabled: false

## @param hostNetworkEnabled if true, the redis will use hostNetwork
## This option is mutually exclusive with fixedPodIPEnabled and nodePortEnabled, When all hostNetworkEnabled, fixedPodIPEnabled, nodePortEnabled are false, the default announce IP will be a headless service.
hostNetworkEnabled: false

## @param sentinel.cpu
## @param sentinel.memory
## @param sentinel.storage
Expand Down
4 changes: 4 additions & 0 deletions addons/redis/config/redis-cluster7-config-constraint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@

"enable-debug-command"?: string & "yes" | "no" | "local"

"io-threads": int & >=2 & <=8 | *4

"io-threads-do-reads"?: string & "yes" | "no"

...
}

Expand Down
3 changes: 3 additions & 0 deletions addons/redis/config/redis-cluster7-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
enable-debug-command yes
aclfile /etc/redis/users.acl
# TODO: dynamic config for io-threads
io-threads 4
io-threads-do-reads yes

# configuration for redis cluster
cluster-enabled yes
Expand Down
4 changes: 4 additions & 0 deletions addons/redis/config/redis7-config-constraint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@

"enable-debug-command"?: string & "yes" | "no" | "local"

"io-threads": int & >=2 & <=8 | *4

"io-threads-do-reads"?: string & "yes" | "no"

...
}

Expand Down
2 changes: 2 additions & 0 deletions addons/redis/config/redis7-config-effect-scope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ staticParameters:
- cluster-enabled
- databases
- maxclients
- io-threads
- io-threads-do-reads

dynamicParameters:
- aof-timestamp-enabled
2 changes: 1 addition & 1 deletion addons/redis/config/redis7-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
enable-debug-command yes
aclfile /etc/redis/users.acl
# THREADED I/O
# TODO: dynamic config for io-threads
io-threads 4
io-threads-do-reads yes

Expand Down
Loading

0 comments on commit 0c8329a

Please sign in to comment.