Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inspect container #841

Merged
merged 23 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
436c3db
feat: inspect container
AmorfEvo Oct 5, 2023
8088533
feat: use prefix and name in container inspect message
AmorfEvo Oct 5, 2023
642fa16
feat: agent and api call (wip)
AmorfEvo Oct 5, 2023
0739813
feat: agent and api call
AmorfEvo Oct 5, 2023
07560fa
chore: linting
AmorfEvo Oct 5, 2023
a5edcc2
feat: container inspection ui (wip)
AmorfEvo Oct 6, 2023
76f8409
feat: container inspection ui (wip)
AmorfEvo Oct 6, 2023
e7ec04e
Merge branch 'develop' into feat/container-inspect
AmorfEvo Oct 9, 2023
147b0dd
chore: remove unused container identifier from container inspection dto
AmorfEvo Oct 9, 2023
606d839
feat: add inspect container endpoint to node global container control…
AmorfEvo Oct 9, 2023
55c030e
doc: better descriptions and summaries on node prefix container contr…
AmorfEvo Oct 9, 2023
f70f5a3
refactor: rename and move secret timeout to shared consts
AmorfEvo Oct 9, 2023
c97741e
refactor: distinct timeout const for inspection too
AmorfEvo Oct 9, 2023
423535d
Merge branch 'develop' into feat/container-inspect
AmorfEvo Oct 10, 2023
2e72e86
feat: container inspection ui with json viewer
AmorfEvo Oct 10, 2023
2576cb3
fix: agent test and linting
AmorfEvo Oct 10, 2023
e57acaf
feat: container inspection ui table view (wip)
AmorfEvo Oct 10, 2023
4e963eb
feat: add node connection status unreachable
AmorfEvo Oct 10, 2023
3c2af03
feat: handle unknown container error
AmorfEvo Oct 10, 2023
93b1ae0
feat: container inspection ui table view
AmorfEvo Oct 10, 2023
5d2f3e8
Merge branch 'develop' into feat/container-inspect
AmorfEvo Oct 10, 2023
176e967
refactor: just code cleaning
AmorfEvo Oct 11, 2023
8bec2ab
Merge branch 'feat/container-inspect' of github.com:dyrector-io/dyrec…
AmorfEvo Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions golang/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type (
ContainerCommandFunc func(context.Context, *common.ContainerCommandRequest) error
DeleteContainersFunc func(context.Context, *common.DeleteContainersRequest) error
ContainerLogFunc func(context.Context, *agent.ContainerLogRequest) (*ContainerLogContext, error)
ContainerInspectFunc func(context.Context, *agent.ContainerInspectRequest) (string, error)
ReplaceTokenFunc func(context.Context, *agent.ReplaceTokenRequest) error
)

Expand All @@ -105,6 +106,7 @@ type WorkerFunctions struct {
ContainerCommand ContainerCommandFunc
DeleteContainers DeleteContainersFunc
ContainerLog ContainerLogFunc
ContainerInspect ContainerInspectFunc
}

type contextKey int
Expand Down Expand Up @@ -271,6 +273,8 @@ func (cl *ClientLoop) grpcProcessCommand(command *agent.AgentCommand) {
go executeDeleteMultipleContainers(cl.Ctx, command.GetDeleteContainers(), cl.WorkerFuncs.DeleteContainers)
case command.GetContainerLog() != nil:
go executeContainerLog(cl.Ctx, command.GetContainerLog(), cl.WorkerFuncs.ContainerLog)
case command.GetContainerInspect() != nil:
go executeContainerInspect(cl.Ctx, command.GetContainerInspect(), cl.WorkerFuncs.ContainerInspect)
case command.GetReplaceToken() != nil:
// NOTE(@m8vago): should be sync?
err := cl.executeReplaceToken(command.GetReplaceToken())
Expand Down Expand Up @@ -837,6 +841,35 @@ func executeContainerLog(ctx context.Context, command *agent.ContainerLogRequest
log.Trace().Str("prefix", prefix).Str("name", name).Msg("Container log exited")
}

func executeContainerInspect(ctx context.Context, command *agent.ContainerInspectRequest, inspectFunc ContainerInspectFunc) {
if inspectFunc == nil {
log.Error().Msg("Container inspect function not implemented")
return
}

prefix := command.Container.Prefix
name := command.Container.Name

log.Info().Str("prefix", prefix).Str("name", name).Msg("Getting container inspection")

inspection, err := inspectFunc(ctx, command)
if err != nil {
log.Error().Stack().Err(err).Msg("Failed to inspect container")
}

resp := &common.ContainerInspectMessage{
Prefix: prefix,
Name: name,
Inspection: inspection,
}

_, err = grpcConn.Client.ContainerInspect(ctx, resp)
if err != nil {
log.Error().Stack().Err(err).Msg("Container inspection response error")
return
}
}

func (cl *ClientLoop) executeReplaceToken(command *agent.ReplaceTokenRequest) error {
log.Debug().Msg("Replace token requested")

Expand Down
1 change: 1 addition & 0 deletions golang/pkg/dagent/dagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Serve(cfg *config.Configuration) {
ContainerCommand: utils.ContainerCommand,
DeleteContainers: utils.DeleteContainers,
ContainerLog: utils.ContainerLog,
ContainerInspect: utils.ContainerInspect,
}, cfg)
}

Expand Down
32 changes: 32 additions & 0 deletions golang/pkg/dagent/utils/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -785,3 +786,34 @@ func ContainerLog(ctx context.Context, request *agent.ContainerLogRequest) (*grp

return logContext, nil
}

func ContainerInspect(ctx context.Context, request *agent.ContainerInspectRequest) (string, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return "", err
}

prefix := request.Container.Prefix
name := request.Container.Name

cont, err := GetContainerByPrefixAndName(ctx, cli, prefix, name)
if cont == nil {
return "", &UnknownContainerError{}
nandor-magyar marked this conversation as resolved.
Show resolved Hide resolved
}
if err != nil {
return "", err
}

containerInfo, err := cli.ContainerInspect(ctx, cont.ID)
if err != nil {
return "", err
}

inspectionJSON, err := json.Marshal(containerInfo)
if err != nil {
return "", err
}
inspection := string(inspectionJSON)

return inspection, nil
}
1,087 changes: 591 additions & 496 deletions protobuf/go/agent/agent.pb.go

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions protobuf/go/agent/agent_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading