Skip to content

Commit d44d269

Browse files
Observability Onboarding Improvements (#81)
### Description Addresses a few potential issues in the observability onboarding process ### Changes - Clarify that `gcloud` is a prerequisite - Explicitly pass `project_id`, since the automatic discovery was causing the tool to exit early in a way that didn't communicate the error to the user - Handle when the `pool` is in a `DELETED` state (by [undeleting](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/providers/undelete) it) - Handle when the `provider` is in a `DELETED` state (by [undeleting](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/undelete) it) ### Testing Tested a missing `project_id` input: ``` leehagoodjames@mac ➜ run-gemini-cli git:(observability-docs) ./scripts/setup_workload_identity.sh --repo google-gemini/logo-maker ❌ GCP project is required. Use --project PROJECT_ID 💡 To find your project name: 1. Go to your GCP console 2. The URL shows: https://pantheon.corp.google.com/welcome?project=PROJECT_ID Use --help for usage information. ``` Tested with the logo-maker project, which updated the `pool` and `provider` from a `DELETED` status to `ACTIVE` --------- Signed-off-by: Lee James <40045512+leehagoodjames@users.noreply.github.com> Co-authored-by: 8bitmp3 <19637339+8bitmp3@users.noreply.github.com>
1 parent 179ca6c commit d44d269

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

docs/observability.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ For detailed setup instructions, see the [Workload Identity Federation documenta
3131

3232
### Quick Setup
3333

34-
Run the following command from the root of this repository:
34+
> Note that setting up this Observability requires a Google Cloud account as well as Google Cloud CLI (install gcloud [here](https://cloud.google.com/sdk/docs/install))
3535
3636
```bash
37-
./scripts/setup_workload_identity.sh --repo <OWNER/REPO>
37+
./scripts/setup_workload_identity.sh --repo <OWNER/REPO> --project <PROJECT_ID>
3838
```
3939

4040
- `<OWNER/REPO>`: Your GitHub repository in the format `owner/repo`.
41+
- `<PROJECT_ID>`: Your Google Cloud `project_id`.
4142

42-
After the script completes, it will output the values for the inputs listed above. You must add these to your GitHub repository's variables (and GEMINI_API_KEY as a secret) to complete the setup.
43+
After the `setup_workload_identity.sh` script finishes running, it will output a link to where you can edit your repository variables. Click on that link and then add the variables output from the script into your GitHub "Repository variables".
44+
45+
Additionally, to complete the setup add your `GEMINI_API_KEY` as a secret - this is discussed in more detail in the `run-gemini-cli` [README](https://github.com/google-github-actions/run-gemini-cli?tab=readme-ov-file#getting-started).
4346

4447
## Advanced Setup
4548

scripts/setup_workload_identity.sh

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ USAGE:
6666
6767
REQUIRED:
6868
-r, --repo OWNER/REPO GitHub repository (e.g., google/my-repo)
69+
-p, --project PROJECT_ID Google Cloud project ID (auto-detected if not provided)
6970
7071
OPTIONS:
71-
-p, --project PROJECT_ID Google Cloud project ID (auto-detected if not provided)
7272
--pool-name NAME Custom workload identity pool name (default: auto-generated)
7373
-h, --help Show this help
7474
@@ -135,6 +135,16 @@ if [[ -z "${GITHUB_REPO}" ]]; then
135135
echo "Use --help for usage information."
136136
exit 1
137137
fi
138+
if [[ -z "${GOOGLE_CLOUD_PROJECT}" ]]; then
139+
print_error "GCP project is required. Use --project PROJECT_ID"
140+
echo ""
141+
echo "💡 To find your project name:"
142+
echo " 1. Go to your Google Cloud console"
143+
echo " 2. The URL displays: https://pantheon.corp.google.com/welcome?project=PROJECT_ID"
144+
echo ""
145+
echo "Use --help for usage information."
146+
exit 1
147+
fi
138148

139149
# Validate repository format
140150
if [[ ! "${GITHUB_REPO}" =~ ^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$ ]]; then
@@ -226,7 +236,30 @@ if ! gcloud iam workload-identity-pools describe "${POOL_NAME}" \
226236
--display-name="GitHub Actions Pool"
227237
print_success "Workload Identity Pool created"
228238
else
229-
print_success "Workload Identity Pool already exists"
239+
print_info "Workload Identity Pool '${POOL_NAME}' exists. Verifying state..."
240+
# Fetch the current state of the existing pool.
241+
POOL_STATE=$(gcloud iam workload-identity-pools describe "${POOL_NAME}" \
242+
--project="${GOOGLE_CLOUD_PROJECT}" \
243+
--location="${GOOGLE_CLOUD_LOCATION}" \
244+
--format="value(state)")
245+
246+
if [[ "${POOL_STATE}" == "ACTIVE" ]]; then
247+
# Pool exists and is in the correct state.
248+
print_success "Workload Identity Pool already exists and is ACTIVE."
249+
else
250+
if [[ "${POOL_STATE}" == "DELETED" ]]; then
251+
# Pool exists but is DELETED. Undelete the pool.
252+
print_warning "Workload Identity Pool already exists but is in a DELETED state. Running 'undelete'."
253+
gcloud iam workload-identity-pools undelete "${POOL_NAME}" \
254+
--project="${GOOGLE_CLOUD_PROJECT}" \
255+
--location="${GOOGLE_CLOUD_LOCATION}"
256+
else
257+
# Pool exists but is in an unexpected state.
258+
print_error "Pool '${POOL_NAME}' is in an unexpected state: '${POOL_STATE}'. Expected states are: {'ACTIVE', 'DELETED'}. Exiting"
259+
exit 1
260+
261+
fi
262+
fi
230263
fi
231264

232265
# Get the pool ID
@@ -254,7 +287,32 @@ if ! gcloud iam workload-identity-pools providers describe "${PROVIDER_NAME}" \
254287
--issuer-uri="https://token.actions.githubusercontent.com"
255288
print_success "Workload Identity Provider created"
256289
else
257-
print_success "Workload Identity Provider already exists"
290+
print_info "Workload Identity Provider '${PROVIDER_NAME}' exists. Verifying state..."
291+
# Fetch the current state of the existing provider.
292+
PROVIDER_STATE=$(gcloud iam workload-identity-pools providers describe "${PROVIDER_NAME}" \
293+
--project="${GOOGLE_CLOUD_PROJECT}" \
294+
--location="${GOOGLE_CLOUD_LOCATION}" \
295+
--workload-identity-pool="${POOL_NAME}" \
296+
--format="value(state)")
297+
298+
if [[ "${PROVIDER_STATE}" == "ACTIVE" ]]; then
299+
# Provider exists and is in the correct state.
300+
print_success "Workload Identity Provider already exists and is ACTIVE."
301+
else
302+
if [[ "${PROVIDER_STATE}" == "DELETED" ]]; then
303+
# Provider exists but is DELETED. Undelete the provider.
304+
print_warning "Workload Identity Provider already exists but is in a DELETED state. Running 'undelete'."
305+
gcloud iam workload-identity-pools providers undelete "${PROVIDER_NAME}" \
306+
--project="${GOOGLE_CLOUD_PROJECT}" \
307+
--location="${GOOGLE_CLOUD_LOCATION}" \
308+
--workload-identity-pool="${POOL_NAME}"
309+
else
310+
# Provider exists but is in an unexpected state.
311+
print_error "Provider '${PROVIDER_NAME}' is in an unexpected state: '${PROVIDER_STATE}'. Expected states are: {'ACTIVE', 'DELETED'}. Exiting"
312+
exit 1
313+
314+
fi
315+
fi
258316
fi
259317

260318
# Step 4: Grant required permissions to the Workload Identity Pool

0 commit comments

Comments
 (0)