Skip to content

Conversation

@samuelkarp
Copy link
Member

The -local flag allows us to separate imports that originate from github.com/containerd/containerd from other imports, making it more clear where various imports come from.

Files can be formatted using the following command:

goimports -w -local github.com/containerd/containerd

To reformat all Go source files (excluding vendor and .pb.go):

goimports -w -local github.com/containerd/containerd \
  $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "*.pb.go")

The -local flag allows us to separate imports that originate from
github.com/containerd/containerd from other imports, making it more
clear where various imports come from.

Files can be formatted using the following command:

goimports -w -local github.com/containerd/containerd

To reformat all Go source files (excluding vendor and .pb.go):

goimports -w -local github.com/containerd/containerd \
  $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "*.pb.go")

Signed-off-by: Samuel Karp <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments inline

Some thoughts in general;

  • This will be disruptive for some time
    • cause quite some merge conflicts on open PRs
    • switching between branches (main <--> 1.6 LTS) will require switching tooling settings to use the expected convention
  • The linter apparently doesn't do a great job on checking these, and doesn't enforce "3 groups (stdlib, external, local)"
  • If we want this format to be enforced, perhaps we need a make fmt target, otherwise contributors must type goimports -w --local github.com/containerd/containerd . (which is a lot to type)

I'm also wondering (if we go ahead with this) would it make sense to change "local" to github.com/containerd/ (all imports from within the containerd org)?

  • Packages may move around within the org, and perhaps we want to make that less disruptive
  • How should separate modules be treated? e.g. if github.com/containerd/containerd/api becomes its own module, is it still "local"? It's in the same repo, but effectively "non-local"

"sync"
"time"

"github.com/sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this one needs to be together with the one below

Comment on lines 43 to 45
"k8s.io/klog/v2"

internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should go together

Comment on lines +47 to 49
internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"

"github.com/containerd/containerd/integration/remote/util"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should go together

Comment on lines 44 to 46
"k8s.io/klog/v2"

internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"
"k8s.io/component-base/logs/logreduction"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should to together

Comment on lines +50 to 52
internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"

"github.com/containerd/containerd/integration/remote/util"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should to together

Comment on lines 28 to 30

snapshotstore "github.com/containerd/containerd/pkg/cri/store/snapshot"
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these together with the containerd group above

Comment on lines +25 to 27
"github.com/containerd/containerd/version"

"github.com/containerd/containerd/pkg/cri/constants"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these together

Comment on lines 32 to 34
"golang.org/x/sys/unix"

"github.com/containerd/console"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these together

Comment on lines +28 to 30
"github.com/containerd/containerd/pkg/shutdown"

api "github.com/containerd/containerd/api/runtime/sandbox/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these together

Comment on lines +24 to 26
"github.com/containerd/containerd/services"

api "github.com/containerd/containerd/api/services/sandbox/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these together

@thaJeztah
Copy link
Member

ARF, GITHUB! Looks like you need to "expand" to see all review comments (they should really fix this)

Screenshot 2022-10-15 at 13 20 00

@samuelkarp
Copy link
Member Author

Thanks for the thorough review @thaJeztah!

  • This will be disruptive for some time
    • cause quite some merge conflicts on open PRs

Yep, I want to see what everyone else thinks about this. It'll definitely be disruptive, but I think it makes the imports clearer (and it'll reduce the chance of me/my IDE changing them in other unrelated PRs 😆).

  • switching between branches (main <--> 1.6 LTS) will require switching tooling settings to use the expected convention

If we're onboard with this change, I think we can do the same thing on the 1.5 and 1.6 branches as well.

  • The linter apparently doesn't do a great job on checking these, and doesn't enforce "3 groups (stdlib, external, local)"

My preference would be to do this with goimports since it's more of a standard tool, but I'm open to other opinions.

  • If we want this format to be enforced, perhaps we need a make fmt target, otherwise contributors must type goimports -w --local github.com/containerd/containerd . (which is a lot to type)

I can do this.

  • I'm also wondering (if we go ahead with this) would it make sense to change "local" to github.com/containerd/ (all imports from within the containerd org)?
    • Packages may move around within the org, and perhaps we want to make that less disruptive
    • How should separate modules be treated? e.g. if github.com/containerd/containerd/api becomes its own module, is it still "local"? It's in the same repo, but effectively "non-local"

I thought about these too and landed on github.com/containerd/containerd as the grouping because I think the same-repository indication was the most meaningful to me; I can see that changes within the same repo are coordinated while cross-repo changes require additional updates.

@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 7 days unless new comments are made or the stale label is removed.

@github-actions github-actions bot added the Stale label Mar 28, 2024
@github-actions
Copy link

github-actions bot commented Apr 4, 2024

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants