Skip to content

Commit

Permalink
fixes worker shutdown and secret revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Dec 12, 2024
1 parent 25aeff6 commit bfd1624
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 382 deletions.
139 changes: 139 additions & 0 deletions backend/charts/api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,142 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Generate the stringData section for environment variables
*/}}
{{- define "neosync-api.env-vars" -}}
DB_HOST: {{ .Values.db.host }}
DB_PORT: {{ .Values.db.port | quote }}
DB_NAME: {{ .Values.db.name }}
DB_USER: {{ .Values.db.username }}
DB_PASS: {{ .Values.db.password }}
DB_SSL_DISABLE: {{ .Values.db.disableSsl | quote}}
{{- if .Values.db.options }}
DB_OPTIONS: {{ .Values.db.options | quote}}
{{- end }}
{{- if .Values.host }}
HOST: {{ .Values.host | quote}}
{{- end }}
PORT: {{ .Values.containerPort | quote }}
{{- if .Values.otel.enabled }}
OTEL_EXPORTER_OTLP_PORT: {{ .Values.otel.otlpPort | quote }} # sends to gRPC receiver
{{- end }}
{{- if .Values.nucleusEnv }}
NUCLEUS_ENV: {{ .Values.nucleusEnv }}
{{- end }}
{{- if .Values.shutdownTimeoutSeconds }}
SHUTDOWN_TIMEOUT_SECONDS: {{ .Values.shutdownTimeoutSeconds | quote }}
{{- end }}
{{- if and .Values.auth .Values.auth.enabled }}
AUTH_ENABLED: {{ .Values.auth.enabled | default "false" | quote }}
{{- end }}
{{- if and .Values.auth .Values.auth.baseUrl }}
AUTH_BASEURL: {{ .Values.auth.baseUrl }}
{{- end }}
{{- if and .Values.auth .Values.auth.expectedIss }}
AUTH_EXPECTED_ISS: {{ .Values.auth.expectedIss }}
{{- end }}
{{- if and .Values.auth .Values.auth.audience }}
AUTH_AUDIENCE: {{ .Values.auth.audience }}
{{- end }}
{{- if and .Values.auth .Values.auth.clientMap }}
AUTH_CLIENTID_SECRET: {{ .Values.auth.clientMap | toJson | quote }}
{{- end }}
{{- if and .Values.auth .Values.auth.cliClientId }}
AUTH_CLI_CLIENT_ID: {{ .Values.auth.cliClientId }}
{{- end }}
{{- if and .Values.auth .Values.auth.cliAudience }}
AUTH_CLI_AUDIENCE: {{ .Values.auth.cliAudience }}
{{- end }}
{{- if and .Values.auth .Values.auth.signatureAlgorithm }}
AUTH_SIGNATURE_ALGORITHM: {{ .Values.auth.signatureAlgorithm }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.url }}
TEMPORAL_URL: {{ .Values.temporal.url }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.keyFilePath }}
TEMPORAL_CERT_KEY_PATH: {{ .Values.temporal.certificate.keyFilePath }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.certFilePath }}
TEMPORAL_CERT_PATH: {{ .Values.temporal.certificate.certFilePath }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.keyContents }}
TEMPORAL_CERT_KEY: {{ .Values.temporal.certificate.keyContents }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.certContents }}
TEMPORAL_CERT: {{ .Values.temporal.certificate.certContents }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.defaultNamespace }}
TEMPORAL_DEFAULT_NAMESPACE: {{ .Values.temporal.defaultNamespace }}
{{- end }}
{{- if and .Values.temporal .Values.temporal.defaultSyncJobQueue }}
TEMPORAL_DEFAULT_SYNCJOB_QUEUE: {{ .Values.temporal.defaultSyncJobQueue }}
{{- end }}
{{- if and .Values.auth .Values.auth.api .Values.auth.api.clientId }}
AUTH_API_CLIENT_ID: {{ .Values.auth.api.clientId }}
{{- end }}
{{- if and .Values.auth .Values.auth.api .Values.auth.api.clientSecret }}
AUTH_API_CLIENT_SECRET: {{ .Values.auth.api.clientSecret }}
{{- end }}
{{- if and .Values.auth .Values.auth.api .Values.auth.api.baseUrl }}
AUTH_API_BASEURL: {{ .Values.auth.api.baseUrl }}
{{- end }}
{{- if and .Values.auth .Values.auth.api .Values.auth.api.provider }}
AUTH_API_PROVIDER: {{ .Values.auth.api.provider }}
{{- end }}
NEOSYNC_CLOUD: {{ .Values.neosyncCloud.enabled | default "false" | quote }}
{{- if .Values.neosyncCloud.enabled }}
NEOSYNC_CLOUD_ALLOWED_WORKER_API_KEYS: {{ join "," .Values.neosyncCloud.workerApiKeys }}
{{- end }}
KUBERNETES_ENABLED: {{ .Values.kubernetes.enabled | default "true" | quote }}
KUBERNETES_NAMESPACE: {{ .Values.kubernetes.namespace | default .Release.Namespace }}
{{- if and .Values.kubernetes .Values.kubernetes.workerAppName }}
KUBERNETES_WORKER_APP_NAME: {{ .Values.kubernetes.workerAppName }}
{{- end }}
{{- if and .Values.protometrics .Values.protometrics.enabled }}
METRICS_SERVICE_ENABLED: {{ .Values.protometrics.enabled | default "false" | quote }}
{{- end }}
{{- if and .Values.protometrics .Values.protometrics.url }}
METRICS_URL: {{ .Values.protometrics.url | quote }}
{{- end }}
{{- if and .Values.protometrics .Values.protometrics.apiKey }}
METRICS_API_KEY: {{ .Values.protometrics.apiKey | quote }}
{{- end }}
{{- if and .Values.runLogs .Values.runLogs.enabled }}
RUN_LOGS_ENABLED: {{ .Values.runLogs.enabled | toString | quote }}
RUN_LOGS_TYPE: {{ .Values.runLogs.type | quote }}
{{- if eq .Values.runLogs.type "k8s-pods" }}
RUN_LOGS_PODCONFIG_WORKER_NAMESPACE: {{ default .Release.Namespace .Values.runLogs.podConfig.workerNamespace | quote }}
RUN_LOGS_PODCONFIG_WORKER_APPNAME: {{ .Values.runLogs.podConfig.workerAppName | quote }}
{{- end }}
{{- if eq .Values.runLogs.type "loki" }}
RUN_LOGS_LOKICONFIG_BASEURL: {{ .Values.runLogs.lokiConfig.baseUrl | quote }}
RUN_LOGS_LOKICONFIG_LABELSQUERY: {{ .Values.runLogs.lokiConfig.labelsQuery | quote }}
{{- if .Values.runLogs.lokiConfig.keepLabels }}
RUN_LOGS_LOKICONFIG_KEEPLABELS: {{ .Values.runLogs.lokiConfig.keepLabels | join "," | quote }}
{{- end }}
{{- end }} # ends loki check
{{- end }} # ends runLogs.enabled check
{{- if and .Values.ee .Values.ee.license }}
EE_LICENSE: {{ .Values.ee.license | quote }}
{{- end }}
{{- end -}}

{{/*
Generate the stringData section for environment variables
*/}}
{{- define "neosync-api.migration-env-vars" -}}
DB_HOST: {{ .Values.migrations.db.host }}
DB_PORT: {{ .Values.migrations.db.port | quote }}
DB_NAME: {{ .Values.migrations.db.name }}
DB_USER: {{ .Values.migrations.db.username }}
DB_PASS: {{ .Values.migrations.db.password }}
DB_SSL_DISABLE: {{ .Values.migrations.db.disableSsl | quote}}
{{- if .Values.migrations.db.options }}
DB_MIGRATIONS_OPTIONS: {{ .Values.migrations.db.options | quote}}
{{- end }}
DB_SCHEMA_DIR: {{ .Values.migrations.db.schemaDir }}
DB_MIGRATIONS_TABLE: {{ .Values.migrations.db.migrationsTableName }}
DB_MIGRATIONS_TABLE_QUOTED: {{ .Values.migrations.db.migrationsTableQuoted | quote }}
{{- end -}}
156 changes: 4 additions & 152 deletions backend/charts/api/templates/api-env-vars.yaml
Original file line number Diff line number Diff line change
@@ -1,158 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "neosync-api.fullname" . }}-service-evs
name: {{ template "neosync-api.fullname" . }}-service-evs-{{ include "neosync-api.env-vars" . | sha256sum | trunc 8 }}
namespace: {{ .Release.Namespace }}
annotations:
checksum/stringdata: {{ include "neosync-api.env-vars" . | sha256sum }}
type: Opaque
stringData:
DB_HOST: {{ .Values.db.host }}
DB_PORT: {{ .Values.db.port | quote }}
DB_NAME: {{ .Values.db.name }}
DB_USER: {{ .Values.db.username }}
DB_PASS: {{ .Values.db.password }}
DB_SSL_DISABLE: {{ .Values.db.disableSsl | quote}}
{{- if .Values.db.options }}
DB_OPTIONS: {{ .Values.db.options | quote}}
{{- end }}

{{- if .Values.host }}
HOST: {{ .Values.host | quote}}
{{- end }}

PORT: {{ .Values.containerPort | quote }}

{{- if .Values.otel.enabled }}
OTEL_EXPORTER_OTLP_PORT: {{ .Values.otel.otlpPort | quote }} # sends to gRPC receiver
{{- end }}

{{- if .Values.nucleusEnv }}
NUCLEUS_ENV: {{ .Values.nucleusEnv }}
{{- end }}

{{- if .Values.shutdownTimeoutSeconds }}
SHUTDOWN_TIMEOUT_SECONDS: {{ .Values.shutdownTimeoutSeconds | quote }}
{{- end }}

{{- if and .Values.auth .Values.auth.enabled }}
AUTH_ENABLED: {{ .Values.auth.enabled | default "false" | quote }}
{{- end }}

{{- if and .Values.auth .Values.auth.baseUrl }}
AUTH_BASEURL: {{ .Values.auth.baseUrl }}
{{- end }}

{{- if and .Values.auth .Values.auth.expectedIss }}
AUTH_EXPECTED_ISS: {{ .Values.auth.expectedIss }}
{{- end }}

{{- if and .Values.auth .Values.auth.audience }}
AUTH_AUDIENCE: {{ .Values.auth.audience }}
{{- end }}

{{- if and .Values.auth .Values.auth.clientMap }}
AUTH_CLIENTID_SECRET: {{ .Values.auth.clientMap | toJson | quote }}
{{- end }}

{{- if and .Values.auth .Values.auth.cliClientId }}
AUTH_CLI_CLIENT_ID: {{ .Values.auth.cliClientId }}
{{- end }}

{{- if and .Values.auth .Values.auth.cliAudience }}
AUTH_CLI_AUDIENCE: {{ .Values.auth.cliAudience }}
{{- end }}

{{- if and .Values.auth .Values.auth.signatureAlgorithm }}
AUTH_SIGNATURE_ALGORITHM: {{ .Values.auth.signatureAlgorithm }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.url }}
TEMPORAL_URL: {{ .Values.temporal.url }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.keyFilePath }}
TEMPORAL_CERT_KEY_PATH: {{ .Values.temporal.certificate.keyFilePath }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.certFilePath }}
TEMPORAL_CERT_PATH: {{ .Values.temporal.certificate.certFilePath }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.keyContents }}
TEMPORAL_CERT_KEY: {{ .Values.temporal.certificate.keyContents }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.certificate .Values.temporal.certificate.certContents }}
TEMPORAL_CERT: {{ .Values.temporal.certificate.certContents }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.defaultNamespace }}
TEMPORAL_DEFAULT_NAMESPACE: {{ .Values.temporal.defaultNamespace }}
{{- end }}

