From f22121dd032e1946849fa4e6fa8153136ad6061c Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 23 Jul 2018 17:42:23 +0800 Subject: [PATCH] Add support for external Redis configuration in helm chart This commit adds "external" part in redis configuration in helm chart, by this way users can use the existing external Redis rather than using the internal one --- contrib/helm/harbor/templates/_helpers.tpl | 51 +++++++++++++++++++ .../templates/jobservice/jobservice-cm.yaml | 2 +- contrib/helm/harbor/values.yaml | 16 ++++-- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/contrib/helm/harbor/templates/_helpers.tpl b/contrib/helm/harbor/templates/_helpers.tpl index eb316d03c..9d8a5f573 100644 --- a/contrib/helm/harbor/templates/_helpers.tpl +++ b/contrib/helm/harbor/templates/_helpers.tpl @@ -141,3 +141,54 @@ postgres://{{ template "harbor.database.username" . }}:{{ template "harbor.datab {{- define "harbor.database.notarySigner" -}} postgres://{{ template "harbor.database.username" . }}:{{ template "harbor.database.rawPassword" . }}@{{ template "harbor.database.host" . }}:{{ template "harbor.database.port" . }}/{{ template "harbor.database.notarySignerDatabase" . }}?sslmode=disable {{- end -}} + +{{- define "harbor.redis.host" -}} + {{- if .Values.redis.external.enabled -}} + {{- .Values.redis.external.host -}} + {{- else -}} + {{- .Release.Name }}-redis-master + {{- end -}} +{{- end -}} + +{{- define "harbor.redis.port" -}} + {{- if .Values.redis.external.enabled -}} + {{- .Values.redis.external.port -}} + {{- else -}} + {{- .Values.redis.master.port }} + {{- end -}} +{{- end -}} + +{{- define "harbor.redis.databaseIndex" -}} + {{- if .Values.redis.external.enabled -}} + {{- .Values.redis.external.databaseIndex -}} + {{- else -}} + {{- printf "%s" "0" }} + {{- end -}} +{{- end -}} + +{{- define "harbor.redis.password" -}} + {{- if and .Values.redis.external.enabled .Values.redis.external.usePassword -}} + {{- .Values.redis.external.password -}} + {{- else if and (not .Values.redis.external.enabled) .Values.redis.usePassword -}} + {{- .Values.redis.password -}} + {{- end -}} +{{- end -}} + +{{/*the username redis is used for a placeholder as no username needed in redis*/}} +{{- define "harbor.redisForJobservice" -}} + {{- if and .Values.redis.external.enabled .Values.redis.external.usePassword -}} + redis:{{ template "harbor.redis.password" . }}@{{ template "harbor.redis.host" . }}:{{ template "harbor.redis.port" . }}/{{ template "harbor.redis.databaseIndex" }} + {{- else if and (not .Values.redis.external.enabled) .Values.redis.usePassword -}} + redis:{{ template "harbor.redis.password" . }}@{{ template "harbor.redis.host" . }}:{{ template "harbor.redis.port" . }}/{{ template "harbor.redis.databaseIndex" }} + {{- else }} + {{- template "harbor.redis.host" . }}:{{ template "harbor.redis.port" . }}/{{ template "harbor.redis.databaseIndex" }} + {{- end -}} +{{- end -}} + +{{/* +host:port,pool_size,password +100 is the default value of pool size +*/}} +{{- define "harbor.redisForUI" -}} + {{- template "harbor.redis.host" . }}:{{ template "harbor.redis.port" . }},100,{{ template "harbor.redis.password" . }} +{{- end -}} diff --git a/contrib/helm/harbor/templates/jobservice/jobservice-cm.yaml b/contrib/helm/harbor/templates/jobservice/jobservice-cm.yaml index 6a21537bf..b52c03fed 100644 --- a/contrib/helm/harbor/templates/jobservice/jobservice-cm.yaml +++ b/contrib/helm/harbor/templates/jobservice/jobservice-cm.yaml @@ -12,7 +12,7 @@ data: workers: {{ .Values.jobservice.maxWorkers }} backend: "redis" redis_pool: - redis_url: "{{ .Release.Name }}-redis-master:{{ .Values.redis.master.port }}" + redis_url: "{{ template "harbor.redisForJobservice" . }}" namespace: "harbor_job_service_namespace" logger: path: "/var/log/jobs" diff --git a/contrib/helm/harbor/values.yaml b/contrib/helm/harbor/values.yaml index 279d30f10..b1ef974ab 100644 --- a/contrib/helm/harbor/values.yaml +++ b/contrib/helm/harbor/values.yaml @@ -149,6 +149,7 @@ ui: tolerations: [] affinity: {} +# TODO: change the style to be same with redis database: # if external database is used, set "type" to "external" # and fill the connection informations in "external" section @@ -271,12 +272,12 @@ clair: tolerations: [] affinity: {} -## Settings for redis dependency. -## see https://github.com/kubernetes/charts/tree/master/stable/redis -## for further configurables. redis: -# Update needed in the cm that defines redis_url if usePassword is set to true. + # if external Redis is used, set "external.enabled" to "true" + # and fill the connection informations in "external" section. + # or the internal Redis will be used usePassword: false + password: "changeit" cluster: enabled: false master: @@ -284,6 +285,13 @@ redis: # TODO: There is a perm issue: Can't open the append-only file: Permission denied # TODO: Setting it to false is a temp workaround. Will re-visit this problem. enabled: false + external: + enabled: false + host: "192.168.0.2" + port: "6379" + databaseIndex: "0" + usePassword: false + password: "changeit" notary: enabled: true