Merge pull request #100746 from mengjiao-liu/fix-nil-call

Fixed a possible nil pointer dereference caused by variable `plug`
This commit is contained in:
Kubernetes Prow Robot 2021-05-26 14:49:38 -07:00 committed by GitHub
commit f7e62dc5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 47 additions and 47 deletions

View File

@ -50,7 +50,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/aws-ebs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/aws-ebs" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -460,7 +460,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/aws-ebs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")

View File

@ -51,7 +51,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/azure-file")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/azure-file" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -41,7 +41,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName(azureDataDiskPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != azureDataDiskPluginName {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -98,7 +98,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName(azureDataDiskPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")

View File

@ -40,7 +40,7 @@ func TestCanSupport(t *testing.T) {
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(t, tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/cephfs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/cephfs" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -240,7 +240,7 @@ func TestGetAccessModes(t *testing.T) {
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/cephfs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
modes := plug.GetAccessModes()
for _, v := range modes {

View File

@ -47,7 +47,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/cinder" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -354,7 +354,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")

View File

@ -308,7 +308,7 @@ func TestCanSupport(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plugin.GetPluginName() != configMapPluginName {
t.Errorf("Wrong name: %s", plugin.GetPluginName())
@ -340,7 +340,7 @@ func TestPlugin(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -406,7 +406,7 @@ func TestPluginReboot(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -464,7 +464,7 @@ func TestPluginOptional(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -563,7 +563,7 @@ func TestPluginKeysOptional(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -643,7 +643,7 @@ func TestInvalidConfigMapSetup(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}

View File

@ -58,7 +58,7 @@ func TestCanSupport(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plugin.GetPluginName() != downwardAPIPluginName {
t.Errorf("Wrong name: %s", plugin.GetPluginName())
@ -229,7 +229,7 @@ func newDownwardAPITest(t *testing.T, name string, volumeFiles, podLabels, podAn
pluginMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, host)
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
volumeSpec := &v1.Volume{

View File

@ -46,7 +46,7 @@ func makePluginUnderTest(t *testing.T, plugName, basePath string) volume.VolumeP
plug, err := plugMgr.FindPluginByName(plugName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
return plug
}

View File

@ -48,7 +48,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/fc")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/fc" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -49,7 +49,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/gce-pd" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -356,7 +356,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")

View File

@ -51,7 +51,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/git-repo" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -47,7 +47,7 @@ func TestCanSupport(t *testing.T) {
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(t, tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/glusterfs" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -46,7 +46,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/iscsi")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/iscsi" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -43,7 +43,7 @@ func TestCanSupport(t *testing.T) {
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), nil /* prober */, volumetest.NewFakeVolumeHost(t, tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/nfs" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -110,7 +110,7 @@ func TestVolumePluginMgrFunc(t *testing.T) {
plug, err := vpm.FindPluginByName(testPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != testPluginName {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -47,7 +47,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/portworx-volume")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/portworx-volume" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -890,7 +890,7 @@ func TestCanSupport(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plugin.GetPluginName() != projectedPluginName {
t.Errorf("Wrong name: %s", plugin.GetPluginName())
@ -921,7 +921,7 @@ func TestPlugin(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -986,7 +986,7 @@ func TestInvalidPathProjected(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -1036,7 +1036,7 @@ func TestPluginReboot(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -1090,7 +1090,7 @@ func TestPluginOptional(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -1188,7 +1188,7 @@ func TestPluginOptionalKeys(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(projectedPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}

View File

@ -43,7 +43,7 @@ func TestCanSupport(t *testing.T) {
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(t, tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/quobyte")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/quobyte" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -106,7 +106,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/rbd" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -252,7 +252,7 @@ func doTestPlugin(t *testing.T, c *testcase) {
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, fakeVolumeHost)
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
fakeMounter := fakeVolumeHost.GetMounter(plug.GetPluginName()).(*mount.FakeMounter)
fakeNodeName := types.NodeName("localhost")
@ -604,7 +604,7 @@ func TestConstructVolumeSpec(t *testing.T) {
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, fakeVolumeHost)
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
fakeMounter := fakeVolumeHost.GetMounter(plug.GetPluginName()).(*mount.FakeMounter)
@ -753,7 +753,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")

View File

@ -279,7 +279,7 @@ func TestCanSupport(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plugin.GetPluginName() != secretPluginName {
t.Errorf("Wrong name: %s", plugin.GetPluginName())
@ -310,7 +310,7 @@ func TestPlugin(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -384,7 +384,7 @@ func TestInvalidPathSecret(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -434,7 +434,7 @@ func TestPluginReboot(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -488,7 +488,7 @@ func TestPluginOptional(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}
@ -586,7 +586,7 @@ func TestPluginOptionalKeys(t *testing.T) {
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: testNamespace, UID: testPodUID}}

View File

@ -46,7 +46,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/storageos")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/storageos" {
t.Errorf("Wrong name: %s", plug.GetPluginName())

View File

@ -47,7 +47,7 @@ func TestCanSupport(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/vsphere-volume")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
if plug.GetPluginName() != "kubernetes.io/vsphere-volume" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
@ -248,7 +248,7 @@ func TestUnsupportedVolumeHost(t *testing.T) {
plug, err := plugMgr.FindPluginByName("kubernetes.io/vsphere-volume")
if err != nil {
t.Errorf("Can't find the plugin by name")
t.Fatal("Can't find the plugin by name")
}
_, err = plug.ConstructVolumeSpec("", "")