servicebinding / spec

Specification for binding services to k8s workloads
https://servicebinding.io
Apache License 2.0
92 stars 35 forks source link

Undefined behavior for of binding annotations with elementType=sliceOfStrings #131

Closed pmacik closed 3 years ago

pmacik commented 3 years ago

The binding annotation spec contains option sliceOfStrings for elementType in annotation.

However the spec does not tell how it should behave in various situations. The following scenarios suggest the behavior:

Scenario 1: sliceOfStrings from array

Given a CRD is annotated with service binding annotation using the sliceOfStrings element type like in the following snippet:

...
metadata:
   annotations:
      service.binding/tags: path={.spec.tags},elementType=sliceOfStrings

and the respective CR contains the following spec:

...
kind: Backend
...
spec:
   tags:
      - knowledge
      - is
      - power

when a service binding is created to bind the service CR to an application the application is enriched by the binding with the following env variables:

BACKEND_TAGS_0="knowledge"
BACKEND_TAGS_1="is"
BACKEND_TAGS_2="power"

Scenario 2: sliceOfStrings from slice of maps

Given a CRD is annotated with service binding annotation using the sliceOfStrings element type like in the following snippet:

...
metadata:
   annotations:
      service.binding/url: path={.spec.connections},elementType=sliceOfStrings,sourceValue=url

and the respective CR contains the following spec:

...
kind: Backend
...
spec:
    connections:
      - type: primary
        url: primary.example.com
      - type: secondary
        url: secondary.example.com
      - type: '404'
        url: black-hole.example.com

when a service binding is created to bind the service CR to an application the application is enriched with the following env variables by the binding:

BACKEND_URL_0="primary.example.com"
BACKEND_URL_1="secondary.example.com"
BACKEND_URL_2="black-hole.example.com"
sbose78 commented 3 years ago

This looks right to me. In scenario one, we have list of strings, and in the latter, we have a list of 'structs'.

@navidsh @Avni-Sharma Scenario 2 was in use by the strimzi proposal. Am I right?

Avni-Sharma commented 3 years ago

yes @sbose78 Scenario 2 is used in the case of strimzi. Referred https://github.com/redhat-developer/service-binding-operator/issues/352#issue-572380983 for cross-checking

arthurdm commented 3 years ago

Discussed in the hangout. @pmacik - thanks for bringing this up. Would you be able to please propose a PR for this one?

pmacik commented 3 years ago

Discussed in the hangout. @pmacik - thanks for bringing this up. Would you be able to please propose a PR for this one?

Sure, I'll send a PR for this