这是indexloc提供的服务,不要输入任何密码
Skip to content

storage: SoftDeletePolicy is not getting disabled on bucket creation #10380

@dominikmueller

Description

@dominikmueller

Client

Storage v1.42.0

Environment

local machine (MB Pro) (also tested in golang:alpine container)

Go Environment

$ go version
go version go1.22.4 darwin/arm64

Code

package main

import (
	"context"
	"log"
	"time"

	"cloud.google.com/go/storage"
)

const (
	BucketName = "<BUCKET_NAME>"
	ProjectID  = "<PROJECT_ID>"
)

func main() {
	ctx := context.Background()

	// Create a client
	client, err := storage.NewClient(ctx)
	if err != nil {
		log.Fatalf("Failed to create client: %v", err)
	}

	// Create the bucket
	err = client.Bucket(BucketName).Create(ctx, ProjectID, &storage.BucketAttrs{
		Location: "EU",
		SoftDeletePolicy: &storage.SoftDeletePolicy{
			// Setting the RetentionDuration to 0 should disable the feature
			RetentionDuration: 0,
		},
	})

	if err != nil {
		log.Fatalf("Failed to create bucket: %v", err)
	}
}

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.

Screenshots

image

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.

Without knowing much about the internal behaviours of the golang storage lib, I would first suspect these lines when looking at the PR that implements the SoftDeletePolicy: https://github.com/googleapis/google-cloud-go/blob/main/storage/bucket.go#L1334-L1336
(But this could also be totally wrong and the issue could be caused by something completely different)

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions