Skip to content

Instantly share code, notes, and snippets.

@jbw976
Created July 12, 2023 16:57
Show Gist options
  • Save jbw976/f81016a081f3bea663c98a5af3bf9da6 to your computer and use it in GitHub Desktop.
Save jbw976/f81016a081f3bea663c98a5af3bf9da6 to your computer and use it in GitHub Desktop.
Composition Connection Details
apiVersion: acme.com/v1
kind: AcmeDatabase
metadata:
name: acme-db-prod
spec:
storageGB: 15
writeConnectionSecretToRef:
name: acme-db-prod-conn
---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xacmedatabases.acme.com
spec:
writeConnectionSecretsToNamespace: crossplane-system
compositeTypeRef:
apiVersion: acme.com/v1
kind: XAcmeDatabase
resources:
- name: DBInstance
base:
apiVersion: sql.gcp.upbound.io/v1beta1
kind: DatabaseInstance
spec:
forProvider:
databaseVersion: POSTGRES_13
deletionProtection: false
region: us-west2
settings:
- diskSize: 20
tier: db-f1-micro
writeConnectionSecretToRef:
namespace: crossplane-system
patches:
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-postgresql"
- fromFieldPath: spec.storageGB
toFieldPath: spec.forProvider.settings[0].diskSize
connectionDetails:
- fromConnectionSecretKey: connectionName
- fromConnectionSecretKey: publicIP
- fromConnectionSecretKey: serverCACertificateCert
- name: DB
base:
apiVersion: sql.gcp.upbound.io/v1beta1
kind: Database
metadata:
name: prod-metrics
spec:
forProvider:
instanceSelector:
matchControllerRef: true
writeConnectionSecretToRef:
namespace: crossplane-system
patches:
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-postgresql-database"
connectionDetails:
- type: FromFieldPath
name: databaseID
fromFieldPath: status.atProvider.id
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xacmedatabases.acme.com
spec:
group: acme.com
names:
kind: XAcmeDatabase
plural: xacmedatabases
claimNames:
kind: AcmeDatabase
plural: acmedatabases
connectionSecretKeys:
- connectionName
- publicIP
- serverCACertificateCert
- databaseID
versions:
- name: v1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
description: "The OpenAPIV3Schema of this Composite Resource Definition."
properties:
storageGB:
type: integer
description: "The desired storage capacity of the database, in GB."
required:
- storageGB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment