Unverified Commit afb26b93 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #51493 from mtanino/pr/BlockVolumesSupport-fc

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Block volumes Support: FC plugin update **What this PR does / why we need it**: Add interface changes to FC volume plugin to enable block volumes support feature. **Which issue this PR fixes**: Based on this proposal (kubernetes/community#805 & kubernetes/community#1265) and this feature issue: kubernetes/features#351 **Special notes for your reviewer**: This PR temporarily includes following changes except FC plugin change for reviewing purpose. These changes will be removed from the PR once they are merged. - (#50457) API Change - (#53385) VolumeMode PV-PVC Binding change - (#51494) Container runtime interface change, volumemanager changes, operationexecutor changes There are another PRs related to this functionality. (#50457) API Change (#53385) VolumeMode PV-PVC Binding change (#51494) Container runtime interface change, volumemanager changes, operationexecutor changes (#55112) Block volume: Command line printer update Plugins (#51493) Block volumes Support: FC plugin update (#54752) Block volumes Support: iSCSI plugin update **Release note**: ``` FC plugin: Support for block volume - This enables uses to allow attaching raw block volume to their pod without filesystem through FC plugin. ```
parents 9a0bbd0a 75829d26
...@@ -17,6 +17,7 @@ go_library( ...@@ -17,6 +17,7 @@ go_library(
], ],
importpath = "k8s.io/kubernetes/pkg/volume/fc", importpath = "k8s.io/kubernetes/pkg/volume/fc",
deps = [ deps = [
"//pkg/features:go_default_library",
"//pkg/util/mount:go_default_library", "//pkg/util/mount:go_default_library",
"//pkg/util/strings:go_default_library", "//pkg/util/strings:go_default_library",
"//pkg/volume:go_default_library", "//pkg/volume:go_default_library",
...@@ -24,7 +25,9 @@ go_library( ...@@ -24,7 +25,9 @@ go_library(
"//pkg/volume/util/volumehelper:go_default_library", "//pkg/volume/util/volumehelper:go_default_library",
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
], ],
) )
......
...@@ -26,6 +26,8 @@ import ( ...@@ -26,6 +26,8 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "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/util/mount"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
...@@ -176,17 +178,32 @@ func volumeSpecToMounter(spec *volume.Spec, host volume.VolumeHost) (*fcDiskMoun ...@@ -176,17 +178,32 @@ func volumeSpecToMounter(spec *volume.Spec, host volume.VolumeHost) (*fcDiskMoun
} else { } else {
return nil, fmt.Errorf("fc: no fc disk information found. failed to make a new mounter") return nil, fmt.Errorf("fc: no fc disk information found. failed to make a new mounter")
} }
fcDisk := &fcDisk{
return &fcDiskMounter{ plugin: &fcPlugin{
fcDisk: &fcDisk{ host: host,
plugin: &fcPlugin{
host: host,
},
wwns: fc.TargetWWNs,
lun: lun,
wwids: wwids,
io: &osIOHandler{},
}, },
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, fsType: fc.FSType,
readOnly: readOnly, readOnly: readOnly,
mounter: volumehelper.NewSafeFormatAndMountFromHost(fcPluginName, host), mounter: volumehelper.NewSafeFormatAndMountFromHost(fcPluginName, host),
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
// Abstract interface to disk operations. // Abstract interface to disk operations.
type diskManager interface { type diskManager interface {
MakeGlobalPDName(disk fcDisk) string MakeGlobalPDName(disk fcDisk) string
MakeGlobalVDPDName(disk fcDisk) string
// Attaches the disk to the kubelet's host machine. // Attaches the disk to the kubelet's host machine.
AttachDisk(b fcDiskMounter) (string, error) AttachDisk(b fcDiskMounter) (string, error)
// Detaches the disk from the kubelet's host machine. // Detaches the disk from the kubelet's host machine.
......
...@@ -91,6 +91,11 @@ func (fake *fakeDiskManager) Cleanup() { ...@@ -91,6 +91,11 @@ func (fake *fakeDiskManager) Cleanup() {
func (fake *fakeDiskManager) MakeGlobalPDName(disk fcDisk) string { func (fake *fakeDiskManager) MakeGlobalPDName(disk fcDisk) string {
return fake.tmpDir return fake.tmpDir
} }
func (fake *fakeDiskManager) MakeGlobalVDPDName(disk fcDisk) string {
return fake.tmpDir
}
func (fake *fakeDiskManager) AttachDisk(b fcDiskMounter) (string, error) { func (fake *fakeDiskManager) AttachDisk(b fcDiskMounter) (string, error) {
globalPath := b.manager.MakeGlobalPDName(*b.fcDisk) globalPath := b.manager.MakeGlobalPDName(*b.fcDisk)
err := os.MkdirAll(globalPath, 0750) err := os.MkdirAll(globalPath, 0750)
...@@ -361,3 +366,40 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -361,3 +366,40 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
t.Errorf("Expected true for mounter.IsReadOnly") 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")
}
}
...@@ -25,6 +25,9 @@ import ( ...@@ -25,6 +25,9 @@ import (
"strings" "strings"
"github.com/golang/glog" "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" "k8s.io/kubernetes/pkg/volume"
) )
...@@ -143,7 +146,7 @@ func scsiHostRescan(io ioHandler) { ...@@ -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 { func makePDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids []string) string {
if len(wwns) != 0 { if len(wwns) != 0 {
return path.Join(host.GetPluginDir(fcPluginName), wwns[0]+"-lun-"+lun) return path.Join(host.GetPluginDir(fcPluginName), wwns[0]+"-lun-"+lun)
...@@ -152,13 +155,27 @@ func makePDNameInternal(host volume.VolumeHost, wwns []string, lun string, wwids ...@@ -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{} type FCUtil struct{}
func (util *FCUtil) MakeGlobalPDName(fc fcDisk) string { func (util *FCUtil) MakeGlobalPDName(fc fcDisk) string {
return makePDNameInternal(fc.plugin.host, fc.wwns, fc.lun, fc.wwids) 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 diskIds []string
var disk string var disk string
var dm string var dm string
...@@ -198,14 +215,6 @@ func searchDisk(b fcDiskMounter) (string, string) { ...@@ -198,14 +215,6 @@ func searchDisk(b fcDiskMounter) (string, string) {
scsiHostRescan(io) scsiHostRescan(io)
rescaned = true 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 no disk matches input wwn and lun, exit
if disk == "" && dm == "" { if disk == "" && dm == "" {
return "", fmt.Errorf("no fc disk found") return "", fmt.Errorf("no fc disk found")
...@@ -213,10 +222,26 @@ func (util *FCUtil) AttachDisk(b fcDiskMounter) (string, error) { ...@@ -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 multipath devicemapper device is found, use it; otherwise use raw disk
if dm != "" { if dm != "" {
devicePath = dm return dm, nil
} else { }
devicePath = disk 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 // mount it
globalPDPath := util.MakeGlobalPDName(*b.fcDisk) globalPDPath := util.MakeGlobalPDName(*b.fcDisk)
if err := os.MkdirAll(globalPDPath, 0750); err != nil { if err := os.MkdirAll(globalPDPath, 0750); err != nil {
......
...@@ -92,9 +92,9 @@ func TestSearchDisk(t *testing.T) { ...@@ -92,9 +92,9 @@ func TestSearchDisk(t *testing.T) {
io: &fakeIOHandler{}, io: &fakeIOHandler{},
}, },
} }
disk, dm := searchDisk(fakeMounter) devicePath, error := searchDisk(fakeMounter)
// if no disk matches input wwn and lun, exit // if no disk matches input wwn and lun, exit
if disk == "" && dm == "" { if devicePath == "" || error != nil {
t.Errorf("no fc disk found") t.Errorf("no fc disk found")
} }
} }
...@@ -106,9 +106,9 @@ func TestSearchDiskWWID(t *testing.T) { ...@@ -106,9 +106,9 @@ func TestSearchDiskWWID(t *testing.T) {
io: &fakeIOHandler{}, io: &fakeIOHandler{},
}, },
} }
disk, dm := searchDisk(fakeMounter) devicePath, error := searchDisk(fakeMounter)
// if no disk matches input wwid, exit // if no disk matches input wwid, exit
if disk == "" && dm == "" { if devicePath == "" || error != nil {
t.Errorf("no fc disk found") t.Errorf("no fc disk found")
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment