Add sync option on lease removal
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
29b72d4ff0
commit
94e132fd07
@ -2546,6 +2546,13 @@ file {
|
|||||||
type: TYPE_STRING
|
type: TYPE_STRING
|
||||||
json_name: "id"
|
json_name: "id"
|
||||||
}
|
}
|
||||||
|
field {
|
||||||
|
name: "sync"
|
||||||
|
number: 2
|
||||||
|
label: LABEL_OPTIONAL
|
||||||
|
type: TYPE_BOOL
|
||||||
|
json_name: "sync"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message_type {
|
message_type {
|
||||||
name: "ListRequest"
|
name: "ListRequest"
|
||||||
|
@ -82,6 +82,11 @@ func (*CreateResponse) Descriptor() ([]byte, []int) { return fileDescriptorLease
|
|||||||
|
|
||||||
type DeleteRequest struct {
|
type DeleteRequest struct {
|
||||||
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
// Sync indicates that the delete and cleanup should be done
|
||||||
|
// synchronously before returning to the caller
|
||||||
|
//
|
||||||
|
// Default is false
|
||||||
|
Sync bool `protobuf:"varint,2,opt,name=sync,proto3" json:"sync,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DeleteRequest) Reset() { *m = DeleteRequest{} }
|
func (m *DeleteRequest) Reset() { *m = DeleteRequest{} }
|
||||||
@ -404,6 +409,16 @@ func (m *DeleteRequest) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
i = encodeVarintLeases(dAtA, i, uint64(len(m.ID)))
|
i = encodeVarintLeases(dAtA, i, uint64(len(m.ID)))
|
||||||
i += copy(dAtA[i:], m.ID)
|
i += copy(dAtA[i:], m.ID)
|
||||||
}
|
}
|
||||||
|
if m.Sync {
|
||||||
|
dAtA[i] = 0x10
|
||||||
|
i++
|
||||||
|
if m.Sync {
|
||||||
|
dAtA[i] = 1
|
||||||
|
} else {
|
||||||
|
dAtA[i] = 0
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,6 +549,9 @@ func (m *DeleteRequest) Size() (n int) {
|
|||||||
if l > 0 {
|
if l > 0 {
|
||||||
n += 1 + l + sovLeases(uint64(l))
|
n += 1 + l + sovLeases(uint64(l))
|
||||||
}
|
}
|
||||||
|
if m.Sync {
|
||||||
|
n += 2
|
||||||
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,6 +651,7 @@ func (this *DeleteRequest) String() string {
|
|||||||
}
|
}
|
||||||
s := strings.Join([]string{`&DeleteRequest{`,
|
s := strings.Join([]string{`&DeleteRequest{`,
|
||||||
`ID:` + fmt.Sprintf("%v", this.ID) + `,`,
|
`ID:` + fmt.Sprintf("%v", this.ID) + `,`,
|
||||||
|
`Sync:` + fmt.Sprintf("%v", this.Sync) + `,`,
|
||||||
`}`,
|
`}`,
|
||||||
}, "")
|
}, "")
|
||||||
return s
|
return s
|
||||||
@ -1230,6 +1249,26 @@ func (m *DeleteRequest) Unmarshal(dAtA []byte) error {
|
|||||||
}
|
}
|
||||||
m.ID = string(dAtA[iNdEx:postIndex])
|
m.ID = string(dAtA[iNdEx:postIndex])
|
||||||
iNdEx = postIndex
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
|
if wireType != 0 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Sync", wireType)
|
||||||
|
}
|
||||||
|
var v int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowLeases
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
v |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Sync = bool(v != 0)
|
||||||
default:
|
default:
|
||||||
iNdEx = preIndex
|
iNdEx = preIndex
|
||||||
skippy, err := skipLeases(dAtA[iNdEx:])
|
skippy, err := skipLeases(dAtA[iNdEx:])
|
||||||
@ -1521,37 +1560,38 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptorLeases = []byte{
|
var fileDescriptorLeases = []byte{
|
||||||
// 504 bytes of a gzipped FileDescriptorProto
|
// 515 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xdf, 0x8a, 0xd3, 0x40,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xdf, 0x8a, 0xd3, 0x40,
|
||||||
0x14, 0xc6, 0x3b, 0xa9, 0x8d, 0xf6, 0xc4, 0x15, 0x19, 0x96, 0x25, 0x44, 0x4c, 0x4b, 0x10, 0xb6,
|
0x14, 0xc6, 0x3b, 0xe9, 0x36, 0x6e, 0x4f, 0x5d, 0x91, 0x61, 0x59, 0x4a, 0xc4, 0xb4, 0x04, 0xc1,
|
||||||
0xf8, 0x67, 0xe2, 0xd6, 0x9b, 0x75, 0x15, 0xc1, 0x6e, 0x17, 0x14, 0x82, 0x48, 0xf0, 0x62, 0xf1,
|
0xe2, 0x9f, 0x89, 0x5b, 0x6f, 0xd6, 0x5d, 0x11, 0xec, 0x76, 0x41, 0x21, 0x88, 0x04, 0x2f, 0x16,
|
||||||
0x66, 0x49, 0xdb, 0xb3, 0x31, 0x98, 0x36, 0x31, 0x33, 0x2d, 0xf4, 0xce, 0x47, 0xf0, 0x11, 0x7c,
|
0x6f, 0x96, 0x34, 0x3d, 0x1b, 0x83, 0x69, 0x12, 0x33, 0xd3, 0x42, 0xef, 0x7c, 0x04, 0x1f, 0xc1,
|
||||||
0x08, 0x1f, 0xa2,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x14, 0x74, 0xdd, 0x12, 0xe5,
|
||||||
|
0x04, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,12 @@ message CreateResponse {
|
|||||||
|
|
||||||
message DeleteRequest {
|
message DeleteRequest {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
|
|
||||||
|
// Sync indicates that the delete and cleanup should be done
|
||||||
|
// synchronously before returning to the caller
|
||||||
|
//
|
||||||
|
// Default is false
|
||||||
|
bool sync = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListRequest {
|
message ListRequest {
|
||||||
|
@ -163,6 +163,12 @@ var deleteCommand = cli.Command{
|
|||||||
Usage: "delete a lease",
|
Usage: "delete a lease",
|
||||||
ArgsUsage: "[flags] <lease id> ...",
|
ArgsUsage: "[flags] <lease id> ...",
|
||||||
Description: "delete a lease",
|
Description: "delete a lease",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "sync",
|
||||||
|
Usage: "Synchronously remove leases and all unreferenced resources",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var lids = context.Args()
|
var lids = context.Args()
|
||||||
if len(lids) == 0 {
|
if len(lids) == 0 {
|
||||||
@ -175,11 +181,17 @@ var deleteCommand = cli.Command{
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
ls := client.LeasesService()
|
ls := client.LeasesService()
|
||||||
for _, lid := range lids {
|
sync := context.Bool("sync")
|
||||||
|
for i, lid := range lids {
|
||||||
|
var opts []leases.DeleteOpt
|
||||||
|
if sync && i == len(lids)-1 {
|
||||||
|
opts = append(opts, leases.SynchronousDelete)
|
||||||
|
}
|
||||||
|
|
||||||
lease := leases.Lease{
|
lease := leases.Lease{
|
||||||
ID: lid,
|
ID: lid,
|
||||||
}
|
}
|
||||||
if err := ls.Delete(ctx, lease); err != nil {
|
if err := ls.Delete(ctx, lease, opts...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(lid)
|
fmt.Println(lid)
|
||||||
|
@ -24,10 +24,13 @@ import (
|
|||||||
// Opt is used to set options on a lease
|
// Opt is used to set options on a lease
|
||||||
type Opt func(*Lease) error
|
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
|
// Manager is used to create, list, and remove leases
|
||||||
type Manager interface {
|
type Manager interface {
|
||||||
Create(context.Context, ...Opt) (Lease, error)
|
Create(context.Context, ...Opt) (Lease, error)
|
||||||
Delete(context.Context, Lease) error
|
Delete(context.Context, Lease, ...DeleteOpt) error
|
||||||
List(context.Context, ...string) ([]Lease, error)
|
List(context.Context, ...string) ([]Lease, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +42,19 @@ type Lease struct {
|
|||||||
Labels map[string]string
|
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
|
// WithLabels sets labels on a lease
|
||||||
func WithLabels(labels map[string]string) Opt {
|
func WithLabels(labels map[string]string) Opt {
|
||||||
return func(l *Lease) error {
|
return func(l *Lease) error {
|
||||||
|
@ -57,9 +57,17 @@ func (pm *proxyManager) Create(ctx context.Context, opts ...leases.Opt) (leases.
|
|||||||
}, nil
|
}, 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{
|
_, err := pm.client.Delete(ctx, &leasesapi.DeleteRequest{
|
||||||
ID: l.ID,
|
ID: l.ID,
|
||||||
|
Sync: do.Synchronous,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func (lm *LeaseManager) Create(ctx context.Context, opts ...leases.Opt) (leases.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete delets the lease with the provided lease ID
|
// Delete delets the lease with the provided lease ID
|
||||||
func (lm *LeaseManager) Delete(ctx context.Context, lease leases.Lease) error {
|
func (lm *LeaseManager) Delete(ctx context.Context, lease leases.Lease, _ ...leases.DeleteOpt) error {
|
||||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
|
"github.com/containerd/containerd/gc"
|
||||||
"github.com/containerd/containerd/leases"
|
"github.com/containerd/containerd/leases"
|
||||||
"github.com/containerd/containerd/metadata"
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
@ -38,13 +39,25 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &local{db: m.(*metadata.DB)}, nil
|
g, err := ic.Get(plugin.GCPlugin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &local{
|
||||||
|
db: m.(*metadata.DB),
|
||||||
|
gc: g.(gcScheduler),
|
||||||
|
}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type gcScheduler interface {
|
||||||
|
ScheduleAndWait(context.Context) (gc.Stats, error)
|
||||||
|
}
|
||||||
|
|
||||||
type local struct {
|
type local struct {
|
||||||
db *metadata.DB
|
db *metadata.DB
|
||||||
|
gc gcScheduler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *local) Create(ctx context.Context, opts ...leases.Opt) (leases.Lease, error) {
|
func (l *local) Create(ctx context.Context, opts ...leases.Opt) (leases.Lease, error) {
|
||||||
@ -59,10 +72,28 @@ func (l *local) Create(ctx context.Context, opts ...leases.Opt) (leases.Lease, e
|
|||||||
return lease, nil
|
return lease, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *local) Delete(ctx context.Context, lease leases.Lease) error {
|
func (l *local) Delete(ctx context.Context, lease leases.Lease, opts ...leases.DeleteOpt) error {
|
||||||
return l.db.Update(func(tx *bolt.Tx) error {
|
var do leases.DeleteOptions
|
||||||
|
for _, opt := range opts {
|
||||||
|
if err := opt(ctx, &do); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := l.db.Update(func(tx *bolt.Tx) error {
|
||||||
return metadata.NewLeaseManager(tx).Delete(ctx, lease)
|
return metadata.NewLeaseManager(tx).Delete(ctx, lease)
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if do.Synchronous {
|
||||||
|
if _, err := l.gc.ScheduleAndWait(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *local) List(ctx context.Context, filters ...string) ([]leases.Lease, error) {
|
func (l *local) List(ctx context.Context, filters ...string) ([]leases.Lease, error) {
|
||||||
|
@ -84,9 +84,13 @@ func (s *service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Delete(ctx context.Context, r *api.DeleteRequest) (*ptypes.Empty, error) {
|
func (s *service) Delete(ctx context.Context, r *api.DeleteRequest) (*ptypes.Empty, error) {
|
||||||
|
var opts []leases.DeleteOpt
|
||||||
|
if r.Sync {
|
||||||
|
opts = append(opts, leases.SynchronousDelete)
|
||||||
|
}
|
||||||
if err := s.lm.Delete(ctx, leases.Lease{
|
if err := s.lm.Delete(ctx, leases.Lease{
|
||||||
ID: r.ID,
|
ID: r.ID,
|
||||||
}); err != nil {
|
}, opts...); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &ptypes.Empty{}, nil
|
return &ptypes.Empty{}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user