Skip to content

OADP-8085: fix(gcp): use errors.Is/As for GCS bucket not-found checks#2232

Open
PrasadJoshi12 wants to merge 1 commit into
openshift:oadp-1.6from
PrasadJoshi12:cloudstorage
Open

OADP-8085: fix(gcp): use errors.Is/As for GCS bucket not-found checks#2232
PrasadJoshi12 wants to merge 1 commit into
openshift:oadp-1.6from
PrasadJoshi12:cloudstorage

Conversation

@PrasadJoshi12

Copy link
Copy Markdown
Contributor

cloud.google.com/go/storage now wraps ErrBucketNotExist around the underlying *googleapi.Error (PR #11519), breaking == comparisons. Replace direct equality and type assertions with errors.Is and errors.As throughout gcp.go to correctly detect 404 bucket-not-found errors.

Fixes: https://redhat.atlassian.net/browse/OADP-8078

Why the changes were made

How to test the changes made

cloud.google.com/go/storage now wraps ErrBucketNotExist around the
underlying *googleapi.Error (PR #11519), breaking == comparisons.
Replace direct equality and type assertions with errors.Is and errors.As
throughout gcp.go to correctly detect 404 bucket-not-found errors.
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 47be5b10-a96b-471b-bd92-b1c6b79187b6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci openshift-ci Bot requested review from kaovilai and mrnold June 3, 2026 14:51
@openshift-ci

openshift-ci Bot commented Jun 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: PrasadJoshi12
Once this PR has been reviewed and has the lgtm label, please assign rayfordj 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

@kaovilai

kaovilai commented Jun 3, 2026

Copy link
Copy Markdown
Member

pkg/bucket/gcp.go:395:2: import-shadowing: The name 'errors' shadows an import name (revive)
errors := make(chan error, maxWorkers)

Copilot AI 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.

Pull request overview

This PR updates GCP/GCS bucket error handling to correctly detect “bucket not found” conditions after upstream changes in cloud.google.com/go/storage began wrapping storage.ErrBucketNotExist, making direct == and type-assertion checks unreliable.

Changes:

  • Replaces err == storage.ErrBucketNotExist checks in Exists() and Delete() with a new isBucketNotFoundError() helper.
  • Switches *googleapi.Error type assertions to errors.As in retry/error-handling helpers.
  • Adds isBucketNotFoundError() to handle both storage.ErrBucketNotExist (including wrapped) and HTTP 404 *googleapi.Error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/bucket/gcp.go
import (
"context"
"encoding/json"
"errors"
Comment thread pkg/bucket/gcp.go
Comment on lines +490 to 492
var gerr *googleapi.Error
if errors.As(err, &gerr) {
switch gerr.Code {
Comment thread pkg/bucket/gcp.go
Comment on lines +522 to +526
if errors.Is(err, storage.ErrBucketNotExist) {
return true
}
var gerr *googleapi.Error
return errors.As(err, &gerr) && gerr.Code == http.StatusNotFound
Comment thread pkg/bucket/gcp.go
// handleGCSError provides consistent error handling for GCS operations
func handleGCSError(err error, operation string, bucketName string) error {
if err == storage.ErrBucketNotExist {
if errors.Is(err, storage.ErrBucketNotExist) {
Comment thread pkg/bucket/gcp.go
Comment on lines +538 to +539
var gerr *googleapi.Error
if errors.As(err, &gerr) {
Comment thread pkg/bucket/gcp.go
Comment on lines +518 to +526
// isBucketNotFoundError reports whether err indicates a GCS bucket does not exist.
// The GCS library may return storage.ErrBucketNotExist directly, wrap it via fmt.Errorf("%w", ...),
// or surface a *googleapi.Error with HTTP 404 — all three must be handled.
func isBucketNotFoundError(err error) bool {
if errors.Is(err, storage.ErrBucketNotExist) {
return true
}
var gerr *googleapi.Error
return errors.As(err, &gerr) && gerr.Code == http.StatusNotFound
@weshayutin

Copy link
Copy Markdown
Contributor

/hold

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 3, 2026
@weshayutin weshayutin changed the title fix(gcp): use errors.Is/As for GCS bucket not-found checks OADP-8085: fix(gcp): use errors.Is/As for GCS bucket not-found checks Jun 3, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 3, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 3, 2026

Copy link
Copy Markdown

@PrasadJoshi12: This pull request references OADP-8085 which is a valid jira issue.

Details

In response to this:

cloud.google.com/go/storage now wraps ErrBucketNotExist around the underlying *googleapi.Error (PR #11519), breaking == comparisons. Replace direct equality and type assertions with errors.Is and errors.As throughout gcp.go to correctly detect 404 bucket-not-found errors.

Fixes: https://redhat.atlassian.net/browse/OADP-8078

Why the changes were made

How to test the changes made

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.

@openshift-ci

openshift-ci Bot commented Jun 3, 2026

Copy link
Copy Markdown

@PrasadJoshi12: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.22-e2e-test-aws ffb6b58 link true /test 4.22-e2e-test-aws
ci/prow/unit-test ffb6b58 link true /test unit-test

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

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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.

5 participants