colearendt / helm

Helm charts for miscellaneous services that I use regularly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Postgrest parameter dbChannelEnabled should be boolean not string

yevon opened this issue · comments

The parameter dbChannelEnabled should be a boolean not a string. If I try to change:

dbChannel: "pgrt"
dbChannelEnabled: true

It fails.

I have to admit I'm not super familiar with these settings. Are these environment variables? Environment variables are all strings, so you just have to quote them to get them to work.

Something like:

dbChannel: "pgrt"
dbChannelEnabled: "true"

If you can share an example values file and the error, that would be helpful if there is something I'm missing here 😄

It's quite a big error when trying to use value "true" or true, but it seems that it requires y/n instead of true or false:

ReadString: expects " or n, but found t, error found in #10 byte of ...|,"value":true}

I will try to change it with "y"

Error: UPGRADE FAILED: cannot patch "test-postgrest" with kind Deployment: "" is invalid: patch: Invalid value: "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{\"deployment.kubernetes.io/revision\":\"3\",\"meta.helm.sh/release-name\":\"postgrest\",\"meta.helm.sh/release-namespace\":\"test-postgrest\"},\"creationTimestamp\":\"2022-02-12T20:37:53Z\",\"generation\":3,\"labels\":{\"app.kubernetes.io/instance\":\"postgrest\",\"app.kubernetes.io/managed-by\":\"Helm\",\"app.kubernetes.io/name\":\"postgrest\",\"app.kubernetes.io/version\":\"v8.0.0\",\"helm.sh/chart\":\"postgrest-0.3.0\"},\"managedFields\":[{\"manager\":\"helm\",\"operation\":\"Update\",\"apiVersion\":\"apps/v1\",\"time\":\"2022-02-13T11:11:22Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:meta.helm.sh/release-name\":{},\"f:meta.helm.sh/release-namespace\":{}},\"f:labels\":{\".\":{},\"f:app.kubernetes.io/instance\":{},\"f:app.kubernetes.io/managed-by\":{},\"f:app.kubernetes.io/name\":{},\"f:app.kubernetes.io/version\":{},\"f:helm.sh/chart\":{}}},\"f:spec\":{\"f:progressDeadlineSeconds\":{},\"f:replicas\":{},\"f:revisionHistoryLimit\":{},\"f:selector\":{},\"f:strategy\":{\"f:rollingUpdate\":{\".\":{},\"f:maxSurge\":{},\"f:maxUnavailable\":{}},\"f:type\":{}},\"f:template\":{\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:checksum/secret\":{}},\"f:labels\":{\".\":{},\"f:app.kubernetes.io/instance\":{},\"f:app.kubernetes.io/name\":{}}},\"f:spec\":{\"f:containers\":{\"k:{\\\"name\\\":\\\"postgrest\\\"}\":{\".\":{},\"f:env\":{\".\":{},\"k:{\\\"name\\\":\\\"PGRST_DB_ANON_ROLE\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}},\"k:{\\\"name\\\":\\\"PGRST_DB_CHANNEL\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}},\"k:{\\\"name\\\":\\\"PGRST_DB_SCHEMA\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}},\"k:{\\\"name\\\":\\\"PGRST_DB_URI\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}},\"k:{\\\"name\\\":\\\"PGRST_OPENAPI_SERVER_PROXY_URI\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}},\"k:{\\\"name\\\":\\\"PGRST_SERVER_PORT\\\"}\":{\".\":{},\"f:name\":{},\"f:value\":{}}},\"f:image\":{},\"f:imagePullPolicy\":{},\"f:name\":{},\"f:ports\":{\".\":{},\"k:{\\\"containerPort\\\":9000,\\\"protocol\\\":\\\"TCP\\\"}\":{\".\":{},\"f:containerPort\":{},\"f:name\":{},\"f:protocol\":{}}},\"f:readinessProbe\":{\".\":{},\"f:failureThreshold\":{},\"f:httpGet\":{\".\":{},\"f:path\":{},\"f:port\":{},\"f:scheme\":{}},\"f:initialDelaySeconds\":{},\"f:periodSeconds\":{},\"f:successThreshold\":{},\"f:timeoutSeconds\":{}},\"f:resources\":{},\"f:terminationMessagePath\":{},\"f:terminationMessagePolicy\":{},\"f:volumeMounts\":{\".\":{},\"k:{\\\"mountPath\\\":\\\"/mnt/secret\\\"}\":{\".\":{},\"f:mountPath\":{},\"f:name\":{}}}}},\"f:dnsPolicy\":{},\"f:restartPolicy\":{},\"f:schedulerName\":{},\"f:securityContext\":{},\"f:serviceAccount\":{},\"f:serviceAccountName\":{},\"f:terminationGracePeriodSeconds\":{},\"f:volumes\":{\".\":{},\"k:{\\\"name\\\":\\\"secret-mount\\\"}\":{\".\":{},\"f:name\":{},\"f:secret\":{\".\":{},\"f:defaultMode\":{},\"f:secretName\":{}}}}}}}}},{\"manager\":\"k3s\",\"operation\":\"Update\",\"apiVersion\":\"apps/v1\",\"time\":\"2022-02-13T11:11:32Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:metadata\":{\"f:annotations\":{\"f:deployment.kubernetes.io/revision\":{}}},\"f:status\":{\"f:availableReplicas\":{},\"f:conditions\":{\".\":{},\"k:{\\\"type\\\":\\\"Available\\\"}\":{\".\":{},\"f:lastTransitionTime\":{},\"f:lastUpdateTime\":{},\"f:message\":{},\"f:reason\":{},\"f:status\":{},\"f:type\":{}},\"k:{\\\"type\\\":\\\"Progressing\\\"}\":{\".\":{},\"f:lastTransitionTime\":{},\"f:lastUpdateTime\":{},\"f:message\":{},\"f:reason\":{},\"f:status\":{},\"f:type\":{}}},\"f:observedGeneration\":{},\"f:readyReplicas\":{},\"f:replicas\":{},\"f:updatedReplicas\":{}}}}],\"name\":\"test-postgrest\",\"namespace\":\"test-postgrest\",\"resourceVersion\":\"30583638\",\"uid\":\"310fa84e-4467-42b9-a4b8-d1b800c5c64e\"},\"spec\":{\"progressDeadlineSeconds\":600,\"replicas\":1,\"revisionHistoryLimit\":10,\"selector\":{\"matchLabels\":{\"app.kubernetes.io/instance\":\"postgrest\",\"app.kubernetes.io/name\":\"postgrest\"}},\"strategy\":{\"type\":\"RollingUpdate\",\"rollingUpdate\":{\"maxUnavailable\":1,\"maxSurge\":1}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"app.kubernetes.io/instance\":\"postgrest\",\"app.kubernetes.io/name\":\"postgrest\"},\"annotations\":{\"checksum/secret\":\"c40c24f77a04de7c8e50feb3863570e22e61aed1152629c141590f206e074f3e\"}},\"spec\":{\"containers\":[{\"env\":[{\"name\":\"PGRST_DB_URI\",\"value\":\"@/mnt/secret/db-uri.txt\"},{\"name\":\"PGRST_DB_SCHEMA\",\"value\":\"test\"},{\"name\":\"PGRST_DB_ANON_ROLE\",\"value\":\"test_anonymous\"},{\"name\":\"PGRST_DB_CHANNEL\",\"value\":\"pgrst\"},{\"name\":\"PGRST_DB_CHANNEL_ENABLED\",\"value\":true},{\"name\":\"PGRST_SERVER_PORT\",\"value\":\"9000\"},{\"name\":\"PGRST_OPENAPI_SERVER_PROXY_URI\",\"value\":\"https://test.com/\"}],\"image\":\"postgrest/postgrest:v9.0.0\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"postgrest\",\"ports\":[{\"containerPort\":9000,\"name\":\"http\",\"protocol\":\"TCP\"}],\"readinessProbe\":{\"httpGet\":{\"path\":\"/\",\"port\":\"http\"},\"initialDelaySeconds\":5,\"periodSeconds\":5},\"volumeMounts\":[{\"mountPath\":\"/mnt/secret\",\"name\":\"secret-mount\"}]}],\"dnsPolicy\":\"ClusterFirst\",\"restartPolicy\":\"Always\",\"schedulerName\":\"default-scheduler\",\"securityContext\":{},\"serviceAccount\":\"test-postgrest\",\"serviceAccountName\":\"test-postgrest\",\"terminationGracePeriodSeconds\":30,\"volumes\":[{\"name\":\"secret-mount\",\"secret\":{\"secretName\":\"test-postgrest-secret\",\"defaultMode\":420}}]}}},\"status\":{\"observedGeneration\":3,\"replicas\":1,\"updatedReplicas\":1,\"readyReplicas\":1,\"availableReplicas\":1,\"conditions\":[{\"type\":\"Available\",\"status\":\"True\",\"lastUpdateTime\":\"2022-02-12T20:37:53Z\",\"lastTransitionTime\":\"2022-02-12T20:37:53Z\",\"reason\":\"MinimumReplicasAvailable\",\"message\":\"Deployment has minimum availability.\"},{\"type\":\"Progressing\",\"status\":\"True\",\"lastUpdateTime\":\"2022-02-13T11:11:32Z\",\"lastTransitionTime\":\"2022-02-12T20:37:53Z\",\"reason\":\"NewReplicaSetAvailable\",\"message\":\"ReplicaSet \\\"test-postgrest-5c8d5ccc58\\\" has successfully progressed.\"}]}}": v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found t, error found in #10 byte of ...|,"value":true},{"nam|..., bigger context ...|rst"},{"name":"PGRST_DB_CHANNEL_ENABLED","value":true},{"name":"PGRST_SERVER_PORT","value":"9000"},{|...

