Skip to content

Commit

Permalink
Merge pull request #239 from vshn/xobjectbucket_delayed_removal
Browse files Browse the repository at this point in the history
adding delayed removal of xobjectbucket
  • Loading branch information
wejdross authored Oct 3, 2024
2 parents 29089fe + 3156fd9 commit 1b45013
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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,16 @@ func (p *XObjectbucketDeletionProtectionHandler) ValidateDelete(ctx context.Cont
return nil, fmt.Errorf("object is not valid")
}

creationTimestamp := bucket.GetCreationTimestamp()
allowedDeletionTime := creationTimestamp.Add(61 * time.Minute)

now := time.Now()
age := now.Sub(creationTimestamp.Time)

if age < 61*time.Minute {
return nil, fmt.Errorf("XObjectBucket is too young to be deleted, need to wait another %.1f minutes to ensure correct billing", allowedDeletionTime.Sub(now).Minutes())
}

l := p.log.WithValues("object", bucket.GetName(), "namespace", bucket.GetNamespace(), "GVK", bucket.GetObjectKind().GroupVersionKind().String())

compInfo, err := checkManagedObject(ctx, bucket, p.client, l)
Expand All @@ -67,7 +78,7 @@ func (p *XObjectbucketDeletionProtectionHandler) ValidateDelete(ctx context.Cont
return nil, fmt.Errorf(protectedMessage, "XObjectBucket", compInfo.Name)
}

l.Info("Allowing deletion of XObjectBucket", "parent", compInfo.Name)
l.Info("Allowing deletion of XObjectBucket", "parent", compInfo.Name, "age", age.String())

return nil, nil
}

0 comments on commit 1b45013

Please sign in to comment.