mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
fix golint problem of volume cephfs/iscsi/nfs
This commit is contained in:
parent
d50e920906
commit
0094e05975
@ -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,
|
secretFile: secretFile,
|
||||||
readonly: readOnly,
|
readonly: readOnly,
|
||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
@ -188,7 +188,7 @@ type cephfs struct {
|
|||||||
path string
|
path string
|
||||||
id string
|
id string
|
||||||
secret string
|
secret string
|
||||||
secret_file string
|
secretFile string
|
||||||
readonly bool
|
readonly bool
|
||||||
mounter mount.Interface
|
mounter mount.Interface
|
||||||
plugin *cephfsPlugin
|
plugin *cephfsPlugin
|
||||||
@ -250,11 +250,10 @@ 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.
|
// 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(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.")
|
||||||
|
|
||||||
err = cephfsVolume.execMount(dir)
|
err = cephfsVolume.execMount(dir)
|
||||||
@ -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_opt := ""
|
cephOpt := ""
|
||||||
// override secretfile if secret is provided
|
// override secretfile if secret is provided
|
||||||
if cephfsVolume.secret != "" {
|
if cephfsVolume.secret != "" {
|
||||||
ceph_opt = "name=" + cephfsVolume.id + ",secret=" + cephfsVolume.secret
|
cephOpt = "name=" + cephfsVolume.id + ",secret=" + cephfsVolume.secret
|
||||||
} else {
|
} else {
|
||||||
ceph_opt = "name=" + cephfsVolume.id + ",secretfile=" + cephfsVolume.secret_file
|
cephOpt = "name=" + cephfsVolume.id + ",secretfile=" + cephfsVolume.secretFile
|
||||||
}
|
}
|
||||||
// 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_opt)
|
opt = append(opt, cephOpt)
|
||||||
|
|
||||||
// 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 {
|
|||||||
|
|
||||||
func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
|
func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
|
||||||
// cephfs keyring file
|
// cephfs keyring file
|
||||||
keyring_file := ""
|
keyringFile := ""
|
||||||
// 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 {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
keyring_file = path.Join(keyringPath, fileName)
|
keyringFile = path.Join(keyringPath, fileName)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
keyring_file = cephfsVolume.secret_file
|
keyringFile = cephfsVolume.secretFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
|||||||
|
|
||||||
mountArgs := []string{}
|
mountArgs := []string{}
|
||||||
mountArgs = append(mountArgs, "-k")
|
mountArgs = append(mountArgs, "-k")
|
||||||
mountArgs = append(mountArgs, keyring_file)
|
mountArgs = append(mountArgs, keyringFile)
|
||||||
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 {
|
|||||||
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\narguments: %s\nOutput: %s\n", err, mountArgs, string(output))
|
return fmt.Errorf("ceph-fuse failed: %v\narguments: %s\nOutput: %s", err, mountArgs, string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -268,8 +268,8 @@ type iscsiDisk struct {
|
|||||||
Iqn string
|
Iqn string
|
||||||
Lun string
|
Lun string
|
||||||
Iface string
|
Iface string
|
||||||
chap_discovery bool
|
chapDiscovery bool
|
||||||
chap_session bool
|
chapSession bool
|
||||||
secret map[string]string
|
secret map[string]string
|
||||||
InitiatorName string
|
InitiatorName string
|
||||||
plugin *iscsiPlugin
|
plugin *iscsiPlugin
|
||||||
@ -545,8 +545,8 @@ func createISCSIDisk(spec *volume.Spec, podUID types.UID, plugin *iscsiPlugin, m
|
|||||||
Iqn: iqn,
|
Iqn: iqn,
|
||||||
Lun: lun,
|
Lun: lun,
|
||||||
Iface: iface,
|
Iface: iface,
|
||||||
chap_discovery: chapDiscovery,
|
chapDiscovery: chapDiscovery,
|
||||||
chap_session: chapSession,
|
chapSession: chapSession,
|
||||||
secret: secret,
|
secret: secret,
|
||||||
InitiatorName: initiatorName,
|
InitiatorName: initiatorName,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
|
@ -54,12 +54,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chap_st = []string{
|
chapSt = []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_sess = []string{
|
chapSess = []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 (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
|
func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
|
||||||
if !b.chap_discovery {
|
if !b.chapDiscovery {
|
||||||
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 {
|
|||||||
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_st {
|
for _, k := range chapSt {
|
||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateISCSINode(b iscsiDiskMounter, tp string) error {
|
func updateISCSINode(b iscsiDiskMounter, tp string) error {
|
||||||
if !b.chap_session {
|
if !b.chapSession {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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_sess {
|
for _, k := range chapSess {
|
||||||
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 {
|
|||||||
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 {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
@ -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_err := plugMgr.FindRecyclablePluginBySpec(spec)
|
_, pluginErr := plugMgr.FindRecyclablePluginBySpec(spec)
|
||||||
if plugin_err != nil {
|
if pluginErr != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user