From de99c252c695d016d3e6250be71df6026a258301 Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Mon, 23 Oct 2023 16:34:39 +0530 Subject: [PATCH 1/3] Support replication of deleted ILM expiry rules Signed-off-by: Shubhendu Ram Tripathi --- api-bucket-lifecycle.go | 8 +++++--- examples/s3/setbucketlifecycle.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api-bucket-lifecycle.go b/api-bucket-lifecycle.go index fec5cece5..7980869db 100644 --- a/api-bucket-lifecycle.go +++ b/api-bucket-lifecycle.go @@ -24,6 +24,7 @@ import ( "io" "net/http" "net/url" + "strconv" "time" "github.com/minio/minio-go/v7/pkg/lifecycle" @@ -31,7 +32,7 @@ import ( ) // SetBucketLifecycle set the lifecycle on an existing bucket. -func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { +func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, config *lifecycle.Configuration, expiryRuleRemoved bool) error { // Input validation. if err := s3utils.CheckValidBucketName(bucketName); err != nil { return err @@ -48,15 +49,16 @@ func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, conf } // Save the updated lifecycle. - return c.putBucketLifecycle(ctx, bucketName, buf) + return c.putBucketLifecycle(ctx, bucketName, buf, expiryRuleRemoved) } // Saves a new bucket lifecycle. -func (c *Client) putBucketLifecycle(ctx context.Context, bucketName string, buf []byte) error { +func (c *Client) putBucketLifecycle(ctx context.Context, bucketName string, buf []byte, expiryRuleRemoved bool) error { // Get resources properly escaped and lined up before // using them in http request. urlValues := make(url.Values) urlValues.Set("lifecycle", "") + urlValues.Set("expiryRuleRemoved", strconv.FormatBool(expiryRuleRemoved)) // Content-length is mandatory for put lifecycle request reqMetadata := requestMetadata{ diff --git a/examples/s3/setbucketlifecycle.go b/examples/s3/setbucketlifecycle.go index a363d5cde..fc7acb6f5 100644 --- a/examples/s3/setbucketlifecycle.go +++ b/examples/s3/setbucketlifecycle.go @@ -59,7 +59,7 @@ func main() { }, }, } - err = s3Client.SetBucketLifecycle(context.Background(), "my-bucketname", config) + err = s3Client.SetBucketLifecycle(context.Background(), "my-bucketname", config, false) if err != nil { log.Fatalln(err) } From 6fbe0293a7b3333a6a056ce99abefc29f97aea95 Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Mon, 30 Oct 2023 13:17:21 +0530 Subject: [PATCH 2/3] Incorporated review comments Signed-off-by: Shubhendu Ram Tripathi --- api-bucket-lifecycle.go | 8 +++----- examples/s3/setbucketlifecycle.go | 2 +- pkg/lifecycle/lifecycle.go | 5 +++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/api-bucket-lifecycle.go b/api-bucket-lifecycle.go index 7980869db..fec5cece5 100644 --- a/api-bucket-lifecycle.go +++ b/api-bucket-lifecycle.go @@ -24,7 +24,6 @@ import ( "io" "net/http" "net/url" - "strconv" "time" "github.com/minio/minio-go/v7/pkg/lifecycle" @@ -32,7 +31,7 @@ import ( ) // SetBucketLifecycle set the lifecycle on an existing bucket. -func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, config *lifecycle.Configuration, expiryRuleRemoved bool) error { +func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { // Input validation. if err := s3utils.CheckValidBucketName(bucketName); err != nil { return err @@ -49,16 +48,15 @@ func (c *Client) SetBucketLifecycle(ctx context.Context, bucketName string, conf } // Save the updated lifecycle. - return c.putBucketLifecycle(ctx, bucketName, buf, expiryRuleRemoved) + return c.putBucketLifecycle(ctx, bucketName, buf) } // Saves a new bucket lifecycle. -func (c *Client) putBucketLifecycle(ctx context.Context, bucketName string, buf []byte, expiryRuleRemoved bool) error { +func (c *Client) putBucketLifecycle(ctx context.Context, bucketName string, buf []byte) error { // Get resources properly escaped and lined up before // using them in http request. urlValues := make(url.Values) urlValues.Set("lifecycle", "") - urlValues.Set("expiryRuleRemoved", strconv.FormatBool(expiryRuleRemoved)) // Content-length is mandatory for put lifecycle request reqMetadata := requestMetadata{ diff --git a/examples/s3/setbucketlifecycle.go b/examples/s3/setbucketlifecycle.go index fc7acb6f5..a363d5cde 100644 --- a/examples/s3/setbucketlifecycle.go +++ b/examples/s3/setbucketlifecycle.go @@ -59,7 +59,7 @@ func main() { }, }, } - err = s3Client.SetBucketLifecycle(context.Background(), "my-bucketname", config, false) + err = s3Client.SetBucketLifecycle(context.Background(), "my-bucketname", config) if err != nil { log.Fatalln(err) } diff --git a/pkg/lifecycle/lifecycle.go b/pkg/lifecycle/lifecycle.go index 830061b8e..eacf5d7ba 100644 --- a/pkg/lifecycle/lifecycle.go +++ b/pkg/lifecycle/lifecycle.go @@ -449,8 +449,9 @@ type Rule struct { // Configuration is a collection of Rule objects. type Configuration struct { - XMLName xml.Name `xml:"LifecycleConfiguration,omitempty" json:"-"` - Rules []Rule `xml:"Rule"` + XMLName xml.Name `xml:"LifecycleConfiguration,omitempty" json:"-"` + Rules []Rule `xml:"Rule"` + ExpiryRuleRemoved bool `xml:"ExpiryRuleRemoved,omitempty" json:"-"` } // Empty check if lifecycle configuration is empty From a9dfa761680d6c92a8ec5d7dab2a1874424574ed Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Mon, 30 Oct 2023 16:37:36 +0530 Subject: [PATCH 3/3] Use pointer type for `ExpiryRuleRemoved` Signed-off-by: Shubhendu Ram Tripathi --- pkg/lifecycle/lifecycle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/lifecycle/lifecycle.go b/pkg/lifecycle/lifecycle.go index eacf5d7ba..44781e0aa 100644 --- a/pkg/lifecycle/lifecycle.go +++ b/pkg/lifecycle/lifecycle.go @@ -451,7 +451,7 @@ type Rule struct { type Configuration struct { XMLName xml.Name `xml:"LifecycleConfiguration,omitempty" json:"-"` Rules []Rule `xml:"Rule"` - ExpiryRuleRemoved bool `xml:"ExpiryRuleRemoved,omitempty" json:"-"` + ExpiryRuleRemoved *bool `xml:"ExpiryRuleRemoved,omitempty" json:"-"` } // Empty check if lifecycle configuration is empty