Skip to content

Commit 5d4d036

Browse files
authored
drivers: Extract drivers/common package (#21266)
Move all files and packages which are not a driver to the drivers/common package. This helps to understand the structure of the code. While moving, move the iso_test.iso into testdata/test.iso to separate code and test data. While fixing the test iso path fix few bugs in the tests using wrong iso path. The test failed because the iso path was wrong instead of issue with source or destination path. New directory structure: % tree -L1 pkg/drivers pkg/drivers ├── common ├── hyperkit ├── kic ├── krunkit ├── kvm ├── none ├── qemu ├── ssh └── vfkit
1 parent 78fc8d9 commit 5d4d036

File tree

19 files changed

+61
-59
lines changed

19 files changed

+61
-59
lines changed

cmd/minikube/cmd/start_flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"github.com/spf13/cobra"
2929
"github.com/spf13/viper"
3030
"k8s.io/klog/v2"
31+
"k8s.io/minikube/pkg/drivers/common/vmnet"
3132
"k8s.io/minikube/pkg/drivers/kic"
3233
"k8s.io/minikube/pkg/drivers/kic/oci"
33-
"k8s.io/minikube/pkg/drivers/vmnet"
3434
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil"
3535
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil/kverify"
3636
"k8s.io/minikube/pkg/minikube/cni"

pkg/drivers/common.go renamed to pkg/drivers/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drivers
17+
package common
1818

1919
import (
2020
"bufio"

pkg/drivers/common_test.go renamed to pkg/drivers/common/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drivers
17+
package common
1818

1919
import (
2020
"os"

pkg/drivers/iso.go renamed to pkg/drivers/common/iso.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drivers
17+
package common
1818

1919
import (
2020
"fmt"

pkg/drivers/iso_test.go renamed to pkg/drivers/common/iso_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package drivers
17+
package common
1818

1919
import (
2020
"testing"
2121
)
2222

23+
const testISOPath = "testdata/test.iso"
24+
2325
func TestExtractFile(t *testing.T) {
2426
testDir := t.TempDir()
2527

@@ -32,42 +34,42 @@ func TestExtractFile(t *testing.T) {
3234
}{
3335
{
3436
name: "all is right",
35-
isoPath: "iso_test.iso",
37+
isoPath: testISOPath,
3638
srcPath: "/test1.txt",
3739
destPath: testDir + "/test1.txt",
3840
expectedError: false,
3941
},
4042
{
4143
name: "isoPath is error",
42-
isoPath: "tests.iso",
44+
isoPath: "testdata/missing.iso",
4345
srcPath: "/test1.txt",
4446
destPath: testDir + "/test1.txt",
4547
expectedError: true,
4648
},
4749
{
4850
name: "srcPath is empty",
49-
isoPath: "iso_tests.iso",
51+
isoPath: testISOPath,
5052
srcPath: "",
5153
destPath: testDir + "/test1.txt",
5254
expectedError: true,
5355
},
5456
{
5557
name: "srcPath is error",
56-
isoPath: "iso_tests.iso",
58+
isoPath: testISOPath,
5759
srcPath: "/t1.txt",
5860
destPath: testDir + "/test1.txt",
5961
expectedError: true,
6062
},
6163
{
6264
name: "destPath is empty",
63-
isoPath: "iso_test.iso",
65+
isoPath: testISOPath,
6466
srcPath: "/test1.txt",
6567
destPath: "",
6668
expectedError: true,
6769
},
6870
{
6971
name: "find files in a folder",
70-
isoPath: "./iso_test.iso",
72+
isoPath: testISOPath,
7173
srcPath: "/test2/test2.txt",
7274
destPath: testDir + "/test2.txt",
7375
expectedError: false,
File renamed without changes.
File renamed without changes.

pkg/drivers/hyperkit/driver.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
ps "github.com/mitchellh/go-ps"
3838
hyperkit "github.com/moby/hyperkit/go"
3939
"github.com/pkg/errors"
40-
pkgdrivers "k8s.io/minikube/pkg/drivers"
40+
"k8s.io/minikube/pkg/drivers/common"
4141
"k8s.io/minikube/pkg/minikube/detect"
4242
)
4343

@@ -53,7 +53,7 @@ const (
5353
// Driver is the machine driver for Hyperkit
5454
type Driver struct {
5555
*drivers.BaseDriver
56-
*pkgdrivers.CommonDriver
56+
*common.CommonDriver
5757
Boot2DockerURL string
5858
DiskSize int
5959
CPU int
@@ -73,7 +73,7 @@ func NewDriver(_, _ string) *Driver {
7373
BaseDriver: &drivers.BaseDriver{
7474
SSHUser: "docker",
7575
},
76-
CommonDriver: &pkgdrivers.CommonDriver{},
76+
CommonDriver: &common.CommonDriver{},
7777
}
7878
}
7979

@@ -103,7 +103,7 @@ func (d *Driver) Create() error {
103103
}
104104

105105
// TODO: handle different disk types.
106-
if err := pkgdrivers.MakeDiskImage(d.BaseDriver, d.Boot2DockerURL, d.DiskSize); err != nil {
106+
if err := common.MakeDiskImage(d.BaseDriver, d.Boot2DockerURL, d.DiskSize); err != nil {
107107
return errors.Wrap(err, "making disk image")
108108
}
109109

@@ -196,7 +196,7 @@ func (d *Driver) Remove() error {
196196

197197
// Restart a host
198198
func (d *Driver) Restart() error {
199-
return pkgdrivers.Restart(d)
199+
return common.Restart(d)
200200
}
201201

202202
func (d *Driver) createHost() (*hyperkit.HyperKit, error) {
@@ -225,14 +225,14 @@ func (d *Driver) createHost() (*hyperkit.HyperKit, error) {
225225

226226
h.Disks = []hyperkit.Disk{
227227
&hyperkit.RawDisk{
228-
Path: pkgdrivers.GetDiskPath(d.BaseDriver),
228+
Path: common.GetDiskPath(d.BaseDriver),
229229
Size: d.DiskSize,
230230
Trim: true,
231231
},
232232
}
233233
for i := 0; i < d.ExtraDisks; i++ {
234234
h.Disks = append(h.Disks, &hyperkit.RawDisk{
235-
Path: pkgdrivers.ExtraDiskPath(d.BaseDriver, i),
235+
Path: common.ExtraDiskPath(d.BaseDriver, i),
236236
Size: d.DiskSize,
237237
Trim: true,
238238
})
@@ -287,7 +287,7 @@ func (d *Driver) setupIP(mac string) error {
287287
return fmt.Errorf("hyperkit crashed! command line:\n hyperkit %s", d.Cmdline)
288288
}
289289

290-
d.IPAddress, err = pkgdrivers.GetIPAddressByMACAddress(mac)
290+
d.IPAddress, err = common.GetIPAddressByMACAddress(mac)
291291
if err != nil {
292292
return &tempError{err}
293293
}
@@ -430,7 +430,7 @@ func (d *Driver) extractKernel(isoPath string) error {
430430
{"/boot/initrd", "initrd"},
431431
} {
432432
fullDestPath := d.ResolveStorePath(f.destPath)
433-
if err := pkgdrivers.ExtractFile(isoPath, f.pathInIso, fullDestPath); err != nil {
433+
if err := common.ExtractFile(isoPath, f.pathInIso, fullDestPath); err != nil {
434434
return err
435435
}
436436
}

0 commit comments

Comments
 (0)