mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
13
vendor/k8s.io/kubernetes/pkg/volume/local/BUILD
generated
vendored
13
vendor/k8s.io/kubernetes/pkg/volume/local/BUILD
generated
vendored
@ -20,7 +20,6 @@ go_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/client-go/kubernetes/scheme:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/record:go_default_library",
|
||||
],
|
||||
)
|
||||
@ -32,6 +31,10 @@ go_test(
|
||||
"local_test.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"local_linux_test.go",
|
||||
"local_test.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:windows": [
|
||||
"local_test.go",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
@ -54,6 +57,14 @@ go_test(
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/testing:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:windows": [
|
||||
"//pkg/volume:go_default_library",
|
||||
"//pkg/volume/testing: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/client-go/util/testing:go_default_library",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
59
vendor/k8s.io/kubernetes/pkg/volume/local/local.go
generated
vendored
59
vendor/k8s.io/kubernetes/pkg/volume/local/local.go
generated
vendored
@ -19,19 +19,20 @@ package local
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/kubernetes/pkg/kubelet/events"
|
||||
"k8s.io/kubernetes/pkg/util/keymutex"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/util/strings"
|
||||
stringsutil "k8s.io/kubernetes/pkg/util/strings"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
"k8s.io/kubernetes/pkg/volume/validation"
|
||||
@ -59,10 +60,7 @@ const (
|
||||
func (plugin *localVolumePlugin) Init(host volume.VolumeHost) error {
|
||||
plugin.host = host
|
||||
plugin.volumeLocks = keymutex.NewKeyMutex()
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
eventBroadcaster.StartLogging(glog.Infof)
|
||||
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "localvolume"})
|
||||
plugin.recorder = recorder
|
||||
plugin.recorder = host.GetEventRecorder()
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -222,7 +220,7 @@ type localVolume struct {
|
||||
}
|
||||
|
||||
func (l *localVolume) GetPath() string {
|
||||
return l.plugin.host.GetPodVolumeDir(l.podUID, strings.EscapeQualifiedNameForDisk(localVolumePluginName), l.volName)
|
||||
return l.plugin.host.GetPodVolumeDir(l.podUID, stringsutil.EscapeQualifiedNameForDisk(localVolumePluginName), l.volName)
|
||||
}
|
||||
|
||||
type localVolumeMounter struct {
|
||||
@ -276,31 +274,35 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
if !notMnt {
|
||||
return nil
|
||||
}
|
||||
refs, err := mount.GetMountRefsByDev(m.mounter, m.globalPath)
|
||||
refs, err := m.mounter.GetMountRefs(m.globalPath)
|
||||
if fsGroup != nil {
|
||||
if err != nil {
|
||||
glog.Errorf("cannot collect mounting information: %s %v", m.globalPath, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Only count mounts from other pods
|
||||
refs = m.filterPodMounts(refs)
|
||||
if len(refs) > 0 {
|
||||
fsGroupNew := int64(*fsGroup)
|
||||
fsGroupSame, fsGroupOld, err := volume.IsSameFSGroup(m.globalPath, fsGroupNew)
|
||||
fsGroupOld, err := m.mounter.GetFSGroup(m.globalPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check fsGroup for %s (%v)", m.globalPath, err)
|
||||
}
|
||||
if !fsGroupSame {
|
||||
if fsGroupNew != fsGroupOld {
|
||||
m.plugin.recorder.Eventf(m.pod, v1.EventTypeWarning, events.WarnAlreadyMountedVolume, "The requested fsGroup is %d, but the volume %s has GID %d. The volume may not be shareable.", fsGroupNew, m.volName, fsGroupOld)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
glog.Errorf("mkdir failed on disk %s (%v)", dir, err)
|
||||
return err
|
||||
if runtime.GOOS != "windows" {
|
||||
// skip below MkdirAll for windows since the "bind mount" logic is implemented differently in mount_wiondows.go
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
glog.Errorf("mkdir failed on disk %s (%v)", dir, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a bind mount to the full path to allow duplicate mounts of the same volume.
|
||||
options := []string{"bind"}
|
||||
if m.readOnly {
|
||||
@ -308,7 +310,8 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
}
|
||||
|
||||
glog.V(4).Infof("attempting to mount %s", dir)
|
||||
err = m.mounter.Mount(m.globalPath, dir, "", options)
|
||||
globalPath := util.MakeAbsolutePath(runtime.GOOS, m.globalPath)
|
||||
err = m.mounter.Mount(globalPath, dir, "", options)
|
||||
if err != nil {
|
||||
glog.Errorf("Mount of volume %s failed: %v", dir, err)
|
||||
notMnt, mntErr := m.mounter.IsNotMountPoint(dir)
|
||||
@ -344,6 +347,17 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// filterPodMounts only returns mount paths inside the kubelet pod directory
|
||||
func (m *localVolumeMounter) filterPodMounts(refs []string) []string {
|
||||
filtered := []string{}
|
||||
for _, r := range refs {
|
||||
if strings.HasPrefix(r, m.plugin.host.GetPodsDir()+string(os.PathSeparator)) {
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
type localVolumeUnmounter struct {
|
||||
*localVolume
|
||||
}
|
||||
@ -371,8 +385,13 @@ var _ volume.BlockVolumeMapper = &localVolumeMapper{}
|
||||
|
||||
// SetUpDevice provides physical device path for the local PV.
|
||||
func (m *localVolumeMapper) SetUpDevice() (string, error) {
|
||||
glog.V(4).Infof("SetupDevice returning path %s", m.globalPath)
|
||||
return m.globalPath, nil
|
||||
globalPath := util.MakeAbsolutePath(runtime.GOOS, m.globalPath)
|
||||
glog.V(4).Infof("SetupDevice returning path %s", globalPath)
|
||||
return globalPath, nil
|
||||
}
|
||||
|
||||
func (m *localVolumeMapper) MapDevice(devicePath, globalMapPath, volumeMapPath, volumeMapName string, podUID types.UID) error {
|
||||
return util.MapBlockVolume(devicePath, globalMapPath, volumeMapPath, volumeMapName, podUID)
|
||||
}
|
||||
|
||||
// localVolumeUnmapper implements the BlockVolumeUnmapper interface for local volumes.
|
||||
@ -391,7 +410,7 @@ func (u *localVolumeUnmapper) TearDownDevice(mapPath, devicePath string) error {
|
||||
// GetGlobalMapPath returns global map path and error.
|
||||
// path: plugins/kubernetes.io/kubernetes.io/local-volume/volumeDevices/{volumeName}
|
||||
func (lv *localVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
|
||||
return path.Join(lv.plugin.host.GetVolumeDevicePluginDir(strings.EscapeQualifiedNameForDisk(localVolumePluginName)),
|
||||
return filepath.Join(lv.plugin.host.GetVolumeDevicePluginDir(stringsutil.EscapeQualifiedNameForDisk(localVolumePluginName)),
|
||||
lv.volName), nil
|
||||
}
|
||||
|
||||
@ -400,5 +419,5 @@ func (lv *localVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
|
||||
// volName: local-pv-ff0d6d4
|
||||
func (lv *localVolume) GetPodDeviceMapPath() (string, string) {
|
||||
return lv.plugin.host.GetPodVolumeDeviceDir(lv.podUID,
|
||||
strings.EscapeQualifiedNameForDisk(localVolumePluginName)), lv.volName
|
||||
stringsutil.EscapeQualifiedNameForDisk(localVolumePluginName)), lv.volName
|
||||
}
|
||||
|
68
vendor/k8s.io/kubernetes/pkg/volume/local/local_linux_test.go
generated
vendored
Normal file
68
vendor/k8s.io/kubernetes/pkg/volume/local/local_linux_test.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
// +build linux darwin
|
||||
|
||||
/*
|
||||
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 local
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
func TestFSGroupMount(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
info, err := os.Stat(tmpDir)
|
||||
if err != nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
s := info.Sys().(*syscall.Stat_t)
|
||||
if s == nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
fsGroup1 := int64(s.Gid)
|
||||
fsGroup2 := fsGroup1 + 1
|
||||
pod1 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
||||
pod1.Spec.SecurityContext = &v1.PodSecurityContext{
|
||||
FSGroup: &fsGroup1,
|
||||
}
|
||||
pod2 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
||||
pod2.Spec.SecurityContext = &v1.PodSecurityContext{
|
||||
FSGroup: &fsGroup2,
|
||||
}
|
||||
err = testFSGroupMount(plug, pod1, tmpDir, fsGroup1)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Mounter: %v", err)
|
||||
}
|
||||
err = testFSGroupMount(plug, pod2, tmpDir, fsGroup2)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Mounter: %v", err)
|
||||
}
|
||||
//Checking if GID of tmpDir has not been changed by mounting it by second pod
|
||||
s = info.Sys().(*syscall.Stat_t)
|
||||
if s == nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
if fsGroup1 != int64(s.Gid) {
|
||||
t.Errorf("Old Gid %d for volume %s got overwritten by new Gid %d", fsGroup1, tmpDir, int64(s.Gid))
|
||||
}
|
||||
}
|
114
vendor/k8s.io/kubernetes/pkg/volume/local/local_test.go
generated
vendored
114
vendor/k8s.io/kubernetes/pkg/volume/local/local_test.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// +build linux darwin
|
||||
// +build linux darwin windows
|
||||
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
@ -22,7 +22,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"syscall"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
@ -199,11 +201,15 @@ func TestMountUnmount(t *testing.T) {
|
||||
if err := mounter.SetUp(nil); err != nil {
|
||||
t.Errorf("Expected success, got: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("SetUp() failed, volume path not created: %s", path)
|
||||
} else {
|
||||
t.Errorf("SetUp() failed: %v", err)
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
// skip this check in windows since the "bind mount" logic is implemented differently in mount_wiondows.go
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("SetUp() failed, volume path not created: %s", path)
|
||||
} else {
|
||||
t.Errorf("SetUp() failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,6 +266,7 @@ func TestMapUnmap(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Failed to SetUpDevice, err: %v", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(devPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("SetUpDevice() failed, volume path not created: %s", devPath)
|
||||
@ -302,45 +309,6 @@ func testFSGroupMount(plug volume.VolumePlugin, pod *v1.Pod, tmpDir string, fsGr
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestFSGroupMount(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
info, err := os.Stat(tmpDir)
|
||||
if err != nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
s := info.Sys().(*syscall.Stat_t)
|
||||
if s == nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
fsGroup1 := int64(s.Gid)
|
||||
fsGroup2 := fsGroup1 + 1
|
||||
pod1 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
||||
pod1.Spec.SecurityContext = &v1.PodSecurityContext{
|
||||
FSGroup: &fsGroup1,
|
||||
}
|
||||
pod2 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
||||
pod2.Spec.SecurityContext = &v1.PodSecurityContext{
|
||||
FSGroup: &fsGroup2,
|
||||
}
|
||||
err = testFSGroupMount(plug, pod1, tmpDir, fsGroup1)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Mounter: %v", err)
|
||||
}
|
||||
err = testFSGroupMount(plug, pod2, tmpDir, fsGroup2)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Mounter: %v", err)
|
||||
}
|
||||
//Checking if GID of tmpDir has not been changed by mounting it by second pod
|
||||
s = info.Sys().(*syscall.Stat_t)
|
||||
if s == nil {
|
||||
t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
|
||||
}
|
||||
if fsGroup1 != int64(s.Gid) {
|
||||
t.Errorf("Old Gid %d for volume %s got overwritten by new Gid %d", fsGroup1, tmpDir, int64(s.Gid))
|
||||
}
|
||||
}
|
||||
|
||||
func TestConstructVolumeSpec(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
@ -481,3 +449,57 @@ func TestUnsupportedPlugins(t *testing.T) {
|
||||
t.Errorf("Provisionable plugin found, expected none")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterPodMounts(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
||||
mounter, err := plug.NewMounter(getTestVolume(false, tmpDir, false), pod, volume.VolumeOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lvMounter, ok := mounter.(*localVolumeMounter)
|
||||
if !ok {
|
||||
t.Fatal("mounter is not localVolumeMounter")
|
||||
}
|
||||
|
||||
host := volumetest.NewFakeVolumeHost(tmpDir, nil, nil)
|
||||
podsDir := host.GetPodsDir()
|
||||
|
||||
cases := map[string]struct {
|
||||
input []string
|
||||
expected []string
|
||||
}{
|
||||
"empty": {
|
||||
[]string{},
|
||||
[]string{},
|
||||
},
|
||||
"not-pod-mount": {
|
||||
[]string{"/mnt/outside"},
|
||||
[]string{},
|
||||
},
|
||||
"pod-mount": {
|
||||
[]string{filepath.Join(podsDir, "pod-mount")},
|
||||
[]string{filepath.Join(podsDir, "pod-mount")},
|
||||
},
|
||||
"not-directory-prefix": {
|
||||
[]string{podsDir + "pod-mount"},
|
||||
[]string{},
|
||||
},
|
||||
"mix": {
|
||||
[]string{"/mnt/outside",
|
||||
filepath.Join(podsDir, "pod-mount"),
|
||||
"/another/outside",
|
||||
filepath.Join(podsDir, "pod-mount2")},
|
||||
[]string{filepath.Join(podsDir, "pod-mount"),
|
||||
filepath.Join(podsDir, "pod-mount2")},
|
||||
},
|
||||
}
|
||||
for name, test := range cases {
|
||||
output := lvMounter.filterPodMounts(test.input)
|
||||
if !reflect.DeepEqual(output, test.expected) {
|
||||
t.Errorf("%v failed: output %+v doesn't equal expected %+v", name, output, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user