mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-14 02:27:07 +02:00
Fixes: #689, #690 Refactor container inspection code into a package of its own with some rudimentary tests. Use this package consistently in osd commands dealing with containers. Improvements for the next PRs: * implement API to fetch info about container by ID (to avoid fetching full list) * handle and display errors on client side, not to the log of the server * more tests, including k8s containers (how can we do that?) Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package containers
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"github.com/containerd/containerd"
|
|
tasks "github.com/containerd/containerd/api/services/tasks/v1"
|
|
"github.com/containerd/containerd/api/types"
|
|
)
|
|
|
|
// Container presents information about a container
|
|
type Container struct {
|
|
inspector *Inspector
|
|
|
|
Display string // Friendly Name
|
|
Name string // container name
|
|
ID string // container sha/id
|
|
Digest string // Container Digest
|
|
Image string
|
|
Status containerd.Status // Running state of container
|
|
Pid uint32
|
|
LogFile string
|
|
Metrics *types.Metric
|
|
}
|
|
|
|
// GetProcessStdout returns process stdout
|
|
func (c *Container) GetProcessStdout() (string, error) {
|
|
task, err := c.inspector.client.TaskService().Get(c.inspector.nsctx, &tasks.GetRequest{ContainerID: c.ID})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return task.Process.Stdout, nil
|
|
}
|
|
|
|
// Kill sends signal to container task
|
|
func (c *Container) Kill(signal syscall.Signal) error {
|
|
_, err := c.inspector.client.TaskService().Kill(c.inspector.nsctx, &tasks.KillRequest{ContainerID: c.ID, Signal: uint32(signal)})
|
|
return err
|
|
}
|