Skip to content

Commit 536828b

Browse files
Update README.md
1 parent 5dd7acf commit 536828b

File tree

1 file changed

+123
-5
lines changed

1 file changed

+123
-5
lines changed

README.md

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,41 @@ It renders manifest files, commits the results into your **continuous deployment
4747
---
4848

4949
### Environment Map
50-
`env_map` must be valid JSON in this form:
50+
51+
The workflow needs an `env_map` that defines your environments, clusters, and related metadata.
52+
You can provide it in **two ways**:
53+
54+
1. As a workflow input (`with: env_map: "<JSON>"`) ✅ **preferred**
55+
2. As an environment variable (`env: ENV_MAP: "<JSON>"`) — fallback for self-hosted runners
56+
57+
If neither is provided, the workflow fails.
58+
59+
---
60+
61+
#### Cluster Resolution Logic
62+
63+
1. If `target_cluster` is set:
64+
- The workflow searches **all clusters across all environments** in the `env_map`.
65+
- If it finds a matching cluster name, it selects that cluster (and its `dns_zone`, `container_registry`, `uami_map`) regardless of the `target` environment.
66+
- This makes it possible to directly target a cluster by name while still requiring `target` for approvals.
67+
68+
2. If `target_cluster` is not set:
69+
- The workflow looks inside the `target` environment only.
70+
- If that environment has a **single cluster**, it is selected automatically.
71+
- If the environment has **multiple clusters**, the workflow fails with a clear error message and lists valid options.
72+
73+
---
74+
75+
#### Example env_map JSON
5176

5277
```json
5378
{
79+
"dev": {
80+
"cluster_count": 1,
81+
"clusters": [
82+
{ "cluster": "aks-dev-weu", "dns_zone": "internal.dev.example.com", "container_registry": "ghcr.io/my-org", "uami_map": [] }
83+
]
84+
},
5485
"prod": {
5586
"cluster_count": 2,
5687
"clusters": [
@@ -61,10 +92,97 @@ It renders manifest files, commits the results into your **continuous deployment
6192
}
6293
```
6394

64-
Precedence:
65-
1. `inputs.env_map` (preferred)
66-
2. `ENV_MAP` environment variable (fallback)
67-
3. None → workflow fails
95+
---
96+
97+
#### Example Usages
98+
99+
**Targeting a cluster globally (preferred for multi-cluster envs):**
100+
```yaml
101+
with:
102+
target: prod
103+
target_cluster: aks-prod-weu
104+
env_map: ${{ secrets.ENV_MAP_JSON }}
105+
```
106+
107+
**Targeting a single-cluster environment (no `target_cluster` needed):**
108+
```yaml
109+
with:
110+
target: dev
111+
env_map: ${{ secrets.ENV_MAP_JSON }}
112+
```
113+
114+
---
115+
116+
## 🔑 UAMI Mapping for Azure Workload Identity
117+
118+
When deploying to **Azure AKS**, some clusters may define **User Assigned Managed Identities (UAMIs)** in the `env_map`.
119+
This workflow automatically exports those UAMI client IDs as environment variables so they can be used for manifest templating.
120+
121+
---
122+
123+
### How It Works
124+
For each `uami_map` entry in the selected cluster:
125+
126+
1. **Take the `uami_name`**
127+
- If it starts with `<cluster>-` (the selected cluster name followed by a dash), that prefix is **removed**.
128+
- Example: `prodcluster-app-uami` → `app-uami`.
129+
130+
2. **Normalize the name**
131+
- Replace `-` with `_`.
132+
- Example: `sidecar-uami` → `sidecar_uami`.
133+
- If the result doesn’t start with a letter or `_`, prepend `_`.
134+
- Example: `123-identity` → `_123_identity`.
135+
136+
3. **Export as environment variable**
137+
- Variable name = normalized `uami_name`.
138+
- Value = `client_id` of the UAMI.
139+
- Written into `$GITHUB_ENV`, so it’s available to all subsequent steps.
140+
141+
4. **Deduplicate**
142+
- If two UAMIs normalize to the same name, duplicates are skipped with a warning.
143+
144+
---
145+
146+
### Example
147+
148+
Given this `env_map` entry for a cluster:
149+
150+
```json
151+
{
152+
"cluster": "prodcluster",
153+
"dns_zone": "internal.example.com",
154+
"container_registry": "ghcr.io/my-org",
155+
"uami_map": [
156+
{"uami_name": "prodcluster-app-uami", "uami_resource_group": "rg-demo", "client_id": "1111-aaaa"},
157+
{"uami_name": "sidecar-uami", "uami_resource_group": "rg-demo", "client_id": "2222-bbbb"}
158+
]
159+
}
160+
```
161+
162+
Exports these environment variables:
163+
164+
```
165+
app_uami=1111-aaaa
166+
sidecar_uami=2222-bbbb
167+
```
168+
169+
---
170+
171+
### Usage in Manifests
172+
173+
You can reference these exported variables during `envsubst` templating.
174+
For example:
175+
176+
```yaml
177+
env:
178+
- name: APP_UAMI_CLIENT_ID
179+
value: ${app_uami}
180+
- name: SIDECAR_UAMI_CLIENT_ID
181+
value: ${sidecar_uami}
182+
```
183+
184+
When the workflow runs, `${app_uami}` and `${sidecar_uami}` will be substituted with the correct client IDs.
185+
68186

69187
---
70188

0 commit comments

Comments
 (0)