diff --git a/chart/redis-cluster-operator/.helmignore b/chart/redis-cluster-operator/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/chart/redis-cluster-operator/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/redis-cluster-operator/Chart.yaml b/chart/redis-cluster-operator/Chart.yaml new file mode 100644 index 000000000..d92d5046e --- /dev/null +++ b/chart/redis-cluster-operator/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: redis-cluster-operator +description: A Helm chart for Redis cluster operator deployment + +type: application + +version: 0.1.0 + +appVersion: 0.1.0 diff --git a/chart/redis-cluster-operator/crds/redis.kun_distributedredisclusters_crd.yaml b/chart/redis-cluster-operator/crds/redis.kun_distributedredisclusters_crd.yaml new file mode 100644 index 000000000..99c3a348f --- /dev/null +++ b/chart/redis-cluster-operator/crds/redis.kun_distributedredisclusters_crd.yaml @@ -0,0 +1,83 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: distributedredisclusters.redis.kun +spec: + group: redis.kun + names: + kind: DistributedRedisCluster + listKind: DistributedRedisClusterList + plural: distributedredisclusters + singular: distributedrediscluster + shortNames: + - drc + scope: Namespaced + additionalPrinterColumns: + - JSONPath: .spec.masterSize + description: The number of redis master node in the ensemble + name: MasterSize + type: integer + - JSONPath: .status.status + description: The status of redis cluster + name: Status + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + - JSONPath: .status.numberOfMaster + priority: 1 + description: The current master number of redis cluster + name: CurrentMasters + type: integer + - JSONPath: .spec.image + priority: 1 + description: The image of redis cluster + name: Images + type: string + subresources: + status: {} + validation: + openAPIV3Schema: + description: DistributedRedisCluster is the Schema for the distributedredisclusters + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: DistributedRedisClusterSpec defines the desired state of + DistributedRedisCluster + properties: + masterSize: + format: int32 + type: integer + minimum: 3 + maximum: 10 + clusterReplicas: + format: int32 + type: integer + minimum: 1 + maximum: 3 + serviceName: + type: string + pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' + type: object + status: + description: DistributedRedisClusterStatus defines the observed state + of DistributedRedisCluster + type: object + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true diff --git a/chart/redis-cluster-operator/crds/redis.kun_redisclusterbackups_crd.yaml b/chart/redis-cluster-operator/crds/redis.kun_redisclusterbackups_crd.yaml new file mode 100644 index 000000000..40ce9094c --- /dev/null +++ b/chart/redis-cluster-operator/crds/redis.kun_redisclusterbackups_crd.yaml @@ -0,0 +1,54 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: redisclusterbackups.redis.kun +spec: + group: redis.kun + names: + kind: RedisClusterBackup + listKind: RedisClusterBackupList + plural: redisclusterbackups + singular: redisclusterbackup + shortNames: + - drcb + scope: Namespaced + additionalPrinterColumns: + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + - JSONPath: .status.phase + description: The phase of redis cluster backup + name: Phase + type: string + subresources: + status: {} + versions: + - name: v1alpha1 + # Each version can be enabled/disabled by Served flag. + served: true + # One and only one version must be marked as the storage version. + storage: true + validation: + openAPIV3Schema: + description: RedisClusterBackup is the Schema for the redisclusterbackups + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: RedisClusterBackupSpec defines the desired state of RedisClusterBackup + type: object + status: + description: RedisClusterBackupStatus defines the observed state of RedisClusterBackup + type: object + type: object diff --git a/chart/redis-cluster-operator/templates/_helpers.tpl b/chart/redis-cluster-operator/templates/_helpers.tpl new file mode 100644 index 000000000..241383953 --- /dev/null +++ b/chart/redis-cluster-operator/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "redis-cluster-operator.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "redis-cluster-operator.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "redis-cluster-operator.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "redis-cluster-operator.labels" -}} +helm.sh/chart: {{ include "redis-cluster-operator.chart" . }} +{{ include "redis-cluster-operator.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "redis-cluster-operator.selectorLabels" -}} +app.kubernetes.io/name: {{ include "redis-cluster-operator.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "redis-cluster-operator.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "redis-cluster-operator.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/redis-cluster-operator/templates/operator.yaml b/chart/redis-cluster-operator/templates/operator.yaml new file mode 100644 index 000000000..c9cccf99b --- /dev/null +++ b/chart/redis-cluster-operator/templates/operator.yaml @@ -0,0 +1,55 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.operator.name }} +spec: + replicas: {{ .Values.operator.replicas }} + selector: + matchLabels: + name: {{ .Values.operator.name }} + template: + metadata: + labels: + name: {{ .Values.operator.name }} + spec: + serviceAccountName: {{ .Values.operator.service_account_name }} + securityContext: + {{- .Values.operator.podsecurityContext | toYaml | nindent 8 }} + containers: + - name: {{ .Values.operator.name }} + # Replace this with the built image name + image: {{ .Values.operator.image_source }}:{{ .Values.operator.image_tag }} + securityContext: + {{- .Values.operator.containersecurityContext | toYaml | nindent 12 }} + command: + - redis-cluster-operator + args: + - --rename-command-path=/etc/redisconf + - --rename-command-file=redis.conf + imagePullPolicy: {{ .Values.operator.imagePullPolicy }} + resources: + {{- .Values.operator.resources | toYaml | nindent 12 }} + env: + - name: WATCH_NAMESPACE + value: {{ .Values.operator.namespace | quote }} + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OPERATOR_NAME + value: {{ .Values.operator.name | quote }} + volumeMounts: + - name: redisconf + mountPath: /etc/redisconf + volumes: + - name: redisconf + configMap: + name: redis-admin +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: redis-admin +data: + redis.conf: |- + {{- .Values.data.redis_conf | nindent 4 }} diff --git a/chart/redis-cluster-operator/templates/role.yaml b/chart/redis-cluster-operator/templates/role.yaml new file mode 100644 index 000000000..53bdf689b --- /dev/null +++ b/chart/redis-cluster-operator/templates/role.yaml @@ -0,0 +1,105 @@ +apiVersion: rbac.authorization.k8s.io/v1 +{{- if eq (len .Values.operator.namespace) 0 }} +kind: ClusterRole +{{- else }} +kind: Role +{{- end }} +metadata: + name: redis-cluster-operator +rules: + - apiGroups: + - "" + resources: + - pods + - secrets + - endpoints + - persistentvolumeclaims + verbs: + - get + - list + - watch + - delete + - apiGroups: + - "" + resources: + - configmaps + - pods/exec + - secrets + - services + - events + - persistentvolumeclaims + verbs: + - create + - get + - list + - patch + - update + - watch + - delete + - apiGroups: + - "" + resources: + - namespaces + verbs: + - get + - list + - watch + - apiGroups: + - batch + resources: + - jobs + verbs: + - create + - get + - list + - patch + - update + - watch + - delete + - apiGroups: + - apps + resources: + - deployments + - replicasets + - statefulsets + verbs: + - create + - get + - list + - patch + - update + - watch + - delete + - apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - create + - get + - list + - patch + - update + - watch + - delete + - apiGroups: + - apps + resourceNames: + - redis-operator + resources: + - deployments/finalizers + verbs: + - update + - apiGroups: + - redis.kun + resources: + - '*' + - redisclusterbackups + verbs: + - delete + - deletecollection + - get + - list + - patch + - update + - watch diff --git a/chart/redis-cluster-operator/templates/role_binding.yaml b/chart/redis-cluster-operator/templates/role_binding.yaml new file mode 100644 index 000000000..c00500608 --- /dev/null +++ b/chart/redis-cluster-operator/templates/role_binding.yaml @@ -0,0 +1,16 @@ +{{- if eq (len .Values.operator.namespace) 0 }} +kind: ClusterRoleBinding +{{- else }} +kind: RoleBinding +{{- end }} +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: redis-cluster-operator +subjects: +- kind: ServiceAccount + name: redis-cluster-operator + namespace: {{.Release.Namespace}} +roleRef: + kind: ClusterRole + name: redis-cluster-operator + apiGroup: rbac.authorization.k8s.io diff --git a/chart/redis-cluster-operator/templates/service_account.yaml b/chart/redis-cluster-operator/templates/service_account.yaml new file mode 100644 index 000000000..9e9dc4048 --- /dev/null +++ b/chart/redis-cluster-operator/templates/service_account.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: redis-cluster-operator + namespace: {{.Release.Namespace}} diff --git a/chart/redis-cluster-operator/values.yaml b/chart/redis-cluster-operator/values.yaml new file mode 100644 index 000000000..84ac9417d --- /dev/null +++ b/chart/redis-cluster-operator/values.yaml @@ -0,0 +1,36 @@ +operator: + backup_enabled: "false" + name: "redis-cluster-operator" + replicas: 1 + service_account_name: "redis-cluster-operator" + namespace: "" # keep this value "" if you want to deploy cluster-wide operator + image_source: "fishu/redis-cluster-operator" + image_tag: "latest" + imagePullPolicy: "Always" + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 100Mi + podsecurityContext: + runAsUser: 1100 + runAsGroup: 1100 + fsGroup: 1100 + supplementalGroups: [1100] + containersecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + +data: + redis_conf: |- + rename-command CONFIG lni07z1p + rename-command BGSAVE pp14qluk + rename-command DEBUG 8a4insyv + rename-command SAVE 6on30p6z + rename-command SHUTDOWN dvui0opr + rename-command SLAVEOF xwxvcw36 + rename-command BGREWRITEAOF www07fko