From 1a6a7b832fee5adecc55a756c683e7d159627c73 Mon Sep 17 00:00:00 2001 From: Simonas Narbutas Date: Fri, 26 Jul 2024 11:02:04 +0300 Subject: [PATCH] PM-1911 add backend ingress --- mina-payout-reports/README.md | 16 +++-- .../files/entrypoint_initdb.sh | 2 + .../templates/deployment-web.yaml | 3 +- .../templates/ingress-api.yaml | 62 ++++++++++++++++++ .../{ingress.yaml => ingress-web.yaml} | 20 +++--- mina-payout-reports/values.yaml | 63 +++++++++++++------ 6 files changed, 130 insertions(+), 36 deletions(-) create mode 100644 mina-payout-reports/templates/ingress-api.yaml rename mina-payout-reports/templates/{ingress.yaml => ingress-web.yaml} (65%) diff --git a/mina-payout-reports/README.md b/mina-payout-reports/README.md index dee5efa2..c7350467 100644 --- a/mina-payout-reports/README.md +++ b/mina-payout-reports/README.md @@ -42,11 +42,6 @@ helmfile status | Key | Type | Default | Description | |-----|------|---------|-------------| | fullnameOverride | string | `""` | The full release name override | -| ingress.annotations | object | `{}` | The Ingress Annotations | -| ingress.className | string | `""` | The Ingress Class Name to use | -| ingress.enabled | bool | `false` | Whether to create a frontend Ingress | -| ingress.hosts | list | `[]` | The Ingress Hosts | -| ingress.tls | list | `[]` | The TLS configuration | | nameOverride | string | `""` | The release name override | | payoutReportsApi.affinity | object | `{}` | Affinity rules | | payoutReportsApi.archiveDB.host | string | `"localhost"` | Mina Archive Database Host | @@ -64,6 +59,11 @@ helmfile status | payoutReportsApi.image.repository | string | `"673156464838.dkr.ecr.us-west-2.amazonaws.com/mina-payout-reports"` | The repository of the image | | payoutReportsApi.image.tag | string | `""` | The tag of the image | | payoutReportsApi.imagePullSecrets | list | `[]` | The secrets used to pull the image | +| payoutReportsApi.ingress.annotations | object | `{}` | The Ingress Annotations | +| payoutReportsApi.ingress.className | string | `""` | The Ingress Class Name to use | +| payoutReportsApi.ingress.enabled | bool | `false` | Whether to create a backend Ingress | +| payoutReportsApi.ingress.hosts | list | `[]` | The Ingress Hosts | +| payoutReportsApi.ingress.tls | list | `[]` | The TLS configuration | | payoutReportsApi.nodeSelector | object | `{}` | Node selector labels | | payoutReportsApi.payoutsDB.host | string | `"localhost"` | Delegation Program Payouts Database Host | | payoutReportsApi.payoutsDB.name | string | `"postgres"` | Delegation Program Payouts Database Name | @@ -84,11 +84,17 @@ helmfile status | payoutReportsApi.walletMappingSpreadsheetTab | string | `""` | Google's public spreadsheet sheet(tab) name | | payoutReportsApi.walletMappingSpreadsheetUrl | string | `""` | Google's public spreadsheet url containing wallet mappings | | payoutReportsWeb.affinity | object | `{}` | Affinity rules | +| payoutReportsWeb.backendExternalUrl | string | `"localhost:5000"` | Payout reports backend url accessible from the client | | payoutReportsWeb.extraEnvVars | list | `[]` | Additional list of Environment Variables | | payoutReportsWeb.image.pullPolicy | string | `"IfNotPresent"` | The pullPolicy used when pulling the image | | payoutReportsWeb.image.repository | string | `"673156464838.dkr.ecr.us-west-2.amazonaws.com/mina-payout-reports"` | The repository of the image | | payoutReportsWeb.image.tag | string | `""` | The tag of the image | | payoutReportsWeb.imagePullSecrets | list | `[]` | The secrets used to pull the image | +| payoutReportsWeb.ingress.annotations | object | `{}` | The Ingress Annotations | +| payoutReportsWeb.ingress.className | string | `""` | The Ingress Class Name to use | +| payoutReportsWeb.ingress.enabled | bool | `false` | Whether to create a frontend Ingress | +| payoutReportsWeb.ingress.hosts | list | `[]` | The Ingress Hosts | +| payoutReportsWeb.ingress.tls | list | `[]` | The TLS configuration | | payoutReportsWeb.nodeSelector | object | `{}` | Node selector labels | | payoutReportsWeb.podAnnotations | object | `{}` | Annotations to add to the pods | | payoutReportsWeb.podSecurityContext | object | `{}` | The Pod Security Context | diff --git a/mina-payout-reports/files/entrypoint_initdb.sh b/mina-payout-reports/files/entrypoint_initdb.sh index c62e0f62..867ee1db 100644 --- a/mina-payout-reports/files/entrypoint_initdb.sh +++ b/mina-payout-reports/files/entrypoint_initdb.sh @@ -2,4 +2,6 @@ set -x +pushd .. invoke create-database +popd || exit diff --git a/mina-payout-reports/templates/deployment-web.yaml b/mina-payout-reports/templates/deployment-web.yaml index 02ba63c7..042815d0 100644 --- a/mina-payout-reports/templates/deployment-web.yaml +++ b/mina-payout-reports/templates/deployment-web.yaml @@ -35,7 +35,8 @@ spec: imagePullPolicy: {{ .image.pullPolicy }} env: - name: REACT_APP_API_URL - value: "{{ include "mina-payout-reports.fullname" $ }}-api:{{ $.Values.payoutReportsApi.service.port }}" + value: {{ .backendExternalUrl | quote }} + {{- if .extraEnvVars }} {{- toYaml .extraEnvVars | nindent 12 }} {{- end }} diff --git a/mina-payout-reports/templates/ingress-api.yaml b/mina-payout-reports/templates/ingress-api.yaml new file mode 100644 index 00000000..749b2ead --- /dev/null +++ b/mina-payout-reports/templates/ingress-api.yaml @@ -0,0 +1,62 @@ +{{- if .Values.payoutReportsApi.ingress.enabled -}} +{{- $fullName := include "mina-payout-reports.fullname" . -}} +{{- $svcPort := .Values.payoutReportsApi.service.port -}} +{{- if and .Values.payoutReportsApi.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.payoutReportsApi.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.payoutReportsApi.ingress.annotations "kubernetes.io/ingress.class" .Values.payoutReportsApi.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "mina-payout-reports.labels" . | nindent 4 }} + {{- include "mina-payout-reports.selectorLabelsApi" . | nindent 4 }} + {{- with .Values.payoutReportsApi.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.payoutReportsApi.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.payoutReportsApi.ingress.className }} + {{- end }} + {{- if .Values.payoutReportsApi.ingress.tls }} + tls: + {{- range .Values.payoutReportsApi.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.payoutReportsApi.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }}-api + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }}-api + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/mina-payout-reports/templates/ingress.yaml b/mina-payout-reports/templates/ingress-web.yaml similarity index 65% rename from mina-payout-reports/templates/ingress.yaml rename to mina-payout-reports/templates/ingress-web.yaml index 152970c7..282e3c03 100644 --- a/mina-payout-reports/templates/ingress.yaml +++ b/mina-payout-reports/templates/ingress-web.yaml @@ -1,9 +1,9 @@ -{{- if .Values.ingress.enabled -}} +{{- if .Values.payoutReportsApi.ingress.enabled -}} {{- $fullName := include "mina-payout-reports.fullname" . -}} {{- $svcPort := .Values.payoutReportsWeb.service.port -}} -{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} - {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} +{{- if and .Values.payoutReportsApi.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.payoutReportsApi.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.payoutReportsApi.ingress.annotations "kubernetes.io/ingress.class" .Values.payoutReportsApi.ingress.className}} {{- end }} {{- end }} {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} @@ -19,17 +19,17 @@ metadata: labels: {{- include "mina-payout-reports.labels" . | nindent 4 }} {{- include "mina-payout-reports.selectorLabelsWeb" . | nindent 4 }} - {{- with .Values.ingress.annotations }} + {{- with .Values.payoutReportsApi.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} + {{- if and .Values.payoutReportsApi.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.payoutReportsApi.ingress.className }} {{- end }} - {{- if .Values.ingress.tls }} + {{- if .Values.payoutReportsApi.ingress.tls }} tls: - {{- range .Values.ingress.tls }} + {{- range .Values.payoutReportsApi.ingress.tls }} - hosts: {{- range .hosts }} - {{ . | quote }} @@ -38,7 +38,7 @@ spec: {{- end }} {{- end }} rules: - {{- range .Values.ingress.hosts }} + {{- range .Values.payoutReportsApi.ingress.hosts }} - host: {{ .host | quote }} http: paths: diff --git a/mina-payout-reports/values.yaml b/mina-payout-reports/values.yaml index b9c8e2d0..36d37259 100644 --- a/mina-payout-reports/values.yaml +++ b/mina-payout-reports/values.yaml @@ -18,6 +18,8 @@ serviceAccount: # Configuration options for `mina-payout-reports` frontend deployment payoutReportsWeb: + # -- Payout reports backend url accessible from the client + backendExternalUrl: localhost:5000 # -- The number of replicas replicaCount: 1 @@ -87,6 +89,27 @@ payoutReportsWeb: # -- Affinity rules affinity: {} + ingress: + # -- Whether to create a frontend Ingress + enabled: false + # -- The Ingress Class Name to use + className: "" + # -- The Ingress Annotations + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + # -- The Ingress Hosts + hosts: [] + # - host: chart-example.local + # paths: + # - path: / + # pathType: ImplementationSpecific + # -- The TLS configuration + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + # Configuration options for `mina-payout-reports` backend deployment payoutReportsApi: payoutsDB: @@ -202,23 +225,23 @@ payoutReportsApi: # -- Affinity rules affinity: {} -ingress: - # -- Whether to create a frontend Ingress - enabled: false - # -- The Ingress Class Name to use - className: "" - # -- The Ingress Annotations - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - # -- The Ingress Hosts - hosts: [] - # - host: chart-example.local - # paths: - # - path: / - # pathType: ImplementationSpecific - # -- The TLS configuration - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local + ingress: + # -- Whether to create a backend Ingress + enabled: false + # -- The Ingress Class Name to use + className: "" + # -- The Ingress Annotations + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + # -- The Ingress Hosts + hosts: [] + # - host: chart-example.local + # paths: + # - path: / + # pathType: ImplementationSpecific + # -- The TLS configuration + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local