Skip to content

feat(gcp): add GCP PSC conditions to metrics and add platform-specific gauges - #9255

Closed
apahim wants to merge 4 commits into
openshift:mainfrom
apahim:gcp-959-new
Closed

feat(gcp): add GCP PSC conditions to metrics and add platform-specific gauges#9255
apahim wants to merge 4 commits into
openshift:mainfrom
apahim:gcp-959-new

Conversation

@apahim

@apahim apahim commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements GCP-959 — Add GCP PSC conditions to metrics and add platform-specific gauges (GA checklist items 6.1, 6.2, 6.3).

Problem

PSC conditions (GCPEndpointAvailable, GCPServiceAttachmentAvailable) are set on the HostedCluster by computeGCPPSCCondition but were not tracked as expected conditions, so PSC failures did not appear in hypershift_hostedclusters_failure_conditions or the transition duration histogram. Additionally, there was no GCP equivalent of hypershift_cluster_invalid_aws_creds.

Changes

Commit 1: feat(gcp): add CredentialStatus type and GetCredentialStatus function

  • Adds a tri-state CredentialStatus type (Valid=0, Invalid=1, Unknown=2) and GetCredentialStatus() to the GCP platform package, mirroring the AWS pattern.
  • Non-GCP clusters naturally return Unknown since neither GCP condition will be present on their HostedCluster.

Commit 2: feat(gcp): add PSC conditions to ExpectedHCConditions (GA 6.1)

  • Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable to the GCP case in ExpectedHCConditions() unconditionally — no EndpointAccess gate needed since both GCP access modes (Private, PublicAndPrivate) use PSC (unlike AWS which has a Public-only mode).
  • PSC failures now appear in hypershift_hostedclusters_failure_conditions.

Commit 3: feat(metrics): add GCP PSC conditions to transition duration metric (GA 6.2)

  • Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable to collectTransitionDurationMetrics().
  • PSC setup latency is now tracked in hypershift_hosted_cluster_transition_seconds.

Commit 4: feat(metrics): add hypershift_cluster_invalid_gcp_creds gauge (GA 6.3)

  • Adds a new hypershift_cluster_invalid_gcp_creds Prometheus gauge (0=valid, 1=invalid, 2=unknown) following the hypershift_cluster_invalid_aws_creds pattern.
  • Emitted unconditionally for all clusters.

Tests

  • TestGetCredentialStatus — 9 cases covering all tri-state combinations
  • TestReportInvalidGcpCreds — 7 cases mirroring TestReportInvalidAwsCreds
  • TestReportTransitionDurationForGCPEndpointConditions — 5 cases mirroring TestReportTransitionDurationForAWSEndpointConditions

Acceptance Criteria

  • PSC failures appear in hypershift_hostedclusters_failure_conditions metric
  • PSC setup latency tracked in hypershift_hostedclusters_transition_duration histogram
  • GCP credential validity exposed as Prometheus gauge metric
  • Metrics are unit tested

Summary by CodeRabbit

  • New Features

    • Added monitoring for invalid GCP credentials, including workload identity status.
    • Added transition-duration metrics for GCP endpoint and service-attachment conditions.
  • Bug Fixes

    • GCP endpoint and service-attachment availability now report correctly for supported endpoint access modes.
  • Tests

    • Added coverage for valid, invalid, unknown, and missing GCP credential conditions.
    • Added coverage for GCP condition transition metrics.

apahim added 4 commits August 7, 2026 13:49
Add a tri-state CredentialStatus type (Valid=0, Invalid=1, Unknown=2)
and GetCredentialStatus() function to the GCP platform package, mirroring
the existing pattern in the AWS platform package.

GetCredentialStatus checks ValidGCPWorkloadIdentity and ValidGCPCredentials
conditions and returns:
- CredentialStatusValid (0) if both are True
- CredentialStatusInvalid (1) if either is explicitly False
- CredentialStatusUnknown (2) if either is missing or Unknown

Non-GCP clusters naturally return CredentialStatusUnknown since neither
condition will be present on their HostedCluster status.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to the GCP
case in ExpectedHCConditions(). These conditions are already set on the
HostedCluster by computeGCPPSCCondition but were not tracked as expected
conditions, so PSC failures did not appear in
hypershift_hostedclusters_failure_conditions.

Both GCP endpoint access modes (GCPEndpointAccessPrivate and
GCPEndpointAccessPublicAndPrivate) use PSC, so no EndpointAccess gate is
needed — unlike AWS which has a Public-only mode.

Covers GA checklist item 6.1.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to the
condition list in collectTransitionDurationMetrics(). PSC setup latency
is now tracked in the hypershift_hosted_cluster_transition_seconds
histogram.

Covers GA checklist item 6.2.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add a hypershift_cluster_invalid_gcp_creds Prometheus gauge metric that
reports GCP credential validity for all HostedClusters:
  0 = valid (both ValidGCPWorkloadIdentity and ValidGCPCredentials are True)
  1 = invalid (either condition is explicitly False)
  2 = unknown (either condition is missing or Unknown)

The metric is emitted unconditionally for all clusters. Non-GCP clusters
report Unknown (2) because neither GCP condition will be present on them,
matching the behavior of hypershift_cluster_invalid_aws_creds.

Covers GA checklist item 6.3.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR adds GCP credential states and evaluates workload identity and credential conditions on each HostedCluster. The metrics collector exposes the result through a Prometheus gauge with valid, invalid, and unknown values. GCP endpoint and service-attachment conditions are included in transition-duration metrics. Tests cover credential evaluation, metric collection, and GCP condition combinations.

Sequence Diagram(s)

sequenceDiagram
  participant HostedCluster
  participant MetricsCollector
  participant GCPPlatform
  participant Prometheus
  MetricsCollector->>HostedCluster: Read GCP conditions
  MetricsCollector->>GCPPlatform: GetCredentialStatus
  GCPPlatform-->>MetricsCollector: Return credential status
  MetricsCollector->>Prometheus: Emit credential gauge
Loading

Possibly related PRs

Suggested reviewers: bryan-cox

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: GCP PSC conditions in metrics and platform-specific credential gauges.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All added tests use static Go test names and literal t.Run labels; no Ginkgo It/Describe/Context/When declarations or dynamic title construction was found.
Test Structure And Quality ✅ Passed Added tests are table-driven Go unit tests, not Ginkgo tests; they use in-memory fake clients, no resource cleanup or waits, and provide diagnostic assertion messages consistent with nearby AWS tests.
Topology-Aware Scheduling Compatibility ✅ Passed The PR adds credential, metric, and expected-condition logic only. The diff adds no affinity, topology spread, node selectors, tolerations, PDBs, or topology-dependent replica logic.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds only Go unit tests (func Test...), not Ginkgo e2e tests; added test code contains no IPv4 assumptions or external connectivity.
No-Weak-Crypto ✅ Passed The full PR diff contains no MD5, SHA1, DES, RC4, Blowfish, ECB, or custom crypto; GetCredentialStatus compares condition statuses, not secrets or tokens.
Container-Privileges ✅ Passed The complete PR diff changes only Go source and tests, with no privileged or host namespace settings; the existing GCP workload uses allowPrivilegeEscalation=false and RunAsNonRoot=true.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no application logging. The only production logger call is an unchanged list-error message, and new code emits credential status values without secrets or customer data.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci openshift-ci Bot added area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/platform/gcp PR/issue for GCP (GCPPlatform) platform and removed do-not-merge/needs-area labels Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: apahim
Once this PR has been reviewed and has the lgtm label, please assign jparrill for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
openshift-ci Bot requested review from clebs and jimdaga August 7, 2026 12:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go (1)

140-255: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the required test-case description format.

Rename each table-case name value to use When ... it should ....

  • hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go#L140-L255: Add it should before the expected credential-status result.
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go#L656-L695: Add it should before the expected metric result.
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go#L1607-L1653: Add it should before the expected transition-duration observation result.

As per coding guidelines, unit-test descriptions must use When ... it should ....

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go`
around lines 140 - 255, The table-case descriptions use inconsistent wording.
Rename every affected test case name to follow the required “When ... it should
...” format: update gcp_conditions_test.go lines 140-255 for credential-status
results, metrics_test.go lines 656-695 for metric results, and metrics_test.go
lines 1607-1653 for transition-duration observations; change only the name
strings and preserve each test’s scenario and expected result.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go`:
- Around line 140-255: The table-case descriptions use inconsistent wording.
Rename every affected test case name to follow the required “When ... it should
...” format: update gcp_conditions_test.go lines 140-255 for credential-status
results, metrics_test.go lines 656-695 for metric results, and metrics_test.go
lines 1607-1653 for transition-duration observations; change only the name
strings and preserve each test’s scenario and expected result.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 867e5142-e796-429c-9e2a-3ac0199f5899

📥 Commits

Reviewing files that changed from the base of the PR and between 8ddee28 and cdae268.

📒 Files selected for processing (5)
  • hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp.go
  • hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go
  • hypershift-operator/controllers/hostedcluster/metrics/metrics.go
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go
  • support/conditions/conditions.go

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.48649% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.04%. Comparing base (60ada1e) to head (cdae268).
⚠️ Report is 95 commits behind head on main.

Files with missing lines Patch % Lines
support/conditions/conditions.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9255      +/-   ##
==========================================
+ Coverage   44.81%   45.04%   +0.22%     
==========================================
  Files         775      778       +3     
  Lines       97219    97576     +357     
==========================================
+ Hits        43572    43949     +377     
+ Misses      50644    50598      -46     
- Partials     3003     3029      +26     
Files with missing lines Coverage Δ
...rollers/hostedcluster/internal/platform/gcp/gcp.go 84.67% <100.00%> (+1.00%) ⬆️
...rator/controllers/hostedcluster/metrics/metrics.go 93.20% <100.00%> (+0.17%) ⬆️
support/conditions/conditions.go 0.00% <0.00%> (ø)

... and 37 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.77% <0.00%> (+0.34%) ⬆️
cpo-hostedcontrolplane 47.24% <ø> (-0.08%) ⬇️
cpo-other 45.79% <ø> (+0.12%) ⬆️
hypershift-operator 55.06% <100.00%> (+0.42%) ⬆️
other 34.32% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@apahim: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@apahim apahim closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/platform/gcp PR/issue for GCP (GCPPlatform) platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant