Skip to content

Commit f7c9a93

Browse files
committed
Fix lint issues in the imported drivers
Note: we can't change exported errors Since they are used in "known issues"
1 parent da783b3 commit f7c9a93

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

pkg/drivers/hyperv/hyperv.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/pkg/errors"
29+
2830
"github.com/docker/machine/libmachine/drivers"
2931
"github.com/docker/machine/libmachine/log"
3032
"github.com/docker/machine/libmachine/mcnflag"
@@ -159,7 +161,7 @@ func (d *Driver) GetURL() (string, error) {
159161
func (d *Driver) GetState() (state.State, error) {
160162
stdout, err := cmdOut("(", "Hyper-V\\Get-VM", d.MachineName, ").state")
161163
if err != nil {
162-
return state.None, fmt.Errorf("Failed to find the VM status")
164+
return state.None, errors.New("Failed to find the VM status")
163165
}
164166

165167
resp := parseLines(stdout)
@@ -320,11 +322,11 @@ func (d *Driver) chooseVirtualSwitch() (string, error) {
320322
// prefer Default Switch over external switches
321323
switches, err := getHyperVSwitches([]string{fmt.Sprintf("Where-Object {($_.SwitchType -eq 'External') -or ($_.Id -eq '%s')}", defaultSwitchID), "Sort-Object -Property SwitchType"})
322324
if err != nil {
323-
return "", fmt.Errorf("unable to get available hyperv switches")
325+
return "", errors.New("unable to get available hyperv switches")
324326
}
325327

326328
if len(switches) < 1 {
327-
return "", fmt.Errorf("no External vswitch nor Default Switch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/")
329+
return "", errors.New("no External vswitch nor Default Switch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/")
328330
}
329331

330332
return switches[0].Name, nil
@@ -333,7 +335,7 @@ func (d *Driver) chooseVirtualSwitch() (string, error) {
333335
// prefer external switches (using descending order)
334336
switches, err := getHyperVSwitches([]string{fmt.Sprintf("Where-Object {$_.Name -eq '%s'}", d.VSwitch), "Sort-Object -Property SwitchType -Descending"})
335337
if err != nil {
336-
return "", fmt.Errorf("unable to get available hyperv switches")
338+
return "", errors.New("unable to get available hyperv switches")
337339
}
338340

339341
if len(switches) < 1 {
@@ -460,7 +462,7 @@ func (d *Driver) GetIP() (string, error) {
460462

461463
resp := parseLines(stdout)
462464
if len(resp) < 1 {
463-
return "", fmt.Errorf("IP not found")
465+
return "", errors.New("IP not found")
464466
}
465467

466468
return resp[0], nil

pkg/drivers/hyperv/powershell.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
var powershell string
3232

33+
//nolint:staticcheck // ST1005: error strings should not be capitalized
3334
var (
3435
ErrPowerShellNotFound = errors.New("Powershell was not found in the path")
3536
ErrNotAdministrator = errors.New("Hyper-v commands have to be run as an Administrator")

pkg/drivers/virtualbox/disk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func getVMDiskInfo(name string, vbox VBoxManager) (*VirtualDisk, error) {
145145
disk.Path = val
146146
case "SATA-ImageUUID-1-0":
147147
disk.UUID = val
148+
default:
148149
}
149150

150151
return nil

pkg/drivers/virtualbox/network.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ const (
3434
dhcpPrefix = "HostInterfaceNetworking-"
3535
)
3636

37+
//nolint:staticcheck // ST1005: error strings should not be capitalized
3738
var (
38-
reHostOnlyAdapterCreated = regexp.MustCompile(`Interface '(.+)' was successfully created`)
39-
errNewHostOnlyAdapterNotVisible = errors.New("The host-only adapter we just created is not visible. This is a well known VirtualBox bug. You might want to uninstall it and reinstall at least version 5.0.12 that is is supposed to fix this issue")
39+
reHostOnlyAdapterCreated = regexp.MustCompile(`Interface '(.+)' was successfully created`)
40+
errNewHostOnlyAdapterNotVisible = errors.New("The host-only adapter we just created is not visible. This is a well known VirtualBox bug. You might want to uninstall it and reinstall at least version 5.0.12 that is is supposed to fix this issue")
41+
errFailedToCreateHostOnlyAdapter = errors.New("Failed to create host-only adapter")
42+
errFailedToFindHostOnlyAdapter = errors.New("Failed to find a new host-only adapter")
4043
)
4144

4245
// Host-only network.
@@ -113,7 +116,7 @@ func createHostonlyAdapter(vbox VBoxManager) (*hostOnlyNetwork, error) {
113116

114117
res := reHostOnlyAdapterCreated.FindStringSubmatch(out)
115118
if res == nil {
116-
return nil, errors.New("Failed to create host-only adapter")
119+
return nil, errFailedToCreateHostOnlyAdapter
117120
}
118121

119122
return &hostOnlyNetwork{Name: res[1]}, nil
@@ -168,6 +171,7 @@ func listHostOnlyAdapters(vbox VBoxManager) (map[string]*hostOnlyNetwork, error)
168171
}
169172

170173
n = &hostOnlyNetwork{}
174+
default:
171175
}
172176

173177
return nil
@@ -245,7 +249,7 @@ func waitForNewHostOnlyNetwork(oldNets map[string]*hostOnlyNetwork, vbox VBoxMan
245249
}
246250
}
247251

248-
return nil, errors.New("Failed to find a new host-only adapter")
252+
return nil, errFailedToFindHostOnlyAdapter
249253
}
250254

251255
// DHCP server info.
@@ -354,6 +358,7 @@ func listDHCPServers(vbox VBoxManager) (map[string]*dhcpServer, error) {
354358
dhcp.IPv4.Mask = parseIPv4Mask(val)
355359
case "Enabled":
356360
dhcp.Enabled = (val == "Yes")
361+
default:
357362
}
358363

359364
return nil

pkg/drivers/virtualbox/vbm.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (v *VBoxCmdManager) vbmOutErrRetry(retry int, args ...string) (string, stri
127127
func checkVBoxManageVersion(version string) error {
128128
major, minor, err := parseVersion(version)
129129
if (err != nil) || (major < 4) || (major == 4 && minor <= 2) {
130+
//nolint:staticcheck // ST1005: error strings should not be capitalized
130131
return fmt.Errorf("We support Virtualbox starting with version 5. Your VirtualBox install is %q. Please upgrade at https://www.virtualbox.org", version)
131132
}
132133

@@ -140,17 +141,17 @@ func checkVBoxManageVersion(version string) error {
140141
func parseVersion(version string) (int, int, error) {
141142
parts := strings.Split(version, ".")
142143
if len(parts) < 2 {
143-
return 0, 0, fmt.Errorf("Invalid version: %q", version)
144+
return 0, 0, fmt.Errorf("invalid version: %q", version)
144145
}
145146

146147
major, err := strconv.Atoi(parts[0])
147148
if err != nil {
148-
return 0, 0, fmt.Errorf("Invalid version: %q", version)
149+
return 0, 0, fmt.Errorf("invalid version: %q", version)
149150
}
150151

151152
minor, err := strconv.Atoi(parts[1])
152153
if err != nil {
153-
return 0, 0, fmt.Errorf("Invalid version: %q", version)
154+
return 0, 0, fmt.Errorf("invalid version: %q", version)
154155
}
155156

156157
return major, minor, err

pkg/drivers/virtualbox/virtualbox.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
defaultHostLoopbackReachable = true
5353
)
5454

55+
//nolint:staticcheck // ST1005: error strings should not be capitalized
5556
var (
5657
ErrUnableToGenerateRandomIP = errors.New("unable to generate random IP")
5758
ErrMustEnableVTX = errors.New("This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory")
@@ -578,6 +579,7 @@ func (d *Driver) Start() error {
578579
log.Infof("Check network to re-create if needed...")
579580

580581
if hostOnlyAdapter, err = d.setupHostOnlyNetwork(d.MachineName); err != nil {
582+
//nolint:staticcheck // ST1005: error strings should not be capitalized
581583
return fmt.Errorf("Error setting up host only network on machine start: %s", err)
582584
}
583585
}
@@ -591,8 +593,10 @@ func (d *Driver) Start() error {
591593

592594
if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil {
593595
if lines, readErr := d.readVBoxLog(); readErr == nil && len(lines) > 0 {
596+
//nolint:staticcheck // ST1005: error strings should not be capitalized
594597
return fmt.Errorf("Unable to start the VM: %s\nDetails: %s", err, lines[len(lines)-1])
595598
}
599+
//nolint:staticcheck // ST1005: error strings should not be capitalized
596600
return fmt.Errorf("Unable to start the VM: %s", err)
597601
}
598602
case state.Paused:
@@ -608,6 +612,7 @@ func (d *Driver) Start() error {
608612
// Verify that VT-X is not disabled in the started VM
609613
vtxIsDisabled, err := d.IsVTXDisabledInTheVM()
610614
if err != nil {
615+
//nolint:staticcheck // ST1005: error strings should not be capitalized
611616
return fmt.Errorf("Checking if hardware virtualization is enabled failed: %s", err)
612617
}
613618

@@ -666,6 +671,7 @@ func (d *Driver) Start() error {
666671
d.sleeper.Sleep(5 * time.Second)
667672

668673
if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil {
674+
//nolint:staticcheck // ST1005: error strings should not be capitalized
669675
return fmt.Errorf("Unable to start the VM: %s", err)
670676
}
671677

@@ -709,10 +715,12 @@ func (d *Driver) Stop() error {
709715
// Restart restarts a machine which is known to be running.
710716
func (d *Driver) Restart() error {
711717
if err := d.Stop(); err != nil {
718+
//nolint:staticcheck // ST1005: error strings should not be capitalized
712719
return fmt.Errorf("Problem stopping the VM: %s", err)
713720
}
714721

715722
if err := d.Start(); err != nil {
723+
//nolint:staticcheck // ST1005: error strings should not be capitalized
716724
return fmt.Errorf("Problem starting the VM: %s", err)
717725
}
718726

@@ -786,6 +794,7 @@ func (d *Driver) getHostOnlyMACAddress() (string, error) {
786794
re := regexp.MustCompile(`(?m)^hostonlyadapter([\d]+)`)
787795
groups := re.FindStringSubmatch(stdout)
788796
if len(groups) < 2 {
797+
//nolint:staticcheck // ST1005: error strings should not be capitalized
789798
return "", errors.New("Machine does not have a host-only adapter")
790799
}
791800

@@ -794,6 +803,7 @@ func (d *Driver) getHostOnlyMACAddress() (string, error) {
794803
re = regexp.MustCompile(fmt.Sprintf("(?m)^macaddress%s=\"(.*)\"", adapterNumber))
795804
groups = re.FindStringSubmatch(stdout)
796805
if len(groups) < 2 {
806+
//nolint:staticcheck // ST1005: error strings should not be capitalized
797807
return "", fmt.Errorf("Could not find MAC address for adapter %v", adapterNumber)
798808
}
799809

@@ -831,6 +841,7 @@ func (d *Driver) parseIPForMACFromIPAddr(ipAddrOutput string, macAddress string)
831841
}
832842
}
833843

844+
//nolint:staticcheck // ST1005: error strings should not be capitalized
834845
return "", fmt.Errorf("Could not find matching IP for MAC address %v", macAddress)
835846
}
836847

@@ -1023,7 +1034,7 @@ func getAvailableTCPPort(port int) (int, error) {
10231034
port = 0 // Throw away the port hint before trying again
10241035
time.Sleep(1 * time.Second)
10251036
}
1026-
return 0, fmt.Errorf("unable to allocate tcp port")
1037+
return 0, errors.New("unable to allocate tcp port")
10271038
}
10281039

10291040
// Setup a NAT port forwarding entry.

pkg/drivers/virtualbox/vm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func getVMInfo(name string, vbox VBoxManager) (*VM, error) {
4545
return err
4646
}
4747
vm.Memory = v
48+
default:
4849
}
4950

5051
return nil

0 commit comments

Comments
 (0)