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
8ef04a84
Commit
8ef04a84
authored
Mar 04, 2015
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor mount utility code out gce_pd volume plugin
parent
9fcb48ca
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
135 additions
and
160 deletions
+135
-160
gce_pd.go
pkg/kubelet/volume/gce_pd/gce_pd.go
+6
-6
gce_pd_test.go
pkg/kubelet/volume/gce_pd/gce_pd_test.go
+3
-2
gce_util.go
pkg/kubelet/volume/gce_pd/gce_util.go
+1
-1
mount_util.go
pkg/kubelet/volume/gce_pd/mount_util.go
+0
-48
mount_util_test.go
pkg/kubelet/volume/gce_pd/mount_util_test.go
+0
-99
fake.go
pkg/util/mount/fake.go
+34
-0
mount.go
pkg/util/mount/mount.go
+27
-0
mount_linux.go
pkg/util/mount/mount_linux.go
+0
-0
mount_linux_test.go
pkg/util/mount/mount_linux_test.go
+60
-0
mount_unsupported.go
pkg/util/mount/mount_unsupported.go
+0
-0
mountpoint_unix.go
pkg/util/mount/mountpoint_unix.go
+2
-2
mountpoint_unsupported.go
pkg/util/mount/mountpoint_unsupported.go
+2
-2
No files found.
pkg/kubelet/volume/gce_pd/gce_pd.go
View file @
8ef04a84
...
...
@@ -170,7 +170,7 @@ func (pd *gcePersistentDisk) SetUp() error {
}
// TODO: handle failed mounts here.
mountpoint
,
err
:=
i
sMountPoint
(
pd
.
GetPath
())
mountpoint
,
err
:=
mount
.
I
sMountPoint
(
pd
.
GetPath
())
glog
.
V
(
4
)
.
Infof
(
"PersistentDisk set up: %s %v %v"
,
pd
.
GetPath
(),
mountpoint
,
err
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
err
...
...
@@ -199,7 +199,7 @@ func (pd *gcePersistentDisk) SetUp() error {
// Perform a bind mount to the full path to allow duplicate mounts of the same PD.
err
=
pd
.
mounter
.
Mount
(
globalPDPath
,
pd
.
GetPath
(),
""
,
mount
.
FlagBind
|
flags
,
""
)
if
err
!=
nil
{
mountpoint
,
mntErr
:=
i
sMountPoint
(
pd
.
GetPath
())
mountpoint
,
mntErr
:=
mount
.
I
sMountPoint
(
pd
.
GetPath
())
if
mntErr
!=
nil
{
glog
.
Errorf
(
"isMountpoint check failed: %v"
,
mntErr
)
return
err
...
...
@@ -209,7 +209,7 @@ func (pd *gcePersistentDisk) SetUp() error {
glog
.
Errorf
(
"Failed to unmount: %v"
,
mntErr
)
return
err
}
mountpoint
,
mntErr
:=
i
sMountPoint
(
pd
.
GetPath
())
mountpoint
,
mntErr
:=
mount
.
I
sMountPoint
(
pd
.
GetPath
())
if
mntErr
!=
nil
{
glog
.
Errorf
(
"isMountpoint check failed: %v"
,
mntErr
)
return
err
...
...
@@ -244,7 +244,7 @@ func (pd *gcePersistentDisk) GetPath() string {
// Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet.
func
(
pd
*
gcePersistentDisk
)
TearDown
()
error
{
mountpoint
,
err
:=
i
sMountPoint
(
pd
.
GetPath
())
mountpoint
,
err
:=
mount
.
I
sMountPoint
(
pd
.
GetPath
())
if
err
!=
nil
{
return
err
}
...
...
@@ -252,7 +252,7 @@ func (pd *gcePersistentDisk) TearDown() error {
return
os
.
Remove
(
pd
.
GetPath
())
}
refs
,
err
:=
g
etMountRefs
(
pd
.
mounter
,
pd
.
GetPath
())
refs
,
err
:=
mount
.
G
etMountRefs
(
pd
.
mounter
,
pd
.
GetPath
())
if
err
!=
nil
{
return
err
}
...
...
@@ -269,7 +269,7 @@ func (pd *gcePersistentDisk) TearDown() error {
return
err
}
}
mountpoint
,
mntErr
:=
i
sMountPoint
(
pd
.
GetPath
())
mountpoint
,
mntErr
:=
mount
.
I
sMountPoint
(
pd
.
GetPath
())
if
mntErr
!=
nil
{
glog
.
Errorf
(
"isMountpoint check failed: %v"
,
mntErr
)
return
err
...
...
pkg/kubelet/volume/gce_pd/gce_pd_test.go
View file @
8ef04a84
...
...
@@ -23,6 +23,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
)
func
TestCanSupport
(
t
*
testing
.
T
)
{
...
...
@@ -80,7 +81,7 @@ func TestPlugin(t *testing.T) {
},
},
}
builder
,
err
:=
plug
.
(
*
gcePersistentDiskPlugin
)
.
newBuilderInternal
(
spec
,
types
.
UID
(
"poduid"
),
&
fakePDManager
{},
&
f
akeMounter
{})
builder
,
err
:=
plug
.
(
*
gcePersistentDiskPlugin
)
.
newBuilderInternal
(
spec
,
types
.
UID
(
"poduid"
),
&
fakePDManager
{},
&
mount
.
F
akeMounter
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
...
...
@@ -111,7 +112,7 @@ func TestPlugin(t *testing.T) {
}
}
cleaner
,
err
:=
plug
.
(
*
gcePersistentDiskPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
fakePDManager
{},
&
f
akeMounter
{})
cleaner
,
err
:=
plug
.
(
*
gcePersistentDiskPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
fakePDManager
{},
&
mount
.
F
akeMounter
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
...
...
pkg/kubelet/volume/gce_pd/gce_util.go
View file @
8ef04a84
...
...
@@ -68,7 +68,7 @@ func (util *GCEDiskUtil) AttachAndMountDisk(pd *gcePersistentDisk, globalPDPath
}
// Only mount the PD globally once.
mountpoint
,
err
:=
i
sMountPoint
(
globalPDPath
)
mountpoint
,
err
:=
mount
.
I
sMountPoint
(
globalPDPath
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
globalPDPath
,
0750
);
err
!=
nil
{
...
...
pkg/kubelet/volume/gce_pd/mount_util.go
deleted
100644 → 0
View file @
9fcb48ca
/*
Copyright 2014 Google Inc. All rights reserved.
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
gce_pd
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
)
// Examines /proc/mounts to find all other references to the device referenced
// by mountPath.
func
getMountRefs
(
mounter
mount
.
Interface
,
mountPath
string
)
([]
string
,
error
)
{
mps
,
err
:=
mounter
.
List
()
if
err
!=
nil
{
return
nil
,
err
}
// Find the device name.
deviceName
:=
""
for
i
:=
range
mps
{
if
mps
[
i
]
.
Path
==
mountPath
{
deviceName
=
mps
[
i
]
.
Device
break
}
}
// Find all references to the device.
var
refs
[]
string
for
i
:=
range
mps
{
if
mps
[
i
]
.
Device
==
deviceName
&&
mps
[
i
]
.
Path
!=
mountPath
{
refs
=
append
(
refs
,
mps
[
i
]
.
Path
)
}
}
return
refs
,
nil
}
pkg/kubelet/volume/gce_pd/mount_util_test.go
deleted
100644 → 0
View file @
9fcb48ca
/*
Copyright 2015 Google Inc. All rights reserved.
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
gce_pd
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
)
type
fakeMounter
struct
{
mountPoints
[]
mount
.
MountPoint
}
func
(
f
*
fakeMounter
)
Mount
(
source
string
,
target
string
,
fstype
string
,
flags
uintptr
,
data
string
)
error
{
return
nil
}
func
(
f
*
fakeMounter
)
Unmount
(
target
string
,
flags
int
)
error
{
return
nil
}
func
(
f
*
fakeMounter
)
List
()
([]
mount
.
MountPoint
,
error
)
{
return
f
.
mountPoints
,
nil
}
func
TestGetMountRefs
(
t
*
testing
.
T
)
{
fm
:=
&
fakeMounter
{
[]
mount
.
MountPoint
{
{
Device
:
"/dev/sdb"
,
Path
:
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd"
},
{
Device
:
"/dev/sdb"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd-in-pod"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod2"
},
},
}
tests
:=
[]
struct
{
mountPath
string
expectedRefs
[]
string
}{
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd-in-pod"
,
[]
string
{
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd"
,
},
},
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod"
,
[]
string
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod2"
,
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
,
},
},
}
for
i
,
test
:=
range
tests
{
if
refs
,
err
:=
getMountRefs
(
fm
,
test
.
mountPath
);
err
!=
nil
||
!
setEquivalent
(
test
.
expectedRefs
,
refs
)
{
t
.
Errorf
(
"%d. getMountRefs(%q) = %v, %v; expected %v, nil"
,
i
,
test
.
mountPath
,
refs
,
err
,
test
.
expectedRefs
)
}
}
}
func
setEquivalent
(
set1
,
set2
[]
string
)
bool
{
map1
:=
make
(
map
[
string
]
bool
)
map2
:=
make
(
map
[
string
]
bool
)
for
_
,
s
:=
range
set1
{
map1
[
s
]
=
true
}
for
_
,
s
:=
range
set2
{
map2
[
s
]
=
true
}
for
s
:=
range
map1
{
if
!
map2
[
s
]
{
return
false
}
}
for
s
:=
range
map2
{
if
!
map1
[
s
]
{
return
false
}
}
return
true
}
pkg/util/mount/fake.go
0 → 100644
View file @
8ef04a84
/*
Copyright 2015 Google Inc. All rights reserved.
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
mount
// FakeMounter implements mount.Interface.
type
FakeMounter
struct
{
mountPoints
[]
MountPoint
}
func
(
f
*
FakeMounter
)
Mount
(
source
string
,
target
string
,
fstype
string
,
flags
uintptr
,
data
string
)
error
{
return
nil
}
func
(
f
*
FakeMounter
)
Unmount
(
target
string
,
flags
int
)
error
{
return
nil
}
func
(
f
*
FakeMounter
)
List
()
([]
MountPoint
,
error
)
{
return
f
.
mountPoints
,
nil
}
pkg/util/mount/mount.go
View file @
8ef04a84
...
...
@@ -49,3 +49,30 @@ type MountPoint struct {
Freq
int
Pass
int
}
// Examines /proc/mounts to find all other references to the device referenced
// by mountPath.
func
GetMountRefs
(
mounter
Interface
,
mountPath
string
)
([]
string
,
error
)
{
mps
,
err
:=
mounter
.
List
()
if
err
!=
nil
{
return
nil
,
err
}
// Find the device name.
deviceName
:=
""
for
i
:=
range
mps
{
if
mps
[
i
]
.
Path
==
mountPath
{
deviceName
=
mps
[
i
]
.
Device
break
}
}
// Find all references to the device.
var
refs
[]
string
for
i
:=
range
mps
{
if
mps
[
i
]
.
Device
==
deviceName
&&
mps
[
i
]
.
Path
!=
mountPath
{
refs
=
append
(
refs
,
mps
[
i
]
.
Path
)
}
}
return
refs
,
nil
}
pkg/util/mount/linux.go
→
pkg/util/mount/
mount_
linux.go
View file @
8ef04a84
File moved
pkg/util/mount/linux_test.go
→
pkg/util/mount/
mount_
linux_test.go
View file @
8ef04a84
...
...
@@ -91,3 +91,63 @@ func slicesEqual(a, b []string) bool {
}
return
true
}
func
TestGetMountRefs
(
t
*
testing
.
T
)
{
fm
:=
&
FakeMounter
{
[]
MountPoint
{
{
Device
:
"/dev/sdb"
,
Path
:
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd"
},
{
Device
:
"/dev/sdb"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd-in-pod"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod"
},
{
Device
:
"/dev/sdc"
,
Path
:
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod2"
},
},
}
tests
:=
[]
struct
{
mountPath
string
expectedRefs
[]
string
}{
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd-in-pod"
,
[]
string
{
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd"
,
},
},
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod"
,
[]
string
{
"/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd2-in-pod2"
,
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
,
},
},
}
for
i
,
test
:=
range
tests
{
if
refs
,
err
:=
GetMountRefs
(
fm
,
test
.
mountPath
);
err
!=
nil
||
!
setEquivalent
(
test
.
expectedRefs
,
refs
)
{
t
.
Errorf
(
"%d. getMountRefs(%q) = %v, %v; expected %v, nil"
,
i
,
test
.
mountPath
,
refs
,
err
,
test
.
expectedRefs
)
}
}
}
func
setEquivalent
(
set1
,
set2
[]
string
)
bool
{
map1
:=
make
(
map
[
string
]
bool
)
map2
:=
make
(
map
[
string
]
bool
)
for
_
,
s
:=
range
set1
{
map1
[
s
]
=
true
}
for
_
,
s
:=
range
set2
{
map2
[
s
]
=
true
}
for
s
:=
range
map1
{
if
!
map2
[
s
]
{
return
false
}
}
for
s
:=
range
map2
{
if
!
map1
[
s
]
{
return
false
}
}
return
true
}
pkg/util/mount/unsupported.go
→
pkg/util/mount/
mount_
unsupported.go
View file @
8ef04a84
File moved
pkg/
kubelet/volume/gce_pd/mount_util
_unix.go
→
pkg/
util/mount/mountpoint
_unix.go
View file @
8ef04a84
...
...
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
gce_pd
package
mount
import
(
"os"
...
...
@@ -26,7 +26,7 @@ import (
// Determine if a directory is a mountpoint, by comparing the device for the directory
// with the device for it's parent. If they are the same, it's not a mountpoint, if they're
// different, it is.
func
i
sMountPoint
(
file
string
)
(
bool
,
error
)
{
func
I
sMountPoint
(
file
string
)
(
bool
,
error
)
{
stat
,
err
:=
os
.
Stat
(
file
)
if
err
!=
nil
{
return
false
,
err
...
...
pkg/
kubelet/volume/gce_pd/mount_util
_unsupported.go
→
pkg/
util/mount/mountpoint
_unsupported.go
View file @
8ef04a84
...
...
@@ -16,13 +16,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
gce_pd
package
mount
import
(
"fmt"
)
// Dummy implementation for Windows
func
i
sMountPoint
(
file
string
)
(
bool
,
error
)
{
func
I
sMountPoint
(
file
string
)
(
bool
,
error
)
{
return
false
,
fmt
.
Errorf
(
"unimplemented"
)
}
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