diff --git a/swh/templates/indexer-storage/_helper_configmap.yaml b/swh/templates/indexer-storage/_helper_configmap.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8f6b68f72440d94e0018173301ef395aed9e79f8 --- /dev/null +++ b/swh/templates/indexer-storage/_helper_configmap.yaml @@ -0,0 +1,20 @@ +{{/* + * Create an storage configmap for service .serviceType + */}} +{{ define "swh.indexer.storage.configmap" }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Values.namespace }} + name: {{ .serviceType }}-configuration-template +data: + config.yml.template: | + {{- include "swh.postgresql" (dict "serviceType" "indexer_storage" + "configurationRef" .configuration.indexerStorageConfigurationRef + "Values" .Values) | nindent 4 -}} + + {{- include "swh.journal.configuration" (dict "serviceType" "journal_writer" + "configurationRef" .configuration.journalWriterConfigurationRef + "Values" .Values) | nindent 4 -}} +{{- end -}} diff --git a/swh/templates/indexer-storage/autoscaling.yaml b/swh/templates/indexer-storage/autoscaling.yaml index bb177574e527d5e80e4f147f8967e6fb75f66e2e..4d7391eeb270d8efa3ef97ca53254ecef6e27456 100644 --- a/swh/templates/indexer-storage/autoscaling.yaml +++ b/swh/templates/indexer-storage/autoscaling.yaml @@ -1,5 +1,11 @@ -{{- if and .Values.indexerStorage.enabled .Values.indexerStorage.autoScaling -}} -{{- include "swh.autoscale" (dict "Values" .Values - "serviceType" "indexer-storage-rpc" - "configuration" .Values.indexerStorage) -}} +{{- if .Values.indexerStorage.enabled -}} +{{ range $storage_type, $storage_config := .Values.indexerStorage.deployments }} +{{- if and (or (not (hasKey $storage_config "enabled")) (get $storage_config "enabled")) + (hasKey $storage_config "autoScaling") -}} +{{- include "swh.autoscale" (dict "Values" $.Values + "serviceType" ( print "indexer-storage-" $storage_type ) + "configuration" $storage_config) -}} {{- end -}} +{{ end -}} +{{- end -}} + diff --git a/swh/templates/indexer-storage/configmap.yaml b/swh/templates/indexer-storage/configmap.yaml index 8218addd0f42291c8d1761e1fc0857fc5ec46733..05ddd8e2c78d7991476871838a8fffe7d9170933 100644 --- a/swh/templates/indexer-storage/configmap.yaml +++ b/swh/templates/indexer-storage/configmap.yaml @@ -1,17 +1,10 @@ {{ if .Values.indexerStorage.enabled -}} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - namespace: {{ .Values.namespace }} - name: indexer-storage-configuration-template -data: - config.yml.template: | - {{- include "swh.postgresql" (dict "serviceType" "indexer_storage" - "configurationRef" .Values.indexerStorage.indexerStorageConfigurationRef - "Values" .Values) | nindent 4 -}} - - {{- include "swh.journal.configuration" (dict "serviceType" "journal_writer" - "configurationRef" .Values.indexerStorage.journalWriterConfigurationRef - "Values" .Values) | nindent 4 -}} +{{ range $storage_type, $storage_config := .Values.indexerStorage.deployments }} +{{- if or (not (hasKey $storage_config "enabled")) (get $storage_config "enabled") -}} +{{ include "swh.indexer.storage.configmap" (dict "serviceType" ( print "indexer-storage-" $storage_type ) + "configuration" $storage_config + "Values" $.Values) }} +{{- end -}} +{{ end -}} {{- end -}} + diff --git a/swh/templates/indexer-storage/deployment.yaml b/swh/templates/indexer-storage/deployment.yaml index 70db1820a96206c02be14dc66ef6a22f4f599f71..fa6a24cafe9a799a6f73d60bf024305a92e7e85e 100644 --- a/swh/templates/indexer-storage/deployment.yaml +++ b/swh/templates/indexer-storage/deployment.yaml @@ -1,20 +1,28 @@ {{ if .Values.indexerStorage.enabled -}} +{{- $databaseUtilsPathChecksum := include (print $.Template.BasePath "/utils/database-utils.yaml") . | sha256sum -}} +{{ range $storage_type, $storage_config := .Values.indexerStorage.deployments }} +{{- if or (not (hasKey $storage_config "enabled")) (get $storage_config "enabled") -}} +{{- $serviceType := ( print "indexer-storage-" $storage_type ) -}} +{{- $configChecksum := include "swh.indexer.storage.configmap" + (dict "serviceType" $serviceType + "configuration" $storage_config + "Values" $.Values) | sha256sum -}} --- apiVersion: apps/v1 kind: Deployment metadata: - namespace: {{ .Values.namespace }} - name: indexer-storage-rpc + namespace: {{ $.Values.namespace }} + name: {{ $serviceType }} labels: - app: indexer-storage-rpc + app: {{ $serviceType }} spec: revisionHistoryLimit: 2 - {{ if .Values.indexerStorage.replicas -}} - replicas: {{ .Values.indexerStorage.replicas }} + {{ if $storage_config.replicas -}} + replicas: {{ $storage_config.replicas }} {{ end -}} selector: matchLabels: - app: indexer-storage-rpc + app: {{ $serviceType }} strategy: type: RollingUpdate rollingUpdate: @@ -22,18 +30,18 @@ spec: template: metadata: labels: - app: indexer-storage-rpc + app: {{ $serviceType }} annotations: - checksum/config: {{ include (print $.Template.BasePath "/indexer-storage/configmap.yaml") . | sha256sum }} - checksum/config-utils: {{ include (print $.Template.BasePath "/utils/database-utils.yaml") . | sha256sum }} + checksum/config: {{ $configChecksum }} + checksum/database-utils: {{ $databaseUtilsPathChecksum }} spec: - {{- if .Values.indexerStorage.affinity }} + {{- if $.Values.indexerStorage.affinity }} affinity: - {{- toYaml .Values.indexerStorage.affinity | nindent 8 }} + {{- toYaml $.Values.indexerStorage.affinity | nindent 8 }} {{- end }} - {{- if and .Values.podPriority.enabled .Values.indexerStorage.priorityClassName }} - priorityClassName: {{ .Values.namespace }}-{{ .Values.indexerStorage.priorityClassName }} + {{- if and $.Values.podPriority.enabled $.Values.indexerStorage.priorityClassName }} + priorityClassName: {{ $.Values.namespace }}-{{ $.Values.indexerStorage.priorityClassName }} {{- end }} initContainers: - name: prepare-configuration @@ -45,37 +53,37 @@ spec: - -c - eval echo "\"$(</etc/swh/configuration-template/config.yml.template)\"" > /etc/swh/config.yml env: - {{ include "swh.secrets.environment" (dict "configurationRef" .Values.indexerStorage.indexerStorageConfigurationRef - "Values" .Values) | nindent 10 }} + {{ include "swh.secrets.environment" (dict "configurationRef" $storage_config.indexerStorageConfigurationRef + "Values" $.Values) | nindent 10 }} volumeMounts: - name: configuration mountPath: /etc/swh - name: configuration-template mountPath: /etc/swh/configuration-template - {{- if .Values.indexerStorage.checkDbVersion }} - {{ include "swh.checkDatabaseVersionContainer" (dict "Values" .Values + {{- if $storage_config.checkDbVersion }} + {{ include "swh.checkDatabaseVersionContainer" (dict "Values" $.Values "imagePrefixName" "swh_indexer_storage_image" "module" "indexer-storage") | nindent 8 }} {{- end }} containers: - - name: indexer-storage-rpc + - name: {{ $serviceType }} resources: requests: - memory: {{ .Values.indexerStorage.requestedMemory | default "512Mi" }} - cpu: {{ .Values.indexerStorage.requestedCpu | default "500m" }} - {{- if or .Values.indexerStorage.limitedMemory .Values.indexerStorage.limitedCpu }} + memory: {{ $storage_config.requestedMemory | default "512Mi" }} + cpu: {{ $storage_config.requestedCpu | default "500m" }} + {{- if or $storage_config.limitedMemory $storage_config.limitedCpu }} limits: - {{- if .Values.indexerStorage.limitedMemory }} - memory: {{ .Values.indexerStorage.limitedMemory }} + {{- if $storage_config.limitedMemory }} + memory: {{ $storage_config.limitedMemory }} {{- end }} - {{- if .Values.indexerStorage.limitedCpu }} - cpu: {{ .Values.indexerStorage.limitedCpu }} + {{- if $storage_config.limitedCpu }} + cpu: {{ $storage_config.limitedCpu }} {{- end }} {{- end }} - image: {{ .Values.swh_indexer_storage_image }}:{{ .Values.swh_indexer_storage_image_version }} + image: {{ $.Values.swh_indexer_storage_image }}:{{ $.Values.swh_indexer_storage_image_version }} imagePullPolicy: IfNotPresent ports: - - containerPort: {{ .Values.indexerStorage.port }} + - containerPort: {{ $storage_config.port | default $.Values.indexerStorage.port }} name: rpc readinessProbe: httpGet: @@ -96,30 +104,30 @@ spec: - -c - /opt/swh/entrypoint.sh env: - {{ if .Values.indexerStorage.gunicorn -}} + {{ if $storage_config.gunicorn -}} - name: THREADS - value: {{ .Values.indexerStorage.gunicorn.threads | default 5 | quote }} + value: {{ $storage_config.gunicorn.threads | default 5 | quote }} - name: WORKERS - value: {{ .Values.indexerStorage.gunicorn.workers | default 2 | quote }} + value: {{ $storage_config.gunicorn.workers | default 2 | quote }} - name: TIMEOUT - value: {{ .Values.indexerStorage.gunicorn.timeout | default 60 | quote }} + value: {{ $storage_config.gunicorn.timeout | default 60 | quote }} {{ end -}} - name: STATSD_HOST - value: {{ .Values.statsdExternalHost | default "prometheus-statsd-exporter" }} + value: {{ $.Values.statsdExternalHost | default "prometheus-statsd-exporter" }} - name: STATSD_PORT - value: {{ .Values.statsdPort | default "9125" | quote }} + value: {{ $.Values.statsdPort | default "9125" | quote }} - name: LOG_LEVEL - value: {{ .Values.indexerStorage.logLevel | quote }} - {{- if .Values.indexerStorage.sentry.enabled }} + value: {{ $storage_config.logLevel | default $.Values.indexerStorage.logLevel | quote }} + {{- if $.Values.indexerStorage.sentry.enabled }} - name: SWH_SENTRY_ENVIRONMENT - value: {{ .Values.sentry.environment }} + value: {{ $.Values.sentry.environment }} - name: SWH_MAIN_PACKAGE value: swh.indexer - name: SWH_SENTRY_DSN valueFrom: secretKeyRef: - name: {{ .Values.indexerStorage.sentry.secretKeyRef }} - key: {{ .Values.indexerStorage.sentry.secretKeyName }} + name: {{ $.Values.indexerStorage.sentry.secretKeyRef }} + key: {{ $.Values.indexerStorage.sentry.secretKeyName }} # 'name' secret should exist & include key # if the setting doesn't exist, sentry pushes will be disabled optional: true @@ -134,7 +142,7 @@ spec: emptyDir: {} - name: configuration-template configMap: - name: indexer-storage-configuration-template + name: {{ $serviceType }}-configuration-template items: - key: "config.yml.template" path: "config.yml.template" @@ -142,4 +150,6 @@ spec: configMap: name: database-utils defaultMode: 0555 +{{ end }} +{{ end -}} {{- end -}} diff --git a/swh/templates/indexer-storage/ingress.yaml b/swh/templates/indexer-storage/ingress.yaml index 4866ee68a7d108ebb8e928a5b7b9122440bb3129..6f44eeb4ba038e467d5eb498c5c3259df670cd53 100644 --- a/swh/templates/indexer-storage/ingress.yaml +++ b/swh/templates/indexer-storage/ingress.yaml @@ -1,5 +1,10 @@ -{{- if and .Values.indexerStorage.enabled .Values.indexerStorage.ingress.enabled }} -{{- include "swh.ingress" (dict "Values" .Values - "serviceType" "indexer-storage-rpc" - "configuration" .Values.indexerStorage) -}} -{{ end }} +{{- if .Values.indexerStorage.enabled -}} +{{ range $storage_type, $storage_config := .Values.indexerStorage.deployments }} +{{- if and (or (not (hasKey $storage_config "enabled")) (get $storage_config "enabled")) + (and (hasKey $storage_config "ingress") $storage_config.ingress.enabled) -}} +{{- include "swh.ingress" (dict "Values" $.Values + "serviceType" ( print "indexer-storage-" $storage_type ) + "configuration" $storage_config) -}} +{{- end -}} +{{ end -}} +{{- end -}} diff --git a/swh/templates/indexer-storage/service.yaml b/swh/templates/indexer-storage/service.yaml index e51023d793091a370d1eb651d23ca1e0486af371..e0d4b08d4e9c9c39c74ca9a314efeac80ad0c3de 100644 --- a/swh/templates/indexer-storage/service.yaml +++ b/swh/templates/indexer-storage/service.yaml @@ -1,5 +1,12 @@ {{ if .Values.indexerStorage.enabled -}} -{{- include "swh.service" (dict "Values" .Values - "serviceType" "indexer-storage-rpc" - "configuration" .Values.indexerStorage) -}} -{{ end }} +{{ range $storage_type, $storage_config := .Values.indexerStorage.deployments }} +{{- if or (not (hasKey $storage_config "enabled")) (get $storage_config "enabled") -}} +{{- if not (hasKey $storage_config "port") }} +{{- $storage_config := set $storage_config "port" $.Values.indexerStorage.port -}} +{{- end -}} +{{- include "swh.service" (dict "serviceType" ( print "indexer-storage-" $storage_type ) + "configuration" $storage_config + "Values" $.Values) -}} +{{- end -}} +{{ end -}} +{{- end -}} diff --git a/swh/templates/storage/ingress.yaml b/swh/templates/storage/ingress.yaml index 9120b6b74480166253b77fc99005c118edea9f16..77fff8867b7c099842f5961e1e87d7e00eac6975 100644 --- a/swh/templates/storage/ingress.yaml +++ b/swh/templates/storage/ingress.yaml @@ -1,4 +1,4 @@ -{{ if .Values.storage.enabled -}} +{{- if .Values.storage.enabled -}} {{ range $storage_type, $deployment_config := .Values.storage.deployments }} {{- if and (or (not (hasKey $deployment_config "enabled")) (get $deployment_config "enabled")) (and (hasKey $deployment_config "ingress") $deployment_config.ingress.enabled) -}} diff --git a/swh/values.yaml b/swh/values.yaml index 358e5e185913806aada3a40cf6bfc9068ff55c46..05079f41d55257a35bf2c19ee883f19a7c40990a 100644 --- a/swh/values.yaml +++ b/swh/values.yaml @@ -554,28 +554,6 @@ indexerStorage: port: 5007 priorityClassName: frontend-rpc logLevel: INFO -# Don't configure the replicas if autoscaling is configured -# and vice-versa -# replicas: 1 - requestedCpu: 50m - requestedMemory: 100Mi -# autoScaling: -# minReplicaCount: 2 -# maxReplicaCount: 10 -# cpuPercentageUsage: 100 -# affinity: -# nodeAffinity: -# requiredDuringSchedulingIgnoredDuringExecution: -# nodeSelectorTerms: -# - matchExpressions: -# - key: "swh/rpc" -# operator: In -# values: -# - "true" -# gunicorn: -# threads: 5 -# workers: 2 -# timeout: 60 sentry: enabled: false # name of the secret containing the $secretKeyName value @@ -583,24 +561,48 @@ indexerStorage: # like https://token@sentry.host/id secretKeyRef: common-secrets secretKeyName: indexer-storage-sentry-dsn - # mandatory - # check defaultStorageConfiguration example to configure your storage - indexerStorageConfigurationRef: defaultIndexerStorageConfiguration - journalWriteConfigurationRef: defaultJournalWriterConfiguration - # When true, check db & code versions and do not start if they diverge - checkDbVersion: false - # Deploy an ingress to access the storage - ingress: - enabled: false - # Optional: the ingress classname to use - # className: nginx - # mandatory if ingress is enabled - # the hostname on which the storage must be reachable - # host: mystorage.localdomain - endpoints: - default: - paths: - - path: / + deployments: + rpc: + # Don't configure the replicas if autoscaling is configured + # and vice-versa + # replicas: 1 + requestedCpu: 50m + requestedMemory: 100Mi + # autoScaling: + # minReplicaCount: 2 + # maxReplicaCount: 10 + # cpuPercentageUsage: 100 + # affinity: + # nodeAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # nodeSelectorTerms: + # - matchExpressions: + # - key: "swh/rpc" + # operator: In + # values: + # - "true" + # gunicorn: + # threads: 5 + # workers: 2 + # timeout: 60 + # mandatory + # check defaultStorageConfiguration example to configure your storage + indexerStorageConfigurationRef: defaultIndexerStorageConfiguration + journalWriteConfigurationRef: defaultJournalWriterConfiguration + # When true, check db & code versions and do not start if they diverge + checkDbVersion: false + # Deploy an ingress to access the storage + ingress: + enabled: false + # Optional: the ingress classname to use + # className: nginx + # mandatory if ingress is enabled + # the hostname on which the storage must be reachable + # host: mystorage.localdomain + endpoints: + default: + paths: + - path: / storage: enabled: false diff --git a/swh/values/minikube.yaml b/swh/values/minikube.yaml index ce9ccf24709f96e71f677c84306307c248cc85c0..b74eda04a5cfaa3b7cc49b9708a006c9df9438d5 100644 --- a/swh/values/minikube.yaml +++ b/swh/values/minikube.yaml @@ -741,22 +741,24 @@ indexerJournalWriterConfiguration: indexerStorage: enabled: false - checkDbVersion: false - autoScaling: - minReplicaCount: 2 - maxReplicaCount: 2 - cpuPercentageUsage: 90 - requestedCpu: 500m - requestedMemory: 512Mi - indexerStorageConfigurationRef: fakePostgresqlIndexerStorageConfiguration - journalWriterConfigurationRef: indexerJournalWriterConfiguration - hosts: - - indexer-storage.i.s.s.n - ingress: - enabled: true - gunicorn: - threads: 2 - workers: 4 + deployments: + read-write: + checkDbVersion: false + autoScaling: + minReplicaCount: 2 + maxReplicaCount: 2 + cpuPercentageUsage: 90 + requestedCpu: 500m + requestedMemory: 512Mi + indexerStorageConfigurationRef: fakePostgresqlIndexerStorageConfiguration + journalWriterConfigurationRef: indexerJournalWriterConfiguration + hosts: + - indexer-storage.i.s.s.n + ingress: + enabled: true + gunicorn: + threads: 2 + workers: 4 defaultElasticsearchHosts: - host: search-esnode0.i.s.s.n diff --git a/swh/values/production/swh.yaml b/swh/values/production/swh.yaml index 9e63cf53f224d84be2285f9ff68f459825278f03..09a05a03ef1537107ab7d978a14b88c462d768f3 100644 --- a/swh/values/production/swh.yaml +++ b/swh/values/production/swh.yaml @@ -688,22 +688,24 @@ toolbox: indexerStorage: enabled: false - checkDbVersion: true - autoScaling: - minReplicaCount: 2 - maxReplicaCount: 4 - cpuPercentageUsage: 90 - requestedCpu: 500m - requestedMemory: 512Mi - indexerStorageConfigurationRef: postgresqlIndexerStorageConfiguration - journalWriterConfigurationRef: journalWriterConfiguration - hosts: - - saam.internal.softwareheritage.org - ingress: - enabled: true - gunicorn: - threads: 2 - workers: 4 + deployments: + read-write: + checkDbVersion: true + autoScaling: + minReplicaCount: 2 + maxReplicaCount: 4 + cpuPercentageUsage: 90 + requestedCpu: 500m + requestedMemory: 512Mi + indexerStorageConfigurationRef: postgresqlIndexerStorageConfiguration + journalWriterConfigurationRef: journalWriterConfiguration + hosts: + - saam.internal.softwareheritage.org + ingress: + enabled: true + gunicorn: + threads: 2 + workers: 4 search: enabled: true diff --git a/swh/values/staging/swh.yaml b/swh/values/staging/swh.yaml index 0b42c1d369a459d299cc825ecb8b4df69f09c10a..097cf9cba24465febb1c5b2d4892c2a34c1abbb7 100644 --- a/swh/values/staging/swh.yaml +++ b/swh/values/staging/swh.yaml @@ -654,34 +654,36 @@ scheduler: indexerStorage: enabled: true - checkDbVersion: true - autoScaling: - minReplicaCount: 2 - maxReplicaCount: 4 - cpuPercentageUsage: 90 - requestedCpu: 10m - requestedMemory: 200Mi - indexerStorageConfigurationRef: postgresqlIndexerStorageConfiguration - journalWriterConfigurationRef: indexerJournalWriterConfiguration - hosts: - - indexer-storage-rpc-ingress - ingress: - enabled: true - extraAnnotations: - nginx.ingress.kubernetes.io/proxy-connect-timeout: "90" - nginx.ingress.kubernetes.io/proxy-send-timeout: "90" - nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" - nginx.ingress.kubernetes.io/proxy-request-buffering: "on" - nginx.ingress.kubernetes.io/proxy-body-size: "4G" - # Default allowed ip ranges that can be extended per ingress definitions paths - whitelistSourceRangeRef: clusterNetworkRanges - endpoints: - default: - paths: - - path: / - gunicorn: - threads: 2 - workers: 4 + deployments: + rpc: + checkDbVersion: true + autoScaling: + minReplicaCount: 2 + maxReplicaCount: 4 + cpuPercentageUsage: 90 + requestedCpu: 10m + requestedMemory: 200Mi + indexerStorageConfigurationRef: postgresqlIndexerStorageConfiguration + journalWriterConfigurationRef: indexerJournalWriterConfiguration + hosts: + - indexer-storage-rpc-ingress + ingress: + enabled: true + extraAnnotations: + nginx.ingress.kubernetes.io/proxy-connect-timeout: "90" + nginx.ingress.kubernetes.io/proxy-send-timeout: "90" + nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" + nginx.ingress.kubernetes.io/proxy-request-buffering: "on" + nginx.ingress.kubernetes.io/proxy-body-size: "4G" + # Default allowed ip ranges that can be extended per ingress definitions paths + whitelistSourceRangeRef: clusterNetworkRanges + endpoints: + default: + paths: + - path: / + gunicorn: + threads: 2 + workers: 4 search: enabled: true