It doesn't accept "y" either, it just wants an empty string "". The PostGrest docs states that this is a true or false value:

https://postgrest.org/en/stable/configuration.html?highlight=PGRST_DB_CHANNEL_ENABLED#db-channel-enabled

Another thing is the latest app version is "v9.0.0" not "v8.0.0"

Yes, I already tried:
yes
"yes"
"y"
"y"

And what is only working is empty string ""

Sorry, I already tried true and "true", i wanted to say true haha

The problem is that I try to reload the api schema cache by executing this:

NOTIFY pgrst, 'reload schema';

And it seems not working and not reflecting the api changes I make in the db. I have to restart postgrest completely as the pgrst dbchannel seems not enabled.

I have to admit I am not super familiar with the db-channel configuration. But it looks to me from here:

image

Like db-channel is enabled by default (and the chart should not be monkeying with that). But if you are trying to set this properly with env vars, you will want to set:

postgrest:
  dbChannel: "pgrst"
  dbChannelEnabled: "true"

If you want to sanity check what the chart is doing, you can exec into the pod and run something like:

env | grep PGRST

(this is explained in more detail here)

It just sets env vars if the value is set in your values file. Otherwise it uses whatever postgrest's default is:

{{- if .Values.postgrest.dbChannel }}
- name: PGRST_DB_CHANNEL
value: {{ .Values.postgrest.dbChannel }}
{{- end }}
{{- if .Values.postgrest.dbChannelEnabled }}
- name: PGRST_DB_CHANNEL_ENABLED
value: {{ .Values.postgrest.dbChannelEnabled }}
{{- end }}

I think that we can close this, you are right, It is enabled by default. The reason that is not working for me is that I have installed postgREST in a different server than the postgres database itself, and I think that in that case the schema cache invalidation doesn't work. I have just added a service restart as part of the ci/cd pipeline and it solved the issue. Thanks!

Interesting!! Thanks for the update! This may be something to pass upstream to postgrest - either to make such a scenario works (I suspect it is common) or add documentation to explain why it does not!

If I get a chance, I'll try to see if I can repro the issue

Not a perfect reproduction b/c the environment is different (two docker containers, one with postgres, one with postgrest), but it is what I had handy and I did a quick sanity check.

  • set PGRST_LOG_LEVEL=info so that we get info log messages
  • started postgrest
  • created a function
CREATE OR REPLACE FUNCTION schema.testthings() RETURNS int AS $BODY$ BEGIN
RETURN 1;
END;
$BODY$
LANGUAGE 'plpgsql';
  • tried to access function (curl localhost:58297/rpc/testthings)
{"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.","message":"Could not find the schema.testthings() function in the schema cache"}%
  • reload schema cache in the DB. (NOTE: I was using reload config first, which is wrong)
NOTIFY pgrst, 'reload schema';
  • Notice log messages in the postgrest instance:
15/Feb/2022:13:09:13 +0000: Config re-loaded
15/Feb/2022:13:10:02 +0000: Schema cache loaded
  • function call / api call works

I hope that helps! It seems like this should be possible!

Thanks for that! I will try to reach the postgrest team and ask for this issue. I have the feeling that this notification is between osnprocesses in the same machine, and it would not work in different machines. I don't know for sure just reading the docs.

Could you please attach your values.yaml file to check if I'm missing some config? I have just set up:

dbUri
dbSchema
dbAnnonRole
serverPort

And nothing more, but I don't get any logs about schema reloading.

Solved, I had dbChannel and openApiServerProxyUri with non empty values. I just set them with empty strings and is now working nicely, thanks!

Woops sorry for missing this! Glad to hear things are working well!