Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
224d39b0
Commit
224d39b0
authored
Aug 30, 2017
by
mtanino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block volumes Support: FC plugin update
This patch adds block volume support to FC volume plugin.
parent
db4134d0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
334 additions
and
42 deletions
+334
-42
attacher.go
pkg/volume/fc/attacher.go
+27
-10
disk_manager.go
pkg/volume/fc/disk_manager.go
+1
-0
fc.go
pkg/volume/fc/fc.go
+222
-15
fc_test.go
pkg/volume/fc/fc_test.go
+42
-0
fc_util.go
pkg/volume/fc/fc_util.go
+38
-13
fc_util_test.go
pkg/volume/fc/fc_util_test.go
+4
-4
No files found.
pkg/volume/fc/attacher.go
View file @
224d39b0
...
...
@@ -26,6 +26,8 @@ import (
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
...
...
@@ -176,17 +178,32 @@ func volumeSpecToMounter(spec *volume.Spec, host volume.VolumeHost) (*fcDiskMoun
}
else
{
return
nil
,
fmt
.
Errorf
(
"fc: no fc disk information found. failed to make a new mounter"
)
}
return
&
fcDiskMounter
{
fcDisk
:
&
fcDisk
{
plugin
:
&
fcPlugin
{
host
:
host
,
},
wwns
:
fc
.
TargetWWNs
,
lun
:
lun
,
wwids
:
wwids
,
io
:
&
osIOHandler
{},
fcDisk
:=
&
fcDisk
{
plugin
:
&
fcPlugin
{
host
:
host
,
},
wwns
:
fc
.
TargetWWNs
,
lun
:
lun
,
wwids
:
wwids
,
io
:
&
osIOHandler
{},
}
// TODO: remove feature gate check after no longer needed
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
BlockVolume
)
{
volumeMode
,
err
:=
volumehelper
.
GetVolumeMode
(
spec
)
if
err
!=
nil
{
return
nil
,
err
}
glog
.
V
(
5
)
.
Infof
(
"fc: volumeSpecToMounter volumeMode %s"
,
volumeMode
)
return
&
fcDiskMounter
{
fcDisk
:
fcDisk
,
fsType
:
fc
.
FSType
,
volumeMode
:
volumeMode
,
readOnly
:
readOnly
,
mounter
:
volumehelper
.
NewSafeFormatAndMountFromHost
(
fcPluginName
,
host
),
},
nil
}
return
&
fcDiskMounter
{
fcDisk
:
fcDisk
,
fsType
:
fc
.
FSType
,
readOnly
:
readOnly
,
mounter
:
volumehelper
.
NewSafeFormatAndMountFromHost
(
fcPluginName
,
host
),
...
...
pkg/volume/fc/disk_manager.go
View file @
224d39b0
...
...
@@ -27,6 +27,7 @@ import (
// Abstract interface to disk operations.
type
diskManager
interface
{
MakeGlobalPDName
(
disk
fcDisk
)
string
MakeGlobalVDPDName
(
disk
fcDisk
)
string
// Attaches the disk to the kubelet's host machine.
AttachDisk
(
b
fcDiskMounter
)
(
string
,
error
)
// Detaches the disk from the kubelet's host machine.
...
...
pkg/volume/fc/fc.go
View file @
224d39b0
This diff is collapsed.
Click to expand it.
pkg/volume/fc/fc_test.go
View file @
224d39b0
...
...
@@ -91,6 +91,11 @@ func (fake *fakeDiskManager) Cleanup() {
func
(
fake
*
fakeDiskManager
)
MakeGlobalPDName
(
disk
fcDisk
)
string
{
return
fake
.
tmpDir
}
func
(
fake
*
fakeDiskManager
)
MakeGlobalVDPDName
(
disk
fcDisk
)
string
{
return
fake
.
tmpDir
}
func
(
fake
*
fakeDiskManager
)
AttachDisk
(
b
fcDiskMounter
)
(
string
,
error
)
{
globalPath
:=
b
.
manager
.
MakeGlobalPDName
(
*
b
.
fcDisk
)
err
:=
os
.
MkdirAll
(
globalPath
,
0750
)
...
...
@@ -361,3 +366,40 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
t
.
Errorf
(
"Expected true for mounter.IsReadOnly"
)
}
}
func
Test_getWwnsLun
(
t
*
testing
.
T
)
{
num
:=
int32
(
0
)
fc
:=
&
v1
.
FCVolumeSource
{
TargetWWNs
:
[]
string
{
"500a0981891b8dc5"
},
FSType
:
"ext4"
,
Lun
:
&
num
,
}
wwn
,
lun
,
_
,
err
:=
getWwnsLunWwids
(
fc
)
// if no wwn and lun, exit
if
(
len
(
wwn
)
==
0
&&
lun
!=
"0"
)
||
err
!=
nil
{
t
.
Errorf
(
"no fc disk found"
)
}
}
func
Test_getWwids
(
t
*
testing
.
T
)
{
fc
:=
&
v1
.
FCVolumeSource
{
FSType
:
"ext4"
,
WWIDs
:
[]
string
{
"3600508b400105e210000900000490000"
},
}
_
,
_
,
wwid
,
err
:=
getWwnsLunWwids
(
fc
)
// if no wwn and lun, exit
if
len
(
wwid
)
==
0
||
err
!=
nil
{
t
.
Errorf
(
"no fc disk found"
)
}
}
func
Test_getWwnsLunWwidsError
(
t
*
testing
.
T
)
{
fc
:=
&
v1
.
FCVolumeSource
{
FSType
:
"ext4"
,
}
wwn
,
lun
,
wwid
,
err
:=
getWwnsLunWwids
(
fc
)
// expected no wwn and lun and wwid
if
(
len
(
wwn
)
!=
0
&&
lun
!=
""
&&
len
(
wwid
)
!=
0
)
||
err
==
nil
{
t
.
Errorf
(
"unexpected fc disk found"
)
}
}
pkg/volume/fc/fc_util.go
View file @
224d39b0
...
...
@@ -25,6 +25,9 @@ import (
"strings"
"github.com/golang/glog"
"k8s.io/api/core/v1"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
)
...
...
@@ -143,7 +146,7 @@ func scsiHostRescan(io ioHandler) {
}
}
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/
pod/
fc/target-lun-0
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/target-lun-0
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
if
len
(
wwns
)
!=
0
{
return
path
.
Join
(
host
.
GetPluginDir
(
fcPluginName
),
wwns
[
0
]
+
"-lun-"
+
lun
)
...
...
@@ -152,13 +155,27 @@ func makePDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids
}
}
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/volumeDevices/target-lun-0
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
if
len
(
wwns
)
!=
0
{
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
wwns
[
0
]
+
"-lun-"
+
lun
)
}
else
{
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
wwids
[
0
])
}
}
type
FCUtil
struct
{}
func
(
util
*
FCUtil
)
MakeGlobalPDName
(
fc
fcDisk
)
string
{
return
makePDNameInternal
(
fc
.
plugin
.
host
,
fc
.
wwns
,
fc
.
lun
,
fc
.
wwids
)
}
func
searchDisk
(
b
fcDiskMounter
)
(
string
,
string
)
{
// Global volume device plugin dir
func
(
util
*
FCUtil
)
MakeGlobalVDPDName
(
fc
fcDisk
)
string
{
return
makeVDPDNameInternal
(
fc
.
plugin
.
host
,
fc
.
wwns
,
fc
.
lun
,
fc
.
wwids
)
}
func
searchDisk
(
b
fcDiskMounter
)
(
string
,
error
)
{
var
diskIds
[]
string
var
disk
string
var
dm
string
...
...
@@ -198,14 +215,6 @@ func searchDisk(b fcDiskMounter) (string, string) {
scsiHostRescan
(
io
)
rescaned
=
true
}
return
disk
,
dm
}
func
(
util
*
FCUtil
)
AttachDisk
(
b
fcDiskMounter
)
(
string
,
error
)
{
devicePath
:=
""
var
disk
,
dm
string
disk
,
dm
=
searchDisk
(
b
)
// if no disk matches input wwn and lun, exit
if
disk
==
""
&&
dm
==
""
{
return
""
,
fmt
.
Errorf
(
"no fc disk found"
)
...
...
@@ -213,10 +222,26 @@ func (util *FCUtil) AttachDisk(b fcDiskMounter) (string, error) {
// if multipath devicemapper device is found, use it; otherwise use raw disk
if
dm
!=
""
{
devicePath
=
dm
}
else
{
devicePath
=
disk
return
dm
,
nil
}
return
disk
,
nil
}
func
(
util
*
FCUtil
)
AttachDisk
(
b
fcDiskMounter
)
(
string
,
error
)
{
devicePath
,
err
:=
searchDisk
(
b
)
if
err
!=
nil
{
return
""
,
err
}
// TODO: remove feature gate check after no longer needed
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
BlockVolume
)
{
// If the volumeMode is 'Block', plugin don't have to format the volume.
// The globalPDPath will be created by operationexecutor. Just return devicePath here.
glog
.
V
(
5
)
.
Infof
(
"fc: AttachDisk volumeMode: %s, devicePath: %s"
,
b
.
volumeMode
,
devicePath
)
if
b
.
volumeMode
==
v1
.
PersistentVolumeBlock
{
return
devicePath
,
nil
}
}
// mount it
globalPDPath
:=
util
.
MakeGlobalPDName
(
*
b
.
fcDisk
)
if
err
:=
os
.
MkdirAll
(
globalPDPath
,
0750
);
err
!=
nil
{
...
...
pkg/volume/fc/fc_util_test.go
View file @
224d39b0
...
...
@@ -92,9 +92,9 @@ func TestSearchDisk(t *testing.T) {
io
:
&
fakeIOHandler
{},
},
}
d
isk
,
dm
:=
searchDisk
(
fakeMounter
)
d
evicePath
,
error
:=
searchDisk
(
fakeMounter
)
// if no disk matches input wwn and lun, exit
if
d
isk
==
""
&&
dm
==
""
{
if
d
evicePath
==
""
||
error
!=
nil
{
t
.
Errorf
(
"no fc disk found"
)
}
}
...
...
@@ -106,9 +106,9 @@ func TestSearchDiskWWID(t *testing.T) {
io
:
&
fakeIOHandler
{},
},
}
d
isk
,
dm
:=
searchDisk
(
fakeMounter
)
d
evicePath
,
error
:=
searchDisk
(
fakeMounter
)
// if no disk matches input wwid, exit
if
d
isk
==
""
&&
dm
==
""
{
if
d
evicePath
==
""
||
error
!=
nil
{
t
.
Errorf
(
"no fc disk found"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment