1/* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15*/ 16 17package server 18 19import ( 20 "context" 21 22 "github.com/containerd/containerd" 23 "github.com/containerd/containerd/log" 24 "github.com/containerd/nri" 25 v1 "github.com/containerd/nri/types/v1" 26) 27 28// WithNRISandboxDelete calls delete for a sandbox'd task 29func WithNRISandboxDelete(sandboxID string) containerd.ProcessDeleteOpts { 30 return func(ctx context.Context, p containerd.Process) error { 31 task, ok := p.(containerd.Task) 32 if !ok { 33 return nil 34 } 35 nric, err := nri.New() 36 if err != nil { 37 log.G(ctx).WithError(err).Error("unable to create nri client") 38 return nil 39 } 40 if nric == nil { 41 return nil 42 } 43 sb := &nri.Sandbox{ 44 ID: sandboxID, 45 } 46 if _, err := nric.InvokeWithSandbox(ctx, task, v1.Delete, sb); err != nil { 47 log.G(ctx).WithError(err).Errorf("Failed to delete nri for %q", task.ID()) 48 } 49 return nil 50 } 51} 52