Skip to content

Instantly share code, notes, and snippets.

@isutton
Last active September 23, 2020 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isutton/4c7b47019527034cc84a773f76e080e2 to your computer and use it in GitHub Desktop.
Save isutton/4c7b47019527034cc84a773f76e080e2 to your computer and use it in GitHub Desktop.
Binding annotations feature
Feature: ConfigMap Scoped Annotations
Scenario: Copy a single key from a ConfigMap related to the Service resource to the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding/certificate: path={.status.data.dbConfiguration},objectType=ConfigMap,sourceKey=certificate"
And Resource "cmsa-1-configmap" is created
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: cmsa-1-configmap
data:
certificate: "certificate value"
"""
And Resource "cmsa-2-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: cmsa-1-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
data:
dbConfiguration: cmsa-1-configmap # ConfigMap
"""
When Resource "cmsa-1" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: cmsa-1
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: cmsa-1-service
"""
Then Secret "cmsa-1" contains "CERTIFICATE" key with value "certificate value"
Scenario: Copy all keys from the ConfigMap related to the Service resource into the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding: path={.status.data.dbConfiguration},objectType=ConfigMap,elementType=map"
And Resource "cmsa-2-configmap" is created
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: cmsa-2-configmap
data:
timeout: 30
certificate: certificate value
"""
And Resource "cmsa-2-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: cmsa-2-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
dbConfiguration: cmsa-2-configmap # ConfigMap
"""
When Resource "cmsa-2" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: cmsa-2
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: cmsa-2-service
"""
Then Secret "cmsa-2" contains "CERTIFICATE" key with value "certificate value"
And Secret "cmsa-2" contains "TIMEOUT" key with value "30"
Feature: Resource Scoped Annotations
Scenario: Copy a single key as string from the Service resource itself to the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding/uri: path={.status.data.url}"
And Resource "rsa-1-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: rsa-1-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
bootstrap:
- type: plain
url: myhost2.example.com
name: hostGroup1
- type: tls
url: myhost1.example.com:9092,myhost2.example.com:9092
name: hostGroup2
data:
dbConfiguration: database-config # ConfigMap
dbCredentials: database-cred-Secret # Secret
url: db.stage.ibm.com
"""
When Resource "rsa-1" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: annotations-1
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: rsa-1-service
"""
Then Secret "rsa-1" contains "URI" key with value "db.stage.ibm.com"
Scenario: Copy a single key as a map to the Service resource itself to the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding/spec: path={.spec}"
And Resource "rsa-2-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: rsa-2-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
bootstrap:
- type: plain
url: myhost2.example.com
name: hostGroup1
- type: tls
url: myhost1.example.com:9092,myhost2.example.com:9092
name: hostGroup2
data:
dbConfiguration: database-config # ConfigMap
dbCredentials: database-cred-Secret # Secret
url: db.stage.ibm.com
"""
When Resource "rsa-2" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: rsa-1
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: rsa-2-service
"""
Then Secret "rsa-2" contains "SPEC_IMAGE" key with value "docker.io/postgres"
And Secret "rsa-2" contains "SPEC_IMAGENAME" key with value "postgres"
And Secret "rsa-2" contains "SPEC_DBNAME" key with value "db-demo"
Feature: Secret Scoped Annotations
Scenario: Copy a single key from the related Secret into the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding/username: path={.status.data.dbConfiguration},objectType=Secret,sourceKey=username"
And Resource "ssa-1-secret" is created
"""
apiVersion: v1
kind: Secret
metadata:
name: ssa-1-secret
data:
username: AzureDiamond
"""
And Resource "ssa-1-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: ssa-1-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
data:
dbCredentials: ssa-1-secret
"""
When Resource "ssa-1" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: ssa-1
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: ssa-1-service
"""
Then Secret "ssa-1" contains "USERNAME" key with value "AzureDiamond"
Scenario: Copy all keys from the Secret related to the Service resource to the binding secret
Given CRD "databases.postgresql.baiju.dev" contains the annotation "service.binding: path={.status.data.dbConfiguration},objectType=Secret,elementType=map"
And Resource "ssa-2-secret" is created
"""
apiVersion: v1
kind: Secret
metadata:
name: ssa-2-secret
data:
username: AzureDiamond
password: hunter2
"""
And Resource "ssa-2-service" is created
"""
apiVersion: postgresql.baiju.dev/v1alpha1
kind: Database
metadata:
name: ssa-2-service
spec:
image: docker.io/postgres
imageName: postgres
dbName: db-demo
status:
data:
dbCredentials: ssa-2-secret
"""
When Resource "ssa-2" is created
"""
apiVersion: apps.openshift.io/v1alpha1
kind: ServiceBindingRequest
metadata:
name: ssa-2
spec:
backingServiceSelector:
group: postgresql.baiju.dev
version: v1alpha1
kind: Database
resourceRef: ssa-2-service
"""
Then Secret "ssa-2" contains "USERNAME" key with value "AzureDiamond"
And Secret "ssa-2" contains "PASSWORD" key with value "hunter2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment