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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ctrd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
)

var (
runtimeRoot = "/run"
defaultTrylockTimeout = 5 * time.Second
runtimeRoot = "/run"
)

type containerPack struct {
Expand Down
51 changes: 1 addition & 50 deletions ctrd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ package ctrd
import (
"context"
"crypto/tls"
"encoding/json"
"net"
"net/http"
"time"

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

"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)

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

// generateID generates image's ID by the SHA256 hash of its configuration JSON.
func generateID(config *types.ImageInfo) (digest.Digest, error) {
var ID digest.Digest

b, err := json.Marshal(config)
if err != nil {
return ID, err
}

ID = digest.FromBytes(b)
return ID, nil
}

// rootFSToAPIType transfer the rootfs from OCI format to Pouch format.
func rootFSToAPIType(rootFs *v1.RootFS) types.ImageInfoRootFS {
var layers []string
Expand All @@ -105,39 +89,6 @@ func rootFSToAPIType(rootFs *v1.RootFS) types.ImageInfoRootFS {
}
}

// ociImageToPouchImage transfer the image from OCI format to Pouch format.
fuweid marked this conversation as resolved.
Show resolved Hide resolved
func ociImageToPouchImage(ociImage v1.Image) (types.ImageInfo, error) {
imageConfig := ociImage.Config

volumes := make(map[string]interface{})
for k, obj := range imageConfig.Volumes {
volumes[k] = obj
}
cfg := &types.ContainerConfig{
// TODO: add more fields
User: imageConfig.User,
Env: imageConfig.Env,
Entrypoint: imageConfig.Entrypoint,
Cmd: imageConfig.Cmd,
WorkingDir: imageConfig.WorkingDir,
Labels: imageConfig.Labels,
StopSignal: imageConfig.StopSignal,
Volumes: volumes,
}

rootFs := rootFSToAPIType(&ociImage.RootFS)

// FIXME need to refactor it and the ociImage's list interface.
imageInfo := types.ImageInfo{
Architecture: ociImage.Architecture,
Config: cfg,
CreatedAt: ociImage.Created.Format(utils.TimeLayout),
Os: ociImage.OS,
RootFS: &rootFs,
}
return imageInfo, nil
}

// toLinuxResources transfers Pouch Resources to LinuxResources.
func toLinuxResources(resources types.Resources) (*specs.LinuxResources, error) {
r := &specs.LinuxResources{}
Expand Down
17 changes: 0 additions & 17 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"path"
"path/filepath"
"plugin"
"reflect"

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

systemddaemon "github.com/coreos/go-systemd/daemon"
systemdutil "github.com/coreos/go-systemd/util"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand All @@ -52,12 +49,6 @@ type Daemon struct {
eventsService *events.Events
}

// router represents the router of daemon.
type router struct {
daemon *Daemon
*mux.Router
}

// NewDaemon constructs a brand new server.
func NewDaemon(cfg *config.Config) *Daemon {
containerStore, err := meta.NewStore(meta.Config{
Expand Down Expand Up @@ -117,14 +108,6 @@ func NewDaemon(cfg *config.Config) *Daemon {
}
}

func loadSymbolByName(p *plugin.Plugin, name string) (plugin.Symbol, error) {
s, err := p.Lookup(name)
if err != nil {
return nil, errors.Wrapf(err, "lookup plugin with name %s error", name)
}
return s, nil
}

func (d *Daemon) loadPlugin() error {
var err error

Expand Down
28 changes: 0 additions & 28 deletions daemon/mgr/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

func isEmpty(mode string) bool {
return mode == ""
}

// isNone indicates whether container's namespace mode is set to "none".
func isNone(mode string) bool {
return mode == "none"
}

// isHost indicates whether the container shares the host's corresponding namespace.
func isHost(mode string) bool {
return mode == "host"
}

// isShareable indicates whether the containers namespace can be shared with another container.
func isShareable(mode string) bool {
return mode == "shareable"
}

// isContainer indicates whether the container uses another container's corresponding namespace.
func isContainer(mode string) bool {
parts := strings.SplitN(mode, ":", 2)
return len(parts) > 1 && parts[0] == "container"
}

// isPrivate indicates whether the container uses its own namespace.
func isPrivate(ns specs.LinuxNamespaceType, mode string) bool {
switch ns {
case specs.IPCNamespace:
return mode == "private"
case specs.NetworkNamespace, specs.PIDNamespace:
return !(isHost(mode) || isContainer(mode))
case specs.UserNamespace, specs.UTSNamespace:
return !(isHost(mode))
}
return false
}

// connectedContainer is the id or name of the container whose namespace this container share with.
func connectedContainer(mode string) string {
parts := strings.SplitN(mode, ":", 2)
Expand Down
18 changes: 0 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/lxcfs"
"github.com/alibaba/pouch/pkg/debug"
"github.com/alibaba/pouch/pkg/exec"
"github.com/alibaba/pouch/pkg/utils"
"github.com/alibaba/pouch/storage/quota"
"github.com/alibaba/pouch/version"
Expand Down Expand Up @@ -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.

if !cfg.IsLxcfsEnabled {
return processes
}

p := &exec.Process{
Path: cfg.LxcfsBinPath,
Args: []string{
cfg.LxcfsHome,
},
}
processes = append(processes, p)

return processes
}

// check lxcfs config
func checkLxcfsCfg() error {
if !cfg.IsLxcfsEnabled {
Expand Down
6 changes: 2 additions & 4 deletions pkg/utils/metrics/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package metrics
type Unit string

const (
nanoseconds Unit = "nanoseconds"
seconds Unit = "seconds"
bytes Unit = "bytes"
total Unit = "total"
seconds Unit = "seconds"
total Unit = "total"
)
5 changes: 0 additions & 5 deletions registry/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func genRegistryEndpoints(addr string) (endpoints []registryEndpoint) {
return endpoints
}

// TODO: generate v2 registry endpoint for login
func genV1Endpoints(addr string) registryEndpoint {
return registryEndpoint{}
}

func genV2Endpoints(addr string) registryEndpoint {
if addr == "" {
addr = defaultV2Registry
Expand Down
4 changes: 0 additions & 4 deletions storage/quota/grpquota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

grpQuotaType = "grpquota"
)

// GrpQuotaDriver represents group quota driver.
type GrpQuotaDriver struct {
lock sync.Mutex
Expand Down
4 changes: 0 additions & 4 deletions storage/quota/prjquota.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"github.com/sirupsen/logrus"
)

var (
prjQuotaType = "prjquota"
)

// PrjQuotaDriver represents project quota driver.
type PrjQuotaDriver struct {
lock sync.Mutex
Expand Down
10 changes: 0 additions & 10 deletions test/util_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,6 @@ func CheckContainerRunning(c *check.C, cname string, isRunning bool) {
c.Assert(gotRunning, check.Equals, isRunning)
}

// DelContainerForceOk forcely deletes the container and asserts success.
func DelContainerForceOk(c *check.C, cname string) {
resp, err := delContainerForce(cname)
c.Assert(err, check.IsNil)

defer resp.Body.Close()
CheckRespStatus(c, resp, 204)
}

func delContainerForce(cname string) (*http.Response, error) {
q := url.Values{}
q.Add("force", "true")
Expand All @@ -154,7 +145,6 @@ func PauseContainerOk(c *check.C, cname string) {
func UnpauseContainerOk(c *check.C, cname string) {
resp, err := request.Post("/containers/" + cname + "/unpause")
c.Assert(err, check.IsNil)

defer resp.Body.Close()
CheckRespStatus(c, resp, 204)
}
Expand Down
7 changes: 0 additions & 7 deletions test/util_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ func StartDefaultDaemon(args ...string) (*daemon.Config, error) {
return &cfg, cfg.StartDaemon()
}

// StartDaemonBareWithArgs starts a deamon with all user specified parameter.
func StartDaemonBareWithArgs(cfg *daemon.Config, args ...string) error {
cfg.NewArgs(args...)

return cfg.StartDaemon()
}

// RestartDaemon restart daemon
func RestartDaemon(cfg *daemon.Config) error {
cfg.KillDaemon()
Expand Down