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

Update golangci-lint, its config, and fix some warnings #3717

Merged
merged 10 commits into from
Jan 19, 2022

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jan 18, 2022

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Currently, golangci-lint used by this repo is old, and its configuration is unsafe (for updates, that it).

Fix both issues, run the updated linter, fix some of its warnings (surely those fixes come first to not break git-bisect).

Please see individual commits for details.

How to verify it

I hope that CI that runs on PRs is sufficient.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Some of the fixes are not too trivial, so a careful review is appreciated.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jan 18, 2022
@kolyshkin
Copy link
Contributor Author

TODO (once this is merged):

  • update other deps in test/tools
  • add test/tools to dependabot config

@rhatdan
Copy link
Member

rhatdan commented Jan 18, 2022

@nalind PTAL
Changes other then tests not running LGTM

@nalind
Copy link
Member

nalind commented Jan 18, 2022

Changes LGTM, but it looks like parts of tests/tools/vendor weren't included in the commit that updated other parts of it.

@TomSweeneyRedHat
Copy link
Member

LGTM once tests are happy

@kolyshkin
Copy link
Contributor Author

it looks like parts of tests/tools/vendor weren't included in the commit that updated other parts of it.

It seems I will never be able to do git add vendor from the first try 🤦🏻

Updated.

Fix this warning from gosimple linter:

