Add sync option on lease removal

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2018-07-19 11:27:48 -07:00
parent 29b72d4ff0
commit 94e132fd07
9 changed files with 167 additions and 43 deletions

View File

@@ -24,10 +24,13 @@ import (
// Opt is used to set options on a lease
type Opt func(*Lease) error
// DeleteOpt allows configuring a delete operation
type DeleteOpt func(context.Context, *DeleteOptions) error
// Manager is used to create, list, and remove leases
type Manager interface {
Create(context.Context, ...Opt) (Lease, error)
Delete(context.Context, Lease) error
Delete(context.Context, Lease, ...DeleteOpt) error
List(context.Context, ...string) ([]Lease, error)
}
@@ -39,6 +42,19 @@ type Lease struct {
Labels map[string]string
}
// DeleteOptions provide options on image delete
type DeleteOptions struct {
Synchronous bool
}
// SynchronousDelete is used to indicate that a lease deletion and removal of
// any unreferenced resources should occur synchronously before returning the
// result.
func SynchronousDelete(ctx context.Context, o *DeleteOptions) error {
o.Synchronous = true
return nil
}
// WithLabels sets labels on a lease
func WithLabels(labels map[string]string) Opt {
return func(l *Lease) error {

View File

@@ -57,9 +57,17 @@ func (pm *proxyManager) Create(ctx context.Context, opts ...leases.Opt) (leases.
}, nil
}
func (pm *proxyManager) Delete(ctx context.Context, l leases.Lease) error {
func (pm *proxyManager) Delete(ctx context.Context, l leases.Lease, opts ...leases.DeleteOpt) error {
var do leases.DeleteOptions
for _, opt := range opts {
if err := opt(ctx, &do); err != nil {
return err
}
}
_, err := pm.client.Delete(ctx, &leasesapi.DeleteRequest{
ID: l.ID,
ID: l.ID,
Sync: do.Synchronous,
})
return err
}