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

Set up go workspace #6702

Merged
merged 10 commits into from
Apr 25, 2024
Merged

Set up go workspace #6702

merged 10 commits into from
Apr 25, 2024

Conversation

mook-as
Copy link
Contributor

@mook-as mook-as commented Apr 11, 2024

This sets up a go workspace to try to keep all of our various go bits in sync.

Note that we disable it for some of the CI because we do a sparse checkout (so not all of the modules are there).

This also includes a ton of lint fixes that this uncovers :( Sorry about that. It might be a good idea to review commit-by-commit; some commits (like the one about defer + fatal) might be best reviewed skipping whitespace.

@mook-as mook-as requested a review from Nino-K April 11, 2024 21:29
//go:build !unix

/*
Copyright © 2023 SUSE LLC
Copy link
Member

Choose a reason for hiding this comment

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

2024?

@@ -0,0 +1,12 @@
//go:build !windows
Copy link
Member

Choose a reason for hiding this comment

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

We should include the license header for the sake of consistency.

@@ -0,0 +1,9 @@
//go:build !debug
Copy link
Member

Choose a reason for hiding this comment

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

Same here, we should probably include the license header.

@@ -0,0 +1,20 @@
/*
Copyright © 2022 SUSE LLC
Copy link
Member

Choose a reason for hiding this comment

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

2024

@@ -0,0 +1,21 @@
/*
Copyright © 2023 SUSE LLC
Copy link
Member

Choose a reason for hiding this comment

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

2024

@@ -59,6 +60,8 @@ IP and port acting as a peer end of the tunnel.`,

func init() {
peerCmd.Flags().String("config-path", "", "Path to the vtunnel's yaml configuration file")
peerCmd.MarkFlagRequired("config-path")
if err := peerCmd.MarkFlagRequired("config-path"); err != nil {
logrus.WithError(err).Fatal("Failed to set up flags")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the same here, lowercase.

@@ -64,6 +65,8 @@ var certificatesCmd = &cobra.Command{
func init() {
certificatesCmd.Flags().StringSlice("stores", []string{"CA", "ROOT"}, "Certificate stores to enumerate")
certificatesViper.AutomaticEnv()
certificatesViper.BindPFlags(certificatesCmd.Flags())
if err := certificatesViper.BindPFlags(certificatesCmd.Flags()); err != nil {
logrus.WithError(err).Fatal("Failed to set up flags")
Copy link
Member

Choose a reason for hiding this comment

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

This one too, and the following.

@@ -53,6 +54,10 @@ type kubeConfig struct {
Extras map[string]interface{} `yaml:",inline"`
}

const (
Copy link
Member

Choose a reason for hiding this comment

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

does it have to be a multi-line style? can it be a single-line declaration since there is only one const?

@@ -0,0 +1,2 @@
// Package models contains the auto-generated OpenAPI models.
Copy link
Member

Choose a reason for hiding this comment

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

License header here too.

@@ -282,7 +282,7 @@ func (b *bindManager) mungeContainersCreateRequest(req *http.Request, contextVal

// containersCreateResponseBody describes the contents of a /containers/create response.
type containersCreateResponseBody struct {
Id string
Id string //nolint:stylecheck // Needs to match API
Copy link
Member

Choose a reason for hiding this comment

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

Should it use json struct tags instead?

Nino-K
Nino-K previously approved these changes Apr 22, 2024
Copy link
Member

@Nino-K Nino-K left a comment

Choose a reason for hiding this comment

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

LGTM, however, it looks like you have a merge conflict to deal with.

This ensures a cross-repo baseline of dependency versions.  This also means
the editors can better track cross-module definitions.

Signed-off-by: Mark Yen <[email protected]>
Dependabot still fails even if the generated packages are listed as an
ignored dependency.  Instead, check in stub files that can be used as
placeholders; they have no contents and therefore should not conflict with
the actual generated data.

Signed-off-by: Mark Yen <[email protected]>
This was already covered by "leave existing file" on line 76.

Signed-off-by: Mark Yen <[email protected]>
`deadcode`, `structcheck`, and `varcheck` have all been marked as
deprecated by golangci-lint; the recommended replacement is `unused` (which
we're already using).

Signed-off-by: Mark Yen <[email protected]>
- Remove gocyclo; in general, this is better replaced by human reviews.
- Disable `gocritic`'s `unnamedResult` rule; we don't seem to care about it
- Mark `os.FileMode` / `os.MkDir` as acceptable with magic numbers; those
  are file permissions, and typical usage uses permission bits.
- Add specific exclusion rules:
  - Disable a case of `stylecheck` not being aware that Windows is a proper
    noun.
  - Disable `lll` for function declarations where it's clearer to have all
    of the parameters on a single line.
  - We copied `vsock_linux.go` from a different project; leave the terse
    `FIXME` comments alone.
  - When using `syscall` (or its moral equivalent) to call FFI, allow
    ignoring the result.

Signed-off-by: Mark Yen <[email protected]>
This was triggered by the linter.

Signed-off-by: Mark Yen <[email protected]>
When we call `log.Fatalf()` or similar that ends up calling `os.Exit()`, we
don't run any deferred statements.  This gets picked up by the linter as an
issue.  Work around this by wrapping the bulk in an inner function, and
then calling `log.Fatalf()` outside of it (after all of the deferred
statements have been run).

Signed-off-by: Mark Yen <[email protected]>
Make packages build across all platforms (because the code analysis falls
over if a dependency is not available on the given platform).

Signed-off-by: Mark Yen <[email protected]>
These are lint errors that are more local in nature; for example:

- io/ioutil is deprecated
- name constants instead of magic numbers all over
- avoid shadowing
- explicitly ignore returned errors in defer statements

Signed-off-by: Mark Yen <[email protected]>
Signed-off-by: Mark Yen <[email protected]>
@mook-as mook-as enabled auto-merge April 25, 2024 16:54
@mook-as mook-as merged commit 57191c5 into rancher-sandbox:main Apr 25, 2024
14 checks passed
@mook-as mook-as deleted the go-workspace branch April 25, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants