Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

egabancho
Copy link
Member

No description provided.

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)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lindhe What do you think about something like this? It should somehow address #112

Copy link
Contributor

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.

Copy link
Member Author

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

It does work 😅
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config

Copy link
Member Author

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)

Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants