Skip to content

Commit

Permalink
feat: new migrations api (#35)
Browse files Browse the repository at this point in the history
* feat: migration job runs cloud api with parameter

* generated all stuff needed

* fix: envs

* generated docs

* fix: rollback _helpers

* fix: migrations job fix

* fix: removed command as entrypoint is already set

* fix: docs

* add migrations job

* resolve conflicts

---------

Co-authored-by: Jacek Wysocki <[email protected]>
  • Loading branch information
2 people authored and povilasv committed Sep 4, 2023
1 parent 1d37390 commit 5366b1f
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 61 deletions.
2 changes: 1 addition & 1 deletion charts/testkube-cloud-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: testkube-cloud-api
description: A Helm chart for Testkube Cloud API
type: application
version: 1.13.87
version: 1.13.88
appVersion: 1.3.6
maintainers:
- name: testkube
Expand Down
6 changes: 4 additions & 2 deletions charts/testkube-cloud-api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testkube-cloud-api

![Version: 1.11.7](https://img.shields.io/badge/Version-1.11.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.2.0-dev-f05d636](https://img.shields.io/badge/AppVersion-1.2.0--dev--f05d636-informational?style=flat-square)
![Version: 1.13.88](https://img.shields.io/badge/Version-1.13.88-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.3.6](https://img.shields.io/badge/AppVersion-1.3.6-informational?style=flat-square)

A Helm chart for Testkube Cloud API

Expand All @@ -22,6 +22,9 @@ A Helm chart for Testkube Cloud API
|-----|------|---------|-------------|
| additionalEnv | object | `{}` | Additional env vars to be added to the deployment |
| affinity | object | `{}` | |
| ai.apiKey | string | `""` | or use api key instead two above |
| ai.secretKey | string | `"key"` | |
| ai.secretRef | string | `"openai-api-key"` | AI config secret ref |
| analytics.hubspot.apiKey | string | `""` | HubSpot write key |
| analytics.hubspot.enabled | bool | `false` | Toggle whether to enable HubSpot sync |
| analytics.hubspot.secretRef | string | `""` | HubSpot secret ref (secret must contain key HUBSPOT_API_KEY) (default is `testkube-cloud-analytics-secret`) |
Expand All @@ -35,7 +38,6 @@ A Helm chart for Testkube Cloud API
| api.dashboardAddress | string | `""` | Dashboard address (used in invitation emails) (example `https://cloud.testkube.xyz`) |
| api.inviteMode | string | `"email"` | Configure which invitation mode to use (email|auto-accept): email uses SMTP protocol to send email invites and auto-accept immediately adds them |
| api.migrations.enabled | bool | `false` | Toggle whether to apply migrations for MongoDB |
| api.migrations.image.repository | string | `"kubeshop/testkube-cloud-api-migrations"` | |
| api.migrations.useHelmHooks | bool | `true` | Toggle whether to enable pre-install & pre-upgrade hooks |
| api.minio.accessKeyId | string | `""` | MinIO access key id |
| api.minio.credsSecretRef | string | `""` | Credentials secret ref (secret should contain keys: MINIO_ACCESS_KEY_ID, MINIO_SECRET_ACCESS_KEY, MINIO_TOKEN) (default is `testkube-cloud-minio-secret`) |
Expand Down
267 changes: 231 additions & 36 deletions charts/testkube-cloud-api/templates/migrations-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,247 @@ spec:
imagePullSecrets:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
initContainers:
- name: wait-for
image: mongo:6.0.5-jammy
command:
- bash
- -c
- |
times=20
until mongosh "$MONGO_DSN" --eval "db.runCommand({ ping: 1 })"; do
echo "Waiting for MongoDB to be ready..."
echo "$times retries left"
times=$((times - 1))
sleep 5
if [ "$times" -eq 0 ]; then
echo "MongoDB is not ready, exiting..."
exit 1
fi
done
echo "Mongo is up!"
containers:
- name: migrations
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
args: ["migrate"]
env:
- name: MONGO_DSN
{{- if .Values.api.mongo.dsnSecretRef }}
- name: ENTERPRISE_MODE
value: "{{ .Values.global.enterpriseMode }}"
{{- if .Values.global.enterpriseMode }}
- name: ENTERPRISE_OFFLINE_ACTIVATION
value: "{{ .Values.global.enterpriseOfflineAccess }}"
{{- end }}
{{- if .Values.global.enterpriseMode }}
- name: ENTERPRISE_LICENSE_KEY
{{- if .Values.global.enterpriseLicenseSecretRef }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.api.mongo.dsn }}
key: LICENSE_KEY
name: {{ .Values.global.enterpriseLicenseSecretRef }}
{{- else }}
value: "{{ .Values.global.enterpriseLicenseKey }}"
{{- end }}
{{- end }}
containers:
- name: migrations
image: {{ .Values.api.migrations.image.repository }}:{{ .Values.image.tag }}
args:
- up
env:
- name: MONGO_URL
{{- if .Values.api.mongo.dsnSecretRef }}
{{- if .Values.global.enterpriseLicenseFile }}
- name: ENTERPRISE_LICENSE_FILE
value: "{{ .Values.global.enterpriseLicenseFile }}"
{{- end }}
- name: OPENAI_API_KEY
{{- if .Values.ai.secretRef }}
valueFrom:
secretKeyRef:
key: {{ .Values.ai.secretKey }}
name: {{ .Values.ai.secretRef }}
{{- else }}
value: {{ .Values.ai.apiKey }}
{{- end }}
- name: INVITE_MODE
value: "{{ .Values.api.inviteMode }}"
{{- if eq .Values.api.inviteMode "email" }}
- name: SMTP_HOST
value: "{{ .Values.api.smtp.host }}"
- name: SMTP_PORT
value: "{{ .Values.api.smtp.port }}"
- name: SMTP_USER
value: "{{ .Values.api.smtp.username }}"
- name: SMTP_PASSWORD
{{- if .Values.api.smtp.passwordSecretRef }}
valueFrom:
secretKeyRef:
key: SMTP_PASSWORD
name: {{ .Values.api.smtp.passwordSecretRef }}
{{- else }}
value: {{ .Values.api.smtp.password }}
{{- end }}
{{- end }}
- name: ROOT_DOMAIN
value: "{{ .Values.global.domain }}"
- name: METRICS_LISTEN_ADDR
value: "0.0.0.0:9100"
{{- if .Values.payments.enabled }}
- name: PAYMENTS_PORTAL_CONFIGURATION_ID
{{- if .Values.payments.secretRef }}
valueFrom:
secretKeyRef:
key: PAYMENTS_PORTAL_CONFIGURATION_ID
name: {{ .Values.payments.secretRef }}
{{- else }}
value: {{ .Values.payments.portalConfigurationId }}
{{- end }}
- name: PAYMENTS_ENDPOINT_SECRET
{{- if .Values.payments.secretRef }}
valueFrom:
secretKeyRef:
key: PAYMENTS_ENDPOINT_SECRET
name: {{ .Values.payments.secretRef }}
{{- else }}
value: {{ .Values.payments.endpointSecret }}
{{- end }}
- name: PAYMENTS_API_KEY
{{- if .Values.payments.secretRef }}
valueFrom:
secretKeyRef:
key: PAYMENTS_API_KEY
name: {{ .Values.payments.secretRef }}
{{- else }}
value: {{ .Values.payments.apiKey }}
{{- end }}
{{- end }}
{{- if .Values.analytics.segmentio.enabled }}
- name: SEGMENTIO_WRITE_KEY
{{- if .Values.analytics.segmentio.secretRef }}
valueFrom:
secretKeyRef:
key: SEGMENTIO_WRITE_KEY
name: {{ .Values.analytics.segmentio.secretRef }}
{{- else }}
value: {{ .Values.analytics.segmentio.writeKey }}
{{- end }}
{{- end }}
{{- if .Values.analytics.hubspot.enabled }}
- name: HUBSPOT_API_KEY
{{- if .Values.analytics.hubspot.secretRef }}
valueFrom:
secretKeyRef:
key: HUBSPOT_API_KEY
name: {{ .Values.analytics.hubspot.secretRef }}
{{- else }}
value: {{ .Values.analytics.hubspot.apiKey }}
{{- end }}
{{- end }}
- name: SENDGRID_API_KEY
{{- if .Values.api.sendgrid.secretRef }}
valueFrom:
secretKeyRef:
key: SENDGRID_API_KEY
name: {{ .Values.api.sendgrid.secretRef }}
{{- else }}
value: "{{ .Values.api.sendgrid.apiKey }}"
{{- end }}
- name: API_MONGO_DSN
{{- if .Values.api.mongo.dsnSecretRef }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.api.mongo.dsnSecretRef }}
{{- else }}
{{- else }}
value: {{ .Values.api.mongo.dsn }}
{{- end }}
- name: MONGO_DB
{{- end }}
- name: API_MONGO_DB
value: {{ .Values.api.mongo.database }}
- name: OAUTH_CLIENT_ID
{{- if .Values.api.oauth.secretRef }}
valueFrom:
secretKeyRef:
key: OAUTH_CLIENT_ID
name: {{ .Values.api.oauth.secretRef }}
{{- else }}
value: "{{ .Values.api.oauth.clientId }}"
{{- end }}
- name: OAUTH_CLI_CLIENT_ID
{{- if .Values.api.oauth.secretRef }}
valueFrom:
secretKeyRef:
key: OAUTH_CLI_CLIENT_ID
name: {{ .Values.api.oauth.secretRef }}
{{- else }}
value: "{{ .Values.api.oauth.cliClientId }}"
{{- end }}
- name: OAUTH_CLIENT_SECRET
{{- if .Values.api.oauth.secretRef }}
valueFrom:
secretKeyRef:
key: OAUTH_CLIENT_SECRET
name: {{ .Values.api.oauth.secretRef }}
{{- else }}
value: "{{ .Values.api.oauth.clientSecret }}"
{{- end }}
- name: OAUTH_ISSUER_URL
{{- if .Values.api.oauth.secretRef }}
valueFrom:
secretKeyRef:
key: OAUTH_ISSUER_URL
name: {{ .Values.api.oauth.secretRef }}
{{- else }}
value: {{ if .Values.global.dex.issuer}}{{ .Values.global.dex.issuer }}{{ else if .Values.api.oauth.issuerUrl }}{{ .Values.api.oauth.issuerUrl }}{{ else }}https://{{ .Values.global.restApiSubdomain }}.{{ .Values.global.domain }}/idp{{ end }}
{{- end }}
- name: OAUTH_REDIRECT_URI
{{- if .Values.api.oauth.secretRef }}
valueFrom:
secretKeyRef:
key: OAUTH_REDIRECT_URI
name: {{ .Values.api.oauth.secretRef }}
{{- else }}
value: "{{ if .Values.api.oauth.redirectUri }}{{ .Values.api.oauth.redirectUri }}{{ else }}https://{{ .Values.global.restApiSubdomain }}.{{ .Values.global.domain }}/auth/callback{{ end }}"
{{- end }}
- name: NATS_URI
value: {{ .Values.api.nats.uri }}
{{- $dashboardAddress := "" }}
{{- if .Values.api.dashboardAddress }}
{{- $dashboardAddress = .Values.api.dashboardAddress }}
{{- else }}
{{- $dashboardAddress = printf "https://%s.%s" .Values.global.uiSubdomain .Values.global.domain }}
{{- end }}
- name: ALLOWED_EXTERNAL_REDIRECT_URIS
value: {{ if .Values.api.oauth.allowedExternalRedirectURIs }}{{ .Values.api.oauth.allowedExternalRedirectURIs }}{{ else }}{{ $dashboardAddress }}{{ end }}
{{- if .Values.api.agent.hide }}
- name: HIDE_AGENT_HOST
value: "{{ .Values.api.agent.hide }}"
{{- end }}
- name: AGENT_HOST
value: {{ if .Values.api.agent.host }}{{ .Values.api.agent.host }}{{ else }}{{ .Values.global.grpcApiSubdomain }}.{{ .Values.global.domain }}{{ end }}
- name: AGENT_PORT
value: "{{ .Values.api.agent.port }}"
- name: API_ADDRESS
value: {{ if .Values.api.apiAddress }}{{ .Values.api.apiAddress }}{{ else }}https://{{ .Values.global.restApiSubdomain }}.{{ .Values.global.domain }}{{ end }}
- name: DASHBOARD_ADDRESS
value: {{ $dashboardAddress }}
- name: USE_TLS
value: "{{ .Values.api.tls.serveHTTPS }}"
- name: TLS_CERT
value: "{{ .Values.api.tls.certPath }}"
- name: TLS_KEY
value: "{{ .Values.api.tls.keyPath }}"
- name: OUTPUTS_BUCKET
value: "{{ .Values.api.outputsBucket }}"
{{- if .Values.minio.enabled }}
- name: MINIO_ENDPOINT
value: "{{ .Values.api.minio.endpoint }}"
- name: MINIO_REGION
value: "{{ .Values.api.minio.region }}"
- name: MINIO_SSL
value: "{{ .Values.api.minio.secure }}"
- name: MINIO_EXPIRATION
value: "{{ .Values.api.minio.expirationPeriod }}"
- name: MINIO_ACCESS_KEY_ID
{{- if .Values.api.minio.credsSecretRef }}
valueFrom:
secretKeyRef:
key: MINIO_ACCESS_KEY_ID
name: {{ .Values.api.minio.credsSecretRef }}
{{- else }}
value: "{{ if .Values.api.minio.accessKeyId }}{{ .Values.api.minio.accessKeyId }}{{ else }}{{ .Values.minio.credentials.accessKeyId }}{{ end }}"
{{- end }}
- name: MINIO_SECRET_ACCESS_KEY
{{- if .Values.api.minio.credsSecretRef }}
valueFrom:
secretKeyRef:
key: MINIO_SECRET_ACCESS_KEY
name: {{ .Values.api.minio.credsSecretRef }}
{{- else }}
value: "{{ if .Values.api.minio.secretAccessKey }}{{ .Values.api.minio.secretAccessKey }}{{ else }}{{ .Values.minio.credentials.secretAccessKey }}{{ end }}"
{{- end }}
- name: MINIO_TOKEN
{{- if .Values.api.minio.credsSecretRef }}
valueFrom:
secretKeyRef:
key: MINIO_TOKEN
name: {{ .Values.api.minio.credsSecretRef }}
{{- else }}
value: "{{ .Values.api.minio.token }}"
{{- end }}
{{- end }}
restartPolicy: Never
backoffLimit: 3
{{- end }}
13 changes: 6 additions & 7 deletions charts/testkube-cloud-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fullnameOverride: ""
# -- Additional env vars to be added to the deployment
additionalEnv:
{}
# FOO: bar
# FOO: bar

analytics:
segmentio:
Expand Down Expand Up @@ -94,8 +94,7 @@ api:
enabled: false
# -- Toggle whether to enable pre-install & pre-upgrade hooks
useHelmHooks: true
image:
repository: kubeshop/testkube-cloud-api-migrations

# -- Configure which invitation mode to use (email|auto-accept): email uses SMTP protocol to send email invites and auto-accept immediately adds them
inviteMode: email
smtp:
Expand Down Expand Up @@ -202,7 +201,7 @@ podAnnotations: {}
# -- Pod Security Context
podSecurityContext:
{}
# fsGroup: 2000
# fsGroup: 2000

# -- Security Context for app container
securityContext:
Expand Down Expand Up @@ -238,7 +237,7 @@ restIngress:
# -- Additional annotations to add to the REST Ingress resource
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/ingress.class: nginx
# -- Hostname for which to create rules and TLS certificates
host: ""

Expand All @@ -250,7 +249,7 @@ grpcIngress:
# -- Additional annotations to add to the gRPC Ingress resource
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/ingress.class: nginx
# -- Hostname for which to create rules and TLS certificates
host: ""

Expand All @@ -262,7 +261,7 @@ websocketsIngress:
# -- Additional annotations to add to the WebSocket Ingress resource
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/ingress.class: nginx
# -- Hostname for which to create rules and TLS certificates
host: ""

Expand Down
2 changes: 1 addition & 1 deletion charts/testkube-cloud-ui/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: testkube-cloud-ui
description: A Helm chart for Testkube Cloud UI
type: application
version: 1.13.78
version: 1.13.79
appVersion: 1.3.1
maintainers:
- name: testkube
Expand Down
2 changes: 1 addition & 1 deletion charts/testkube-cloud-ui/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testkube-cloud-ui

![Version: 1.11.10](https://img.shields.io/badge/Version-1.11.10-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.2.0-dev-19f8fbf](https://img.shields.io/badge/AppVersion-1.2.0--dev--19f8fbf-informational?style=flat-square)
![Version: 1.13.79](https://img.shields.io/badge/Version-1.13.79-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.3.1](https://img.shields.io/badge/AppVersion-1.3.1-informational?style=flat-square)

A Helm chart for Testkube Cloud UI

Expand Down
Loading

0 comments on commit 5366b1f

Please sign in to comment.