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

Rename binding keys #224

Open
werne2j opened this issue Oct 2, 2020 · 5 comments
Open

Rename binding keys #224

werne2j opened this issue Oct 2, 2020 · 5 comments

Comments

@werne2j
Copy link

werne2j commented Oct 2, 2020

Is there a way to select a name for the keys that get returned in a binding? For example, i have an application that uses 2 separate cloudants. If that application were to use the bindings from those 2 separate cloudants as env vars, the keys would clash as they would be the exact same for both cloudant bindings.

@vazirim
Copy link
Member

vazirim commented Oct 2, 2020

@werne2j yes, when you specify the Bindings resources, there is an optional SecretName field, which can help in differentiating the names.

@werne2j
Copy link
Author

werne2j commented Oct 2, 2020

Does that help differentiate the keys? Since both bindings because environment variables, there would be an overwrite of the url key for example? Or does it add a prefix based on the secret name?

@werne2j
Copy link
Author

werne2j commented Oct 2, 2020

For example..

apiVersion: ibmcloud.ibm.com/v1
kind: Binding
metadata:
  name: cloudant-binding-1
spec:
  serviceName: cloudant1
  secretName: cloudant1

and

apiVersion: ibmcloud.ibm.com/v1
kind: Binding
metadata:
  name: cloudant-binding-2
spec:
  serviceName: cloudant2
  secretName: cloudant2

And then in my kubernetes deployment

        envFrom:
        - secretRef:
            name: cloudant1
        - secretRef:
            name: cloudant2

Since both have the same format...

{
  "username": "...",
  "password": "...",
  "host": "...",
  "port": ...,
  "url": "..."
}

The keys would collide in the container as environment variables

@pdettori
Copy link
Member

pdettori commented Oct 2, 2020

@werne2j for your use case I think that it's best use valueFrom for each individual env var so you avoid collisions.

- name: <Your Key name 1>
        valueFrom:
          secretKeyRef:
            name: cloudant1
            key: password
- name: <Your Key name 2>
        valueFrom:
          secretKeyRef:
            name: cloudant2
            key: password
......

@werne2j
Copy link
Author

werne2j commented Oct 6, 2020

Would it be a worth while addition to be able to do something like...

apiVersion: ibmcloud.ibm.com/v1
kind: Binding
metadata:
  name: cloudant-binding-1
spec:
  serviceName: cloudant1
  secretName: cloudant1
  keys:
    url1: <path-to-url>

As a simplistic example

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

No branches or pull requests

3 participants