Skip to content

GCP-959: Add GCP PSC conditions to metrics and add platform-specific gauges - #9258

Open
apahim wants to merge 4 commits into
openshift:mainfrom
apahim:gcp-959-impl
Open

GCP-959: Add GCP PSC conditions to metrics and add platform-specific gauges#9258
apahim wants to merge 4 commits into
openshift:mainfrom
apahim:gcp-959-impl

Conversation

@apahim

@apahim apahim commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Adds GCP PSC (Private Service Connect) conditions to HyperShift monitoring metrics and introduces a new GCP credential validity gauge, bringing GCP monitoring to parity with AWS.

Changes:

  1. GetCredentialStatus() in GCP platform package — New tri-state function (valid/invalid/unknown) mirroring the AWS pattern, checking ValidGCPWorkloadIdentity and ValidGCPCredentials conditions.

  2. PSC conditions in ExpectedHCConditions() — Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable unconditionally (both GCP endpoint access modes use PSC). PSC failures now appear in hypershift_hostedclusters_failure_conditions.

  3. PSC conditions in transition duration metrics — Adds same conditions to collectTransitionDurationMetrics(). PSC setup latency is now tracked in hypershift_hostedclusters_transition_duration.

  4. hypershift_cluster_invalid_gcp_creds gauge — New Prometheus gauge exposing GCP credential status (0=valid, 1=invalid, 2=unknown), following the hypershift_cluster_invalid_aws_creds pattern.

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/GCP-959

Special notes for your reviewer:

  • The Jira ticket mentions gating PSC conditions on EndpointAccess != Public, but GCP has no Public-only endpoint access mode (only Private and PublicAndPrivate), so conditions are added unconditionally.
  • CredentialStatus type is intentionally duplicated from the AWS package to avoid cross-platform import dependencies.
  • The GCP creds gauge is collected unconditionally for all clusters (non-GCP clusters report Unknown=2), consistent with the AWS gauge behavior.
  • All unit tests follow the "When ... it should ..." naming convention per TESTING.md.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • New Features
    • Added monitoring for GCP credential validity, including valid, invalid, and unknown states.
    • Added transition-duration metrics for GCP endpoint and service-attachment availability.
  • Bug Fixes
    • Improved GCP condition handling so endpoint and service-attachment readiness is accurately recognized across supported endpoint access modes.
  • Tests
    • Added coverage for GCP credential status, credential metrics, and availability transition metrics.

apahim added 4 commits August 7, 2026 14:31
Add CredentialStatus type and GetCredentialStatus() function to the GCP
platform package, mirroring the existing AWS pattern. The function checks
ValidGCPWorkloadIdentity and ValidGCPCredentials conditions and returns
a tri-state result: Valid (0), Invalid (1), or Unknown (2).

This is the foundation for the new hypershift_cluster_invalid_gcp_creds
Prometheus gauge metric.

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(). Both GCP endpoint access modes (Private
and PublicAndPrivate) use PSC, so no EndpointAccess gate is needed.

This ensures PSC failures appear in the
hypershift_hostedclusters_failure_conditions metric.

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

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add a Prometheus gauge metric that exposes GCP credential validity as a
tri-state value: 0=valid, 1=invalid, 2=unknown. This mirrors the
existing hypershift_cluster_invalid_aws_creds pattern.

The metric is collected unconditionally for all clusters; non-GCP
clusters report unknown (2), consistent with the AWS gauge behavior.

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

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 7, 2026
@openshift-ci-robot

openshift-ci-robot commented Aug 7, 2026

Copy link
Copy Markdown

@apahim: This pull request references GCP-959 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

What this PR does / why we need it:

Adds GCP PSC (Private Service Connect) conditions to HyperShift monitoring metrics and introduces a new GCP credential validity gauge, bringing GCP monitoring to parity with AWS.

Changes:

  1. GetCredentialStatus() in GCP platform package — New tri-state function (valid/invalid/unknown) mirroring the AWS pattern, checking ValidGCPWorkloadIdentity and ValidGCPCredentials conditions.

  2. PSC conditions in ExpectedHCConditions() — Adds GCPEndpointAvailable and GCPServiceAttachmentAvailable unconditionally (both GCP endpoint access modes use PSC). PSC failures now appear in hypershift_hostedclusters_failure_conditions.

  3. PSC conditions in transition duration metrics — Adds same conditions to collectTransitionDurationMetrics(). PSC setup latency is now tracked in hypershift_hostedclusters_transition_duration.

  4. hypershift_cluster_invalid_gcp_creds gauge — New Prometheus gauge exposing GCP credential status (0=valid, 1=invalid, 2=unknown), following the hypershift_cluster_invalid_aws_creds pattern.

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/GCP-959

Special notes for your reviewer:

  • The Jira ticket mentions gating PSC conditions on EndpointAccess != Public, but GCP has no Public-only endpoint access mode (only Private and PublicAndPrivate), so conditions are added unconditionally.
  • CredentialStatus type is intentionally duplicated from the AWS package to avoid cross-platform import dependencies.
  • The GCP creds gauge is collected unconditionally for all clusters (non-GCP clusters report Unknown=2), consistent with the AWS gauge behavior.
  • All unit tests follow the "When ... it should ..." naming convention per TESTING.md.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The change adds a GCP credential status type and evaluator. It reports valid, invalid, and unknown credential states through Prometheus metrics. GCP endpoint and service-attachment conditions now contribute to transition-duration metrics and expected condition handling. Tests cover credential evaluation, metric values, and GCP condition transitions.

