Skip to content

Commit dfb51ac

Browse files
fix: failed to keep s3 bucket retain
1 parent b8b1684 commit dfb51ac

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

api/core/v1alpha1/logset_types.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,29 @@ func (l *LogSetSpec) GetStoreFailureTimeout() metav1.Duration {
8585
}
8686

8787
func (l *LogSetSpec) GetPVCRetentionPolicy() PVCRetentionPolicy {
88-
if l.PVCRetentionPolicy == nil {
89-
l.setDefaultRetentionPolicy()
88+
if l.PVCRetentionPolicy != nil {
89+
return *l.PVCRetentionPolicy
9090
}
91-
return *l.PVCRetentionPolicy
91+
// inherit from s3 policy if only s3 is set (e.g. old objects without pvcRetentionPolicy)
92+
if l.SharedStorage.S3 != nil && l.SharedStorage.S3.S3RetentionPolicy != nil {
93+
return *l.SharedStorage.S3.S3RetentionPolicy
94+
}
95+
return PVCRetentionPolicyDelete
9296
}
9397

9498
func (l *LogSetSpec) GetS3RetentionPolicy() *PVCRetentionPolicy {
9599
if l.SharedStorage.S3 == nil {
96100
return nil
97101
}
98-
if l.SharedStorage.S3.S3RetentionPolicy == nil {
99-
l.setDefaultRetentionPolicy()
102+
if l.SharedStorage.S3.S3RetentionPolicy != nil {
103+
return l.SharedStorage.S3.S3RetentionPolicy
104+
}
105+
// inherit from pvc policy if only pvc is set (e.g. old objects without s3RetentionPolicy)
106+
if l.PVCRetentionPolicy != nil {
107+
return l.PVCRetentionPolicy
100108
}
101-
return l.SharedStorage.S3.S3RetentionPolicy
109+
defaultPolicy := PVCRetentionPolicyDelete
110+
return &defaultPolicy
102111
}
103112

104113
type InitialConfig struct {

pkg/controllers/bucketclaim/controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Matrix Origin
1+
// Copyright 2025-2026 Matrix Origin
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -71,6 +71,16 @@ func (bca *Actor) Finalize(ctx *recon.Context[*v1alpha1.BucketClaim]) (bool, err
7171
return false, ctx.Update(bucket)
7272
}
7373

74+
// if bucket is Released (s3RetentionPolicy=Retain), skip data deletion and release the finalizer directly
75+
if bucket.Status.State == v1alpha1.StatusReleased {
76+
ctx.Log.Info(fmt.Sprintf("skip data deletion for released bucket %v (s3RetentionPolicy=Retain)", client.ObjectKeyFromObject(ctx.Obj)))
77+
controllerutil.RemoveFinalizer(bucket, v1alpha1.BucketDataFinalizer)
78+
if err := ctx.Update(bucket); err != nil {
79+
return false, err
80+
}
81+
return true, nil
82+
}
83+
7484
// if AnnAnyInstanceRunning is not set, indicates that there is no running pod instance found for its mo cluster
7585
// so there is no need to start a job to finalize bucket data.
7686
// NOTE: generally LogSet start successfully is a precondition of starting DN and CN, if no running pod found means that

0 commit comments

Comments
 (0)