Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support external pg in stacks-api #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.idea/*
.vscode
.DS_Store
**/charts/**
71 changes: 70 additions & 1 deletion hirosystems/stacks-blockchain-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,78 @@ Return name of the CDN secret
Return name of the Postgres user
*/}}
{{- define "stacksBlockchainApi.postgresql.username" -}}
{{ default "postgres" (include "postgresql.v1.username" .Subcharts.postgresql) }}
{{- if .Values.postgresql.enabled -}}
{{ default "postgres" (include "postgresql.v1.username" .Subcharts.postgresql) }}
{{- else -}}
{{ default "postgres" .Values.connections.db_user }}
{{- end -}}
{{- end -}}

{{/*
Return name of the Postgres database name
*/}}
{{- define "stacksBlockchainApi.postgresql.database" -}}
{{- if .Values.postgresql.enabled -}}
{{ default "postgres" (include "postgresql.v1.database" .Subcharts.postgresql) }}
{{- else -}}
{{ default "postgres" .Values.connections.db_name }}
{{- end -}}
{{- end -}}

{{/*
Return name of the Postgres host
*/}}
{{- define "stacksBlockchainApi.postgresql.host" -}}
{{- if .Values.postgresql.enabled -}}
{{ include "common.names.fullname" .Subcharts.postgresql }}-all
{{- else -}}
{{ .Values.connections.db_host }}
{{- end -}}
{{- end -}}

{{/*
Return name of the Postgres host
*/}}
{{- define "stacksBlockchainApi.postgresql.primary_host" -}}
{{- if .Values.postgresql.enabled -}}
{{ include "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
{{- else -}}
{{ default .Values.connections.db_host .Values.connections.db_primary_host }}
{{- end -}}
{{- end -}}

{{/*
Return name of the Postgres port
*/}}
{{- define "stacksBlockchainApi.postgresql.port" -}}
{{- if .Values.postgresql.enabled -}}
{{ default 5432 (include "postgresql.v1.service.port" .Subcharts.postgresql) }}
{{- else -}}
{{ default 5432 .Values.connections.db_port }}
{{- end -}}
{{- end -}}

{{/*
Return name of the k8s secret which includes Postgres password
*/}}
{{- define "stacksBlockchainApi.postgresql.passwordSecretName" -}}
{{- if .Values.postgresql.enabled -}}
{{ include "postgresql.v1.secretName" .Subcharts.postgresql }}
{{- else -}}
{{ .Values.connections.db_password_secret_name }}
{{- end -}}
{{- end -}}

{{/*
Return name of the Postgres password key in k8s secret
*/}}
{{- define "stacksBlockchainApi.postgresql.passwordSecretKey" -}}
{{- if .Values.postgresql.enabled -}}
{{ default "password" (include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql) }}
{{- else -}}
{{ default "password" .Values.connections.db_password_secret_key }}
{{- end -}}
{{- end -}}

{{/*
Compile all warnings into a single message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ spec:
- name: STACKS_ADDRESS_CACHE_SIZE
value: {{ default "50000" .Values.apiReader.config.stacksAddressCacheSize | quote }}
- name: PG_DATABASE
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_SCHEMA
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_PRIMARY_HOST
value: {{ include "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.primary_host" . }}
- name: PG_HOST
value: {{ include "common.names.fullname" .Subcharts.postgresql }}-all
value: {{ include "stacksBlockchainApi.postgresql.host" . }}
- name: PG_PORT
value: {{ include "postgresql.v1.service.port" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.port" . | quote }}
- name: PG_USER
value: {{ include "stacksBlockchainApi.postgresql.username" . }}
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
key: {{ include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql }}
name: {{ include "postgresql.v1.secretName" .Subcharts.postgresql }}
key: {{ include "stacksBlockchainApi.postgresql.passwordSecretKey" . }}
name: {{ include "stacksBlockchainApi.postgresql.passwordSecretName" . }}
- name: PG_APPLICATION_NAME
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ spec:
- name: STACKS_ADDRESS_CACHE_SIZE
value: {{ default "50000" .Values.apiRosettaReader.config.stacksAddressCacheSize | quote }}
- name: PG_DATABASE
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_SCHEMA
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_PRIMARY_HOST
value: {{ include "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.primary_host" . }}
- name: PG_HOST
value: {{ include "common.names.fullname" .Subcharts.postgresql }}-all
value: {{ include "stacksBlockchainApi.postgresql.host" . }}
- name: PG_PORT
value: {{ include "postgresql.v1.service.port" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.port" . | quote }}
- name: PG_USER
value: {{ include "stacksBlockchainApi.postgresql.username" . }}
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
key: {{ include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql }}
name: {{ include "postgresql.v1.secretName" .Subcharts.postgresql }}
key: {{ include "stacksBlockchainApi.postgresql.passwordSecretKey" . }}
name: {{ include "stacksBlockchainApi.postgresql.passwordSecretName" . }}
- name: PG_APPLICATION_NAME
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ spec:
- name: STACKS_EXPORT_EVENTS_FILE
value: {{ .Values.apiWriter.persistence.data.mountPath }}/stacks-node-events.tsv
- name: PG_HOST
value: {{ include "common.names.fullname" .Subcharts.postgresql }}-all
value: {{ include "stacksBlockchainApi.postgresql.host" . }}
- name: PG_PORT
value: {{ include "postgresql.v1.service.port" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.port" . | quote }}
- name: PG_USER
value: {{ include "stacksBlockchainApi.postgresql.username" . }}
- name: PG_DATABASE
value: {{ include "postgresql.v1.database" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_SCHEMA
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_CONNECTION_POOL_MAX
value: {{ .Values.apiWriter.config.pgConnectionPoolMax | quote }}
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
key: {{ include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql | quote }}
name: {{ include "postgresql.v1.secretName" .Subcharts.postgresql | quote }}
key: {{ include "stacksBlockchainApi.postgresql.passwordSecretKey" . }}
name: {{ include "stacksBlockchainApi.postgresql.passwordSecretName" . }}
- name: DATA_DIR
value: {{ .Values.apiWriter.persistence.data.mountPath }}
command:
Expand Down Expand Up @@ -253,22 +253,22 @@ spec:
- name: STACKS_EVENTS_DIR
value: {{ .Values.apiWriter.persistence.data.mountPath }}/events
- name: PG_DATABASE
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_SCHEMA
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_PRIMARY_HOST
value: {{ include "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.primary_host" . }}
- name: PG_HOST
value: {{ include "common.names.fullname" .Subcharts.postgresql }}-all
value: {{ include "stacksBlockchainApi.postgresql.host" . }}
- name: PG_PORT
value: {{ include "postgresql.v1.service.port" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.port" . | quote }}
- name: PG_USER
value: {{ include "stacksBlockchainApi.postgresql.username" . }}
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
key: {{ include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql | quote }}
name: {{ include "postgresql.v1.secretName" .Subcharts.postgresql | quote }}
key: {{ include "stacksBlockchainApi.postgresql.passwordSecretKey" . }}
name: {{ include "stacksBlockchainApi.postgresql.passwordSecretName" . }}
- name: PG_APPLICATION_NAME
valueFrom:
fieldRef:
Expand Down Expand Up @@ -364,22 +364,22 @@ spec:
- name: STACKS_API_TOKEN_METADATA_STRICT_MODE
value: {{ ternary "1" "0" .Values.apiWriter.config.enableTokenMetadataStrictMode | quote }}
- name: PG_DATABASE
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_SCHEMA
value: {{ include "postgresql.v1.database" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.database" . }}
- name: PG_PRIMARY_HOST
value: {{ include "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
value: {{ include "stacksBlockchainApi.postgresql.primary_host" . }}
- name: PG_HOST
value: {{ include "common.names.fullname" .Subcharts.postgresql }}-all
value: {{ include "stacksBlockchainApi.postgresql.host" . }}
- name: PG_PORT
value: {{ include "postgresql.v1.service.port" .Subcharts.postgresql | quote }}
value: {{ include "stacksBlockchainApi.postgresql.port" . | quote }}
- name: PG_USER
value: {{ include "stacksBlockchainApi.postgresql.username" . }}
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
key: {{ include "postgresql.v1.adminPasswordKey" .Subcharts.postgresql }}
name: {{ include "postgresql.v1.secretName" .Subcharts.postgresql }}
key: {{ include "stacksBlockchainApi.postgresql.passwordSecretKey" . }}
name: {{ include "stacksBlockchainApi.postgresql.passwordSecretName" . }}
- name: PG_APPLICATION_NAME
valueFrom:
fieldRef:
Expand Down
13 changes: 13 additions & 0 deletions hirosystems/stacks-blockchain-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,19 @@ stacks-blockchain:
# retry_count = 255
# events_keys = ["*"]

## Postgresql Connection
## You need to change below configuration in case of bringing your own PostgresSQL instance and also set postgresql.enabled:false
connections:
db_host: postgresql
db_primary_host: postgresql
db_user: stacksuser
db_name: stacksdb
db_port: 5432
## @param connections.serviceMonitor.db_password_secret_name Specify the k8s secret name for db password
db_password_secret_name: stackssecret
## @param connections.serviceMonitor.db_password_secret_key Specify the password key name inside the k8s secret
db_password_secret_key: password

## Postgresql Subchart
##
postgresql:
Expand Down