diff --git a/cmd/flexvolume_driver/flexvolume_driver.go b/cmd/flexvolume_driver/flexvolume_driver.go index ae88d59d4..a37c20fb1 100644 --- a/cmd/flexvolume_driver/flexvolume_driver.go +++ b/cmd/flexvolume_driver/flexvolume_driver.go @@ -27,6 +27,6 @@ import ( func main() { rand.Seed(time.Now().UnixNano()) - driver := flexvolume.NewFlexVolumeDriver(utils.NewUUID, utils.NewMounter()) + driver := flexvolume.NewDriver(utils.NewUUID, utils.NewMounter()) os.Stdout.WriteString(driver.Run(os.Args[1:])) } diff --git a/pkg/config/crd.go b/pkg/config/crd.go index 00b46b8ca..1cca13d24 100644 --- a/pkg/config/crd.go +++ b/pkg/config/crd.go @@ -27,12 +27,12 @@ import ( func configMappingProps() *apiext.JSONSchemaProps { return &apiext.JSONSchemaProps{ Properties: map[string]apiext.JSONSchemaProps{ - "spec": apiext.JSONSchemaProps{ + "spec": { Properties: map[string]apiext.JSONSchemaProps{ - "nodeName": apiext.JSONSchemaProps{ + "nodeName": { Type: "string", }, - "nodeSelector": apiext.JSONSchemaProps{ + "nodeSelector": { Type: "object", // FIXME: https://github.com/kubernetes/kubernetes/issues/59485 // AdditionalProperties: &apiext.JSONSchemaPropsOrBool{ @@ -42,10 +42,10 @@ func configMappingProps() *apiext.JSONSchemaProps { // }, // }, }, - "priority": apiext.JSONSchemaProps{ + "priority": { Type: "integer", }, - "config": apiext.JSONSchemaProps{ + "config": { Properties: configFieldSet(&virtlet_v1.VirtletConfig{}).schemaProps(), }, }, diff --git a/pkg/diag/diag_test.go b/pkg/diag/diag_test.go index 37275f206..4a1d61695 100644 --- a/pkg/diag/diag_test.go +++ b/pkg/diag/diag_test.go @@ -100,38 +100,38 @@ func TestDiagServer(t *testing.T) { Name: "diagnostics", IsDir: true, Children: map[string]Result{ - "foo": Result{ + "foo": { Name: "foo", Ext: "txt", Data: "this is foo", }, - "bar": Result{ + "bar": { Name: "bar", Ext: "log", Data: "this is bar", }, - "simple_text": Result{ + "simple_text": { Name: "simple_text", Ext: "txt", Data: "baz", }, - "logdir": Result{ + "logdir": { Name: "logdir", IsDir: true, Children: map[string]Result{ - "log1": Result{ + "log1": { Name: "log1", Ext: "txt", Data: "log1 contents", }, - "log2": Result{ + "log2": { Name: "log2", Ext: "txt", Data: "log2 contents", }, }, }, - "fail": Result{ + "fail": { Name: "fail", Error: "oops", }, diff --git a/pkg/flexvolume/flexvolume.go b/pkg/flexvolume/flexvolume.go index e1cee42e5..80348730a 100644 --- a/pkg/flexvolume/flexvolume.go +++ b/pkg/flexvolume/flexvolume.go @@ -46,19 +46,22 @@ func init() { } } -type UuidGen func() string +// UUIDGen type function returns newly generated UUIDv4 as a string +type UUIDGen func() string -type FlexVolumeDriver struct { - uuidGen UuidGen +// Driver provides a virtlet specific implementation of +// https://kubernetes.io/docs/concepts/storage/volumes/#flexVolume +type Driver struct { + uuidGen UUIDGen mounter utils.Mounter } -// NewFlexVolumeDriver creates a FlexVolumeDriver struct -func NewFlexVolumeDriver(uuidGen UuidGen, mounter utils.Mounter) *FlexVolumeDriver { - return &FlexVolumeDriver{uuidGen: uuidGen, mounter: mounter} +// NewDriver creates a Driver struct +func NewDriver(uuidGen UUIDGen, mounter utils.Mounter) *Driver { + return &Driver{uuidGen: uuidGen, mounter: mounter} } -func (d *FlexVolumeDriver) populateVolumeDir(targetDir string, opts map[string]interface{}) error { +func (d *Driver) populateVolumeDir(targetDir string, opts map[string]interface{}) error { return utils.WriteJSON(filepath.Join(targetDir, flexvolumeDataFile), opts, 0700) } @@ -66,32 +69,32 @@ func (d *FlexVolumeDriver) populateVolumeDir(targetDir string, opts map[string]i // keeping them to make it easier to actually implement them // Invocation: init -func (d *FlexVolumeDriver) init() (map[string]interface{}, error) { +func (d *Driver) init() (map[string]interface{}, error) { return nil, nil } // Invocation: attach -func (d *FlexVolumeDriver) attach(jsonOptions, nodeName string) (map[string]interface{}, error) { +func (d *Driver) attach(jsonOptions, nodeName string) (map[string]interface{}, error) { return nil, nil } // Invocation: detach -func (d *FlexVolumeDriver) detach(mountDev, nodeName string) (map[string]interface{}, error) { +func (d *Driver) detach(mountDev, nodeName string) (map[string]interface{}, error) { return nil, nil } // Invocation: waitforattach -func (d *FlexVolumeDriver) waitForAttach(mountDev, jsonOptions string) (map[string]interface{}, error) { +func (d *Driver) waitForAttach(mountDev, jsonOptions string) (map[string]interface{}, error) { return map[string]interface{}{"device": mountDev}, nil } // Invocation: isattached -func (d *FlexVolumeDriver) isAttached(jsonOptions, nodeName string) (map[string]interface{}, error) { +func (d *Driver) isAttached(jsonOptions, nodeName string) (map[string]interface{}, error) { return map[string]interface{}{"attached": true}, nil } //Invocation: mount -func (d *FlexVolumeDriver) mount(targetMountDir, jsonOptions string) (map[string]interface{}, error) { +func (d *Driver) mount(targetMountDir, jsonOptions string) (map[string]interface{}, error) { var opts map[string]interface{} if err := json.Unmarshal([]byte(jsonOptions), &opts); err != nil { return nil, fmt.Errorf("failed to unmarshal json options: %v", err) @@ -137,7 +140,7 @@ func (d *FlexVolumeDriver) mount(targetMountDir, jsonOptions string) (map[string } // Invocation: unmount -func (d *FlexVolumeDriver) unmount(targetMountDir string) (map[string]interface{}, error) { +func (d *Driver) unmount(targetMountDir string) (map[string]interface{}, error) { if err := d.mounter.Unmount(targetMountDir, true); err != nil { return nil, fmt.Errorf("unmount %q: %v", targetMountDir, err.Error()) } @@ -149,7 +152,7 @@ func (d *FlexVolumeDriver) unmount(targetMountDir string) (map[string]interface{ return nil, nil } -type driverOp func(*FlexVolumeDriver, []string) (map[string]interface{}, error) +type driverOp func(*Driver, []string) (map[string]interface{}, error) type cmdInfo struct { numArgs int @@ -158,43 +161,43 @@ type cmdInfo struct { var commands = map[string]cmdInfo{ "init": { - 0, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 0, func(d *Driver, args []string) (map[string]interface{}, error) { return d.init() }, }, "attach": { - 2, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 2, func(d *Driver, args []string) (map[string]interface{}, error) { return d.attach(args[0], args[1]) }, }, "detach": { - 2, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 2, func(d *Driver, args []string) (map[string]interface{}, error) { return d.detach(args[0], args[1]) }, }, "waitforattach": { - 2, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 2, func(d *Driver, args []string) (map[string]interface{}, error) { return d.waitForAttach(args[0], args[1]) }, }, "isattached": { - 2, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 2, func(d *Driver, args []string) (map[string]interface{}, error) { return d.isAttached(args[0], args[1]) }, }, "mount": { - 2, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 2, func(d *Driver, args []string) (map[string]interface{}, error) { return d.mount(args[0], args[1]) }, }, "unmount": { - 1, func(d *FlexVolumeDriver, args []string) (map[string]interface{}, error) { + 1, func(d *Driver, args []string) (map[string]interface{}, error) { return d.unmount(args[0]) }, }, } -func (d *FlexVolumeDriver) doRun(args []string) (map[string]interface{}, error) { +func (d *Driver) doRun(args []string) (map[string]interface{}, error) { if len(args) == 0 { return nil, errors.New("no arguments passed to flexvolume driver") } @@ -203,17 +206,16 @@ func (d *FlexVolumeDriver) doRun(args []string) (map[string]interface{}, error) if cmdInfo, found := commands[op]; found { if cmdInfo.numArgs == nArgs { return cmdInfo.run(d, args[1:]) - } else { - return nil, fmt.Errorf("unexpected number of args %d (expected %d) for operation %q", nArgs, cmdInfo.numArgs, op) } - } else { - return map[string]interface{}{ - "status": "Not supported", - }, nil + return nil, fmt.Errorf("unexpected number of args %d (expected %d) for operation %q", nArgs, cmdInfo.numArgs, op) } + return map[string]interface{}{ + "status": "Not supported", + }, nil } -func (d *FlexVolumeDriver) Run(args []string) string { +// Run runs the driver +func (d *Driver) Run(args []string) string { r := formatResult(d.doRun(args)) if flexVolumeDebug { diff --git a/pkg/flexvolume/flexvolume_test.go b/pkg/flexvolume/flexvolume_test.go index 560ae41ce..b0103696e 100644 --- a/pkg/flexvolume/flexvolume_test.go +++ b/pkg/flexvolume/flexvolume_test.go @@ -32,7 +32,7 @@ import ( ) const ( - fakeUuid = "abb67e3c-71b3-4ddd-5505-8c4215d5c4eb" + fakeUUID = "abb67e3c-71b3-4ddd-5505-8c4215d5c4eb" ) type fakeMounter struct { @@ -120,7 +120,7 @@ func TestFlexVolume(t *testing.T) { "user": "libvirt", } cephJSONVolumeInfo := map[string]interface{}{ - "uuid": fakeUuid, + "uuid": fakeUUID, } for k, v := range cephJSONOpts { cephJSONVolumeInfo[k] = v @@ -257,8 +257,8 @@ func TestFlexVolume(t *testing.T) { var subdir string args := step.args mounter := newFakeMounter(t, tmpDir) - d := NewFlexVolumeDriver(func() string { - return fakeUuid + d := NewDriver(func() string { + return fakeUUID }, mounter) result := d.Run(args) var m map[string]interface{} diff --git a/pkg/libvirttools/cloudinit_test.go b/pkg/libvirttools/cloudinit_test.go index 489bf7e61..e74d5b0eb 100644 --- a/pkg/libvirttools/cloudinit_test.go +++ b/pkg/libvirttools/cloudinit_test.go @@ -935,7 +935,7 @@ func TestAddingFileLikeMount(t *testing.T) { func TestMtuForMacAddress(t *testing.T) { interfaces := []*network.InterfaceDescription{ - &network.InterfaceDescription{ + { MTU: 1234, HardwareAddr: net.HardwareAddr{0, 0, 0, 0, 0xa, 0xb}, }, diff --git a/pkg/libvirttools/virtualization_test.go b/pkg/libvirttools/virtualization_test.go index 7ac99c65f..29adefc0d 100644 --- a/pkg/libvirttools/virtualization_test.go +++ b/pkg/libvirttools/virtualization_test.go @@ -330,7 +330,7 @@ type volDevice struct { } func TestDomainDefinitions(t *testing.T) { - flexVolumeDriver := flexvolume.NewFlexVolumeDriver(func() string { + flexVolumeDriver := flexvolume.NewDriver(func() string { // note that this is only good for just one flexvolume return fakeUUID }, utils.NullMounter) diff --git a/pkg/manager/image.go b/pkg/manager/image.go index 50932e6d5..24041690d 100644 --- a/pkg/manager/image.go +++ b/pkg/manager/image.go @@ -98,7 +98,7 @@ func (v *VirtletImageService) ImageFsInfo(ctx context.Context, in *kubeapi.Image } return &kubeapi.ImageFsInfoResponse{ ImageFilesystems: []*kubeapi.FilesystemUsage{ - &kubeapi.FilesystemUsage{ + { Timestamp: v.clock.Now().UnixNano(), FsId: &kubeapi.FilesystemIdentifier{ Mountpoint: stats.Mountpoint, diff --git a/pkg/manager/runtime_test.go b/pkg/manager/runtime_test.go index 50765bd3e..76f737d44 100644 --- a/pkg/manager/runtime_test.go +++ b/pkg/manager/runtime_test.go @@ -283,15 +283,14 @@ func (tst *virtletCRITester) invoke(name string, req interface{}, failOnError bo } } return nil, err - } else { - resp := vals[0].Interface() - tst.rec.Rec("leave: "+name, resp) - return resp, nil } + resp := vals[0].Interface() + tst.rec.Rec("leave: "+name, resp) + return resp, nil } func (tst *virtletCRITester) getSampleFlexvolMounts(podSandboxID string) []*kubeapi.Mount { - flexVolumeDriver := flexvolume.NewFlexVolumeDriver(func() string { + flexVolumeDriver := flexvolume.NewDriver(func() string { return "abb67e3c-71b3-4ddd-5505-8c4215d5c4eb" }, utils.NullMounter) flexVolDir := filepath.Join(tst.kubeletRootDir, podSandboxID, "volumes/virtlet~flexvolume_driver", "vol1") @@ -385,10 +384,9 @@ func (tst *virtletCRITester) createContainer(sandbox *kubeapi.PodSandboxConfig, } if r, ok := resp.(*kubeapi.CreateContainerResponse); ok { return r.ContainerId - } else { - tst.t.Fatalf("bad value returned by CreateContainer: %#v", resp) - return "" // unreachable } + tst.t.Fatalf("bad value returned by CreateContainer: %#v", resp) + return "" // unreachable } func (tst *virtletCRITester) containerStatus(containerID string) { diff --git a/pkg/metadata/types/types.go b/pkg/metadata/types/types.go index 9c263e1d3..ccab9f6f0 100644 --- a/pkg/metadata/types/types.go +++ b/pkg/metadata/types/types.go @@ -280,7 +280,7 @@ type VMConfig struct { // RootVolumeDevice returns the volume device that should be used for // a persistent root filesystem, that is, its DevicePath is "/" func (c *VMConfig) RootVolumeDevice() *VMVolumeDevice { - for n, _ := range c.VolumeDevices { + for n := range c.VolumeDevices { dev := &c.VolumeDevices[n] if dev.IsRoot() { return dev diff --git a/pkg/tools/diag_test.go b/pkg/tools/diag_test.go index c6123165a..7221d5065 100644 --- a/pkg/tools/diag_test.go +++ b/pkg/tools/diag_test.go @@ -37,7 +37,7 @@ var ( Name: "diagnostics", IsDir: true, Children: map[string]diag.Result{ - "foo": diag.Result{ + "foo": { Name: "foo", Ext: "txt", Data: "foobar", @@ -48,12 +48,12 @@ var ( Name: "diagnostics", IsDir: true, Children: map[string]diag.Result{ - "r1": diag.Result{ + "r1": { Name: "r1", Ext: "log", Data: "baz1", }, - "r2": diag.Result{ + "r2": { Name: "r2", Ext: "log", Data: "baz2", @@ -65,35 +65,35 @@ var ( Name: "nodes", IsDir: true, Children: map[string]diag.Result{ - "kube-node-1": diag.Result{ + "kube-node-1": { Name: "kube-node-1", IsDir: true, Children: map[string]diag.Result{ "foo": fakeDiagResults[0].Children["foo"], - "virtlet-pod-virtlet": diag.Result{ + "virtlet-pod-virtlet": { Name: "virtlet-pod-virtlet", Ext: "log", Data: "foo-logs-virtlet", }, - "virtlet-pod-libvirt": diag.Result{ + "virtlet-pod-libvirt": { Name: "virtlet-pod-libvirt", Ext: "log", Data: "foo-logs-libvirt", }, }, }, - "kube-node-2": diag.Result{ + "kube-node-2": { Name: "kube-node-2", IsDir: true, Children: map[string]diag.Result{ "r1": fakeDiagResults[1].Children["r1"], "r2": fakeDiagResults[1].Children["r2"], - "virtlet-pod-virtlet": diag.Result{ + "virtlet-pod-virtlet": { Name: "virtlet-pod-virtlet", Ext: "log", Data: "bar-logs-virtlet", }, - "virtlet-pod-libvirt": diag.Result{ + "virtlet-pod-libvirt": { Name: "virtlet-pod-libvirt", Ext: "log", Data: "bar-logs-libvirt", diff --git a/pkg/virt/fake/fake_storage.go b/pkg/virt/fake/fake_storage.go index b2faf3b9c..a1591c7da 100644 --- a/pkg/virt/fake/fake_storage.go +++ b/pkg/virt/fake/fake_storage.go @@ -75,9 +75,8 @@ func (sc *FakeStorageConnection) CreateStoragePool(def *libvirtxml.StoragePool) func (sc *FakeStorageConnection) LookupStoragePoolByName(name string) (virt.StoragePool, error) { if p, found := sc.pools[name]; found { return p, nil - } else { - return nil, virt.ErrStoragePoolNotFound } + return nil, virt.ErrStoragePoolNotFound } // ListPools implements ListPools method of StorageConnection interface. diff --git a/tests/e2e/framework/pod_interface.go b/tests/e2e/framework/pod_interface.go index 0ef43cb47..73b192d71 100644 --- a/tests/e2e/framework/pod_interface.go +++ b/tests/e2e/framework/pod_interface.go @@ -112,9 +112,9 @@ func (pi *PodInterface) WaitForPodStatus(expectedContainerErrors []string, timin case !needErrors && cs.State.Running == nil: return fmt.Errorf("container %s in pod %s is not running: %s", cs.Name, podUpdated.Name, spew.Sdump(cs.State)) case !needErrors && !cs.Ready: - return fmt.Errorf("container %s in pod %s in not ready", cs.Name, podUpdated.Name) + return fmt.Errorf("container %s in pod %s did not passed its readiness probe", cs.Name, podUpdated.Name) case needErrors && cs.State.Waiting == nil: - return fmt.Errorf("container %s in pod %s not in waiting state", cs.Name) + return fmt.Errorf("container %s in pod %s not in waiting state", cs.Name, podUpdated.Name) case needErrors: for _, errStr := range expectedContainerErrors { if cs.State.Waiting.Reason == errStr { diff --git a/tests/e2e/restart_virtlet_test.go b/tests/e2e/restart_virtlet_test.go index 50e6fb968..f9e64b2a0 100644 --- a/tests/e2e/restart_virtlet_test.go +++ b/tests/e2e/restart_virtlet_test.go @@ -66,7 +66,6 @@ var _ = Describe("Virtlet restart [Disruptive]", func() { By(fmt.Sprintf("Running command: kubectl logs -n %s %s", controller.Namespace(), vm.Name)) err := localExecutor.Run(nil, &stdout, &stdout, "kubectl", "-n", controller.Namespace(), "logs", vm.Name) - fmt.Sprintf(stdout.String()) Expect(err).NotTo(HaveOccurred()) Expect(stdout.String()).Should(ContainSubstring("login as 'cirros' user.")) diff --git a/tests/integration/container_test.go b/tests/integration/container_test.go index bae19cf82..f9a8e5b47 100644 --- a/tests/integration/container_test.go +++ b/tests/integration/container_test.go @@ -46,7 +46,7 @@ type containerTester struct { sandboxes []*kubeapi.PodSandboxConfig containers []*criapi.ContainerTestConfig imageSpecs []*kubeapi.ImageSpec - fv *flexvolume.FlexVolumeDriver + fv *flexvolume.Driver podDirs []string volumeDirs []string } @@ -67,7 +67,7 @@ func newContainerTester(t *testing.T) *containerTester { {Image: imageCirrosUrl}, {Image: imageCopyCirrosUrl}, }, - fv: flexvolume.NewFlexVolumeDriver(utils.NewUUID, utils.NewMounter()), + fv: flexvolume.NewDriver(utils.NewUUID, utils.NewMounter()), } } diff --git a/tests/longevity/runner.go b/tests/longevity/runner.go index 8e3bf7ad0..20b34abd6 100644 --- a/tests/longevity/runner.go +++ b/tests/longevity/runner.go @@ -108,6 +108,7 @@ func Run(controller *framework.Controller, instances []*VMInstance) error { go instance.Test(ctx, instance, testVM, errChan) } +MainLoop: for { select { case err = <-errChan: @@ -116,7 +117,7 @@ func Run(controller *framework.Controller, instances []*VMInstance) error { return err case <-ctx.Done(): glog.Infof("Finishing testing...") - return nil + break MainLoop } } return nil diff --git a/tests/network/vm_network_test.go b/tests/network/vm_network_test.go index 1044c47c6..cdd1e7b6b 100644 --- a/tests/network/vm_network_test.go +++ b/tests/network/vm_network_test.go @@ -185,10 +185,7 @@ func (vnt *vmNetworkTester) teardown() { if err := netlink.LinkSetDown(link); err != nil { return err } - if err := netlink.LinkDel(link); err != nil { - return err - } - return nil + return netlink.LinkDel(link) }); err != nil { vnt.t.Logf("WARNING: error tearing down client tap: %v", err) }