Skip to content

Commit 69b5035

Browse files
zhangyueallencloud
authored andcommitted
bugfix: fix deadcode reports by gometalinter
Signed-off-by: zhangyue <[email protected]>
1 parent b83956b commit 69b5035

File tree

11 files changed

+4
-149
lines changed

11 files changed

+4
-149
lines changed

ctrd/container.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import (
3232
)
3333

3434
var (
35-
runtimeRoot = "/run"
36-
defaultTrylockTimeout = 5 * time.Second
35+
runtimeRoot = "/run"
3736
)
3837

3938
type containerPack struct {

ctrd/utils.go

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@ package ctrd
33
import (
44
"context"
55
"crypto/tls"
6-
"encoding/json"
76
"net"
87
"net/http"
98
"time"
109

1110
"github.com/alibaba/pouch/apis/types"
1211
"github.com/alibaba/pouch/pkg/errtypes"
13-
"github.com/alibaba/pouch/pkg/utils"
1412

1513
"github.com/containerd/containerd/containers"
1614
"github.com/containerd/containerd/errdefs"
1715
"github.com/containerd/containerd/namespaces"
1816
"github.com/containerd/containerd/oci"
1917
"github.com/containerd/containerd/remotes"
2018
"github.com/containerd/containerd/remotes/docker"
21-
"github.com/opencontainers/go-digest"
2219
"github.com/opencontainers/image-spec/specs-go/v1"
23-
specs "github.com/opencontainers/runtime-spec/specs-go"
20+
"github.com/opencontainers/runtime-spec/specs-go"
2421
"github.com/pkg/errors"
2522
)
2623

@@ -80,19 +77,6 @@ func resolver(authConfig *types.AuthConfig) (remotes.Resolver, error) {
8077
return docker.NewResolver(options), nil
8178
}
8279

83-
// generateID generates image's ID by the SHA256 hash of its configuration JSON.
84-
func generateID(config *types.ImageInfo) (digest.Digest, error) {
85-
var ID digest.Digest
86-
87-
b, err := json.Marshal(config)
88-
if err != nil {
89-
return ID, err
90-
}
91-
92-
ID = digest.FromBytes(b)
93-
return ID, nil
94-
}
95-
9680
// rootFSToAPIType transfer the rootfs from OCI format to Pouch format.
9781
func rootFSToAPIType(rootFs *v1.RootFS) types.ImageInfoRootFS {
9882
var layers []string
@@ -105,39 +89,6 @@ func rootFSToAPIType(rootFs *v1.RootFS) types.ImageInfoRootFS {
10589
}
10690
}
10791

108-
// ociImageToPouchImage transfer the image from OCI format to Pouch format.
109-
func ociImageToPouchImage(ociImage v1.Image) (types.ImageInfo, error) {
110-
imageConfig := ociImage.Config
111-
112-
volumes := make(map[string]interface{})
113-
for k, obj := range imageConfig.Volumes {
114-
volumes[k] = obj
115-
}
116-
cfg := &types.ContainerConfig{
117-
// TODO: add more fields
118-
User: imageConfig.User,
119-
Env: imageConfig.Env,
120-
Entrypoint: imageConfig.Entrypoint,
121-
Cmd: imageConfig.Cmd,
122-
WorkingDir: imageConfig.WorkingDir,
123-
Labels: imageConfig.Labels,
124-
StopSignal: imageConfig.StopSignal,
125-
Volumes: volumes,
126-
}
127-
128-
rootFs := rootFSToAPIType(&ociImage.RootFS)
129-
130-
// FIXME need to refactor it and the ociImage's list interface.
131-
imageInfo := types.ImageInfo{
132-
Architecture: ociImage.Architecture,
133-
Config: cfg,
134-
CreatedAt: ociImage.Created.Format(utils.TimeLayout),
135-
Os: ociImage.OS,
136-
RootFS: &rootFs,
137-
}
138-
return imageInfo, nil
139-
}
140-
14192
// toLinuxResources transfers Pouch Resources to LinuxResources.
14293
func toLinuxResources(resources types.Resources) (*specs.LinuxResources, error) {
14394
r := &specs.LinuxResources{}

daemon/daemon.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"path"
77
"path/filepath"
8-
"plugin"
98
"reflect"
109

1110
"github.com/alibaba/pouch/apis/server"
@@ -24,8 +23,6 @@ import (
2423

2524
systemddaemon "github.com/coreos/go-systemd/daemon"
2625
systemdutil "github.com/coreos/go-systemd/util"
27-
"github.com/gorilla/mux"
28-
"github.com/pkg/errors"
2926
"github.com/sirupsen/logrus"
3027
)
3128

@@ -52,12 +49,6 @@ type Daemon struct {
5249
eventsService *events.Events
5350
}
5451

55-
// router represents the router of daemon.
56-
type router struct {
57-
daemon *Daemon
58-
*mux.Router
59-
}
60-
6152
// NewDaemon constructs a brand new server.
6253
func NewDaemon(cfg *config.Config) *Daemon {
6354
containerStore, err := meta.NewStore(meta.Config{
@@ -117,14 +108,6 @@ func NewDaemon(cfg *config.Config) *Daemon {
117108
}
118109
}
119110

120-
func loadSymbolByName(p *plugin.Plugin, name string) (plugin.Symbol, error) {
121-
s, err := p.Lookup(name)
122-
if err != nil {
123-
return nil, errors.Wrapf(err, "lookup plugin with name %s error", name)
124-
}
125-
return s, nil
126-
}
127-
128111
func (d *Daemon) loadPlugin() error {
129112
var err error
130113

daemon/mgr/spec_linux.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -373,45 +373,17 @@ func setupNamespaces(ctx context.Context, c *Container, specWrapper *SpecWrapper
373373
return setupUtsNamespace(ctx, c, specWrapper)
374374
}
375375

376-
// isEmpty indicates whether namespace mode is empty.
377-
func isEmpty(mode string) bool {
378-
return mode == ""
379-
}
380-
381-
// isNone indicates whether container's namespace mode is set to "none".
382-
func isNone(mode string) bool {
383-
return mode == "none"
384-
}
385-
386376
// isHost indicates whether the container shares the host's corresponding namespace.
387377
func isHost(mode string) bool {
388378
return mode == "host"
389379
}
390380

391-
// isShareable indicates whether the containers namespace can be shared with another container.
392-
func isShareable(mode string) bool {
393-
return mode == "shareable"
394-
}
395-
396381
// isContainer indicates whether the container uses another container's corresponding namespace.
397382
func isContainer(mode string) bool {
398383
parts := strings.SplitN(mode, ":", 2)
399384
return len(parts) > 1 && parts[0] == "container"
400385
}
401386

402-
// isPrivate indicates whether the container uses its own namespace.
403-
func isPrivate(ns specs.LinuxNamespaceType, mode string) bool {
404-
switch ns {
405-
case specs.IPCNamespace:
406-
return mode == "private"
407-
case specs.NetworkNamespace, specs.PIDNamespace:
408-
return !(isHost(mode) || isContainer(mode))
409-
case specs.UserNamespace, specs.UTSNamespace:
410-
return !(isHost(mode))
411-
}
412-
return false
413-
}
414-
415387
// connectedContainer is the id or name of the container whose namespace this container share with.
416388
func connectedContainer(mode string) string {
417389
parts := strings.SplitN(mode, ":", 2)

main.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/alibaba/pouch/daemon/config"
1818
"github.com/alibaba/pouch/lxcfs"
1919
"github.com/alibaba/pouch/pkg/debug"
20-
"github.com/alibaba/pouch/pkg/exec"
2120
"github.com/alibaba/pouch/pkg/utils"
2221
"github.com/alibaba/pouch/storage/quota"
2322
"github.com/alibaba/pouch/version"
@@ -258,23 +257,6 @@ func initLog() {
258257
logrus.SetFormatter(formatter)
259258
}
260259

261-
// define lxcfs processe.
262-
func setLxcfsProcess(processes exec.Processes) exec.Processes {
263-
if !cfg.IsLxcfsEnabled {
264-
return processes
265-
}
266-
267-
p := &exec.Process{
268-
Path: cfg.LxcfsBinPath,
269-
Args: []string{
270-
cfg.LxcfsHome,
271-
},
272-
}
273-
processes = append(processes, p)
274-
275-
return processes
276-
}
277-
278260
// check lxcfs config
279261
func checkLxcfsCfg() error {
280262
if !cfg.IsLxcfsEnabled {

pkg/utils/metrics/unit.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package metrics
55
type Unit string
66

77
const (
8-
nanoseconds Unit = "nanoseconds"
9-
seconds Unit = "seconds"
10-
bytes Unit = "bytes"
11-
total Unit = "total"
8+
seconds Unit = "seconds"
9+
total Unit = "total"
1210
)

registry/auth.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func genRegistryEndpoints(addr string) (endpoints []registryEndpoint) {
7070
return endpoints
7171
}
7272

73-
// TODO: generate v2 registry endpoint for login
74-
func genV1Endpoints(addr string) registryEndpoint {
75-
return registryEndpoint{}
76-
}
77-
7873
func genV2Endpoints(addr string) registryEndpoint {
7974
if addr == "" {
8075
addr = defaultV2Registry

storage/quota/grpquota.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import (
1818
"github.com/sirupsen/logrus"
1919
)
2020

21-
var (
22-
grpQuotaType = "grpquota"
23-
)
24-
2521
// GrpQuotaDriver represents group quota driver.
2622
type GrpQuotaDriver struct {
2723
lock sync.Mutex

storage/quota/prjquota.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import (
1818
"github.com/sirupsen/logrus"
1919
)
2020

21-
var (
22-
prjQuotaType = "prjquota"
23-
)
24-
2521
// PrjQuotaDriver represents project quota driver.
2622
type PrjQuotaDriver struct {
2723
lock sync.Mutex

test/util_api.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,6 @@ func CheckContainerRunning(c *check.C, cname string, isRunning bool) {
124124
c.Assert(gotRunning, check.Equals, isRunning)
125125
}
126126

127-
// DelContainerForceOk forcely deletes the container and asserts success.
128-
func DelContainerForceOk(c *check.C, cname string) {
129-
resp, err := delContainerForce(cname)
130-
c.Assert(err, check.IsNil)
131-
132-
defer resp.Body.Close()
133-
CheckRespStatus(c, resp, 204)
134-
}
135-
136127
func delContainerForce(cname string) (*http.Response, error) {
137128
q := url.Values{}
138129
q.Add("force", "true")
@@ -154,7 +145,6 @@ func PauseContainerOk(c *check.C, cname string) {
154145
func UnpauseContainerOk(c *check.C, cname string) {
155146
resp, err := request.Post("/containers/" + cname + "/unpause")
156147
c.Assert(err, check.IsNil)
157-
158148
defer resp.Body.Close()
159149
CheckRespStatus(c, resp, 204)
160150
}

0 commit comments

Comments
 (0)