fix: remove linting issues

pull/350/head^2
Simon Aronsson 5 years ago
parent 6c507433e8
commit e4e1127f8e

@ -62,7 +62,7 @@ func Execute() {
func PreRun(cmd *cobra.Command, args []string) { func PreRun(cmd *cobra.Command, args []string) {
f := cmd.PersistentFlags() f := cmd.PersistentFlags()
if enabled, _ := f.GetBool("debug"); enabled == true { if enabled, _ := f.GetBool("debug"); enabled {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} }
@ -120,7 +120,10 @@ func Run(c *cobra.Command, names []string) {
log.Fatal(err) log.Fatal(err)
} }
runUpgradesOnSchedule(filter) if err := runUpgradesOnSchedule(filter); err != nil {
log.Error(err)
}
os.Exit(1) os.Exit(1)
} }

@ -50,7 +50,7 @@ func cleanupExcessWatchtowers(containers []container.Container, client container
continue continue
} }
if cleanup == true { if cleanup {
if err := client.RemoveImage(c); err != nil { if err := client.RemoveImage(c); err != nil {
// logging the original here as we're just returning a count // logging the original here as we're just returning a count
logrus.Error(err) logrus.Error(err)

@ -95,7 +95,9 @@ func restartStaleContainer(container container.Container, client container.Clien
} }
if params.Cleanup { if params.Cleanup {
client.RemoveImage(container) if err := client.RemoveImage(container); err != nil {
log.Error(err)
}
} }
} }

@ -271,7 +271,7 @@ func setEnvOptStr(env string, opt string) error {
} }
func setEnvOptBool(env string, opt bool) error { func setEnvOptBool(env string, opt bool) error {
if opt == true { if opt {
return setEnvOptStr(env, "1") return setEnvOptStr(env, "1")
} }
return nil return nil

@ -1,17 +1,10 @@
package main // import "github.com/containrrr/watchtower" package main
import ( import (
"github.com/containrrr/watchtower/cmd" "github.com/containrrr/watchtower/cmd"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// DockerAPIMinVersion is the version of the docker API, which is minimally required by
// watchtower. Currently we require at least API 1.24 and therefore Docker 1.12 or later.
var version = "master"
var commit = "unknown"
var date = "unknown"
func init() { func init() {
log.SetLevel(log.InfoLevel) log.SetLevel(log.InfoLevel)
} }

@ -126,8 +126,8 @@ func (client dockerClient) StopContainer(c Container, timeout time.Duration) err
} }
} }
// Wait for container to exit, but proceed anyway after the timeout elapses // TODO: This should probably be checked.
client.waitForStop(c, timeout) _ = client.waitForStopOrTimeout(c, timeout)
if c.containerInfo.HostConfig.AutoRemove { if c.containerInfo.HostConfig.AutoRemove {
log.Debugf("AutoRemove container %s, skipping ContainerRemove call.", c.ID()) log.Debugf("AutoRemove container %s, skipping ContainerRemove call.", c.ID())
@ -140,7 +140,7 @@ func (client dockerClient) StopContainer(c Container, timeout time.Duration) err
} }
// Wait for container to be removed. In this case an error is a good thing // Wait for container to be removed. In this case an error is a good thing
if err := client.waitForStop(c, timeout); err == nil { if err := client.waitForStopOrTimeout(c, timeout); err == nil {
return fmt.Errorf("Container %s (%s) could not be removed", c.Name(), c.ID()) return fmt.Errorf("Container %s (%s) could not be removed", c.Name(), c.ID())
} }
@ -245,7 +245,9 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) {
defer response.Close() defer response.Close()
// the pull request will be aborted prematurely unless the response is read // the pull request will be aborted prematurely unless the response is read
_, err = ioutil.ReadAll(response) if _, err = ioutil.ReadAll(response); err != nil {
log.Error(err)
}
} }
newImageInfo, _, err := client.api.ImageInspectWithRaw(bg, imageName) newImageInfo, _, err := client.api.ImageInspectWithRaw(bg, imageName)
@ -269,7 +271,7 @@ func (client dockerClient) RemoveImage(c Container) error {
return err return err
} }
func (client dockerClient) waitForStop(c Container, waitTime time.Duration) error { func (client dockerClient) waitForStopOrTimeout(c Container, waitTime time.Duration) error {
bg := context.Background() bg := context.Background()
timeout := time.After(waitTime) timeout := time.After(waitTime)

@ -48,6 +48,10 @@ func EncodedEnvAuth(ref string) (string, error) {
// The docker config must be mounted on the container // The docker config must be mounted on the container
func EncodedConfigAuth(ref string) (string, error) { func EncodedConfigAuth(ref string) (string, error) {
server, err := ParseServerAddress(ref) server, err := ParseServerAddress(ref)
if err != nil {
log.Errorf("Unable to parse the image ref %s", err)
return "", err
}
configDir := os.Getenv("DOCKER_CONFIG") configDir := os.Getenv("DOCKER_CONFIG")
if configDir == "" { if configDir == "" {
configDir = "/" configDir = "/"
@ -58,7 +62,8 @@ func EncodedConfigAuth(ref string) (string, error) {
return "", err return "", err
} }
credStore := CredentialsStore(*configFile) credStore := CredentialsStore(*configFile)
auth, err := credStore.Get(server) // returns (types.AuthConfig{}) if server not in credStore auth, _ := credStore.Get(server) // returns (types.AuthConfig{}) if server not in credStore
if auth == (types.AuthConfig{}) { if auth == (types.AuthConfig{}) {
log.Debugf("No credentials for %s in %s", server, configFile.Filename) log.Debugf("No credentials for %s in %s", server, configFile.Filename)
return "", nil return "", nil

Loading…
Cancel
Save