From 1ed1169cb0d8eda38f9cb0baed3870166a25a66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Lafarge?= Date: Sat, 2 Mar 2019 11:56:40 +0100 Subject: [PATCH] [pr-review] Lighten docs & validate SQL dialect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Étienne Lafarge --- docs/install.md | 6 +-- docs/sql-storage.md | 89 --------------------------------------- pkg/storage/driver/sql.go | 8 ++++ 3 files changed, 11 insertions(+), 92 deletions(-) delete mode 100644 docs/sql-storage.md diff --git a/docs/install.md b/docs/install.md index a23dfbb3b..d240e72cf 100755 --- a/docs/install.md +++ b/docs/install.md @@ -380,13 +380,13 @@ Using such a storage backend is particularly useful if your release information weighs more than 1MB (in which case, it can't be stored in ConfigMaps/Secrets because of internal limits in Kubernetes' underlying etcd key-value store). -To enable the SQL backend, you'll need to [deploy an SQL -database](./sql-storage.md) and init Tiller with the following options: +To enable the SQL backend, you'll need to deploy a SQL database and init Tiller +with the following options: ```shell helm init \ --override \ - 'spec.template.spec.containers[0].args'='{--storage=sql,--sql-dialect=postgres,--sql-connection-string=postgresql://tiller-postgres:5432/helm?user=helm&password=changemeforgodssake&sslmode=disable}' + 'spec.template.spec.containers[0].args'='{--storage=sql,--sql-dialect=postgres,--sql-connection-string=postgresql://tiller-postgres:5432/helm?user=helm&password=changeme}' ``` **PRODUCTION NOTES**: it's recommended to change the username and password of diff --git a/docs/sql-storage.md b/docs/sql-storage.md deleted file mode 100644 index 19f7a5eb1..000000000 --- a/docs/sql-storage.md +++ /dev/null @@ -1,89 +0,0 @@ -# Store release information in an SQL database - -You may be willing to store release information in an SQL database - in -particular, if your releases weigh more than 1MB and therefore [can't be stored in ConfigMaps or Secrets](https://github.com/helm/helm/issues/1413). - -We recommend using [PostgreSQL](https://www.postgresql.org/). - -This document describes how to deploy `postgres` atop Kubernetes. This being -said, using an out-of-cluster (managed or not) PostreSQL instance is totally -possible as well. - -Here's a Kubernetes manifest you can apply to get a minimal PostreSQL pod -running on your Kubernetes cluster. **Don't forget to change the credentials -and, optionally, enable TLS in production deployments**. - -```yaml -apiVersion: v1 -kind: Service -metadata: - name: tiller-postgres - namespace: kube-system -spec: - ports: - - port: 5432 - selector: - app: helm - name: postgres ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: tiller-postgres - namespace: kube-system -spec: - serviceName: tiller-postgres - selector: - matchLabels: - app: helm - name: postgres - replicas: 1 - template: - metadata: - labels: - app: helm - name: postgres - spec: - containers: - - name: postgres - image: postgres:11-alpine - imagePullPolicy: Always - ports: - - containerPort: 5432 - env: - - name: POSTGRES_DB - value: helm - - name: POSTGRES_USER - value: helm - - name: POSTGRES_PASSWORD - value: changemeforgodssake - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - resources: - limits: - memory: 128Mi - requests: - cpu: 50m - memory: 128Mi - volumeMounts: - - mountPath: /var/lib/postgresql/data - name: tiller-postgres-data - volumeClaimTemplates: - - metadata: - name: tiller-postgres-data - spec: - accessModes: ["ReadWriteOnce"] - storageClassName: default - resources: - requests: - storage: 5Gi -``` - -Once postgres is deployed, you'll need to install Tiller using `helm init`, with -a few custom CLI flags: - -```shell -helm init \ - --override \ - 'spec.template.spec.containers[0].args'='{--storage=sql,--sql-dialect=postgres,--sql-connection-string=postgresql://tiller-postgres:5432/helm?user=helm&password=changemeforgodssake&sslmode=disable}' -``` diff --git a/pkg/storage/driver/sql.go b/pkg/storage/driver/sql.go index 3b3438577..7849f84b4 100644 --- a/pkg/storage/driver/sql.go +++ b/pkg/storage/driver/sql.go @@ -43,6 +43,10 @@ var labelMap = map[string]string{ "NAME": "name", } +var supportedSQLDialects = map[string]struct{}{ + "postgres": struct{}{}, +} + // SQLDriverName is the string name of this driver. const SQLDriverName = "SQL" @@ -113,6 +117,10 @@ type Release struct { // NewSQL initializes a new memory driver. func NewSQL(dialect, connectionString string, logger func(string, ...interface{})) (*SQL, error) { + if _, ok := supportedSQLDialects[dialect]; !ok { + return nil, fmt.Errorf("%s dialect isn't supported, only \"postgres\" is available for now", dialect) + } + db, err := sqlx.Connect(dialect, connectionString) if err != nil { return nil, err