Skip to content

Commit ed47102

Browse files
author
yanggang
committed
Code clean for nri_api.
Signed-off-by: yanggang <[email protected]>
1 parent f276561 commit ed47102

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pkg/cri/nri/nri_api_linux.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/containerd/containerd/v2/pkg/errdefs"
3333
"github.com/containerd/log"
3434
"github.com/containerd/typeurl/v2"
35-
"github.com/opencontainers/runtime-spec/specs-go"
3635
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
3736
"github.com/opencontainers/runtime-tools/generate"
3837
cri "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -117,7 +116,7 @@ func (a *API) RemovePodSandbox(ctx context.Context, criPod *sstore.Sandbox) erro
117116
return err
118117
}
119118

120-
func (a *API) CreateContainer(ctx context.Context, ctrs *containers.Container, spec *specs.Spec) (*api.ContainerAdjustment, error) {
119+
func (a *API) CreateContainer(ctx context.Context, ctrs *containers.Container, spec *runtimespec.Spec) (*api.ContainerAdjustment, error) {
121120
ctr := a.nriContainer(ctrs, spec)
122121

123122
criPod, err := a.cri.SandboxStore().Get(ctr.GetPodSandboxID())
@@ -256,7 +255,7 @@ func (a *API) RemoveContainer(ctx context.Context, criPod *sstore.Sandbox, criCt
256255
return err
257256
}
258257

259-
func (a *API) UndoCreateContainer(ctx context.Context, criPod *sstore.Sandbox, id string, spec *specs.Spec) {
258+
func (a *API) UndoCreateContainer(ctx context.Context, criPod *sstore.Sandbox, id string, spec *runtimespec.Spec) {
260259
if a.IsDisabled() {
261260
return
262261
}
@@ -318,7 +317,7 @@ func (a *API) WithContainerAdjustment() containerd.NewContainerOpts {
318317
)
319318

320319
return func(ctx context.Context, _ *containerd.Client, c *containers.Container) error {
321-
spec := &specs.Spec{}
320+
spec := &runtimespec.Spec{}
322321
if err := json.Unmarshal(c.Spec.GetValue(), spec); err != nil {
323322
return fmt.Errorf("failed to unmarshal container OCI Spec for NRI: %w", err)
324323
}
@@ -463,14 +462,14 @@ func (a *API) EvictContainer(ctx context.Context, e *api.ContainerEviction) erro
463462

464463
type criPodSandbox struct {
465464
*sstore.Sandbox
466-
spec *specs.Spec
465+
spec *runtimespec.Spec
467466
pid uint32
468467
}
469468

470469
func (a *API) nriPodSandbox(pod *sstore.Sandbox) *criPodSandbox {
471470
criPod := &criPodSandbox{
472471
Sandbox: pod,
473-
spec: &specs.Spec{},
472+
spec: &runtimespec.Spec{},
474473
}
475474

476475
if pod == nil || pod.Container == nil {
@@ -490,13 +489,10 @@ func (a *API) nriPodSandbox(pod *sstore.Sandbox) *criPodSandbox {
490489
criPod.pid = task.Pid()
491490
spec, err := task.Spec(ctx)
492491
if err != nil {
493-
if err != nil {
494-
log.L.WithError(err).Errorf("failed to get spec for sandbox container %s",
495-
pod.Container.ID())
496-
}
492+
log.L.WithError(err).Errorf("failed to get spec for sandbox container %s",
493+
pod.Container.ID())
497494
return criPod
498495
}
499-
500496
criPod.spec = spec
501497

502498
return criPod
@@ -644,12 +640,12 @@ func (p *criPodSandbox) GetPid() uint32 {
644640
type criContainer struct {
645641
api *API
646642
ctrs *containers.Container
647-
spec *specs.Spec
643+
spec *runtimespec.Spec
648644
meta *cstore.Metadata
649645
pid uint32
650646
}
651647

652-
func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
648+
func (a *API) nriContainer(ctr interface{}, spec *runtimespec.Spec) *criContainer {
653649
switch c := ctr.(type) {
654650
case *cstore.Container:
655651
ctx := ctrdutil.NamespacedContext()
@@ -662,7 +658,7 @@ func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
662658
spec, err := ctrd.Spec(ctx)
663659
if err != nil {
664660
log.L.WithError(err).Errorf("failed to get OCI Spec for container %s", ctrd.ID())
665-
spec = &specs.Spec{}
661+
spec = &runtimespec.Spec{}
666662
}
667663
task, err := ctrd.Task(ctx, nil)
668664
if err != nil {
@@ -703,7 +699,7 @@ func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
703699
return &criContainer{
704700
api: a,
705701
meta: &cstore.Metadata{},
706-
spec: &specs.Spec{},
702+
spec: &runtimespec.Spec{},
707703
}
708704
}
709705

0 commit comments

Comments
 (0)