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
129 changes: 110 additions & 19 deletions docs/docs/06-crossplane-3xx/07-provider-arubacloud.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,107 @@ NAME SYNCED READY EXTERNAL-NAME

<ValidateCheck check="aruba-mr-ready" />

## 7.4 Connect with `mysql` ⏱️ 7m
## 7.4 Connect with `mysql` ⏱️ 12m

Crossplane has written the connection details to a Secret named `<your-pair-id>-mysql-conn` in `default`. Inspect what keys are inside before you wire them to a Pod:
A DBaaS instance is just the MySQL server. To actually connect, you need a **logical database** to query and a **user** authorised to query it. Both are managed resources in the same provider you already used for the DBaaS: `Database`, `DBaaSUser`, `DatabaseGrant`. You'll compose all three, then look up the DBaaS endpoint (the one piece the provider doesn't yet publish), assemble a connection Secret, and ping the DB.

### 1. Capture the DBaaS's Aruba ID

The Aruba API uses opaque IDs to link these resources together. Read your DBaaS's ID once and reuse it:

```bash
DBAAS_ID=$(kubectl get dbaas <your-pair-id>-mysql -o jsonpath='{.status.atProvider.id}')
PROJECT_ID=$(kubectl get configmap workshop-aruba-shared -o jsonpath='{.data.projectId}')
echo "DBAAS_ID=$DBAAS_ID PROJECT_ID=$PROJECT_ID"
```

### 2. Compose Database + DBaaSUser

The user's password is a Secret *you* create; the provider just reads it and tells Aruba. Aruba enforces password rules server-side — 8+ characters with upper + lower + digit + a single safe special is the lowest-common-denominator pick:

```bash
kubectl get secret <your-pair-id>-mysql-conn -o jsonpath='{.data}' | jq 'keys'
kubectl create secret generic appuser-pw \
--from-literal=password='Workshop2026!ok'

cat <<EOF | kubectl apply -f -
apiVersion: database.arubacloud.crossplane.io/v1alpha1
kind: Database
metadata:
name: appdb
spec:
forProvider:
name: appdb
dbaasId: ${DBAAS_ID}
projectId: ${PROJECT_ID}
providerConfigRef: { name: default }
---
apiVersion: dbaasuser.arubacloud.crossplane.io/v1alpha1
kind: DBaaSUser
metadata:
name: appuser
spec:
forProvider:
username: appuser
dbaasId: ${DBAAS_ID}
projectId: ${PROJECT_ID}
passwordSecretRef:
name: appuser-pw
namespace: default
key: password
providerConfigRef: { name: default }
EOF
```

Expected output (key names may vary slightly):
Wait for both to reach `Ready=True` — usually under a minute:

```json
[
"endpoint",
"password",
"port",
"username"
]
```bash
kubectl wait --for=condition=Ready database/appdb dbaasuser/appuser --timeout=2m
```

The provider exposes whatever connection-detail keys it sees from Aruba's API; the Secret is the contract.
### 3. Wire them together with a `DatabaseGrant`

### Run a one-shot Pod that pings the DB
`DatabaseGrant` is the `GRANT … TO …` row: it tells Aruba which user can access which database with which role. It references both of the resources you just created, so look up their IDs first:

```bash
DB_ID=$(kubectl get database appdb -o jsonpath='{.status.atProvider.id}')
USER_ID=$(kubectl get dbaasuser appuser -o jsonpath='{.status.atProvider.id}')

cat <<EOF | kubectl apply -f -
apiVersion: databasegrant.arubacloud.crossplane.io/v1alpha1
kind: DatabaseGrant
metadata:
name: appuser-on-appdb
spec:
forProvider:
projectId: ${PROJECT_ID}
dbaasId: ${DBAAS_ID}
database: ${DB_ID}
userId: ${USER_ID}
role: readwrite
providerConfigRef: { name: default }
EOF

kubectl wait --for=condition=Ready databasegrant/appuser-on-appdb --timeout=2m
```

### 4. Look up the DBaaS endpoint

The provider doesn't yet publish the DBaaS's endpoint to the MR's connection Secret (the Secret is created, but it's empty — see the "Under the hood" callout below). Open your DBaaS in the Aruba console, click the **Networking** tab, and copy the private endpoint. Standard MySQL port is `3306`.

### 5. Build the connection Secret

Stitch the endpoint with the user/password/database names into a Kubernetes Secret the Pod can read:

```bash
kubectl create secret generic <your-pair-id>-mysql-conn \
--from-literal=endpoint='<endpoint-from-step-4>' \
--from-literal=port='3306' \
--from-literal=username='appuser' \
--from-literal=password='Workshop2026!ok' \
--from-literal=database='appdb'
```

### 6. Run a one-shot Pod that pings the DB

```bash
kubectl apply -f - <<'EOF'
Expand All @@ -186,14 +265,14 @@ spec:
image: mysql:8
command: ["sh", "-c"]
args:
- mysql -h "$endpoint" -P "$port" -u "$username" -p"$password" -e 'SELECT 1 AS ok;'
- mysql -h "$endpoint" -P "$port" -u "$username" -p"$password" "$database" -e 'SELECT 1 AS ok;'
envFrom:
- secretRef:
name: <your-pair-id>-mysql-conn
EOF
```

`envFrom: secretRef` loads every key from the connection Secret as an environment variable with the key name. The shell command then references each by name. If your Secret had different keys (e.g., `host` instead of `endpoint`), update the `mysql -h "$endpoint"` argument accordingly.
`envFrom: secretRef` loads every key from the connection Secret as an environment variable with the key name. The shell command then references each by name.

When the Pod completes:

Expand All @@ -208,18 +287,30 @@ ok
1
```

You've routed a SQL query through `kubectl apply` of a Crossplane MR, into a real Aruba MySQL instance, back through your workshop cluster's network, and out the other side.
You've routed a SQL query through four `kubectl apply`s of Crossplane MRs, into a real Aruba MySQL instance, back through your workshop cluster's network, and out the other side.

:::note Under the hood

In a fully-finished provider, step 4 wouldn't exist — the DBaaS MR would write `endpoint` / `port` straight to its connection Secret and the user MR would add `username` / `password`. `provider-arubacloud` doesn't yet, because the embedded Terraform provider doesn't return those attributes from the create call. There's no Crossplane gap here; it's an upstream provider gap. Tracked in the provider's issue queue.

There's also one ergonomic wart in steps 2–3: each MR's `dbaasId` / `database` / `userId` is a literal Aruba ID you copy between apply steps. When the provider grows `dbaasIdRef` / `databaseRef` / `userIdRef` cross-resource references, those fields become declarative pointers between the MRs and the order-of-apply pain disappears.

:::

## 7.5 Clean up ⏱️ 3m

Aruba bills the DBaaS hourly. Delete it now:
Aruba bills the DBaaS hourly. Delete the MRs in reverse-dependency order so each child resource is cleanly removed from Aruba before its parent disappears:

```bash
kubectl delete pod <your-pair-id>-db-test
kubectl delete secret <your-pair-id>-mysql-conn appuser-pw
kubectl delete databasegrant appuser-on-appdb
kubectl delete dbaasuser appuser
kubectl delete database appdb
kubectl delete dbaas <your-pair-id>-mysql
```

Crossplane reconciles the delete against Aruba, which tears down the MySQL instance. The connection Secret is owned by the DBaaS MR and is reaped along with it.
Crossplane reconciles each delete against Aruba, which tears down the MySQL instance and its associated resources.

If you forget, your instructor sweeps up everything at workshop teardown — but the DBaaS will keep accruing hours until then.

Expand All @@ -235,6 +326,6 @@ Same `Provider` → `ProviderConfig` → MR shape as AWS / GCP / Azure, applied

### Go deeper

- **Compose a least-privilege MySQL stack.** This module created the DBaaS instance and connected as admin — fine for a workshop, never for production. Real apps need a non-admin login: a `Database.database.arubacloud.crossplane.io` (logical schema) + `DBaaSUser` (non-admin login) + `DatabaseGrant` (the `GRANT … TO …` row that wires them together). Wrap the four MRs in an XR like `AppDatabase` so platform users get an opinionated "give me a DB for app X" workflow from one line of YAML — same shape as the [`Application`](../crossplane-101/define-application) you wrote in 101 module 4.
- **Wrap §7.4's four MRs in an `AppDatabase` XR.** Right now a developer who wants a database has to author `DBaaS` + `Database` + `DBaaSUser` + `DatabaseGrant`, paste IDs between them, look up the endpoint by hand. A platform team turns that into a single Composite Resource — `AppDatabase` — whose XRD asks the developer for two fields (app name, size) and whose Composition fans out into the four MRs. Same shape as the [`Application`](../crossplane-101/define-application) XR you wrote in 101 module 4. Once the upstream provider adds `dbaasIdRef` / `databaseRef` / `userIdRef` cross-resource references and publishes the endpoint to the connection Secret, your XR's developer-facing surface collapses to `kind: AppDatabase` + a name, and the rest of §7.4 disappears.
- [`provider-arubacloud`](https://github.com/ricCap/provider-arubacloud) — provider source, full Kind catalogue, version index. The workshop pins `v0.3.0-workshop`.
- [Aruba Cloud API reference](https://api.arubacloud.com/docs/) — the upstream API the provider talks to.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
sidebar_position: 7
title: (Guidato) Crea risorse in Aruba
translation_source_commit: b9740d8f59a6d14db97207972119970ee1df640e
translation_source_commit: a8bf03892b6de5d5992bc9b88d95de805047d54a
---

import PairId from '@site/src/components/PairId';
Expand Down Expand Up @@ -151,28 +151,107 @@ NAME SYNCED READY EXTERNAL-NAME

<ValidateCheck check="aruba-mr-ready" />

## 7.4 Connettiti con `mysql` ⏱️ 7m
## 7.4 Connettiti con `mysql` ⏱️ 12m

Crossplane ha scritto i dettagli di connessione in un Secret chiamato `<your-pair-id>-mysql-conn` in `default`. Ispeziona quali chiavi ci sono dentro prima di cablarlo a un Pod:
Un'istanza DBaaS è solo il server MySQL. Per connetterti davvero ti serve un **database logico** da interrogare e un **utente** autorizzato a interrogarlo. Entrambi sono managed resource dello stesso provider che hai già usato per il DBaaS: `Database`, `DBaaSUser`, `DatabaseGrant`. Comporrai tutte e tre, poi recupererai l'endpoint del DBaaS (l'unico pezzo che il provider non pubblica ancora), assemblerai un Secret di connessione, e farai il ping del DB.

### 1. Cattura l'ID Aruba del DBaaS

L'API Aruba usa ID opachi per collegare queste risorse. Leggi l'ID del tuo DBaaS una volta e riusalo:

```bash
DBAAS_ID=$(kubectl get dbaas <your-pair-id>-mysql -o jsonpath='{.status.atProvider.id}')
PROJECT_ID=$(kubectl get configmap workshop-aruba-shared -o jsonpath='{.data.projectId}')
echo "DBAAS_ID=$DBAAS_ID PROJECT_ID=$PROJECT_ID"
```

### 2. Componi Database + DBaaSUser

La password dell'utente è un Secret che crei *tu*; il provider la legge e la passa ad Aruba. Aruba applica le regole sulla password lato server — 8+ caratteri con maiuscola + minuscola + cifra + un singolo carattere speciale sicuro è la scelta minima comune:

```bash
kubectl get secret <your-pair-id>-mysql-conn -o jsonpath='{.data}' | jq 'keys'
kubectl create secret generic appuser-pw \
--from-literal=password='Workshop2026!ok'

cat <<EOF | kubectl apply -f -
apiVersion: database.arubacloud.crossplane.io/v1alpha1
kind: Database
metadata:
name: appdb
spec:
forProvider:
name: appdb
dbaasId: ${DBAAS_ID}
projectId: ${PROJECT_ID}
providerConfigRef: { name: default }
---
apiVersion: dbaasuser.arubacloud.crossplane.io/v1alpha1
kind: DBaaSUser
metadata:
name: appuser
spec:
forProvider:
username: appuser
dbaasId: ${DBAAS_ID}
projectId: ${PROJECT_ID}
passwordSecretRef:
name: appuser-pw
namespace: default
key: password
providerConfigRef: { name: default }
EOF
```

Output atteso (i nomi delle chiavi possono variare leggermente):
Aspetta che entrambe raggiungano `Ready=True` — di solito sotto il minuto:

```json
[
"endpoint",
"password",
"port",
"username"
]
```bash
kubectl wait --for=condition=Ready database/appdb dbaasuser/appuser --timeout=2m
```

Il provider espone le chiavi di connection-detail che vede dall'API Aruba; il Secret è il contratto.
### 3. Collegali con un `DatabaseGrant`

### Esegui un Pod one-shot che fa il ping del DB
`DatabaseGrant` è la riga `GRANT … TO …`: dice ad Aruba quale utente può accedere a quale database con quale ruolo. Fa riferimento alle due risorse che hai appena creato, quindi recupera prima i loro ID:

```bash
DB_ID=$(kubectl get database appdb -o jsonpath='{.status.atProvider.id}')
USER_ID=$(kubectl get dbaasuser appuser -o jsonpath='{.status.atProvider.id}')

cat <<EOF | kubectl apply -f -
apiVersion: databasegrant.arubacloud.crossplane.io/v1alpha1
kind: DatabaseGrant
metadata:
name: appuser-on-appdb
spec:
forProvider:
projectId: ${PROJECT_ID}
dbaasId: ${DBAAS_ID}
database: ${DB_ID}
userId: ${USER_ID}
role: readwrite
providerConfigRef: { name: default }
EOF

kubectl wait --for=condition=Ready databasegrant/appuser-on-appdb --timeout=2m
```

### 4. Recupera l'endpoint del DBaaS

Il provider non pubblica ancora l'endpoint del DBaaS nel Secret di connessione della MR (il Secret viene creato, ma è vuoto — vedi il callout "Sotto il cofano" sotto). Apri il tuo DBaaS nella console Aruba, clicca la scheda **Networking** e copia l'endpoint privato. La porta MySQL standard è `3306`.

### 5. Costruisci il Secret di connessione

Cuci insieme l'endpoint con i nomi di utente/password/database in un Secret di Kubernetes che il Pod possa leggere:

```bash
kubectl create secret generic <your-pair-id>-mysql-conn \
--from-literal=endpoint='<endpoint-dal-passo-4>' \
--from-literal=port='3306' \
--from-literal=username='appuser' \
--from-literal=password='Workshop2026!ok' \
--from-literal=database='appdb'
```

### 6. Esegui un Pod one-shot che fa il ping del DB

```bash
kubectl apply -f - <<'EOF'
Expand All @@ -187,14 +266,14 @@ spec:
image: mysql:8
command: ["sh", "-c"]
args:
- mysql -h "$endpoint" -P "$port" -u "$username" -p"$password" -e 'SELECT 1 AS ok;'
- mysql -h "$endpoint" -P "$port" -u "$username" -p"$password" "$database" -e 'SELECT 1 AS ok;'
envFrom:
- secretRef:
name: <your-pair-id>-mysql-conn
EOF
```

`envFrom: secretRef` carica ogni chiave del Secret di connessione come variabile d'ambiente con il nome della chiave. Il comando shell poi le richiama per nome. Se il tuo Secret avesse chiavi diverse (ad es. `host` invece di `endpoint`), aggiorna l'argomento `mysql -h "$endpoint"` di conseguenza.
`envFrom: secretRef` carica ogni chiave del Secret di connessione come variabile d'ambiente con il nome della chiave. Il comando shell poi le richiama per nome.

Quando il Pod completa:

Expand All @@ -209,18 +288,30 @@ ok
1
```

Hai instradato una query SQL attraverso un `kubectl apply` di una MR Crossplane, dentro una vera istanza MySQL Aruba, di ritorno attraverso la rete del cluster del workshop, e fuori dall'altra parte.
Hai instradato una query SQL attraverso quattro `kubectl apply` di MR Crossplane, dentro una vera istanza MySQL Aruba, di ritorno attraverso la rete del cluster del workshop, e fuori dall'altra parte.

:::note Sotto il cofano

In un provider completo, il passo 4 non esisterebbe — la MR DBaaS scriverebbe `endpoint` / `port` direttamente nel suo Secret di connessione, e la MR utente aggiungerebbe `username` / `password`. `provider-arubacloud` non lo fa ancora, perché il Terraform provider embedded non restituisce quegli attributi dalla chiamata di create. Non c'è un gap Crossplane qui; è un gap del provider upstream. Tracciato nella issue queue del provider.

C'è anche una verruca ergonomica nei passi 2–3: `dbaasId` / `database` / `userId` di ogni MR sono ID Aruba letterali che copi tra i passi di apply. Quando il provider farà crescere riferimenti cross-resource `dbaasIdRef` / `databaseRef` / `userIdRef`, quei campi diventeranno puntatori dichiarativi tra le MR e il dolore dell'ordine di apply sparisce.

:::

## 7.5 Pulizia ⏱️ 3m

Aruba fattura il DBaaS a ore. Cancellalo subito:
Aruba fattura il DBaaS a ore. Cancella le MR in ordine inverso di dipendenza così ogni risorsa figlia viene rimossa pulitamente da Aruba prima che il suo parent sparisca:

```bash
kubectl delete pod <your-pair-id>-db-test
kubectl delete secret <your-pair-id>-mysql-conn appuser-pw
kubectl delete databasegrant appuser-on-appdb
kubectl delete dbaasuser appuser
kubectl delete database appdb
kubectl delete dbaas <your-pair-id>-mysql
```

Crossplane riconcilia la cancellazione contro Aruba, che smonta l'istanza MySQL. Il Secret di connessione è di proprietà della MR DBaaS e viene mietuto insieme a lei.
Crossplane riconcilia ogni cancellazione contro Aruba, che smonta l'istanza MySQL e le sue risorse collegate.

Se ti dimentichi, il tuo istruttore farà ripulisce tutto al teardown del workshop — ma il DBaaS continuerà ad accumulare ore fino ad allora.

Expand All @@ -236,6 +327,6 @@ Stessa forma `Provider` → `ProviderConfig` → MR di AWS / GCP / Azure, applic

### Per approfondire

- **Componi uno stack MySQL a privilegio minimo.** Questo modulo ha creato l'istanza DBaaS e si è collegato come admin — bene per un workshop, mai per produzione. Le app reali hanno bisogno di un login non-admin: un `Database.database.arubacloud.crossplane.io` (schema logico) + `DBaaSUser` (login non-admin) + `DatabaseGrant` (la riga `GRANT … TO …` che li collega). Avvolgi le quattro MR in un XR come `AppDatabase` così gli utenti della piattaforma ottengono un workflow opinionated "dammi un DB per l'app X" da una sola riga di YAML — stessa forma dell'[`Application`](../crossplane-101/define-application) che hai scritto nel modulo 4 del 101.
- **Avvolgi le quattro MR di §7.4 in un XR `AppDatabase`.** Adesso uno sviluppatore che vuole un database deve scrivere `DBaaS` + `Database` + `DBaaSUser` + `DatabaseGrant`, incollare ID tra loro, recuperare l'endpoint a mano. Un team di piattaforma trasforma questo in una sola Composite Resource — `AppDatabase` — il cui XRD chiede allo sviluppatore due campi (nome app, dimensione) e la cui Composition si srotola nelle quattro MR. Stessa forma dell'XR [`Application`](../crossplane-101/define-application) che hai scritto nel modulo 4 del 101. Una volta che il provider upstream aggiunge i riferimenti cross-resource `dbaasIdRef` / `databaseRef` / `userIdRef` e pubblica l'endpoint nel Secret di connessione, la superficie sviluppatore-facing del tuo XR collassa a `kind: AppDatabase` + un nome, e il resto di §7.4 sparisce.
- [`provider-arubacloud`](https://github.com/ricCap/provider-arubacloud) — sorgente del provider, catalogo completo dei Kind, indice delle versioni. Il workshop pinna `v0.3.0-workshop`.
- [Riferimento API Aruba Cloud](https://api.arubacloud.com/docs/) — l'API upstream con cui parla il provider.
Loading