Sequence Diagram(s)

sequenceDiagram
  participant HostedClusterMetrics
  participant HostedCluster
  participant GetCredentialStatus
  participant PrometheusMetrics
  HostedClusterMetrics->>HostedCluster: read GCP conditions
  HostedClusterMetrics->>GetCredentialStatus: evaluate credential status
  GetCredentialStatus-->>HostedClusterMetrics: return credential status
  HostedClusterMetrics->>PrometheusMetrics: emit credential status
  HostedClusterMetrics->>PrometheusMetrics: emit condition transition metrics
Loading

Possibly related PRs

Suggested reviewers: bryan-cox

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
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 static Go Test and t.Run names; no Ginkgo titles or dynamic values such as timestamps, IDs, namespaces, nodes, IPs, or UUIDs appear in titles.
Test Structure And Quality ✅ Passed The changed tests use standard testing.T/t.Run with fake clients, not Ginkgo; no It blocks, lifecycle hooks, cluster resources, Eventually, or Consistently calls are present.
Topology-Aware Scheduling Compatibility ✅ Passed The complete PR diff adds credential and condition metrics only; it introduces no anti-affinity, topology spread, selectors, tolerations, replica logic, or PDB scheduling constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added tests are standard testing.T unit tests; structural searches found no Ginkgo calls, IPv4-only values, or external connectivity operations.
No-Weak-Crypto ✅ Passed The full PR patch adds no MD5, SHA1, DES, RC4, Blowfish, ECB, custom crypto, or secret/token comparisons; existing RSA/X.509 test code predates the PR.
Container-Privileges ✅ Passed The PR changes only Go source and tests; the complete diff adds no Kubernetes manifests or privilege-related settings such as privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, or allowPrivilege...
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no logging or print calls and emits only tri-state credential values; the GCP metric reuses existing cluster labels without passwords, tokens, PII, or customer data.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: GCP PSC condition metrics and platform-specific credential gauges.
✨ 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 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 sjenning 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 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

@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: 1

🤖 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/metrics/metrics.go`:
- Around line 610-619: Update collectGcpCredsMetric in
hypershift-operator/controllers/hostedcluster/metrics/metrics.go:610-619 to
initialize status as platformgcp.CredentialStatusUnknown and call
GetCredentialStatus only when hcluster.Spec.Platform.Type is
hyperv1.GCPPlatform. Update the valid and invalid cases in
hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go:613-630 to
use GCPPlatform, and add a non-GCP case expecting status 2.
🪄 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: 200bcc62-1b99-4108-8637-0de1ee0179dc

📥 Commits

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

📒 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

Comment on lines +610 to +619
// Use detailed credential status: 0=valid, 1=invalid, 2=unknown
func collectGcpCredsMetric(ch chan<- prometheus.Metric, hcluster *hyperv1.HostedCluster, hclusterLabelValues []string) {
credStatus := platformgcp.GetCredentialStatus(hcluster)
ch <- prometheus.MustNewConstMetric(
invalidGcpCredsMetricDesc,
prometheus.GaugeValue,
float64(credStatus),
hclusterLabelValues...,
)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Report unknown for non-GCP HostedClusters.

collectGcpCredsMetric calls platformgcp.GetCredentialStatus for every HostedCluster. A non-GCP HostedCluster can then report 0 or 1 if GCP-named conditions are present. This violates the required metric contract.

  • hypershift-operator/controllers/hostedcluster/metrics/metrics.go#L610-L619: Initialize the status to platformgcp.CredentialStatusUnknown. Call GetCredentialStatus only when hcluster.Spec.Platform.Type == hyperv1.GCPPlatform.
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go#L613-L630: Set the platform type to hyperv1.GCPPlatform for valid and invalid cases. Add a non-GCP case that expects 2.
📍 Affects 2 files
  • hypershift-operator/controllers/hostedcluster/metrics/metrics.go#L610-L619 (this comment)
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go#L613-L630
🤖 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/metrics/metrics.go` around
lines 610 - 619, Update collectGcpCredsMetric in
hypershift-operator/controllers/hostedcluster/metrics/metrics.go:610-619 to
initialize status as platformgcp.CredentialStatusUnknown and call
GetCredentialStatus only when hcluster.Spec.Platform.Type is
hyperv1.GCPPlatform. Update the valid and invalid cases in
hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go:613-630 to
use GCPPlatform, and add a non-GCP case expecting status 2.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
support/conditions/conditions.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9258      +/-   ##
==========================================
+ Coverage   44.81%   45.04%   +0.22%     
==========================================
  Files         775      778       +3     
  Lines       97219    97576     +357     
==========================================
+ Hits        43572    43950     +378     
+ Misses      50644    50597      -47     
- Partials     3003     3029      +26     
Files with missing lines Coverage Δ
...rollers/hostedcluster/internal/platform/gcp/gcp.go 84.72% <100.00%> (+1.04%) ⬆️
...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.

@apahim
apahim marked this pull request as ready for review August 7, 2026 13:48
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 7, 2026
@openshift-ci
openshift-ci Bot requested review from ckandag and ironcladlou August 7, 2026 13:49
@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.

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 jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants