Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: SoftDeletePolicy is not getting disabled on bucket update #11199

Closed
vsharma-code opened this issue Nov 27, 2024 · 1 comment · Fixed by #11226
Closed

storage: SoftDeletePolicy is not getting disabled on bucket update #11199

vsharma-code opened this issue Nov 27, 2024 · 1 comment · Fixed by #11226
Assignees
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@vsharma-code
Copy link

vsharma-code commented Nov 27, 2024

Client

Storage v1.47.0

Environment

go version go1.23.3 linux/amd64

Code and Dependencies

package main

import (
	"cloud.google.com/go/storage"
	"context"
	"fmt"
	_ "fmt"
	"github.com/googleapis/gax-go/v2"
	"google.golang.org/api/option"
	"time"
)

type GCPConfig struct {
	ProjectID string
	Region    string
	Options   []option.ClientOption
}

func main() {
	bgCtx := context.Background()
	gcpConf := &GCPConfig{
		ProjectID: "something",
		Region:    "us-east4",
	}
	gcs, err := storage.NewClient(bgCtx, gcpConf.Options...)
	if err != nil {
		fmt.Printf("Failed to create GCS client: %v", err)
		fmt.Println(err)
		return
	}
	gcs.SetRetry(storage.WithPolicy(storage.RetryAlways),
		storage.WithBackoff(gax.Backoff{
			// Set the initial retry delay to a maximum of 2 seconds. The length of
			// pauses between retries is subject to random jitter.
			Initial: 2 * time.Second,
			// Set the maximum retry delay to 60 seconds.
			Max: 60 * time.Second,
			// Set the backoff multiplier to 3.0.
			Multiplier: 3,
		}))
	bucket := gcs.Bucket("A bucket")
	_, err = bucket.Update(context.Background(), storage.BucketAttrsToUpdate{
		SoftDeletePolicy: &storage.SoftDeletePolicy{
			RetentionDuration: 0,
		},

		VersioningEnabled: true,
	})
}
go.mod
module my-go-project

go 1.23.3

require cloud.google.com/go/storage v1.47.0

require (
	cel.dev/expr v0.16.1 // indirect
	cloud.google.com/go v0.116.0 // indirect
	cloud.google.com/go/auth v0.10.2 // indirect
	cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
	cloud.google.com/go/compute/metadata v0.5.2 // indirect
	cloud.google.com/go/iam v1.2.1 // indirect
	cloud.google.com/go/monitoring v1.21.1 // indirect
	github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 // indirect
	github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
	github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
	github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
	github.com/envoyproxy/go-control-plane v0.13.0 // indirect
	github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
	github.com/felixge/httpsnoop v1.0.4 // indirect
	github.com/go-logr/logr v1.4.2 // indirect
	github.com/go-logr/stdr v1.2.2 // indirect
	github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
	github.com/google/s2a-go v0.1.8 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
	github.com/googleapis/gax-go/v2 v2.13.0 // indirect
	github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
	go.opencensus.io v0.24.0 // indirect
	go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
	go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
	go.opentelemetry.io/otel v1.29.0 // indirect
	go.opentelemetry.io/otel/metric v1.29.0 // indirect
	go.opentelemetry.io/otel/sdk v1.29.0 // indirect
	go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
	go.opentelemetry.io/otel/trace v1.29.0 // indirect
	golang.org/x/crypto v0.28.0 // indirect
	golang.org/x/net v0.30.0 // indirect
	golang.org/x/oauth2 v0.23.0 // indirect
	golang.org/x/sync v0.8.0 // indirect
	golang.org/x/sys v0.27.0 // indirect
	golang.org/x/text v0.19.0 // indirect
	golang.org/x/time v0.7.0 // indirect
	google.golang.org/api v0.203.0 // indirect
	google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 // indirect
	google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
	google.golang.org/grpc v1.67.1 // indirect
	google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
	google.golang.org/protobuf v1.35.1 // indirect
)

Expected behavior

Bucket gets created without a SoftDeletePolicy / SoftDelete Protection as mentioned in the docs:
https://github.com/googleapis/google-cloud-go/blob/storage/v1.42.0/storage/bucket.go#L491-L492

In order to fully disable soft delete, you need to set a policy with a RetentionDuration of 0.

Actual behavior

Bucket has the default 7 day soft delete policy set.

Additional context

Using any other valid RetentionDuration - e.g. 10 days using 10 * 24 * time.hour - is working as expected and sets the SoftDelete Policy to a 10 day retention duration.

Similar issue on bucket creation was fixed
#10380

@vsharma-code vsharma-code added the triage me I really want to be triaged. label Nov 27, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Nov 27, 2024
@tritone tritone added status: investigating The issue is under investigation, which is determined to be non-trivial. and removed triage me I really want to be triaged. labels Nov 28, 2024
@frankyn frankyn assigned frankyn and unassigned tritone Dec 4, 2024
@tritone tritone added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed status: investigating The issue is under investigation, which is determined to be non-trivial. labels Dec 5, 2024
@tritone
Copy link
Contributor

tritone commented Dec 5, 2024

Thanks for filing the issue; it sounds like some behavior recently changed on the service side regarding how the soft delete policy can get removed in a bucket update request. @frankyn has a PR that will fix the issue in this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants