@@ -3,6 +3,7 @@ package bucketcontroller
3
3
import (
4
4
"context"
5
5
"fmt"
6
+
6
7
pipeline "github.com/ccremer/go-command-pipeline"
7
8
"github.com/crossplane/crossplane-runtime/pkg/errors"
8
9
"github.com/crossplane/crossplane-runtime/pkg/event"
@@ -55,12 +56,28 @@ func (p *ProvisioningPipeline) deleteAllObjects(ctx *pipelineContext) error {
55
56
}
56
57
}()
57
58
58
- for obj := range p .minioClient .RemoveObjects (ctx , bucketName , objectsCh , minio.RemoveObjectsOptions {GovernanceBypass : true }) {
59
+ bypassGovernance , err := p .isBucketLockEnabled (ctx , bucketName )
60
+ if err != nil {
61
+ log .Error (err , "not able to determine ObjectLock status for bucket" , "bucket" , bucketName )
62
+ }
63
+
64
+ for obj := range p .minioClient .RemoveObjects (ctx , bucketName , objectsCh , minio.RemoveObjectsOptions {GovernanceBypass : bypassGovernance }) {
59
65
return fmt .Errorf ("object %q cannot be removed: %w" , obj .ObjectName , obj .Err )
60
66
}
61
67
return nil
62
68
}
63
69
70
+ func (p * ProvisioningPipeline ) isBucketLockEnabled (ctx context.Context , bucketName string ) (bool , error ) {
71
+ _ , mode , _ , _ , err := p .minioClient .GetObjectLockConfig (ctx , bucketName )
72
+ if err != nil && err .Error () == "Object Lock configuration does not exist for this bucket" {
73
+ return false , nil
74
+ } else if err != nil {
75
+ return false , err
76
+ }
77
+ // If there's an objectLockConfig it could still be disabled...
78
+ return mode != nil , nil
79
+ }
80
+
64
81
// deleteS3Bucket deletes the bucket.
65
82
// NOTE: The removal fails if there are still objects in the bucket.
66
83
// This func does not recursively delete all objects beforehand.
0 commit comments