Add structcheck, unused, and varcheck linters.

Warn on unused and dead code

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin
2017-11-13 16:21:26 -05:00
parent 96e2f30250
commit f74862a0dd
35 changed files with 29 additions and 444 deletions

View File

@@ -29,16 +29,6 @@ import (
"google.golang.org/grpc"
)
const usage = `
__ _ __ __ _
_________ ____ / /_____ _(_)___ ___ _________/ / _____/ /_ (_)___ ___
/ ___/ __ \/ __ \/ __/ __ ` + "`" + `/ / __ \/ _ \/ ___/ __ /_____/ ___/ __ \/ / __ ` + "`" + `__ \
/ /__/ /_/ / / / / /_/ /_/ / / / / / __/ / / /_/ /_____(__ ) / / / / / / / / /
\___/\____/_/ /_/\__/\__,_/_/_/ /_/\___/_/ \__,_/ /____/_/ /_/_/_/ /_/ /_/
shim for container lifecycle and reconnection
`
var (
debugFlag bool
namespaceFlag string

View File

@@ -236,16 +236,6 @@ func (w *worker) getID() string {
return fmt.Sprintf("%d-%d", w.id, w.count)
}
func (w *worker) cleanup(ctx context.Context, c containerd.Container) {
if err := c.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
if err == context.DeadlineExceeded {
return
}
w.failures++
logrus.WithError(err).Errorf("delete container %s", c.ID())
}
}
// cleanup cleans up any containers in the "stress" namespace before the test run
func cleanup(ctx context.Context, client *containerd.Client) error {
containers, err := client.Containers(ctx)

View File

@@ -8,7 +8,6 @@ import (
"net"
"os"
"os/signal"
"runtime"
"time"
"google.golang.org/grpc/grpclog"
@@ -196,18 +195,3 @@ func setLevel(context *cli.Context, config *server.Config) error {
}
return nil
}
func dumpStacks() {
var (
buf []byte
stackSize int
)
bufferLen := 16384
for stackSize == len(buf) {
buf = make([]byte, bufferLen)
stackSize = runtime.Stack(buf, true)
bufferLen *= 2
}
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

View File

@@ -5,7 +5,9 @@ package main
import (
"context"
"os"
"runtime"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"github.com/containerd/containerd/log"
@@ -55,3 +57,18 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se
}()
return done
}
func dumpStacks() {
var (
buf []byte
stackSize int
)
bufferLen := 16384
for stackSize == len(buf) {
buf = make([]byte, bufferLen)
stackSize = runtime.Stack(buf, true)
bufferLen *= 2
}
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

View File

@@ -133,13 +133,6 @@ var pushCommand = cli.Command{
},
}
type pushStatus struct {
name string
started bool
written int64
total int64
}
type pushjobs struct {
jobs map[string]struct{}
ordered []string

View File

@@ -14,8 +14,6 @@ import (
"github.com/urfave/cli"
)
const pipeRoot = `\\.\pipe`
func init() {
Command.Flags = append(Command.Flags, cli.StringSliceFlag{
Name: "layer",
@@ -50,10 +48,6 @@ func withTTY(terminal bool) containerd.SpecOpts {
return containerd.WithTTY(int(size.Width), int(size.Height))
}
func setHostNetworking() containerd.SpecOpts {
return nil
}
func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
var (
// ref = context.Args().First()

View File

@@ -1,91 +0,0 @@
package shim
import (
"io"
"net"
"os"
"sync"
"github.com/Microsoft/go-winio"
clog "github.com/containerd/containerd/log"
"github.com/pkg/errors"
)
func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup, error) {
var wg sync.WaitGroup
if stdin != "" {
l, err := winio.ListenPipe(stdin, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", stdin)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
go func() {
c, err := l.Accept()
if err != nil {
clog.L.WithError(err).Errorf("failed to accept stdin connection on %s", stdin)
return
}
io.Copy(c, os.Stdin)
c.Close()
l.Close()
}()
}
if stdout != "" {
l, err := winio.ListenPipe(stdout, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", stdout)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
wg.Add(1)
go func() {
defer wg.Done()
c, err := l.Accept()
if err != nil {
clog.L.WithError(err).Errorf("failed to accept stdout connection on %s", stdout)
return
}
io.Copy(os.Stdout, c)
c.Close()
l.Close()
}()
}
if !console && stderr != "" {
l, err := winio.ListenPipe(stderr, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stderr pipe %s", stderr)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
wg.Add(1)
go func() {
defer wg.Done()
c, err := l.Accept()
if err != nil {
clog.L.WithError(err).Errorf("failed to accept stderr connection on %s", stderr)
return
}
io.Copy(os.Stderr, c)
c.Close()
l.Close()
}()
}
return &wg, nil
}