{{- if and .Values.temporal .Values.temporal.defaultSyncJobQueue }}
TEMPORAL_DEFAULT_SYNCJOB_QUEUE: {{ .Values.temporal.defaultSyncJobQueue }}
{{- end }}

{{- if and .Values.auth .Values.auth.api .Values.auth.api.clientId }}
AUTH_API_CLIENT_ID: {{ .Values.auth.api.clientId }}
{{- end }}

{{- if and .Values.auth .Values.auth.api .Values.auth.api.clientSecret }}
AUTH_API_CLIENT_SECRET: {{ .Values.auth.api.clientSecret }}
{{- end }}

{{- if and .Values.auth .Values.auth.api .Values.auth.api.baseUrl }}
AUTH_API_BASEURL: {{ .Values.auth.api.baseUrl }}
{{- end }}

{{- if and .Values.auth .Values.auth.api .Values.auth.api.provider }}
AUTH_API_PROVIDER: {{ .Values.auth.api.provider }}
{{- end }}

NEOSYNC_CLOUD: {{ .Values.neosyncCloud.enabled | default "false" | quote }}
{{- if .Values.neosyncCloud.enabled }}
NEOSYNC_CLOUD_ALLOWED_WORKER_API_KEYS: {{ join "," .Values.neosyncCloud.workerApiKeys }}
{{- end }}

KUBERNETES_ENABLED: {{ .Values.kubernetes.enabled | default "true" | quote }}
KUBERNETES_NAMESPACE: {{ .Values.kubernetes.namespace | default .Release.Namespace }}

{{- if and .Values.kubernetes .Values.kubernetes.workerAppName }}
KUBERNETES_WORKER_APP_NAME: {{ .Values.kubernetes.workerAppName }}
{{- end }}

{{- if and .Values.protometrics .Values.protometrics.enabled }}
METRICS_SERVICE_ENABLED: {{ .Values.protometrics.enabled | default "false" | quote }}
{{- end }}
{{- if and .Values.protometrics .Values.protometrics.url }}
METRICS_URL: {{ .Values.protometrics.url | quote }}
{{- end }}
{{- if and .Values.protometrics .Values.protometrics.apiKey }}
METRICS_API_KEY: {{ .Values.protometrics.apiKey | quote }}
{{- end }}


{{- if and .Values.runLogs .Values.runLogs.enabled }}

RUN_LOGS_ENABLED: {{ .Values.runLogs.enabled | toString | quote }}
RUN_LOGS_TYPE: {{ .Values.runLogs.type | quote }}

{{- if eq .Values.runLogs.type "k8s-pods" }}
RUN_LOGS_PODCONFIG_WORKER_NAMESPACE: {{ default .Release.Namespace .Values.runLogs.podConfig.workerNamespace | quote }}
RUN_LOGS_PODCONFIG_WORKER_APPNAME: {{ .Values.runLogs.podConfig.workerAppName | quote }}
{{- end }}

{{- if eq .Values.runLogs.type "loki" }}
RUN_LOGS_LOKICONFIG_BASEURL: {{ .Values.runLogs.lokiConfig.baseUrl | quote }}
RUN_LOGS_LOKICONFIG_LABELSQUERY: {{ .Values.runLogs.lokiConfig.labelsQuery | quote }}

{{- if .Values.runLogs.lokiConfig.keepLabels }}
RUN_LOGS_LOKICONFIG_KEEPLABELS: {{ .Values.runLogs.lokiConfig.keepLabels | join "," | quote }}
{{- end }}
{{- end }} # ends loki check

{{- end }} # ends runLogs.enabled check

{{- if and .Values.ee .Values.ee.license }}
EE_LICENSE: {{ .Values.ee.license | quote }}
{{- end }}
{{ include "neosync-api.env-vars" . | indent 4 }}
19 changes: 4 additions & 15 deletions backend/charts/api/templates/db-migrations-env-vars.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "neosync-api.fullname" . }}-migration-evs
name: {{ template "neosync-api.fullname" . }}-migration-evs-{{ include "neosync-api.migration-env-vars" . | sha256sum | trunc 8 }}
namespace: {{ .Release.Namespace }}
annotations:
checksum/stringdata: {{ include "neosync-api.migration-env-vars" . | sha256sum }}
type: Opaque
stringData:
DB_HOST: {{ .Values.migrations.db.host }}
DB_PORT: {{ .Values.migrations.db.port | quote }}
DB_NAME: {{ .Values.migrations.db.name }}
DB_USER: {{ .Values.migrations.db.username }}
DB_PASS: {{ .Values.migrations.db.password }}
DB_SSL_DISABLE: {{ .Values.migrations.db.disableSsl | quote}}
{{- if .Values.migrations.db.options }}
DB_MIGRATIONS_OPTIONS: {{ .Values.migrations.db.options | quote}}
{{- end }}

DB_SCHEMA_DIR: {{ .Values.migrations.db.schemaDir }}
DB_MIGRATIONS_TABLE: {{ .Values.migrations.db.migrationsTableName }}
DB_MIGRATIONS_TABLE_QUOTED: {{ .Values.migrations.db.migrationsTableQuoted | quote }}

{{ include "neosync-api.migration-env-vars" . | indent 4 }}
5 changes: 2 additions & 3 deletions backend/charts/api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ spec:
{{- if eq .Values.istio.enabled true }}
proxy.istio.io/config: '{ "holdApplicationUntilProxyStarts": true }'
{{- end }}
rollme: {{ randAlphaNum 5 | quote }} # causes deployment to always roll on helm upgrade
labels:
{{- include "neosync-api.labels" . | nindent 8 }}
app: {{ template "neosync-api.fullname" . }}
Expand Down Expand Up @@ -117,7 +116,7 @@ spec:

envFrom:
- secretRef:
name: {{ template "neosync-api.fullname" . }}-migration-evs
name: {{ template "neosync-api.fullname" . }}-migration-evs-{{ include "neosync-api.migration-env-vars" . | sha256sum | trunc 8 }}
{{- end }}

{{- with .Values.volumes }}
Expand Down Expand Up @@ -220,7 +219,7 @@ spec:

envFrom:
- secretRef:
name: {{ template "neosync-api.fullname" . }}-service-evs
name: {{ template "neosync-api.fullname" . }}-service-evs-{{ include "neosync-api.env-vars" . | sha256sum | trunc 8 }}

{{- if .Values.sidecarContainers }}
{{- toYaml .Values.sidecarContainers | nindent 8 }}
Expand Down
12 changes: 10 additions & 2 deletions backend/internal/cmds/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package mgmt_cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"

migrate_cmd "github.com/nucleuscloud/neosync/backend/internal/cmds/mgmt/migrate"
run_cmd "github.com/nucleuscloud/neosync/backend/internal/cmds/mgmt/run"
serve "github.com/nucleuscloud/neosync/backend/internal/cmds/mgmt/serve"
neosynclogger "github.com/nucleuscloud/neosync/backend/pkg/logger"
)

func Execute() {
cobra.OnInitialize(func() { initConfig() })

rootCmd := &cobra.Command{
Use: "mgmt",
Short: "Terminal UI that interfaces with the Nucleus system.",
Short: "Terminal app that is used to manage the Neosync API system.",
Long: "",
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
cmd.SilenceErrors = true
Expand All @@ -30,7 +32,13 @@ func Execute() {
rootCmd.AddCommand(migrate_cmd.NewCmd())
rootCmd.AddCommand(run_cmd.NewCmd())

cobra.CheckErr(rootCmd.Execute())
logger, _ := neosynclogger.NewLoggers()

err := rootCmd.Execute()
if err != nil {
logger.Error(fmt.Sprintf("error executing root command: %v", err))
os.Exit(1)
}
}

// initConfig reads in config file and ENV variables if set.
Expand Down
Loading

0 comments on commit bfd1624

Please sign in to comment.