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

bugfix: fix deadcode reports by gometalinter #2426

Merged
merged 1 commit into from
Nov 5, 2018

Conversation

ZYecho
Copy link
Contributor

@ZYecho ZYecho commented Nov 5, 2018

Signed-off-by: zhangyue [email protected]

Ⅰ. Describe what this PR did

As the title desc.

Ⅱ. Does this pull request fix one issue?

fix #2423

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

None.

Ⅳ. Describe how to verify it

None.

Ⅴ. Special notes for reviews

The go tool's report about the deadcode have many errors, such as PullImage and inspectFilter func obviously being used in other code, maybe caused by lacking of --tests opt when use gometalinter.
I have double-check based on the reports.

updated:
still have errors even if use gometalinter --tests --enable=deadcode ./...
more deadcode not included in the report, such as rootFSToAPIType in pouch/ctrd/utils.go

@codecov
Copy link

codecov bot commented Nov 5, 2018

Codecov Report

Merging #2426 into master will increase coverage by 0.42%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2426      +/-   ##
==========================================
+ Coverage   68.35%   68.77%   +0.42%     
==========================================
  Files         272      272              
  Lines       18206    18155      -51     
==========================================
+ Hits        12445    12487      +42     
+ Misses       4332     4254      -78     
+ Partials     1429     1414      -15
Flag Coverage Δ
#criv1alpha1test 31.49% <ø> (+0.21%) ⬆️
#criv1alpha2test 35.68% <ø> (+0.25%) ⬆️
#integrationtest 40.07% <ø> (+0.19%) ⬆️
#nodee2etest 32.97% <ø> (+0.24%) ⬆️
#unittest 26.52% <ø> (+0.07%) ⬆️
Impacted Files Coverage Δ
daemon/daemon.go 69.44% <ø> (+1.87%) ⬆️
ctrd/utils.go 90.41% <ø> (+25.7%) ⬆️
storage/quota/prjquota.go 27.51% <ø> (ø) ⬆️
daemon/mgr/spec_linux.go 78.3% <ø> (+3.78%) ⬆️
registry/auth.go 55.14% <ø> (+1.01%) ⬆️
storage/quota/grpquota.go 0% <ø> (ø) ⬆️
ctrd/container.go 58.89% <ø> (+1.18%) ⬆️
cri/v1alpha2/cri_utils.go 91.21% <0%> (+0.29%) ⬆️
cri/v1alpha1/cri.go 60.59% <0%> (+0.33%) ⬆️
daemon/mgr/container.go 58.79% <0%> (+0.43%) ⬆️
... and 8 more

@pouchrobot pouchrobot added kind/bug This is bug report for project size/L labels Nov 5, 2018
@pouchrobot pouchrobot added size/XL and removed size/L labels Nov 5, 2018
@allencloud
Copy link
Collaborator

code check fails with the error:

#!/bin/bash -eo pipefail
make check
gometalinter
gometalinter --config .gometalinter.json ./...
ctrd/container.go:1::warning: file is not gofmted with -s (gofmt)
pkg/utils/metrics/unit.go:1::warning: file is not gofmted with -s (gofmt)
ctrd/container.go:1::warning: file is not goimported (goimports)
pkg/utils/metrics/unit.go:1::warning: file is not goimported (goimports)
Makefile:151: recipe for target 'gometalinter' failed
make: *** [gometalinter] Error 1
Exited with code 2

Please take a look.

@ZYecho
Copy link
Contributor Author

ZYecho commented Nov 5, 2018

code check fails with the error:

#!/bin/bash -eo pipefail
make check
gometalinter
gometalinter --config .gometalinter.json ./...
ctrd/container.go:1::warning: file is not gofmted with -s (gofmt)
pkg/utils/metrics/unit.go:1::warning: file is not gofmted with -s (gofmt)
ctrd/container.go:1::warning: file is not goimported (goimports)
pkg/utils/metrics/unit.go:1::warning: file is not goimported (goimports)
Makefile:151: recipe for target 'gometalinter' failed
make: *** [gometalinter] Error 1
Exited with code 2

Please take a look.

updated.

test/util_api.go Outdated
@@ -150,15 +141,6 @@ func PauseContainerOk(c *check.C, cname string) {
CheckRespStatus(c, resp, 204)
}

// UnpauseContainerOk unpauses the container and asserts success..
Copy link
Collaborator

@allencloud allencloud Nov 5, 2018

Choose a reason for hiding this comment

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

For this part, I do not think removal of code is a good idea. Instead, I am afraid that we should try to take advantages of that in the test code, like:

	// unpause it
	resp, err = request.Post("/containers/" + cname + "/unpause")
	c.Assert(err, check.IsNil)
	CheckRespStatus(c, resp, 204)

WDYT? @ZYecho

Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition, maybe in another pr, we could use PauseContainerOk to replace

	resp, err := request.Post("/containers/" + cname + "/pause")
	c.Assert(err, check.IsNil)
	CheckRespStatus(c, resp, 204)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, replace it in the next patch.

@ZYecho ZYecho force-pushed the fix-deadcode branch 2 times, most recently from aadc4ea to cf12a38 Compare November 5, 2018 02:36
@pouchrobot pouchrobot added size/L and removed size/XL labels Nov 5, 2018
ctrd/utils.go Outdated
"net"
"net/http"
"time"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/pkg/errtypes"
"github.com/alibaba/pouch/pkg/utils"

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep the blank line, thanks

@@ -373,45 +373,17 @@ func setupNamespaces(ctx context.Context, c *Container, specWrapper *SpecWrapper
return setupUtsNamespace(ctx, c, specWrapper)
}

// isEmpty indicates whether namespace mode is empty.
Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @Ace-Tang to check this part.

@@ -258,23 +257,6 @@ func initLog() {
logrus.SetFormatter(formatter)
}

// define lxcfs processe.
func setLxcfsProcess(processes exec.Processes) exec.Processes {
Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @CodeJuan to check lxcfs part.

@@ -18,10 +18,6 @@ import (
"github.com/sirupsen/logrus"
)

var (
Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @rudyfly to check quota part.

@allencloud
Copy link
Collaborator

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 5, 2018
@allencloud allencloud merged commit 69b5035 into AliyunContainerService:master Nov 5, 2018
@allencloud
Copy link
Collaborator

Thanks a lot for your work. @ZYecho This will definitely decrease the maintenance effort.

And please help continue a followup pr to take advantages of common code in the test code, like PauseContainerOk , UnPauseContainerOk .

@ZYecho ZYecho deleted the fix-deadcode branch November 6, 2018 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project LGTM one maintainer or community participant agrees to merge the pull reuqest. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[linter issues] some deadcode are detected by tool gometalinter/deadcode
5 participants