Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,3 @@ source .container-use/container-use.sh
cu-spec # Show available specs
cu-new my-config apps # Create new config with guidance
```

### Available Tasks

```bash
task: Available tasks for this project:
* branch: Create branch from main
* check: Run pre-commit hooks
* commit: Commit + push code into branch
* do: Select a task to run
* pr: Create pull request into main
* run-pre-commit-hook: Run the pre-commit hook script to replace .example.com with .example.com
* xplane-push: Push crossplane package
```
13 changes: 4 additions & 9 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ vars:
includes:
git:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/git/git.yaml
#crossplane:
# taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/configuration/crossplane.yaml
crossplane:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/configuration/crossplane.yaml
k2n:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/configuration/k2n.yaml
dagger:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/dagger/modules.yaml

tasks:
apply-configuration-packages:
desc: Apply crossplane configuration packages
cmds:
- |
set -e


push-configuration-package:
desc: Push crossplane configuration package
cmds:
Expand Down
61 changes: 16 additions & 45 deletions configurations/apps/postgres-db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@

## REQUIREMENTS

<details><summary><b>DEPLOY POSTGRESDB w/ HELM</b></summary>
<details><summary><b>CONNECT TO POSTGRESDB</b></summary>

```bash
cat <<EOF > values.yaml
---
global:
postgresql:
auth:
postgresPassword: volki123
username: volki
password: volki123
database: volki
EOF
# GET SERVICE
kubectk get svc -m postgres

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
# GET USER
kubectl get pod -n postgres -l app.kubernetes.io/name=postgres -o yaml | grep -A5 POSTGRESES

helm upgrade --install postgresql bitnami/postgresql \
--version 16.7.13 \
-n xplane \
--create-namespace \
--values values.yaml
```
# RUN SQL CLIENT
kubectl run -n postgres -it psql-client --rm --image=postgres --restart=Never -- bash

```bash
kubectl run -n xplane -it psql-client --rm --image=postgres --restart=Never -- bash

psql -h postgresql.xplane.svc.cluster.local -U postgres -p 5432
# CONNECT TO DB
psql \
-h my-postgres-d499897318cc \
-U appuser \
-d appdb \
-p 5432

\l # list databases
```
Expand All @@ -46,42 +36,23 @@ kind: Provider
metadata:
name: provider-sql
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-sql:v0.12.0
package: xpkg.upbound.io/crossplane-contrib/provider-sql:v0.13.0
EOF
```

```bash
kubectl apply -f - <<EOF
---
apiVersion: v1
kind: Secret
type: kubernetes.io/basic-auth
metadata:
name: volki-postgres-secret
namespace: xplane
stringData:
username: postgres
password: volki123
endpoint: postgresql.xplane.svc.cluster.local
port: "5432"
EOF
```

```bash
kubectl apply -f - <<EOF
---
apiVersion: postgresql.sql.crossplane.io/v1alpha1
apiVersion: postgresql.sql.m.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: default
spec:
defaultDatabase: postgres
sslMode: disable
credentials:
source: PostgreSQLConnectionSecret
connectionSecretRef:
namespace: xplane
name: volki-postgres-secret
name: postgresdb-creds
EOF
```

Expand Down
50 changes: 33 additions & 17 deletions configurations/apps/postgres-db/apis/composition.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: postgresdb
spec:
compositeTypeRef:
apiVersion: resources.stuttgart-things.com/v1alpha1
kind: XPostgresDB
kind: PostgresDB
mode: Pipeline
pipeline:
- step: create-db
Expand All @@ -18,48 +17,65 @@ spec:
source: Inline
inline:
template: | # pragma: allowlist secret
apiVersion: postgresql.sql.crossplane.io/v1alpha1
{{- $xr := .observed.composite.resource }}
{{- $ns := $xr.metadata.namespace }}
{{- $pc := $xr.spec.providerConfigRef.name | default "default" }}

apiVersion: postgresql.sql.m.crossplane.io/v1alpha1
kind: Role
metadata:
name: {{ .observed.composite.resource.spec.roleName }}
name: {{ $xr.spec.roleName }}
namespace: {{ $ns }}
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: role
gotemplating.fn.crossplane.io/ready: "True"
spec:
deletionPolicy: {{ .observed.composite.resource.spec.deletionPolicy }}
writeConnectionSecretToRef:
name: {{ .observed.composite.resource.spec.roleName }}-secret
namespace: default
deletionPolicy: {{ $xr.spec.deletionPolicy }}
forProvider:
privileges:
createDb: true
login: true
createRole: true
inherit: true
writeConnectionSecretToRef:
name: {{ $xr.spec.roleName }}-secret
providerConfigRef:
kind: ProviderConfig
name: {{ $pc }}

---
apiVersion: postgresql.sql.crossplane.io/v1alpha1
apiVersion: postgresql.sql.m.crossplane.io/v1alpha1
kind: Grant
metadata:
name: {{ .observed.composite.resource.spec.roleName }}
name: grant-postgres-{{ $xr.spec.roleName }}
namespace: {{ $ns }}
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: grant
gotemplating.fn.crossplane.io/ready: "True"
spec:
deletionPolicy: {{ .observed.composite.resource.spec.deletionPolicy }}
deletionPolicy: {{ $xr.spec.deletionPolicy }}
forProvider:
role: "postgres"
role: postgres
memberOfRef:
name: "{{ .observed.composite.resource.spec.roleName }}"
name: {{ $xr.spec.roleName }}
providerConfigRef:
kind: ProviderConfig
name: {{ $pc }}

