diff --git a/pkg/controller/webhooks/xobjectbuckets.go b/pkg/controller/webhooks/xobjectbuckets.go index ce631fb4e4..7e773a7700 100644 --- a/pkg/controller/webhooks/xobjectbuckets.go +++ b/pkg/controller/webhooks/xobjectbuckets.go @@ -3,6 +3,7 @@ package webhooks import ( "context" "fmt" + "time" "github.com/go-logr/logr" appcatv1 "github.com/vshn/appcat/v4/apis/v1" @@ -55,6 +56,15 @@ func (p *XObjectbucketDeletionProtectionHandler) ValidateDelete(ctx context.Cont return nil, fmt.Errorf("object is not valid") } + creationTimestamp := bucket.GetCreationTimestamp() + + now := time.Now() + age := now.Sub(creationTimestamp.Time) + + if age < 61*time.Minute { + return nil, fmt.Errorf("XObjectBucket is too young to be deleted") + } + l := p.log.WithValues("object", bucket.GetName(), "namespace", bucket.GetNamespace(), "GVK", bucket.GetObjectKind().GroupVersionKind().String()) compInfo, err := checkManagedObject(ctx, bucket, p.client, l)