Skip to content

Commit

Permalink
fix: refactor pkg/infoutil in order to resolve import cycle
Browse files Browse the repository at this point in the history
This pull request will add the fields such as `CONTAINER_NAME` and
`IMAGE_NAME` to the journald log entries sent by containers when
`nerdctl run` is run with `--log-driver=journald`.

However, the following `import cycle not allowed` error occurs when trying
to import `containerutil package` in `logging package` in the
implementation to be changed in this pull request.

```
> make
CGO_ENABLED=0 GOOS=linux go -C /local/home/haytok/workspace/nerdctl build -ldflags "-s -w  -X github.com/containerd/nerdctl/v2/pkg/version.Version=0d7dc8ec.m -X github.com/containerd/nerdctl/v2/pkg/version.Revision=0d7dc8ec4cda815acfca165b0281e801c4c5ef6e.m"   -o /local/home/haytok/workspace/nerdctl/_output/nerdctl ./cmd/nerdctl
package github.com/containerd/nerdctl/v2/cmd/nerdctl
...
	imports github.com/containerd/nerdctl/v2/pkg/infoutil: import cycle not allowed
make: *** [nerdctl] Error 1
```

Therefore, this commit refactors `infoutil package` to avoid
`import cycle not allowd` error in the next commit.

Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
  • Loading branch information
haytok committed Nov 20, 2024
1 parent db20fec commit f128aac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/cmd/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/containerd/nerdctl/v2/pkg/infoutil"
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
"github.com/containerd/nerdctl/v2/pkg/logging"
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
"github.com/containerd/nerdctl/v2/pkg/strutil"
)
Expand Down Expand Up @@ -72,6 +73,7 @@ func Info(ctx context.Context, client *containerd.Client, options types.SystemIn
if err != nil {
return err
}
infoCompat.Plugins.Log = logging.Drivers()
default:
return fmt.Errorf("unknown mode %q", options.Mode)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/infoutil/infoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/containerd/nerdctl/v2/pkg/buildkitutil"
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
"github.com/containerd/nerdctl/v2/pkg/logging"
"github.com/containerd/nerdctl/v2/pkg/version"
)

Expand Down Expand Up @@ -82,7 +81,6 @@ func Info(ctx context.Context, client *containerd.Client, snapshotter, cgroupMan
info.ID = daemonIntro.UUID
// Storage drivers and logging drivers are not really Server concept for nerdctl, but mimics `docker info` output
info.Driver = snapshotter
info.Plugins.Log = logging.Drivers()
info.Plugins.Storage = snapshotterPlugins
info.SystemTime = time.Now().Format(time.RFC3339Nano)
info.LoggingDriver = "json-file" // hard-coded
Expand Down

0 comments on commit f128aac

Please sign in to comment.