diff --git a/docs/docs/06-crossplane-3xx/07-provider-arubacloud.mdx b/docs/docs/06-crossplane-3xx/07-provider-arubacloud.mdx index fdf1bdf..e1ee13d 100644 --- a/docs/docs/06-crossplane-3xx/07-provider-arubacloud.mdx +++ b/docs/docs/06-crossplane-3xx/07-provider-arubacloud.mdx @@ -150,28 +150,107 @@ NAME SYNCED READY EXTERNAL-NAME -## 7.4 Connect with `mysql` ⏱️ 7m +## 7.4 Connect with `mysql` ⏱️ 12m -Crossplane has written the connection details to a Secret named `-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 -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 -mysql-conn -o jsonpath='{.data}' | jq 'keys' +kubectl create secret generic appuser-pw \ + --from-literal=password='Workshop2026!ok' + +cat <-mysql-conn \ + --from-literal=endpoint='' \ + --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' @@ -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: -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: @@ -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 -db-test +kubectl delete secret -mysql-conn appuser-pw +kubectl delete databasegrant appuser-on-appdb +kubectl delete dbaasuser appuser +kubectl delete database appdb kubectl delete dbaas -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. @@ -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. diff --git a/docs/i18n/it/docusaurus-plugin-content-docs/current/06-crossplane-3xx/07-provider-arubacloud.mdx b/docs/i18n/it/docusaurus-plugin-content-docs/current/06-crossplane-3xx/07-provider-arubacloud.mdx index 31f01bf..3afb8a3 100644 --- a/docs/i18n/it/docusaurus-plugin-content-docs/current/06-crossplane-3xx/07-provider-arubacloud.mdx +++ b/docs/i18n/it/docusaurus-plugin-content-docs/current/06-crossplane-3xx/07-provider-arubacloud.mdx @@ -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'; @@ -151,28 +151,107 @@ NAME SYNCED READY EXTERNAL-NAME -## 7.4 Connettiti con `mysql` ⏱️ 7m +## 7.4 Connettiti con `mysql` ⏱️ 12m -Crossplane ha scritto i dettagli di connessione in un Secret chiamato `-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 -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 -mysql-conn -o jsonpath='{.data}' | jq 'keys' +kubectl create secret generic appuser-pw \ + --from-literal=password='Workshop2026!ok' + +cat <-mysql-conn \ + --from-literal=endpoint='' \ + --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' @@ -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: -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: @@ -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 -db-test +kubectl delete secret -mysql-conn appuser-pw +kubectl delete databasegrant appuser-on-appdb +kubectl delete dbaasuser appuser +kubectl delete database appdb kubectl delete dbaas -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. @@ -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.