Skip to content

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

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

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

Conversation

@apahim

@apahim apahim commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements GCP-959 — GA checklist items 6.1, 6.2, 6.3.

GCP PSC conditions (GCPEndpointAvailable, GCPServiceAttachmentAvailable) 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 or the transition duration histogram.

Changes

Commit 1: CredentialStatus type + GetCredentialStatus() (GCP platform package)

  • Adds a tri-state CredentialStatus type (Valid=0, Invalid=1, Unknown=2) mirroring the AWS pattern
  • Adds GetCredentialStatus(hc) checking ValidGCPWorkloadIdentity and ValidGCPCredentials conditions
  • Adds TestGetCredentialStatus with 9 test cases

Commit 2: PSC conditions in ExpectedHCConditions()

  • Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable unconditionally to the GCP case
  • No EndpointAccess gate needed: GCP only defines Private and PublicAndPrivate — both use PSC
  • PSC failures now appear in hypershift_hostedclusters_failure_conditions

Commit 3: Metrics — transition duration + GCP creds gauge

  • Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable to collectTransitionDurationMetrics() so PSC setup latency is tracked in hypershift_hosted_cluster_transition_seconds
  • Adds new hypershift_cluster_invalid_gcp_creds gauge (0=valid, 1=invalid, 2=unknown), emitted unconditionally for all clusters (non-GCP clusters report Unknown=2, consistent with the AWS pattern)
  • Adds TestReportInvalidGcpCreds (7 cases) and TestReportTransitionDurationForGCPEndpointConditions (5 cases)

Testing

All 21 new tests pass. No existing tests broken.

ok  github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform/gcp
ok  github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/metrics

Summary by CodeRabbit

  • New Features
    • Added GCP credential readiness reporting with valid, invalid, and unknown states.
    • Added metrics for invalid GCP credentials and transition times for GCP endpoint conditions.
  • Bug Fixes
    • Improved hosted cluster condition reporting for supported GCP endpoint access modes.
  • Tests
    • Added coverage for GCP credential states, metrics, and endpoint condition transitions.

apahim added 3 commits August 6, 2026 14:48
Add a tri-state CredentialStatus type (Valid=0, Invalid=1, Unknown=2)
and GetCredentialStatus function to the GCP platform package, mirroring
the existing AWS pattern in platform/aws.

GetCredentialStatus checks ValidGCPWorkloadIdentity and ValidGCPCredentials
conditions: returns Invalid if either is False, Valid if both are True,
and Unknown otherwise (missing or Unknown conditions). The Unknown state
also covers non-GCP clusters naturally, matching AWS behavior.

This is a prerequisite for the hypershift_cluster_invalid_gcp_creds
Prometheus gauge introduced in a subsequent commit.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
… to ExpectedHCConditions

Both GCP endpoint access modes (Private and PublicAndPrivate) use Private
Service Connect, so PSC conditions are included unconditionally in the GCP
case — there is no GCPEndpointAccessPublic constant unlike AWS.

This causes PSC failures to appear in the
hypershift_hostedclusters_failure_conditions metric.

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

Track GCP Private Service Connect setup latency and credential validity
in Prometheus, mirroring existing AWS metric patterns.

Transition duration (hypershift_hosted_cluster_transition_seconds):
- Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to the
  condition slice in collectTransitionDurationMetrics so PSC setup
  latency is captured in the histogram.

Credentials gauge (hypershift_cluster_invalid_gcp_creds):
- New gauge emitting 0=valid, 1=invalid, 2=unknown per HostedCluster.
- Calls gcp.GetCredentialStatus; non-GCP clusters report Unknown (2),
  consistent with the AWS collectAwsCredsMetric pattern.
- Wired unconditionally into collectPerClusterMetrics.

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 6, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 87a45aaa-496f-4b5f-95de-d6983f7f4680

📥 Commits

Reviewing files that changed from the base of the PR and between dba0184 and 4a61331.

📒 Files selected for processing (1)
  • support/conditions/conditions_test.go

📝 Walkthrough

Walkthrough

The change adds tri-state GCP credential status evaluation for HostedCluster conditions. The metrics collector emits the status as a Prometheus gauge and tracks GCP endpoint and service-attachment transition durations. GCP condition setup marks both availability conditions as true. Tests cover credential status evaluation, metric values, and transition-duration reporting.

Sequence Diagram(s)

sequenceDiagram
  participant MetricsCollector
  participant HostedCluster
  participant GCPPlatform
  participant Prometheus
  MetricsCollector->>HostedCluster: read GCP conditions
  MetricsCollector->>GCPPlatform: call GetCredentialStatus
  GCPPlatform-->>MetricsCollector: return valid, invalid, or unknown
  MetricsCollector->>Prometheus: emit credential gauge and transition metrics
Loading

Suggested reviewers: gbarabasz, sdminonne

🚥 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 accurately and clearly summarizes the main changes: GCP PSC condition 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 Changed tests use Go t.Run with literal table names; no Ginkgo title APIs, interpolation, generated identifiers, timestamps, namespaces, nodes, IPs, or UUIDs appear in titles.
Test Structure And Quality ✅ Passed Changed tests are standard table-driven Go tests, not Ginkgo; they use fake clients only, perform no cluster waits or resource cleanup, and include diagnostic assertion messages.
Topology-Aware Scheduling Compatibility ✅ Passed The changed files add GCP credential, condition, and metric logic only; the combined diff adds no affinity, topology spread, selectors, tolerations, replica, or PDB constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds only standard Go unit tests (Test...); added lines contain no Ginkgo tests, IPv4 assumptions, or external connectivity.
No-Weak-Crypto ✅ Passed The PR additions only inspect condition statuses and emit Prometheus gauges; no MD5, SHA1, DES, RC4, Blowfish, ECB, custom crypto, or secret/token comparisons were introduced.
Container-Privileges ✅ Passed The PR changes only Go source and tests; no manifest adds privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, root, or allowPrivilegeEscalation:true settings. Existing GCP deployment uses non-roo...
No-Sensitive-Data-In-Logs ✅ Passed PR additions contain no logging calls or sensitive values; GCP changes inspect conditions and emit only a numeric metric using existing cluster labels.
✨ 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 6, 2026
@openshift-ci

openshift-ci Bot commented Aug 6, 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 devguyio 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 gbarabasz and sdminonne August 6, 2026 13:50

@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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In
`@hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go`:
- Around line 141-215: Rename every affected table-test case to follow the
required “When ... it should ...” format: update all cases in
hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go
lines 141-215, each credential metric case in
hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go lines
656-695, and the no-condition case in lines 1607-1662. Preserve the existing
test behavior and descriptions.
- Around line 134-215: Add both mixed condition cases to the credential-status
table in
hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go:
one with ValidGCPWorkloadIdentity false and ValidGCPCredentials unknown, and the
reverse, expecting CredentialStatusInvalid. Add the same two cases to the metric
table in hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go,
expecting gauge value 1.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 421b163a-b38d-4591-ace4-c695438e5ad9

📥 Commits

Reviewing files that changed from the base of the PR and between 78bf2df and 4722c73.

📒 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 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.03%. Comparing base (60ada1e) to head (dba0184).
⚠️ Report is 75 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9242      +/-   ##
==========================================
+ Coverage   44.81%   45.03%   +0.22%     
==========================================
  Files         775      778       +3     
  Lines       97219    97481     +262     
==========================================
+ Hits        43572    43904     +332     
+ Misses      50644    50550      -94     
- Partials     3003     3027      +24     
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 38.57% <100.00%> (+38.57%) ⬆️

... and 34 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.81% <100.00%> (+0.38%) ⬆️
cpo-hostedcontrolplane 47.24% <ø> (-0.08%) ⬇️
cpo-other 45.67% <ø> (ø)
hypershift-operator 55.06% <100.00%> (+0.42%) ⬆️

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.

apahim added 2 commits August 6, 2026 15:41
- Rename all new GCP test case names to follow the required
  "When ..., it should ..." format per TESTING.md conventions.
- Add two mixed False/Unknown condition test cases to TestGetCredentialStatus
  to cover the contract that False overrides Unknown, producing Invalid status.
- Add matching mixed cases to TestReportInvalidGcpCreds expecting gauge value 1.
- Fix TestReportTransitionDurationForGCPEndpointConditions case names to
  follow the same convention.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add support/conditions/conditions_test.go to cover the GCP-specific
conditions added to ExpectedHCConditions. The file had 0% patch coverage
as reported by Codecov; these tests bring the GCP case to full coverage.

Tests verify that all four GCP-specific conditions are present and set
to True for GCP clusters, and absent for non-GCP clusters:
- ValidGCPWorkloadIdentity
- ValidGCPCredentials
- GCPEndpointAvailable
- GCPServiceAttachmentAvailable

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

@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)
support/conditions/conditions_test.go (1)

93-94: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid shadowing the outer test handle.

Line 93 declares a second t that shadows the t parameter from TestExpectedHCConditionsGCPPlatform. Rename the callback parameter to subtest and pass it to NewWithT.

Proposed fix
-		t.Run(tt.name, func(t *testing.T) {
-			g := NewWithT(t)
+		t.Run(tt.name, func(subtest *testing.T) {
+			g := NewWithT(subtest)
🤖 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 `@support/conditions/conditions_test.go` around lines 93 - 94, Rename the t
parameter in the t.Run callback within TestExpectedHCConditionsGCPPlatform to
subtest, and pass subtest to NewWithT to avoid shadowing the outer test handle.

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 `@support/conditions/conditions_test.go`:
- Around line 93-94: Rename the t parameter in the t.Run callback within
TestExpectedHCConditionsGCPPlatform to subtest, and pass subtest to NewWithT to
avoid shadowing the outer test handle.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 35192938-f6ed-44b5-88a8-b2b89370acaf

📥 Commits

Reviewing files that changed from the base of the PR and between 400d21b and dba0184.

📒 Files selected for processing (1)
  • support/conditions/conditions_test.go

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

openshift-ci Bot commented Aug 6, 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.

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