-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better connection strings #152
base: master
Are you sure you want to change the base?
Better connection strings #152
Conversation
key: {{ include "invenio.postgresql.secretKey" .}} | ||
{{- end }} | ||
- name: INVENIO_SQLALCHEMY_DATABASE_URI | ||
value: "$(INVENIO_DB_PROTOCOL)://$(INVENIO_DB_USER):$(INVENIO_DB_PASSWORD)@$(INVENIO_DB_HOST):$(INVENIO_DB_PORT)/$(INVENIO_DB_NAME)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. Maybe. 👀 The logic with defining each part as a separate env is sound, no issues there. But composing a new env value based on other envs like this, I'm unfamiliar with. If it works as your code indicates, then yeah I think this looks very promising.
How does this work? Does Kubernetes support the $(ENV)
syntax in string values, or does that happen inside the container? I feel lost as to why this works. 😅 I assumed you tried it and it seems to work?
Assuming it works, I really like this because I think it should be forwards-compatible with inveniosoftware/invenio-config#57 and/or inveniosoftware/invenio-app-rdm#2918 which is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# compose-env.yaml
---
apiVersion: v1
data:
secret: c2VjcmV0 # secret
kind: Secret
metadata:
name: compose-env
---
apiVersion: v1
kind: Pod
metadata:
name: compose-env
spec:
containers:
- name: compose-env
image: bash
env:
- name: SECRET
valueFrom:
secretKeyRef:
name: compose-env
key: secret
- name: PLAIN
value: plain
- name: MESSAGE
value: "$(PLAIN) - $(SECRET)"
command: ["echo"]
args: ["$(MESSAGE)"]
$ kubectl apply -f compose-env.yaml
secret/compose-env created
pod/compose-env created
$ kubectl logs compose-env
plain - secret
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure when it happens, in particular after reading this in the docs Variables making use of others defined in the same context must come later in the list.
.
I would think the interpolation happens at run time inside the container. This Environment
section of the output of kubectl describe pod
Environment:
SECRET: <set to the key 'secret' in secret 'compose-env'> Optional: false
PLAIN: plain
MESSAGE: $(PLAIN) - $(SECRET)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds convincing! Wow, this is so powerful (and a bit confusing)! 😀
I think this would be a great first step towards handling connection credentials better!
No description provided.