Skip to content

Commit

Permalink
Use container info as get outpu
Browse files Browse the repository at this point in the history
  • Loading branch information
crosbymichael committed Aug 20, 2018
1 parent f49a445 commit 9a2e144
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apk add --no-cache git alpine-sdk make
ADD . /go/src/github.com/crosbymichael/boss
WORKDIR /go/src/github.com/crosbymichael/boss

RUN make
RUN make static

FROM scratch

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
PACKAGES=$(shell go list ./... | grep -v /vendor/)
REVISION=$(shell git rev-parse HEAD)
GO_LDFLAGS=-s -w -X github.com/crosbymichael/boss/version.Version=$(REVISION) -extldflags "-static"
GO_LDFLAGS=-s -w -X github.com/crosbymichael/boss/version.Version=$(REVISION)

all:
CGO_ENALBED=0 go build -v -ldflags '${GO_LDFLAGS}'
go build -v -ldflags '${GO_LDFLAGS}'

static:
CGO_ENALBED=0 go build -v -ldflags '${GO_LDFLAGS} -extldflags "-static"'

install:
@install boss /usr/local/bin/boss
Expand Down
15 changes: 8 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,24 @@ func (a *Agent) Get(ctx context.Context, req *v1.GetRequest) (*v1.GetResponse, e
if err != nil {
return nil, err
}
config, err := opts.GetConfig(ctx, container)
i, err := a.info(ctx, container)
if err != nil {
return nil, err
}
return &v1.GetResponse{
Container: config,
Container: i,
}, nil
}

func (a *Agent) listContainer(ctx context.Context, c containerd.Container) (*v1.ListContainer, error) {
func (a *Agent) info(ctx context.Context, c containerd.Container) (*v1.ContainerInfo, error) {
info, err := c.Info(ctx)
if err != nil {
return nil, err
}
task, err := c.Task(ctx, nil)
if err != nil {
if errdefs.IsNotFound(err) {
return &v1.ListContainer{
return &v1.ContainerInfo{
ID: c.ID(),
Image: info.Image,
Status: string(containerd.Stopped),
Expand Down Expand Up @@ -193,7 +193,7 @@ func (a *Agent) listContainer(ctx context.Context, c containerd.Container) (*v1.
if err != nil {
return nil, err
}
return &v1.ListContainer{
return &v1.ContainerInfo{
ID: c.ID(),
Image: info.Image,
Status: string(status.Status),
Expand All @@ -204,6 +204,7 @@ func (a *Agent) listContainer(ctx context.Context, c containerd.Container) (*v1.
PidUsage: cg.Pids.Current,
PidLimit: cg.Pids.Limit,
FsSize: usage.Size + bindSizes,
Config: cfg,
}, nil
}

Expand All @@ -215,9 +216,9 @@ func (a *Agent) List(ctx context.Context, req *v1.ListRequest) (*v1.ListResponse
return nil, err
}
for _, c := range containers {
l, err := a.listContainer(ctx, c)
l, err := a.info(ctx, c)
if err != nil {
resp.Containers = append(resp.Containers, &v1.ListContainer{
resp.Containers = append(resp.Containers, &v1.ContainerInfo{
ID: c.ID(),
Status: "list error",
})
Expand Down
Loading

0 comments on commit 9a2e144

Please sign in to comment.