Commit 0bf37175 authored by Pedro Pombeiro's avatar Pedro Pombeiro Committed by Georgi N. Georgiev
Browse files

Enable shadowing checking in govet

parent 2f679168
......@@ -129,13 +129,13 @@ func (c *ArtifactsUploaderCommand) Run() error {
}
func (c *ArtifactsUploaderCommand) ShouldRetry(tries int, err error) bool {
var retryableErr retryableErr
if !errors.As(err, &retryableErr) {
var errAs retryableErr
if !errors.As(err, &errAs) {
return false
}
maxTries := defaultTries
if errors.Is(retryableErr, errServiceUnavailable) {
if errors.Is(errAs, errServiceUnavailable) {
maxTries = serviceUnavailableTries
}
......
......@@ -741,8 +741,8 @@ func (b *Build) Run(globalConfig *Config, trace JobTrace) (err error) {
if err == nil {
err = b.run(ctx, executor)
if err := b.waitForTerminal(ctx, globalConfig.SessionServer.GetSessionTimeout()); err != nil {
b.Log().WithError(err).Debug("Stopped waiting for terminal")
if errWait := b.waitForTerminal(ctx, globalConfig.SessionServer.GetSessionTimeout()); errWait != nil {
b.Log().WithError(errWait).Debug("Stopped waiting for terminal")
}
}
......
......@@ -38,23 +38,24 @@ import (
)
const (
DockerExecutorStagePrepare common.ExecutorStage = "docker_prepare"
DockerExecutorStageRun common.ExecutorStage = "docker_run"
DockerExecutorStageCleanup common.ExecutorStage = "docker_cleanup"
DockerExecutorStageCreatingBuildVolumes common.ExecutorStage = "docker_creating_build_volumes"
DockerExecutorStageCreatingServices common.ExecutorStage = "docker_creating_services"
DockerExecutorStageCreatingUserVolumes common.ExecutorStage = "docker_creating_user_volumes"
DockerExecutorStagePullingImage common.ExecutorStage = "docker_pulling_image"
ExecutorStagePrepare common.ExecutorStage = "docker_prepare"
ExecutorStageRun common.ExecutorStage = "docker_run"
ExecutorStageCleanup common.ExecutorStage = "docker_cleanup"
ExecutorStageCreatingBuildVolumes common.ExecutorStage = "docker_creating_build_volumes"
ExecutorStageCreatingServices common.ExecutorStage = "docker_creating_services"
ExecutorStageCreatingUserVolumes common.ExecutorStage = "docker_creating_user_volumes"
ExecutorStagePullingImage common.ExecutorStage = "docker_pulling_image"
)
var DockerPrebuiltImagesPaths []string
var PrebuiltImagesPaths []string
var neverRestartPolicy = container.RestartPolicy{Name: "no"}
var errVolumesManagerUndefined = errors.New("volumesManager is undefined")
var errNetworksManagerUndefined = errors.New("networksManager is undefined")
var (
errVolumesManagerUndefined = errors.New("volumesManager is undefined")
errNetworksManagerUndefined = errors.New("networksManager is undefined")
)
type executor struct {
executors.AbstractExecutor
......@@ -92,7 +93,7 @@ func init() {
logrus.Errorln("Docker executor: unable to detect gitlab-runner folder, prebuilt image helpers will be loaded from DockerHub.", err)
}
DockerPrebuiltImagesPaths = []string{
PrebuiltImagesPaths = []string{
filepath.Join(runnerFolder, "helper-images"),
filepath.Join(runnerFolder, "out/helper-images"),
}
......@@ -103,7 +104,7 @@ func (e *executor) getServiceVariables() []string {
}
func (e *executor) pullDockerImage(imageName string, ac *types.AuthConfig) (*types.ImageInspect, error) {
e.SetCurrentStage(DockerExecutorStagePullingImage)
e.SetCurrentStage(ExecutorStagePullingImage)
e.Println("Pulling docker image", imageName, "...")
ref := imageName
......@@ -214,7 +215,7 @@ func (e *executor) loadPrebuiltImage(path, ref, tag string) (*types.ImageInspect
}
options := types.ImageImportOptions{Tag: tag}
if err := e.client.ImageImportBlocking(e.Context, source, ref, options); err != nil {
if err = e.client.ImageImportBlocking(e.Context, source, ref, options); err != nil {
return nil, fmt.Errorf("failed to import image: %w", err)
}
......@@ -259,7 +260,7 @@ func (e *executor) getLocalHelperImage() *types.ImageInspect {
}
architecture := e.helperImageInfo.Architecture
for _, dockerPrebuiltImagesPath := range DockerPrebuiltImagesPaths {
for _, dockerPrebuiltImagesPath := range PrebuiltImagesPaths {
dockerPrebuiltImageFilePath := filepath.Join(dockerPrebuiltImagesPath, "prebuilt-"+architecture+prebuiltImageExtension)
image, err := e.loadPrebuiltImage(dockerPrebuiltImageFilePath, prebuiltImageName, e.helperImageInfo.Tag)
if err != nil {
......@@ -592,7 +593,7 @@ func (e *executor) cleanupNetwork(ctx context.Context) error {
}
func (e *executor) createServices() (err error) {
e.SetCurrentStage(DockerExecutorStageCreatingServices)
e.SetCurrentStage(ExecutorStageCreatingServices)
e.Debugln("Creating services...")
servicesDefinitions, err := e.getServicesDefinitions()
......@@ -745,17 +746,17 @@ func (e *executor) watchContainer(ctx context.Context, id string, input io.Reade
// Copy any output to the build trace
stdoutErrCh := make(chan error)
go func() {
_, err := stdcopy.StdCopy(e.Trace, e.Trace, hijacked.Reader)
stdoutErrCh <- err
_, errCopy := stdcopy.StdCopy(e.Trace, e.Trace, hijacked.Reader)
stdoutErrCh <- errCopy
}()
// Write the input to the container and close its STDIN to get it to finish
stdinErrCh := make(chan error)
go func() {
_, err := io.Copy(hijacked.Conn, input)
_, errCopy := io.Copy(hijacked.Conn, input)
hijacked.CloseWrite()
if err != nil {
stdinErrCh <- err
if errCopy != nil {
stdinErrCh <- errCopy
}
}()
......@@ -951,7 +952,7 @@ func (e *executor) createDependencies() error {
}
func (e *executor) createVolumes() error {
e.SetCurrentStage(DockerExecutorStageCreatingUserVolumes)
e.SetCurrentStage(ExecutorStageCreatingUserVolumes)
e.Debugln("Creating user-defined volumes...")
if e.volumesManager == nil {
......@@ -977,7 +978,7 @@ func (e *executor) createVolumes() error {
}
func (e *executor) createBuildVolume() error {
e.SetCurrentStage(DockerExecutorStageCreatingBuildVolumes)
e.SetCurrentStage(ExecutorStageCreatingBuildVolumes)
e.Debugln("Creating build volume...")
if e.volumesManager == nil {
......@@ -1012,7 +1013,7 @@ func (e *executor) createBuildVolume() error {
}
func (e *executor) Prepare(options common.ExecutorPrepareOptions) error {
e.SetCurrentStage(DockerExecutorStagePrepare)
e.SetCurrentStage(ExecutorStagePrepare)
if options.Config.Docker == nil {
return errors.New("missing docker configuration")
......@@ -1076,7 +1077,7 @@ func (e *executor) prepareBuildsDir(options common.ExecutorPrepareOptions) error
}
func (e *executor) Cleanup() {
e.SetCurrentStage(DockerExecutorStageCleanup)
e.SetCurrentStage(ExecutorStageCleanup)
var wg sync.WaitGroup
......
......@@ -112,7 +112,7 @@ func (s *commandExecutor) Run(cmd common.ExecutorCommand) error {
}
s.Debugln("Executing on", ctr.Name, "the", cmd.Script)
s.SetCurrentStage(DockerExecutorStageRun)
s.SetCurrentStage(ExecutorStageRun)
runErr = s.watchContainer(cmd.Context, ctr.ID, bytes.NewBufferString(cmd.Script))
if !docker.IsErrNotFound(runErr) {
......
......@@ -1362,7 +1362,7 @@ func TestDockerCommand_WriteToVolumeNonRootImage(t *testing.T) {
defer func() {
volumeName := fmt.Sprintf("%s-cache-%x", build.ProjectUniqueName(), md5.Sum([]byte(volumeBind)))
err := client.VolumeRemove(context.Background(), volumeName, true)
err = client.VolumeRemove(context.Background(), volumeName, true)
require.NoError(t, err)
}()
......
......@@ -64,7 +64,7 @@ func (s *sshExecutor) Prepare(options common.ExecutorPrepareOptions) error {
}
func (s *sshExecutor) Run(cmd common.ExecutorCommand) error {
s.SetCurrentStage(DockerExecutorStageRun)
s.SetCurrentStage(ExecutorStageRun)
err := s.sshCommand.Run(cmd.Context, ssh.Command{
Environment: s.BuildShell.Environment,
......
......@@ -37,7 +37,7 @@ import (
)
func TestMain(m *testing.M) {
DockerPrebuiltImagesPaths = []string{"../../out/helper-images/"}
PrebuiltImagesPaths = []string{"../../out/helper-images/"}
flag.Parse()
os.Exit(m.Run())
......@@ -1720,7 +1720,7 @@ func TestCheckOSType(t *testing.T) {
for name, c := range cases {
t.Run(name, func(t *testing.T) {
executor := executor{
e := executor{
info: types.Info{
OSType: c.dockerInfoOSType,
},
......@@ -1731,7 +1731,7 @@ func TestCheckOSType(t *testing.T) {
},
}
err := executor.validateOSType()
err := e.validateOSType()
if c.expectedErr == "" {
assert.NoError(t, err)
return
......
......@@ -956,7 +956,7 @@ func (s *executor) makePodProxyServices() ([]api.Service, error) {
wg.Add(len(s.ProxyPool))
for serviceName, serviceProxy := range s.ProxyPool {
serviceName := dns.MakeRFC1123Compatible(serviceName)
serviceName = dns.MakeRFC1123Compatible(serviceName)
servicePorts := make([]api.ServicePort, len(serviceProxy.Settings.Ports))
for i, port := range serviceProxy.Settings.Ports {
// When there is more than one port Kubernetes requires a port name
......
......@@ -552,15 +552,15 @@ func testSetupBuildPodServiceCreationErrorFeatureFlag(t *testing.T, featureFlagN
}
fakeRoundTripper := func(req *http.Request) (*http.Response, error) {
body, err := ioutil.ReadAll(req.Body)
if !assert.NoError(t, err, "failed to read request body") {
return nil, err
body, errRT := ioutil.ReadAll(req.Body)
if !assert.NoError(t, errRT, "failed to read request body") {
return nil, errRT
}
p := new(api.Pod)
err = json.Unmarshal(body, p)
if !assert.NoError(t, err, "failed to read request body") {
return nil, err
errRT = json.Unmarshal(body, p)
if !assert.NoError(t, errRT, "failed to read request body") {
return nil, errRT
}
if req.URL.Path == "/api/v1/namespaces/default/services" {
......
......@@ -221,7 +221,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
if prl.Exist(s.vmName) {
s.Println("Restoring VM from snapshot...")
err := s.restoreFromSnapshot()
err = s.restoreFromSnapshot()
if err != nil {
s.Println("Previous VM failed. Deleting, because", err)
prl.Kill(s.vmName)
......@@ -232,7 +232,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
if !prl.Exist(s.vmName) {
s.Println("Creating new VM...")
err := s.createVM()
err = s.createVM()
if err != nil {
return err
}
......@@ -255,7 +255,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
// Start VM if stopped
if status == prl.Stopped || status == prl.Suspended {
s.Println("Starting VM...")
err := prl.Start(s.vmName)
err = prl.Start(s.vmName)
if err != nil {
return err
}
......
......@@ -190,12 +190,12 @@ func (s *executor) run(cmd common.ExecutorCommand) error {
// Wait for process to finish
waitCh := make(chan error)
go func() {
err := c.Wait()
waitErr := c.Wait()
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
err = &common.BuildError{Inner: err}
if errors.As(waitErr, &exitErr) {
waitErr = &common.BuildError{Inner: waitErr}
}
waitCh <- err
waitCh <- waitErr
}()
// Support process abort
......
......@@ -1116,13 +1116,13 @@ func TestInteractiveTerminal(t *testing.T) {
go func() {
buf := bytes.NewBuffer(nil)
err := buildtest.RunBuildWithOptions(
errRun := buildtest.RunBuildWithOptions(
t,
build,
&common.Trace{Writer: buf},
&common.Config{SessionServer: common.SessionServer{SessionTimeout: 2}},
)
require.NoError(t, err)
require.NoError(t, errRun)
buildOut <- buf.String()
}()
......
......@@ -194,7 +194,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
if vbox.Exist(s.vmName) {
s.Println("Restoring VM from snapshot...")
err := s.restoreFromSnapshot()
err = s.restoreFromSnapshot()
if err != nil {
s.Println("Previous VM failed. Deleting, because", err)
vbox.Kill(s.vmName)
......@@ -205,7 +205,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
if !vbox.Exist(s.vmName) {
s.Println("Creating new VM...")
err := s.createVM(s.vmName)
err = s.createVM(s.vmName)
if err != nil {
return err
}
......@@ -227,7 +227,7 @@ func (s *executor) Prepare(options common.ExecutorPrepareOptions) error {
if !vbox.IsStatusOnlineOrTransient(status) {
s.Println("Starting VM...")
err := vbox.Start(s.vmName)
err = vbox.Start(s.vmName)
if err != nil {
return err
}
......
......@@ -28,8 +28,8 @@ func TestCertificate(t *testing.T) {
Addr: tlsListener.Addr().String(),
}
go func() {
err := srv.Serve(tlsListener)
require.EqualError(t, err, "http: Server closed")
errServe := srv.Serve(tlsListener)
require.EqualError(t, errServe, "http: Server closed")
}()
defer srv.Close()
......
......@@ -179,10 +179,10 @@ func TestDefaultBuilder_BuildChainFromTLSConnectionState(t *testing.T) {
builder := NewBuilder(logrus.StandardLogger()).(*defaultBuilder)
if tc.setupResolverMock != nil {
resolver, cleanup := tc.setupResolverMock(t)
resolverMock, cleanup := tc.setupResolverMock(t)
defer cleanup()
builder.resolver = resolver
builder.resolver = resolverMock
}
TLS := new(tls.ConnectionState)
......
......@@ -211,8 +211,8 @@ func TestMetricsRefereeExecute(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// parse request
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(r.Body)
require.NoError(t, err)
_, errReq := buf.ReadFrom(r.Body)
require.NoError(t, errReq)
actual := buf.String()
t.Log("REQUEST: " + actual)
query := fmt.Sprintf("metric%d", requestIndex)
......@@ -221,8 +221,8 @@ func TestMetricsRefereeExecute(t *testing.T) {
require.Equal(t, expected, actual)
// send response
t.Log("RESPONSE: " + string(responseJSON))
_, err = w.Write(responseJSON)
require.NoError(t, err)
_, errReq = w.Write(responseJSON)
require.NoError(t, errReq)
requestIndex++
}))
defer ts.Close()
......
......@@ -97,8 +97,8 @@ func TestCertificate(t *testing.T) {
defer server.Close()
go func() {
err := server.Start()
require.NoError(t, err)
errStart := server.Start()
require.NoError(t, errStart)
}()
caCertPool := x509.NewCertPool()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment