Code clean for nri_api.
Signed-off-by: yanggang <gang.yang@daocloud.io>
This commit is contained in:
parent
f2765617c5
commit
ed47102411
@ -32,7 +32,6 @@ import (
|
|||||||
"github.com/containerd/containerd/v2/pkg/errdefs"
|
"github.com/containerd/containerd/v2/pkg/errdefs"
|
||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
"github.com/containerd/typeurl/v2"
|
"github.com/containerd/typeurl/v2"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/opencontainers/runtime-tools/generate"
|
"github.com/opencontainers/runtime-tools/generate"
|
||||||
cri "k8s.io/cri-api/pkg/apis/runtime/v1"
|
cri "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
@ -117,7 +116,7 @@ func (a *API) RemovePodSandbox(ctx context.Context, criPod *sstore.Sandbox) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) CreateContainer(ctx context.Context, ctrs *containers.Container, spec *specs.Spec) (*api.ContainerAdjustment, error) {
|
func (a *API) CreateContainer(ctx context.Context, ctrs *containers.Container, spec *runtimespec.Spec) (*api.ContainerAdjustment, error) {
|
||||||
ctr := a.nriContainer(ctrs, spec)
|
ctr := a.nriContainer(ctrs, spec)
|
||||||
|
|
||||||
criPod, err := a.cri.SandboxStore().Get(ctr.GetPodSandboxID())
|
criPod, err := a.cri.SandboxStore().Get(ctr.GetPodSandboxID())
|
||||||
@ -256,7 +255,7 @@ func (a *API) RemoveContainer(ctx context.Context, criPod *sstore.Sandbox, criCt
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) UndoCreateContainer(ctx context.Context, criPod *sstore.Sandbox, id string, spec *specs.Spec) {
|
func (a *API) UndoCreateContainer(ctx context.Context, criPod *sstore.Sandbox, id string, spec *runtimespec.Spec) {
|
||||||
if a.IsDisabled() {
|
if a.IsDisabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -318,7 +317,7 @@ func (a *API) WithContainerAdjustment() containerd.NewContainerOpts {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return func(ctx context.Context, _ *containerd.Client, c *containers.Container) error {
|
return func(ctx context.Context, _ *containerd.Client, c *containers.Container) error {
|
||||||
spec := &specs.Spec{}
|
spec := &runtimespec.Spec{}
|
||||||
if err := json.Unmarshal(c.Spec.GetValue(), spec); err != nil {
|
if err := json.Unmarshal(c.Spec.GetValue(), spec); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal container OCI Spec for NRI: %w", err)
|
return fmt.Errorf("failed to unmarshal container OCI Spec for NRI: %w", err)
|
||||||
}
|
}
|
||||||
@ -463,14 +462,14 @@ func (a *API) EvictContainer(ctx context.Context, e *api.ContainerEviction) erro
|
|||||||
|
|
||||||
type criPodSandbox struct {
|
type criPodSandbox struct {
|
||||||
*sstore.Sandbox
|
*sstore.Sandbox
|
||||||
spec *specs.Spec
|
spec *runtimespec.Spec
|
||||||
pid uint32
|
pid uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) nriPodSandbox(pod *sstore.Sandbox) *criPodSandbox {
|
func (a *API) nriPodSandbox(pod *sstore.Sandbox) *criPodSandbox {
|
||||||
criPod := &criPodSandbox{
|
criPod := &criPodSandbox{
|
||||||
Sandbox: pod,
|
Sandbox: pod,
|
||||||
spec: &specs.Spec{},
|
spec: &runtimespec.Spec{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if pod == nil || pod.Container == nil {
|
if pod == nil || pod.Container == nil {
|
||||||
@ -489,14 +488,11 @@ func (a *API) nriPodSandbox(pod *sstore.Sandbox) *criPodSandbox {
|
|||||||
|
|
||||||
criPod.pid = task.Pid()
|
criPod.pid = task.Pid()
|
||||||
spec, err := task.Spec(ctx)
|
spec, err := task.Spec(ctx)
|
||||||
if err != nil {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.L.WithError(err).Errorf("failed to get spec for sandbox container %s",
|
log.L.WithError(err).Errorf("failed to get spec for sandbox container %s",
|
||||||
pod.Container.ID())
|
pod.Container.ID())
|
||||||
}
|
|
||||||
return criPod
|
return criPod
|
||||||
}
|
}
|
||||||
|
|
||||||
criPod.spec = spec
|
criPod.spec = spec
|
||||||
|
|
||||||
return criPod
|
return criPod
|
||||||
@ -644,12 +640,12 @@ func (p *criPodSandbox) GetPid() uint32 {
|
|||||||
type criContainer struct {
|
type criContainer struct {
|
||||||
api *API
|
api *API
|
||||||
ctrs *containers.Container
|
ctrs *containers.Container
|
||||||
spec *specs.Spec
|
spec *runtimespec.Spec
|
||||||
meta *cstore.Metadata
|
meta *cstore.Metadata
|
||||||
pid uint32
|
pid uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
|
func (a *API) nriContainer(ctr interface{}, spec *runtimespec.Spec) *criContainer {
|
||||||
switch c := ctr.(type) {
|
switch c := ctr.(type) {
|
||||||
case *cstore.Container:
|
case *cstore.Container:
|
||||||
ctx := ctrdutil.NamespacedContext()
|
ctx := ctrdutil.NamespacedContext()
|
||||||
@ -662,7 +658,7 @@ func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
|
|||||||
spec, err := ctrd.Spec(ctx)
|
spec, err := ctrd.Spec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.L.WithError(err).Errorf("failed to get OCI Spec for container %s", ctrd.ID())
|
log.L.WithError(err).Errorf("failed to get OCI Spec for container %s", ctrd.ID())
|
||||||
spec = &specs.Spec{}
|
spec = &runtimespec.Spec{}
|
||||||
}
|
}
|
||||||
task, err := ctrd.Task(ctx, nil)
|
task, err := ctrd.Task(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -703,7 +699,7 @@ func (a *API) nriContainer(ctr interface{}, spec *specs.Spec) *criContainer {
|
|||||||
return &criContainer{
|
return &criContainer{
|
||||||
api: a,
|
api: a,
|
||||||
meta: &cstore.Metadata{},
|
meta: &cstore.Metadata{},
|
||||||
spec: &specs.Spec{},
|
spec: &runtimespec.Spec{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user