Skip to content

Commit

Permalink
adding delayed removal of xobjectbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz.widera@vshn.ch committed Oct 3, 2024
1 parent 29089fe commit b5d6a1f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/webhooks/xobjectbuckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webhooks
import (
"context"
"fmt"
"time"

"github.com/go-logr/logr"
appcatv1 "github.com/vshn/appcat/v4/apis/v1"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b5d6a1f

Please sign in to comment.