Skip to content

Commit e814f13

Browse files
authored
Merge pull request #85 from vshn/bugfix-bucket
bypass governance retention when deleting s3 bucket
2 parents 7fc3c8e + 379a936 commit e814f13

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
The PR has a meaningful description that sums up the change. It will be
99
linked in the changelog.
1010
- [ ] PR contains a single logical change (to build a better changelog).
11+
- [ ] I have run successfully `make test-e2e` locally.
1112
- [ ] Update the documentation.
1213
- [ ] Categorize the PR by adding one of the labels:
1314
`bug`, `enhancement`, `documentation`, `change`, `breaking`, `dependency`

operator/bucketcontroller/delete.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bucketcontroller
33
import (
44
"context"
55
"fmt"
6+
67
pipeline "github.com/ccremer/go-command-pipeline"
78
"github.com/crossplane/crossplane-runtime/pkg/errors"
89
"github.com/crossplane/crossplane-runtime/pkg/event"
@@ -55,12 +56,28 @@ func (p *ProvisioningPipeline) deleteAllObjects(ctx *pipelineContext) error {
5556
}
5657
}()
5758

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}) {
5965
return fmt.Errorf("object %q cannot be removed: %w", obj.ObjectName, obj.Err)
6066
}
6167
return nil
6268
}
6369

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+
6481
// deleteS3Bucket deletes the bucket.
6582
// NOTE: The removal fails if there are still objects in the bucket.
6683
// This func does not recursively delete all objects beforehand.

test/local.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ test-e2e: $(kuttl_bin) $(mc_bin) local-install provider-config ## E2E tests
128128
@rm -f kubeconfig
129129
# kuttl leaves kubeconfig garbage: https://github.com/kudobuilder/kuttl/issues/297
130130

131+
run-single-e2e: export KUBECONFIG = $(KIND_KUBECONFIG)
132+
run-single-e2e: $(kuttl_bin) $(mc_bin) local-install provider-config ## Run specific e2e test with `run-single-e2e test=$name`
133+
GOBIN=$(go_bin) $(kuttl_bin) test ./test/e2e --config ./test/e2e/kuttl-test.yaml --suppress-log=Events --test $(test)
134+
@rm -f kubeconfig
135+
131136
.PHONY: .e2e-test-clean
132137
.e2e-test-clean: export KUBECONFIG = $(KIND_KUBECONFIG)
133138
.e2e-test-clean:

0 commit comments

Comments
 (0)