From c3f071092d36b3cf02728aa7e06785a343e68f3c Mon Sep 17 00:00:00 2001 From: Yevgeny Kulikov <86586195+justgithubaccount@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:35:10 +0000 Subject: [PATCH 1/2] fix: align chart with current FastAPI image --- Chart.yaml | 4 ++-- README.md | 28 +++++++++++++++------------- templates/_helpers.tpl | 6 +++++- templates/deployment.yaml | 22 ++++++++++++---------- templates/ingress.yaml | 2 +- templates/pg-service.yaml | 8 ++++---- templates/secret.yaml | 4 ++-- templates/service.yaml | 4 ++-- templates/serviceaccount.yaml | 4 ++-- tests/test_chart.sh | 12 ++++++++++++ values.yaml | 29 +++++++++++++---------------- 11 files changed, 70 insertions(+), 53 deletions(-) create mode 100755 tests/test_chart.sh diff --git a/Chart.yaml b/Chart.yaml index 264bf33..a1f768c 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: chat-api description: ai-app (mind) type: application -version: 0.3.0 -appVersion: "1.0.0" +version: 0.4.0 +appVersion: "1.1.1" diff --git a/README.md b/README.md index 5b03022..c1f2bc0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,17 @@ Helm chart для деплоя [Chat API Microservice](https://github.com/justgi ## Быстрый старт -### 1. Создать secrets +### 1. Установить chart + +Для health-check и локальной SQLite secrets не нужны: + +```bash +helm install chat-api . \ + --namespace chat-api \ + --create-namespace +``` + +### 2. Опционально подключить внешние сервисы ```bash # OpenRouter API key @@ -18,14 +28,6 @@ kubectl create secret generic chat-postgres \ --from-literal=DATABASE_URL=postgresql://user:pass@host:5432/db ``` -### 2. Установить chart - -```bash -helm install chat-api . \ - --namespace chat-api \ - --create-namespace -``` - ### 3. Проверить ```bash @@ -39,9 +41,9 @@ kubectl logs -f deployment/chat-api -n chat-api | Параметр | Описание | Default | |----------|----------|---------| -| `replicaCount` | Количество реплик | `2` | -| `image.repository` | Docker image | `ghcr.io/justgithubaccount/chat-api` | -| `image.tag` | Image tag | `1.0.0` | +| `replicaCount` | Количество реплик | `1` | +| `image.repository` | Docker image | `ghcr.io/justgithubaccount/app-poly-gitops-fastapi` | +| `image.tag` | Image tag | `1.1.1` | | `containerPort` | Порт приложения | `8000` | | `service.type` | Тип сервиса | `ClusterIP` | | `service.port` | Порт сервиса | `80` | @@ -98,7 +100,7 @@ env: ``` . -├── Chart.yaml # Metadata (v0.3.0) +├── Chart.yaml # Metadata (v0.4.0) ├── values.yaml # Default values └── templates/ ├── _helpers.tpl # Template helpers diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 86d0255..4111f21 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -15,6 +15,10 @@ {{- end }} {{- end }} +{{- define "chat-api.namespace" -}} +{{- default .Release.Namespace .Values.namespace -}} +{{- end }} + {{- define "chat-api.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} @@ -31,4 +35,4 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- define "chat-api.selectorLabels" -}} app.kubernetes.io/name: {{ include "chat-api.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 400a006..37f7571 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "chat-api.fullname" . }} - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} labels: {{- include "chat-api.labels" . | nindent 4 }} spec: @@ -73,13 +73,17 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} + {{- if or .Values.openrouterSecretRefName .Values.postgresSecretRefName }} envFrom: + {{- if .Values.openrouterSecretRefName }} - secretRef: - name: {{ .Values.openrouterSecretRefName | default "chat-openrouter" }} + name: {{ .Values.openrouterSecretRefName }} + {{- end }} {{- if .Values.postgresSecretRefName }} - secretRef: name: {{ .Values.postgresSecretRefName }} {{- end }} + {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} @@ -98,13 +102,11 @@ spec: initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds | default 10 }} periodSeconds: {{ .Values.livenessProbe.periodSeconds | default 30 }} - {{- if .Values.command }} - command: {{ .Values.command }} + {{- with .Values.command }} + command: + {{- toYaml . | nindent 12 }} {{- end }} - {{- if .Values.args }} - args: {{ .Values.args }} - {{- else }} - command: ["/bin/sh", "-c"] + {{- with .Values.args }} args: - - uvicorn app.main:app --host 0.0.0.0 --port {{ .Values.containerPort }} - {{- end }} \ No newline at end of file + {{- toYaml . | nindent 12 }} + {{- end }} diff --git a/templates/ingress.yaml b/templates/ingress.yaml index 1eb6f6e..ac3853b 100644 --- a/templates/ingress.yaml +++ b/templates/ingress.yaml @@ -3,7 +3,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ include "chat-api.fullname" . }} - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} labels: app: {{ include "chat-api.name" . }} annotations: diff --git a/templates/pg-service.yaml b/templates/pg-service.yaml index c1b6126..921bf39 100644 --- a/templates/pg-service.yaml +++ b/templates/pg-service.yaml @@ -3,7 +3,7 @@ apiVersion: v1 kind: Service metadata: name: postgres-external - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} labels: app: {{ include "chat-api.name" . }} component: database @@ -11,6 +11,6 @@ spec: type: ExternalName externalName: {{ .Values.postgres.externalService.host }} ports: - - port: 5432 - targetPort: 5432 -{{- end }} \ No newline at end of file + - port: {{ .Values.postgres.externalService.port }} + targetPort: {{ .Values.postgres.externalService.port }} +{{- end }} diff --git a/templates/secret.yaml b/templates/secret.yaml index 059c405..1d1bea4 100644 --- a/templates/secret.yaml +++ b/templates/secret.yaml @@ -4,7 +4,7 @@ apiVersion: v1 kind: Secret metadata: name: {{ include "chat-api.fullname" . }}-config - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} type: Opaque stringData: # OpenRouter Configuration @@ -16,4 +16,4 @@ stringData: {{- if .Values.openrouter.xTitle }} OPENROUTER_X_TITLE: {{ .Values.openrouter.xTitle | quote }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/templates/service.yaml b/templates/service.yaml index a8f539d..0f6e466 100644 --- a/templates/service.yaml +++ b/templates/service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: {{ include "chat-api.fullname" . }} - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} labels: app: {{ include "chat-api.name" . }} spec: @@ -11,4 +11,4 @@ spec: - port: {{ .Values.service.port | default 80 }} targetPort: {{ .Values.containerPort | default 8000 }} selector: - {{- include "chat-api.selectorLabels" . | nindent 4 }} \ No newline at end of file + {{- include "chat-api.selectorLabels" . | nindent 4 }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index c2724f7..fe68d27 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -3,11 +3,11 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ include "chat-api.fullname" . }} - namespace: {{ .Values.namespace | default "chat-api" }} + namespace: {{ include "chat-api.namespace" . }} labels: {{- include "chat-api.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/tests/test_chart.sh b/tests/test_chart.sh new file mode 100755 index 0000000..1b36b9d --- /dev/null +++ b/tests/test_chart.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +helm lint "${repo_root}" +rendered="$(helm template chat-api "${repo_root}" --namespace smoke)" + +grep -q 'namespace: smoke' <<<"${rendered}" +grep -q 'image: "ghcr.io/justgithubaccount/app-poly-gitops-fastapi:1.1.1"' <<<"${rendered}" +! grep -q 'secretRef:' <<<"${rendered}" +! grep -q 'command:' <<<"${rendered}" diff --git a/values.yaml b/values.yaml index a6cd1b2..e15793a 100644 --- a/values.yaml +++ b/values.yaml @@ -1,14 +1,14 @@ # charts/chat/values.yaml # === Основные настройки приложения === -replicaCount: 2 -namespace: "chat-api" +replicaCount: 1 +namespace: "" # === Docker образ === image: - repository: ghcr.io/justgithubaccount/chat-api - pullPolicy: Always - tag: "1.0.0" + repository: ghcr.io/justgithubaccount/app-poly-gitops-fastapi + pullPolicy: IfNotPresent + tag: "1.1.1" # === Сетевые настройки === containerPort: 8000 @@ -43,10 +43,10 @@ serviceAccount: env: # OpenTelemetry OTEL_SERVICE_NAME: "chat-api" - OTEL_EXPORTER_OTLP_ENDPOINT: "http://vector-gateway.observability.svc.cluster.local:4318" + OTEL_EXPORTER_OTLP_ENDPOINT: "" OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf" - OTEL_TRACES_EXPORTER: "otlp" - OTEL_LOGS_EXPORTER: "otlp" + OTEL_TRACES_EXPORTER: "none" + OTEL_LOGS_EXPORTER: "none" # Application ENVIRONMENT: "production" @@ -63,20 +63,16 @@ openrouter: # xTitle: "Chat Microservice" # Optional # === External Dependencies === -externalServices: - postgresql: - enabled: false - host: "" - port: 5432 - # Secrets -openrouterSecretRefName: "chat-openrouter" -postgresSecretRefName: "chat-postgree" +openrouterSecretRefName: "" +postgresSecretRefName: "" # PostgreSQL postgres: externalService: enabled: false + host: "" + port: 5432 # Ingress ingress: @@ -85,6 +81,7 @@ ingress: host: "" path: / tls: false + tlsSecretName: "" # Extra environment variables (for PGO secrets mapping, etc.) extraEnv: [] From 7b928fcda3358b089bbf664de9bc5d63ffc5980c Mon Sep 17 00:00:00 2001 From: Yevgeny Kulikov <86586195+justgithubaccount@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:49:00 +0000 Subject: [PATCH 2/2] ci: validate Helm chart --- .github/workflows/validate.yaml | 25 +++++++++++++++++++++++++ tests/test_chart.sh | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/validate.yaml diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml new file mode 100644 index 0000000..87aaa17 --- /dev/null +++ b/.github/workflows/validate.yaml @@ -0,0 +1,25 @@ +name: Validate Helm chart + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: azure/setup-helm@v4 + with: + version: v3.19.0 + + - name: Chart contract + run: bash tests/test_chart.sh + + - name: Render standalone chart + run: helm template chat-api . --namespace smoke >/dev/null diff --git a/tests/test_chart.sh b/tests/test_chart.sh index 1b36b9d..ac77ad9 100755 --- a/tests/test_chart.sh +++ b/tests/test_chart.sh @@ -10,3 +10,7 @@ grep -q 'namespace: smoke' <<<"${rendered}" grep -q 'image: "ghcr.io/justgithubaccount/app-poly-gitops-fastapi:1.1.1"' <<<"${rendered}" ! grep -q 'secretRef:' <<<"${rendered}" ! grep -q 'command:' <<<"${rendered}" + +workflow="${repo_root}/.github/workflows/validate.yaml" +test -f "${workflow}" +grep -q 'bash tests/test_chart.sh' "${workflow}"