>	util.go:127:19: S1040: type assertion to the same type: ref.DockerReference() already has type reference.Named (gosimple)
>			if named, ok := ref.DockerReference().(reference.Named); ok {
>					^

Since containers/image commit dfe2fafaa2d702e5a932721aed55b996024051b1
(made in 2017), DockerReference() always return reference.Named type.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fix the following warning:

> 	imagebuildah/executor.go:307:6: S1033: unnecessary guard around call to delete (gosimple)
>						if _, stillUnused := exec.unusedArgs[list[0]]; stillUnused {
>						^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
> tests/e2e/buildah_suite_test.go:166:27: S1025: the argument's underlying type is a slice of bytes, should use a simple conversion instead of fmt.Sprintf (gosimple)
> 	fields := strings.Fields(fmt.Sprintf("%s", s.Out.Contents()))
> 	                         ^
> tests/e2e/buildah_suite_test.go:173:12: S1025: the argument's underlying type is a slice of bytes, should use a simple conversion instead of fmt.Sprintf (gosimple)
> 	output := fmt.Sprintf("%s", s.Out.Contents())
> 	          ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
AKA "unnecessary use of fmt.Sprintf (gosimple)"

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Newer golangci-lint does not understand the nolint: directive
because it is followed by some comment.

To fix, add a comment before the (human) comment.

While at it, remove the space after // since comments targeted for
non-humans should not have space (this is currently not enforced by
golangci-lint).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Since commit 3eef1ed (January 2019) using
capabilities.NewPid() is deprecated.

Replace with NewPid2().

Note that in chroot/run.go we used to load then clear all capabilities
bits. With NewPid2, this is no longer needed -- we do not load caps, so
there is no need to clear.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 3a122aa added ignoring any file or directory named result,
which is wrong. What it meant to do is to ignore top-level result
directory. Fix accordingly.

Same for tests/tools -- this is meant to be the top-level directory
only.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
... and its dependencies.

Also, modify .golangci.yml since new golangci-lint no longer have some
of the linters mentioned. Besides, it is unsafe to enable all linters,
because (1) not all linters are good/useful; (2) new golangci-lint
releases can bring more linters and thus more CI issues. Instead, use
the default set of linters, plus enable a few more:

 * revive (which replaces golint)
 * unconvert

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
As pointed out by unparam linter, the bool returned by resolveName is
never used (at least since commit e1444dd).

Also, since commit dcd2a92, resolveName is no longer public.

Remove the bool and the code which calculates it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

Ah, now top-level .gitignore stands in a way of proper vendoring. Fixed.

@kolyshkin
Copy link
Contributor Author

@vrothberg can you please review the 0b86b16?

@kolyshkin
Copy link
Contributor Author

It seems like fedora CI failure is a temp glitch (quay.io timeout). Can someone please restart it?

[+2834s] not ok 535 pull image with TMPDIR set
[+2834s] # (from function die' in file ./helpers.bash, line 250, [+2834s] # from function run_buildah' in file ./helpers.bash, line 237,
[+2834s] # in test file ./pull.bats, line 366)
[+2834s] # `run_buildah pull --policy always --signature-policy ${TESTSDIR}/policy.json quay.io/libpod/alpine_nginx:latest' failed with status 125
[+2834s] # /var/tmp/go/src/github.com/containers/buildah/tests /var/tmp/go/src/github.com/containers/buildah/tests
[+2834s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah pull --policy always --signature-policy /var/tmp/go/src/github.com/containers/buildah/tests/./policy.json quay.io/libpod/alpine_nginx:latest
[+2834s] # Trying to pull quay.io/libpod/alpine_nginx:latest...
[+2834s] # Getting image source signatures
[+2834s] # Copying blob sha256:ac35fae19c6cb4820a5745bd6ce22fb9fe38c4d7e2225e184315cb4bc5e9ece8
[+2834s] # Copying blob sha256:4c0d98bf9879488e0407f897d9dd4bf758555a78e39675e72b5124ccf12c2580
[+2834s] # Copying blob sha256:5b0fccc9c35f7ea2f4a1c876e0a0be91677a378eb07361ba3e48ca86565d5790
[+2834s] # Copying blob sha256:4c0d98bf9879488e0407f897d9dd4bf758555a78e39675e72b5124ccf12c2580
[+2834s] # Copying blob sha256:ac35fae19c6cb4820a5745bd6ce22fb9fe38c4d7e2225e184315cb4bc5e9ece8
[+2834s] # Copying blob sha256:5b0fccc9c35f7ea2f4a1c876e0a0be91677a378eb07361ba3e48ca86565d5790
[+2834s] # writing blob: storing blob to file "/var/tmp/buildah_tests.ymqwhm/buildah-test/storage060557362/1": write /var/tmp/buildah_tests.ymqwhm/buildah-test/storage060557362/1: no space left on device
[+2834s] # [ rc=125 (expected) ]
[+2834s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah pull --policy always --signature-policy /var/tmp/go/src/github.com/containers/buildah/tests/./policy.json quay.io/libpod/alpine_nginx:latest
[+2834s] # Trying to pull quay.io/libpod/alpine_nginx:latest...
[+2834s] # Getting image source signatures
[+2834s] # Copying blob sha256:4c0d98bf9879488e0407f897d9dd4bf758555a78e39675e72b5124ccf12c2580
[+2834s] # Copying blob sha256:5b0fccc9c35f7ea2f4a1c876e0a0be91677a378eb07361ba3e48ca86565d5790
[+2834s] # Copying blob sha256:ac35fae19c6cb4820a5745bd6ce22fb9fe38c4d7e2225e184315cb4bc5e9ece8
[+2834s] # Copying blob sha256:5b0fccc9c35f7ea2f4a1c876e0a0be91677a378eb07361ba3e48ca86565d5790
[+2834s] # Copying blob sha256:4c0d98bf9879488e0407f897d9dd4bf758555a78e39675e72b5124ccf12c2580
[+2834s] # reading blob sha256:ac35fae19c6cb4820a5745bd6ce22fb9fe38c4d7e2225e184315cb4bc5e9ece8: Get "https://cdn02.quay.io/sha256/ac/ac35fae19c6cb4820a5745bd6ce22fb9fe38c4d7e2225e184315cb4bc5e9ece8?Expires=1642546144&Signature=E5~djLnUfA~pnSYnJ20lvLdLm3vEpMqOLfqWB4a7j9hYosc3aKX1kdjHZhVJbHgifjYyo4Y1Ss5Fe2gSGC4AkK6fL6P9bgbjiqH0zX2RKUtZSdJa9JXAYm2aRH35ChgE50gjAFuSarAgZIKujL28kLbACQVzF2aoO6uExP0WZFWwh56zhMmGcF~5R4srNfXXChZg0-zdniSjDCCYyB~DP0Wgg3Eqxx0DMSwBezcUE20AJgwT21uea79PaSDWwzKauGhFp3dPgpzEfLmnbBKB1D7RXlzC23dJOnH-dJ75d6Wb0KxJWS5bn8F2huro1JjcvvIobbbgxDoxH~-euTwvQw__&Key-Pair-Id=APKAJ67PQLWGCSP66DGA": net/http: TLS handshake timeout
[+2834s] # [ rc=125 (** EXPECTED 0 **) ]
[+2834s] # #/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
[+2834s] # #| FAIL: exit code is 125; expected 0
[+2834s] # #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[+2834s] # /var/tmp/go/src/github.com/containers/buildah/tests

@kolyshkin
Copy link
Contributor Author

"Unit tests w/ vfs" job timed out after 60 minutes. A flake?

@vrothberg
Copy link
Member

@vrothberg can you please review the 0b86b16?

LGTM, thanks for cleaning up!

@vrothberg
Copy link
Member

Restarted both failed jobs; looked like flakes to me.

@nalind
Copy link
Member

nalind commented Jan 19, 2022

LGTM, and since I don't see any unresolved requests for changes from other maintainers,
/lgtm

@rhatdan
Copy link
Member

rhatdan commented Jan 19, 2022

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kolyshkin, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 4b3aaee into containers:main Jan 19, 2022
@kolyshkin kolyshkin mentioned this pull request Jan 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm locked - please file new issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants