forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#48940 from rootfs/fc-fencing
Automatic merge from submit-queue (batch tested with PRs 48377, 48940, 49144, 49062, 49148) support fc volume attach and detach **What this PR does / why we need it**: Support FC volume attach and detach to enforce RWO access **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes#48953 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
- Loading branch information
Showing
7 changed files
with
185 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package fc | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/kubernetes/pkg/util/exec" | ||
"k8s.io/kubernetes/pkg/util/mount" | ||
"k8s.io/kubernetes/pkg/volume" | ||
volumeutil "k8s.io/kubernetes/pkg/volume/util" | ||
) | ||
|
||
type fcAttacher struct { | ||
host volume.VolumeHost | ||
manager diskManager | ||
exe exec.Interface | ||
} | ||
|
||
var _ volume.Attacher = &fcAttacher{} | ||
|
||
var _ volume.AttachableVolumePlugin = &fcPlugin{} | ||
|
||
func (plugin *fcPlugin) NewAttacher() (volume.Attacher, error) { | ||
return &fcAttacher{ | ||
host: plugin.host, | ||
manager: &FCUtil{}, | ||
exe: exec.New(), | ||
}, nil | ||
} | ||
|
||
func (plugin *fcPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) { | ||
mounter := plugin.host.GetMounter() | ||
return mount.GetMountRefs(mounter, deviceMountPath) | ||
} | ||
|
||
func (attacher *fcAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (attacher *fcAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { | ||
volumesAttachedCheck := make(map[*volume.Spec]bool) | ||
for _, spec := range specs { | ||
volumesAttachedCheck[spec] = true | ||
} | ||
|
||
return volumesAttachedCheck, nil | ||
} | ||
|
||
func (attacher *fcAttacher) WaitForAttach(spec *volume.Spec, devicePath string, timeout time.Duration) (string, error) { | ||
mounter, err := volumeSpecToMounter(spec, attacher.host) | ||
if err != nil { | ||
glog.Warningf("failed to get fc mounter: %v", err) | ||
return "", err | ||
} | ||
return attacher.manager.AttachDisk(*mounter) | ||
} | ||
|
||
func (attacher *fcAttacher) GetDeviceMountPath( | ||
spec *volume.Spec) (string, error) { | ||
mounter, err := volumeSpecToMounter(spec, attacher.host) | ||
if err != nil { | ||
glog.Warningf("failed to get fc mounter: %v", err) | ||
return "", err | ||
} | ||
|
||
return attacher.manager.MakeGlobalPDName(*mounter.fcDisk), nil | ||
} | ||
|
||
func (attacher *fcAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { | ||
mounter := attacher.host.GetMounter() | ||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
if err := os.MkdirAll(deviceMountPath, 0750); err != nil { | ||
return err | ||
} | ||
notMnt = true | ||
} else { | ||
return err | ||
} | ||
} | ||
|
||
volumeSource, readOnly, err := getVolumeSource(spec) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
options := []string{} | ||
if readOnly { | ||
options = append(options, "ro") | ||
} | ||
if notMnt { | ||
diskMounter := &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()} | ||
mountOptions := volume.MountOptionFromSpec(spec, options...) | ||
err = diskMounter.FormatAndMount(devicePath, deviceMountPath, volumeSource.FSType, mountOptions) | ||
if err != nil { | ||
os.Remove(deviceMountPath) | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type fcDetacher struct { | ||
mounter mount.Interface | ||
manager diskManager | ||
exe exec.Interface | ||
} | ||
|
||
var _ volume.Detacher = &fcDetacher{} | ||
|
||
func (plugin *fcPlugin) NewDetacher() (volume.Detacher, error) { | ||
return &fcDetacher{ | ||
mounter: plugin.host.GetMounter(), | ||
manager: &FCUtil{}, | ||
exe: exec.New(), | ||
}, nil | ||
} | ||
|
||
func (detacher *fcDetacher) Detach(deviceMountPath string, nodeName types.NodeName) error { | ||
return nil | ||
} | ||
|
||
func (detacher *fcDetacher) UnmountDevice(deviceMountPath string) error { | ||
return volumeutil.UnmountPath(deviceMountPath, detacher.mounter) | ||
} | ||
|
||
func volumeSpecToMounter(spec *volume.Spec, host volume.VolumeHost) (*fcDiskMounter, error) { | ||
fc, readOnly, err := getVolumeSource(spec) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if fc.Lun == nil { | ||
return nil, fmt.Errorf("empty lun") | ||
} | ||
lun := strconv.Itoa(int(*fc.Lun)) | ||
return &fcDiskMounter{ | ||
fcDisk: &fcDisk{ | ||
plugin: &fcPlugin{ | ||
host: host, | ||
}, | ||
wwns: fc.TargetWWNs, | ||
lun: lun, | ||
io: &osIOHandler{}, | ||
}, | ||
fsType: fc.FSType, | ||
readOnly: readOnly, | ||
mounter: &mount.SafeFormatAndMount{Interface: host.GetMounter(), Runner: exec.New()}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters