From 340cfcc28470746b8979307164b3dfd8e7edcd68 Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Tue, 13 Oct 2015 13:31:59 -0400 Subject: [PATCH 1/3] iscsi: if port is not provided, use default 3260 for target portal Signed-off-by: Huamin Chen --- pkg/volume/iscsi/iscsi.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 1d67e04385f..60fa9a8b0d0 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -18,6 +18,7 @@ package iscsi import ( "strconv" + "strings" "github.com/golang/glog" "k8s.io/kubernetes/pkg/api" @@ -94,12 +95,16 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI } lun := strconv.Itoa(iscsi.Lun) + portal := iscsi.TargetPortal + if !strings.Contains(portal, ":") { + portal = iscsi.TargetPortal + ":3260" + } return &iscsiDiskBuilder{ iscsiDisk: &iscsiDisk{ podUID: podUID, volName: spec.Name(), - portal: iscsi.TargetPortal, + portal: portal, iqn: iscsi.IQN, lun: lun, manager: manager, From 69a1f33dd5fe17e7811c5ce028f3467a49549c88 Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Wed, 14 Oct 2015 10:30:04 -0400 Subject: [PATCH 2/3] iscsi: format disk if no filesystem is found Signed-off-by: Huamin Chen --- pkg/volume/iscsi/iscsi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 60fa9a8b0d0..9c75334348a 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -108,7 +108,7 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI iqn: iscsi.IQN, lun: lun, manager: manager, - mounter: mounter, + mounter: &mount.SafeFormatAndMount{mounter, exec.New()}, plugin: plugin}, fsType: iscsi.FSType, readOnly: readOnly, From 76df88f68ba7d0f0687d46a3a6c7a803be4b566c Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Wed, 14 Oct 2015 13:30:30 -0400 Subject: [PATCH 3/3] iscsi: make portal builder testable Signed-off-by: Huamin Chen --- pkg/volume/iscsi/iscsi.go | 12 ++++++++---- pkg/volume/iscsi/iscsi_test.go | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 9c75334348a..492f9175bfc 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -95,10 +95,7 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI } lun := strconv.Itoa(iscsi.Lun) - portal := iscsi.TargetPortal - if !strings.Contains(portal, ":") { - portal = iscsi.TargetPortal + ":3260" - } + portal := portalBuilder(iscsi.TargetPortal) return &iscsiDiskBuilder{ iscsiDisk: &iscsiDisk{ @@ -193,3 +190,10 @@ func (c *iscsiDiskCleaner) TearDown() error { func (c *iscsiDiskCleaner) TearDownAt(dir string) error { return diskTearDown(c.manager, *c, dir, c.mounter) } + +func portalBuilder(portal string) string { + if !strings.Contains(portal, ":") { + portal = portal + ":3260" + } + return portal +} diff --git a/pkg/volume/iscsi/iscsi_test.go b/pkg/volume/iscsi/iscsi_test.go index 9ee8eef9769..2025d922c75 100644 --- a/pkg/volume/iscsi/iscsi_test.go +++ b/pkg/volume/iscsi/iscsi_test.go @@ -250,3 +250,12 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { t.Errorf("Expected true for builder.IsReadOnly") } } + +func TestPortalBuilder(t *testing.T) { + if portal := portalBuilder("127.0.0.1"); portal != "127.0.0.1:3260" { + t.Errorf("wrong portal: %s", portal) + } + if portal := portalBuilder("127.0.0.1:3260"); portal != "127.0.0.1:3260" { + t.Errorf("wrong portal: %s", portal) + } +}