---
apiVersion: postgresql.sql.crossplane.io/v1alpha1
apiVersion: postgresql.sql.m.crossplane.io/v1alpha1
kind: Database
metadata:
name: {{ .observed.composite.resource.spec.dbName }}
name: {{ $xr.spec.dbName }}
namespace: {{ $ns }}
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: db
gotemplating.fn.crossplane.io/ready: "True"
spec:
deletionPolicy: {{ .observed.composite.resource.spec.deletionPolicy }}
deletionPolicy: {{ $xr.spec.deletionPolicy }}
forProvider:
allowConnections: true
owner: "{{ .observed.composite.resource.spec.roleName }}"
owner: {{ $xr.spec.roleName }}
providerConfigRef:
kind: ProviderConfig
name: {{ $pc }}
41 changes: 33 additions & 8 deletions configurations/apps/postgres-db/apis/defintion.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
---
apiVersion: apiextensions.crossplane.io/v1
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
name: xpostgresdbs.resources.stuttgart-things.com
spec:
group: resources.stuttgart-things.com
defaultCompositeDeletePolicy: Foreground
scope: Namespaced

names:
kind: XPostgresDB
plural: xpostgresdbs
singular: xpostgresdb

claimNames:
kind: PostgresDB
plural: postgresdbs
defaultCompositionRef:
name: postgresdb
singular: postgresdb

versions:
- name: v1alpha1
served: true
Expand All @@ -23,17 +27,38 @@ spec:
properties:
spec:
type: object
required:
- dbName
- roleName
properties:
dbName:
type: string
description: Database name

roleName:
type: string
description: Role name

deletionPolicy:
type: string
description: Database deletion policy
default: Orphan
description: db deletion policy
required:
- dbName
- roleName
enum:
- Orphan
- Delete

providerConfigRef:
type: object
description: PostgreSQL ProviderConfig reference
properties:
name:
type: string
default: postgresql

status:
type: object
properties:
ready:
type: boolean
observedGeneration:
type: integer
11 changes: 6 additions & 5 deletions configurations/apps/postgres-db/examples/claim.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
apiVersion: resources.stuttgart-things.com/v1alpha1
kind: PostgresDB
metadata:
name: app
name: example-db
namespace: default
spec:
dbName: app
roleName: app
deletionPolicy: Delete
dbName: appdb
roleName: appuser
# providerConfigRef:
# name: default
7 changes: 7 additions & 0 deletions configurations/apps/postgres-db/examples/provider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-sql
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-sql:v0.13.0
69 changes: 68 additions & 1 deletion configurations/apps/postgres-server/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
# stuttgart-things/crossplane/postgres-server
# Postgres Server (Crossplane Dev)

A concise Crossplane configuration for a `PostgresServer` claim: it includes the XRD (CompositeResourceDefinition), a Composition (e.g., via provider-helm), and an example claim.

## Overview
- XRD/Definition: apis/definition.yaml
- Composition: apis/composition.yaml
- Claim example: examples/claim.yaml
- Functions/Pipeline: examples/functions.yaml
- Configuration metadata: crossplane.yaml

## Prerequisites
- Crossplane installed on the target cluster
- provider-helm and (if used) provider-kubernetes installed and configured
- kubectl access to the Crossplane cluster
- Namespace for database workloads, e.g., postgres

## Quickstart
1. Render locally (validate pipeline):
```bash
crossplane render examples/claim.yaml \
apis/composition.yaml \
examples/functions.yaml \
--include-function-results
```

2. Create the app credentials Secret in the target namespace (make sure your claim uses the same namespace):
```bash
kubectl -n postgres apply -f - <<'EOF'
apiVersion: v1
kind: Secret
metadata:
name: postgres-app-credentials
type: Opaque
stringData:
postgres-password: supersecret
EOF
```

3. Apply the claim:
```bash
kubectl apply -f examples/claim.yaml
```

4. Verify Helm release (via provider-helm):
```bash
kubectl get releases.helm.m.crossplane.io -A
kubectl describe releases.helm.m.crossplane.io my-postgres-d499897318cc
```

5. Inspect Crossplane resources:
```bash
kubectl get composite -A | grep -i postgres
kubectl get xr -A | grep -i postgres
kubectl get claim -A | grep -i PostgresServer
```

## Troubleshooting
- Namespace mismatch: Ensure the claim uses the same namespace as your Secrets/workloads (e.g., postgres).
- Missing Secret: postgres-app-credentials must exist before provisioning (or be optional in the chart/composition).
- Helm CRD ownership conflicts: Stale CRDs/owner annotations can cause conflicts; remove/update safely.
- Provider config: provider-helm must have access to the target cluster/namespace.

## Cleanup
```bash
kubectl delete -f examples/claim.yaml
kubectl -n postgres delete secret postgres-app-credentials
```
Loading