Select Git revision
Forked from
GitLab.org / gitlab-runner
8719 commits behind, 11 commits ahead of the upstream repository.
-
Tomasz Maczukin authored
Some time ago [we had a discussion](!934 (comment 91891281)) about why we're aliasing some of the imports of `github.com/sirupsen/logrus` package with a `log` alias. At that moment we've been doing that in 17 from 68 cases when logrus was imported in Runners codebase. The conclusion was this aliasing is unnecessary, because: - we relay on logrus interface so much that moving to another logging library will be not so simple as switching the import name; - we're totally not consistent in the alias usage which makes the code even more messy. Three GitLab Runner maintainers agreeded hat there is no reason to use the aliasing and that we should just use `logrus` everywhere. But no action was don since then. The cleanup was left for a future. Unfortunately, because GitLab Runner is one of our biggest projects in Go, for some people it becomes a source of suggestions of how certain things should be handled. For example here is a discussion in a new project that creates a go-based tool for our Serverless integration: gitlabktl!9 (comment 152472275) The most important statement is: > perhaps we could leave it as is since it is how we are exposing logrus in the runner project Because we already know that it should be changed and others start to look on Runner's code to find good patterns, let's finally cleanup the `log` aliasing mess.
Tomasz Maczukin authoredSome time ago [we had a discussion](!934 (comment 91891281)) about why we're aliasing some of the imports of `github.com/sirupsen/logrus` package with a `log` alias. At that moment we've been doing that in 17 from 68 cases when logrus was imported in Runners codebase. The conclusion was this aliasing is unnecessary, because: - we relay on logrus interface so much that moving to another logging library will be not so simple as switching the import name; - we're totally not consistent in the alias usage which makes the code even more messy. Three GitLab Runner maintainers agreeded hat there is no reason to use the aliasing and that we should just use `logrus` everywhere. But no action was don since then. The cleanup was left for a future. Unfortunately, because GitLab Runner is one of our biggest projects in Go, for some people it becomes a source of suggestions of how certain things should be handled. For example here is a discussion in a new project that creates a go-based tool for our Serverless integration: gitlabktl!9 (comment 152472275) The most important statement is: > perhaps we could leave it as is since it is how we are exposing logrus in the runner project Because we already know that it should be changed and others start to look on Runner's code to find good patterns, let's finally cleanup the `log` aliasing mess.
verify.go 2.06 KiB
package commands
import (
"errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/network"
)
type VerifyCommand struct {
configOptions
common.RunnerCredentials
network common.Network
Name string `toml:"name" json:"name" short:"n" long:"name" description:"Name of the runner you wish to verify"`
DeleteNonExisting bool `long:"delete" description:"Delete no longer existing runners?"`
}
func (c *VerifyCommand) Execute(context *cli.Context) {
userModeWarning(true)
err := c.loadConfig()
if err != nil {
logrus.Fatalln(err)
return
}
// check if there's something to verify
toVerify, okRunners, err := c.selectRunners()
if err != nil {
logrus.Fatalln(err)
return
}
// verify if runner exist
for _, runner := range toVerify {
if c.network.VerifyRunner(runner.RunnerCredentials) {
okRunners = append(okRunners, runner)
}
}
// check if anything changed
if len(c.config.Runners) == len(okRunners) {
return
}
if !c.DeleteNonExisting {
logrus.Fatalln("Failed to verify runners")
return
}
c.config.Runners = okRunners
// save config file
err = c.saveConfig()
if err != nil {
logrus.Fatalln("Failed to update", c.ConfigFile, err)
}
logrus.Println("Updated", c.ConfigFile)
}
func (c *VerifyCommand) selectRunners() (toVerify []*common.RunnerConfig, okRunners []*common.RunnerConfig, err error) {
var selectorPresent = c.Name != "" || c.RunnerCredentials.URL != "" || c.RunnerCredentials.Token != ""
for _, runner := range c.config.Runners {
selected := !selectorPresent || runner.Name == c.Name || runner.RunnerCredentials.SameAs(&c.RunnerCredentials)
if selected {
toVerify = append(toVerify, runner)
} else {
okRunners = append(okRunners, runner)
}
}
if selectorPresent && len(toVerify) == 0 {
err = errors.New("No runner matches the filtering parameters")
}
return
}
func init() {
common.RegisterCommand2("verify", "verify all registered runners", &VerifyCommand{
network: network.NewGitLabClient(),
})
}