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
0094e059
Commit
0094e059
authored
Nov 17, 2018
by
jianglingxia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix golint problem of volume cephfs/iscsi/nfs
parent
d50e9209
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
56 deletions
+55
-56
cephfs.go
pkg/volume/cephfs/cephfs.go
+22
-23
iscsi.go
pkg/volume/iscsi/iscsi.go
+23
-23
iscsi_util.go
pkg/volume/iscsi/iscsi_util.go
+8
-8
nfs_test.go
pkg/volume/nfs/nfs_test.go
+2
-2
No files found.
pkg/volume/cephfs/cephfs.go
View file @
0094e059
...
@@ -144,7 +144,7 @@ func (plugin *cephfsPlugin) newMounterInternal(spec *volume.Spec, podUID types.U
...
@@ -144,7 +144,7 @@ func (plugin *cephfsPlugin) newMounterInternal(spec *volume.Spec, podUID types.U
path
:
path
,
path
:
path
,
secret
:
secret
,
secret
:
secret
,
id
:
id
,
id
:
id
,
secret
_file
:
secretFile
,
secret
File
:
secretFile
,
readonly
:
readOnly
,
readonly
:
readOnly
,
mounter
:
mounter
,
mounter
:
mounter
,
plugin
:
plugin
,
plugin
:
plugin
,
...
@@ -182,16 +182,16 @@ func (plugin *cephfsPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*
...
@@ -182,16 +182,16 @@ func (plugin *cephfsPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*
// CephFS volumes represent a bare host file or directory mount of an CephFS export.
// CephFS volumes represent a bare host file or directory mount of an CephFS export.
type
cephfs
struct
{
type
cephfs
struct
{
volName
string
volName
string
podUID
types
.
UID
podUID
types
.
UID
mon
[]
string
mon
[]
string
path
string
path
string
id
string
id
string
secret
string
secret
string
secret
_f
ile
string
secret
F
ile
string
readonly
bool
readonly
bool
mounter
mount
.
Interface
mounter
mount
.
Interface
plugin
*
cephfsPlugin
plugin
*
cephfsPlugin
volume
.
MetricsNil
volume
.
MetricsNil
mountOptions
[]
string
mountOptions
[]
string
}
}
...
@@ -250,10 +250,9 @@ func (cephfsVolume *cephfsMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -250,10 +250,9 @@ func (cephfsVolume *cephfsMounter) SetUpAt(dir string, fsGroup *int64) error {
if
err
==
nil
{
if
err
==
nil
{
// cephfs fuse mount succeeded.
// cephfs fuse mount succeeded.
return
nil
return
nil
}
else
{
// if cephfs fuse mount failed, fallback to kernel mount.
glog
.
V
(
2
)
.
Infof
(
"CephFS fuse mount failed: %v, fallback to kernel mount."
,
err
)
}
}
// if cephfs fuse mount failed, fallback to kernel mount.
glog
.
V
(
2
)
.
Infof
(
"CephFS fuse mount failed: %v, fallback to kernel mount."
,
err
)
}
}
glog
.
V
(
4
)
.
Info
(
"CephFS kernel mount."
)
glog
.
V
(
4
)
.
Info
(
"CephFS kernel mount."
)
...
@@ -298,19 +297,19 @@ func (cephfsVolume *cephfs) GetKeyringPath() string {
...
@@ -298,19 +297,19 @@ func (cephfsVolume *cephfs) GetKeyringPath() string {
func
(
cephfsVolume
*
cephfs
)
execMount
(
mountpoint
string
)
error
{
func
(
cephfsVolume
*
cephfs
)
execMount
(
mountpoint
string
)
error
{
// cephfs mount option
// cephfs mount option
ceph
_o
pt
:=
""
ceph
O
pt
:=
""
// override secretfile if secret is provided
// override secretfile if secret is provided
if
cephfsVolume
.
secret
!=
""
{
if
cephfsVolume
.
secret
!=
""
{
ceph
_o
pt
=
"name="
+
cephfsVolume
.
id
+
",secret="
+
cephfsVolume
.
secret
ceph
O
pt
=
"name="
+
cephfsVolume
.
id
+
",secret="
+
cephfsVolume
.
secret
}
else
{
}
else
{
ceph
_opt
=
"name="
+
cephfsVolume
.
id
+
",secretfile="
+
cephfsVolume
.
secret_f
ile
ceph
Opt
=
"name="
+
cephfsVolume
.
id
+
",secretfile="
+
cephfsVolume
.
secretF
ile
}
}
// build option array
// build option array
opt
:=
[]
string
{}
opt
:=
[]
string
{}
if
cephfsVolume
.
readonly
{
if
cephfsVolume
.
readonly
{
opt
=
append
(
opt
,
"ro"
)
opt
=
append
(
opt
,
"ro"
)
}
}
opt
=
append
(
opt
,
ceph
_o
pt
)
opt
=
append
(
opt
,
ceph
O
pt
)
// build src like mon1:6789,mon2:6789,mon3:6789:/
// build src like mon1:6789,mon2:6789,mon3:6789:/
hosts
:=
cephfsVolume
.
mon
hosts
:=
cephfsVolume
.
mon
...
@@ -346,7 +345,7 @@ func (cephfsMounter *cephfsMounter) checkFuseMount() bool {
...
@@ -346,7 +345,7 @@ func (cephfsMounter *cephfsMounter) checkFuseMount() bool {
func
(
cephfsVolume
*
cephfs
)
execFuseMount
(
mountpoint
string
)
error
{
func
(
cephfsVolume
*
cephfs
)
execFuseMount
(
mountpoint
string
)
error
{
// cephfs keyring file
// cephfs keyring file
keyring
_f
ile
:=
""
keyring
F
ile
:=
""
// override secretfile if secret is provided
// override secretfile if secret is provided
if
cephfsVolume
.
secret
!=
""
{
if
cephfsVolume
.
secret
!=
""
{
// TODO: cephfs fuse currently doesn't support secret option,
// TODO: cephfs fuse currently doesn't support secret option,
...
@@ -380,10 +379,10 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
...
@@ -380,10 +379,10 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
return
err
return
err
}
}
keyring
_f
ile
=
path
.
Join
(
keyringPath
,
fileName
)
keyring
F
ile
=
path
.
Join
(
keyringPath
,
fileName
)
}
else
{
}
else
{
keyring
_file
=
cephfsVolume
.
secret_f
ile
keyring
File
=
cephfsVolume
.
secretF
ile
}
}
// build src like mon1:6789,mon2:6789,mon3:6789:/
// build src like mon1:6789,mon2:6789,mon3:6789:/
...
@@ -399,7 +398,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
...
@@ -399,7 +398,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
mountArgs
:=
[]
string
{}
mountArgs
:=
[]
string
{}
mountArgs
=
append
(
mountArgs
,
"-k"
)
mountArgs
=
append
(
mountArgs
,
"-k"
)
mountArgs
=
append
(
mountArgs
,
keyring
_f
ile
)
mountArgs
=
append
(
mountArgs
,
keyring
F
ile
)
mountArgs
=
append
(
mountArgs
,
"-m"
)
mountArgs
=
append
(
mountArgs
,
"-m"
)
mountArgs
=
append
(
mountArgs
,
src
)
mountArgs
=
append
(
mountArgs
,
src
)
mountArgs
=
append
(
mountArgs
,
mountpoint
)
mountArgs
=
append
(
mountArgs
,
mountpoint
)
...
@@ -423,7 +422,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
...
@@ -423,7 +422,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
command
:=
exec
.
Command
(
"ceph-fuse"
,
mountArgs
...
)
command
:=
exec
.
Command
(
"ceph-fuse"
,
mountArgs
...
)
output
,
err
:=
command
.
CombinedOutput
()
output
,
err
:=
command
.
CombinedOutput
()
if
err
!=
nil
||
!
(
strings
.
Contains
(
string
(
output
),
"starting fuse"
))
{
if
err
!=
nil
||
!
(
strings
.
Contains
(
string
(
output
),
"starting fuse"
))
{
return
fmt
.
Errorf
(
"
Ceph-fuse failed: %v
\n
arguments: %s
\n
Output: %s
\n
"
,
err
,
mountArgs
,
string
(
output
))
return
fmt
.
Errorf
(
"
ceph-fuse failed: %v
\n
arguments: %s
\n
Output: %s
"
,
err
,
mountArgs
,
string
(
output
))
}
}
return
nil
return
nil
...
...
pkg/volume/iscsi/iscsi.go
View file @
0094e059
...
@@ -262,17 +262,17 @@ func (plugin *iscsiPlugin) ConstructBlockVolumeSpec(podUID types.UID, volumeName
...
@@ -262,17 +262,17 @@ func (plugin *iscsiPlugin) ConstructBlockVolumeSpec(podUID types.UID, volumeName
}
}
type
iscsiDisk
struct
{
type
iscsiDisk
struct
{
VolName
string
VolName
string
podUID
types
.
UID
podUID
types
.
UID
Portals
[]
string
Portals
[]
string
Iqn
string
Iqn
string
Lun
string
Lun
string
Iface
string
Iface
string
chap
_d
iscovery
bool
chap
D
iscovery
bool
chap
_s
ession
bool
chap
S
ession
bool
secret
map
[
string
]
string
secret
map
[
string
]
string
InitiatorName
string
InitiatorName
string
plugin
*
iscsiPlugin
plugin
*
iscsiPlugin
// Utility interface that provides API calls to the provider to attach/detach disks.
// Utility interface that provides API calls to the provider to attach/detach disks.
manager
diskManager
manager
diskManager
volume
.
MetricsProvider
volume
.
MetricsProvider
...
@@ -539,18 +539,18 @@ func createISCSIDisk(spec *volume.Spec, podUID types.UID, plugin *iscsiPlugin, m
...
@@ -539,18 +539,18 @@ func createISCSIDisk(spec *volume.Spec, podUID types.UID, plugin *iscsiPlugin, m
}
}
return
&
iscsiDisk
{
return
&
iscsiDisk
{
podUID
:
podUID
,
podUID
:
podUID
,
VolName
:
spec
.
Name
(),
VolName
:
spec
.
Name
(),
Portals
:
bkportal
,
Portals
:
bkportal
,
Iqn
:
iqn
,
Iqn
:
iqn
,
Lun
:
lun
,
Lun
:
lun
,
Iface
:
iface
,
Iface
:
iface
,
chap
_d
iscovery
:
chapDiscovery
,
chap
D
iscovery
:
chapDiscovery
,
chap
_s
ession
:
chapSession
,
chap
S
ession
:
chapSession
,
secret
:
secret
,
secret
:
secret
,
InitiatorName
:
initiatorName
,
InitiatorName
:
initiatorName
,
manager
:
manager
,
manager
:
manager
,
plugin
:
plugin
},
nil
plugin
:
plugin
},
nil
}
}
func
createSecretMap
(
spec
*
volume
.
Spec
,
plugin
*
iscsiPlugin
,
namespace
string
)
(
map
[
string
]
string
,
error
)
{
func
createSecretMap
(
spec
*
volume
.
Spec
,
plugin
*
iscsiPlugin
,
namespace
string
)
(
map
[
string
]
string
,
error
)
{
...
...
pkg/volume/iscsi/iscsi_util.go
View file @
0094e059
...
@@ -54,12 +54,12 @@ const (
...
@@ -54,12 +54,12 @@ const (
)
)
var
(
var
(
chap
_s
t
=
[]
string
{
chap
S
t
=
[]
string
{
"discovery.sendtargets.auth.username"
,
"discovery.sendtargets.auth.username"
,
"discovery.sendtargets.auth.password"
,
"discovery.sendtargets.auth.password"
,
"discovery.sendtargets.auth.username_in"
,
"discovery.sendtargets.auth.username_in"
,
"discovery.sendtargets.auth.password_in"
}
"discovery.sendtargets.auth.password_in"
}
chap
_s
ess
=
[]
string
{
chap
S
ess
=
[]
string
{
"node.session.auth.username"
,
"node.session.auth.username"
,
"node.session.auth.password"
,
"node.session.auth.password"
,
"node.session.auth.username_in"
,
"node.session.auth.username_in"
,
...
@@ -69,7 +69,7 @@ var (
...
@@ -69,7 +69,7 @@ var (
)
)
func
updateISCSIDiscoverydb
(
b
iscsiDiskMounter
,
tp
string
)
error
{
func
updateISCSIDiscoverydb
(
b
iscsiDiskMounter
,
tp
string
)
error
{
if
!
b
.
chap
_d
iscovery
{
if
!
b
.
chap
D
iscovery
{
return
nil
return
nil
}
}
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"discoverydb"
,
"-t"
,
"sendtargets"
,
"-p"
,
tp
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
"discovery.sendtargets.auth.authmethod"
,
"-v"
,
"CHAP"
)
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"discoverydb"
,
"-t"
,
"sendtargets"
,
"-p"
,
tp
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
"discovery.sendtargets.auth.authmethod"
,
"-v"
,
"CHAP"
)
...
@@ -77,7 +77,7 @@ func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
...
@@ -77,7 +77,7 @@ func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
return
fmt
.
Errorf
(
"iscsi: failed to update discoverydb with CHAP, output: %v"
,
string
(
out
))
return
fmt
.
Errorf
(
"iscsi: failed to update discoverydb with CHAP, output: %v"
,
string
(
out
))
}
}
for
_
,
k
:=
range
chap
_s
t
{
for
_
,
k
:=
range
chap
S
t
{
v
:=
b
.
secret
[
k
]
v
:=
b
.
secret
[
k
]
if
len
(
v
)
>
0
{
if
len
(
v
)
>
0
{
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"discoverydb"
,
"-t"
,
"sendtargets"
,
"-p"
,
tp
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
k
,
"-v"
,
v
)
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"discoverydb"
,
"-t"
,
"sendtargets"
,
"-p"
,
tp
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
k
,
"-v"
,
v
)
...
@@ -90,7 +90,7 @@ func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
...
@@ -90,7 +90,7 @@ func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
}
}
func
updateISCSINode
(
b
iscsiDiskMounter
,
tp
string
)
error
{
func
updateISCSINode
(
b
iscsiDiskMounter
,
tp
string
)
error
{
if
!
b
.
chap
_s
ession
{
if
!
b
.
chap
S
ession
{
return
nil
return
nil
}
}
...
@@ -99,7 +99,7 @@ func updateISCSINode(b iscsiDiskMounter, tp string) error {
...
@@ -99,7 +99,7 @@ func updateISCSINode(b iscsiDiskMounter, tp string) error {
return
fmt
.
Errorf
(
"iscsi: failed to update node with CHAP, output: %v"
,
string
(
out
))
return
fmt
.
Errorf
(
"iscsi: failed to update node with CHAP, output: %v"
,
string
(
out
))
}
}
for
_
,
k
:=
range
chap
_s
ess
{
for
_
,
k
:=
range
chap
S
ess
{
v
:=
b
.
secret
[
k
]
v
:=
b
.
secret
[
k
]
if
len
(
v
)
>
0
{
if
len
(
v
)
>
0
{
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"node"
,
"-p"
,
tp
,
"-T"
,
b
.
Iqn
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
k
,
"-v"
,
v
)
out
,
err
:=
b
.
exec
.
Run
(
"iscsiadm"
,
"-m"
,
"node"
,
"-p"
,
tp
,
"-T"
,
b
.
Iqn
,
"-I"
,
b
.
Iface
,
"-o"
,
"update"
,
"-n"
,
k
,
"-v"
,
v
)
...
@@ -210,7 +210,7 @@ func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
...
@@ -210,7 +210,7 @@ func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
defer
fp
.
Close
()
defer
fp
.
Close
()
encoder
:=
json
.
NewEncoder
(
fp
)
encoder
:=
json
.
NewEncoder
(
fp
)
if
err
=
encoder
.
Encode
(
conf
);
err
!=
nil
{
if
err
=
encoder
.
Encode
(
conf
);
err
!=
nil
{
return
fmt
.
Errorf
(
"iscsi: encode err: %v
.
"
,
err
)
return
fmt
.
Errorf
(
"iscsi: encode err: %v"
,
err
)
}
}
return
nil
return
nil
}
}
...
@@ -224,7 +224,7 @@ func (util *ISCSIUtil) loadISCSI(conf *iscsiDisk, mnt string) error {
...
@@ -224,7 +224,7 @@ func (util *ISCSIUtil) loadISCSI(conf *iscsiDisk, mnt string) error {
defer
fp
.
Close
()
defer
fp
.
Close
()
decoder
:=
json
.
NewDecoder
(
fp
)
decoder
:=
json
.
NewDecoder
(
fp
)
if
err
=
decoder
.
Decode
(
conf
);
err
!=
nil
{
if
err
=
decoder
.
Decode
(
conf
);
err
!=
nil
{
return
fmt
.
Errorf
(
"iscsi: decode err: %v
.
"
,
err
)
return
fmt
.
Errorf
(
"iscsi: decode err: %v"
,
err
)
}
}
return
nil
return
nil
}
}
...
...
pkg/volume/nfs/nfs_test.go
View file @
0094e059
...
@@ -89,8 +89,8 @@ func TestRecycler(t *testing.T) {
...
@@ -89,8 +89,8 @@ func TestRecycler(t *testing.T) {
plugMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
&
nfsPlugin
{
nil
,
volume
.
VolumeConfig
{}}},
nil
,
volumetest
.
NewFakeVolumeHost
(
tmpDir
,
nil
,
nil
))
plugMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
&
nfsPlugin
{
nil
,
volume
.
VolumeConfig
{}}},
nil
,
volumetest
.
NewFakeVolumeHost
(
tmpDir
,
nil
,
nil
))
spec
:=
&
volume
.
Spec
{
PersistentVolume
:
&
v1
.
PersistentVolume
{
Spec
:
v1
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
NFS
:
&
v1
.
NFSVolumeSource
{
Path
:
"/foo"
}}}}}
spec
:=
&
volume
.
Spec
{
PersistentVolume
:
&
v1
.
PersistentVolume
{
Spec
:
v1
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
NFS
:
&
v1
.
NFSVolumeSource
{
Path
:
"/foo"
}}}}}
_
,
plugin
_e
rr
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
_
,
plugin
E
rr
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
if
plugin
_e
rr
!=
nil
{
if
plugin
E
rr
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
t
.
Errorf
(
"Can't find the plugin by name"
)
}
}
}
}
...
...
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