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
12907467
Commit
12907467
authored
Dec 12, 2014
by
Tim Hockin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2886 from brendandburns/pd2
Fix GCE-PD so that it works even if the PD is attached.
parents
ef76981e
3da84e18
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
12 deletions
+107
-12
gce.go
pkg/cloudprovider/gce/gce.go
+15
-0
gce_util.go
pkg/volume/gce_util.go
+10
-6
mount_utils.go
pkg/volume/mount_utils.go
+40
-0
mount_utils_windows.go
pkg/volume/mount_utils_windows.go
+28
-0
volume.go
pkg/volume/volume.go
+14
-6
No files found.
pkg/cloudprovider/gce/gce.go
View file @
12907467
...
@@ -376,6 +376,21 @@ func (gce *GCECloud) AttachDisk(diskName string, readOnly bool) error {
...
@@ -376,6 +376,21 @@ func (gce *GCECloud) AttachDisk(diskName string, readOnly bool) error {
}
}
attachedDisk
:=
gce
.
convertDiskToAttachedDisk
(
disk
,
readWrite
)
attachedDisk
:=
gce
.
convertDiskToAttachedDisk
(
disk
,
readWrite
)
_
,
err
=
gce
.
service
.
Instances
.
AttachDisk
(
gce
.
projectID
,
gce
.
zone
,
gce
.
instanceID
,
attachedDisk
)
.
Do
()
_
,
err
=
gce
.
service
.
Instances
.
AttachDisk
(
gce
.
projectID
,
gce
.
zone
,
gce
.
instanceID
,
attachedDisk
)
.
Do
()
if
err
!=
nil
{
// Check if the disk is already attached to this instance. We do this only
// in the error case, since it is expected to be exceptional.
instance
,
err
:=
gce
.
service
.
Instances
.
Get
(
gce
.
projectID
,
gce
.
zone
,
gce
.
instanceID
)
.
Do
()
if
err
!=
nil
{
return
err
}
for
_
,
disk
:=
range
instance
.
Disks
{
if
disk
.
InitializeParams
.
DiskName
==
diskName
{
// Disk is already attached, we're good to go.
return
nil
}
}
}
return
err
return
err
}
}
...
...
pkg/volume/gce_util.go
View file @
12907467
...
@@ -72,19 +72,23 @@ func (util *GCEDiskUtil) AttachDisk(GCEPD *GCEPersistentDisk) error {
...
@@ -72,19 +72,23 @@ func (util *GCEDiskUtil) AttachDisk(GCEPD *GCEPersistentDisk) error {
}
}
globalPDPath
:=
makeGlobalPDName
(
GCEPD
.
RootDir
,
GCEPD
.
PDName
,
GCEPD
.
ReadOnly
)
globalPDPath
:=
makeGlobalPDName
(
GCEPD
.
RootDir
,
GCEPD
.
PDName
,
GCEPD
.
ReadOnly
)
// Only mount the PD globally once.
// Only mount the PD globally once.
_
,
err
=
os
.
Stat
(
globalPDPath
)
mountpoint
,
err
:=
isMountPoint
(
globalPDPath
)
if
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
{
err
=
os
.
MkdirAll
(
globalPDPath
,
0750
)
if
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
globalPDPath
,
0750
);
err
!=
nil
{
return
err
}
mountpoint
=
false
}
else
{
return
err
return
err
}
}
}
if
!
mountpoint
{
err
=
GCEPD
.
mounter
.
Mount
(
devicePath
,
globalPDPath
,
GCEPD
.
FSType
,
flags
,
""
)
err
=
GCEPD
.
mounter
.
Mount
(
devicePath
,
globalPDPath
,
GCEPD
.
FSType
,
flags
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
os
.
RemoveAll
(
globalPDPath
)
os
.
RemoveAll
(
globalPDPath
)
return
err
return
err
}
}
}
else
if
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
...
pkg/volume/mount_utils.go
0 → 100644
View file @
12907467
// +build !windows
/*
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
volume
import
(
"os"
"syscall"
)
// 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
isMountPoint
(
file
string
)
(
bool
,
error
)
{
stat
,
err
:=
os
.
Stat
(
file
)
if
err
!=
nil
{
return
false
,
err
}
rootStat
,
err
:=
os
.
Lstat
(
file
+
"/.."
)
if
err
!=
nil
{
return
false
,
err
}
// If the directory has the same device as parent, then it's not a mountpoint.
return
stat
.
Sys
()
.
(
*
syscall
.
Stat_t
)
.
Dev
!=
rootStat
.
Sys
()
.
(
*
syscall
.
Stat_t
)
.
Dev
,
nil
}
pkg/volume/mount_utils_windows.go
0 → 100644
View file @
12907467
// +build windows
/*
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
volume
import
(
"fmt"
)
// Dummy implementation for Windows
func
isMountPoint
(
file
string
)
(
bool
,
error
)
{
return
false
,
fmt
.
Errorf
(
"unimplemented"
)
}
pkg/volume/volume.go
View file @
12907467
...
@@ -235,11 +235,15 @@ func (PD *GCEPersistentDisk) GetPath() string {
...
@@ -235,11 +235,15 @@ func (PD *GCEPersistentDisk) GetPath() string {
// Attaches the disk and bind mounts to the volume path.
// Attaches the disk and bind mounts to the volume path.
func
(
PD
*
GCEPersistentDisk
)
SetUp
()
error
{
func
(
PD
*
GCEPersistentDisk
)
SetUp
()
error
{
// TODO: handle failed mounts here.
// TODO: handle failed mounts here.
if
_
,
err
:=
os
.
Stat
(
PD
.
GetPath
());
!
os
.
IsNotExist
(
err
)
{
mountpoint
,
err
:=
isMountPoint
(
PD
.
GetPath
())
glog
.
V
(
4
)
.
Infof
(
"PersistentDisk set up: %s %v %v"
,
PD
.
GetPath
(),
mountpoint
,
err
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
err
}
if
mountpoint
{
return
nil
return
nil
}
}
err
:=
PD
.
util
.
AttachDisk
(
PD
)
if
err
:=
PD
.
util
.
AttachDisk
(
PD
);
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
flags
:=
uintptr
(
0
)
flags
:=
uintptr
(
0
)
...
@@ -265,6 +269,13 @@ func (PD *GCEPersistentDisk) SetUp() error {
...
@@ -265,6 +269,13 @@ func (PD *GCEPersistentDisk) SetUp() error {
// Unmounts the bind mount, and detaches the disk only if the PD
// Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet.
// resource was the last reference to that disk on the kubelet.
func
(
PD
*
GCEPersistentDisk
)
TearDown
()
error
{
func
(
PD
*
GCEPersistentDisk
)
TearDown
()
error
{
mountpoint
,
err
:=
isMountPoint
(
PD
.
GetPath
())
if
err
!=
nil
{
return
err
}
if
!
mountpoint
{
return
os
.
RemoveAll
(
PD
.
GetPath
())
}
devicePath
,
refCount
,
err
:=
PD
.
mounter
.
RefCount
(
PD
)
devicePath
,
refCount
,
err
:=
PD
.
mounter
.
RefCount
(
PD
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -276,9 +287,6 @@ func (PD *GCEPersistentDisk) TearDown() error {
...
@@ -276,9 +287,6 @@ func (PD *GCEPersistentDisk) TearDown() error {
if
err
:=
os
.
RemoveAll
(
PD
.
GetPath
());
err
!=
nil
{
if
err
:=
os
.
RemoveAll
(
PD
.
GetPath
());
err
!=
nil
{
return
err
return
err
}
}
if
err
!=
nil
{
return
err
}
// If refCount is 1, then all bind mounts have been removed, and the
// If refCount is 1, then all bind mounts have been removed, and the
// remaining reference is the global mount. It is safe to detach.
// remaining reference is the global mount. It is safe to detach.
if
refCount
==
1
{
if
refCount
==
1
{
...
...
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