mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Detach the PD disk from the VM in some failure cases.
This commit is contained in:
parent
c3da4f0b19
commit
bc055d2bd0
@ -151,6 +151,13 @@ type gcePersistentDisk struct {
|
||||
legacyMode bool
|
||||
}
|
||||
|
||||
func detachDiskLogError(pd *gcePersistentDisk) {
|
||||
err := pd.manager.DetachDisk(pd, "/dev/disk/by-id/google-"+pd.pdName)
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to detach disk: %v (%v)", pd, err)
|
||||
}
|
||||
}
|
||||
|
||||
// SetUp attaches the disk and bind mounts to the volume path.
|
||||
func (pd *gcePersistentDisk) SetUp() error {
|
||||
if pd.legacyMode {
|
||||
@ -178,6 +185,8 @@ func (pd *gcePersistentDisk) SetUp() error {
|
||||
|
||||
volPath := pd.GetPath()
|
||||
if err := os.MkdirAll(volPath, 0750); err != nil {
|
||||
// TODO: we should really eject the attach/detach out into its own control loop.
|
||||
detachDiskLogError(pd)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -186,6 +195,8 @@ func (pd *gcePersistentDisk) SetUp() error {
|
||||
err = pd.mounter.Mount(globalPDPath, pd.GetPath(), "", mount.FlagBind|flags, "")
|
||||
if err != nil {
|
||||
os.RemoveAll(pd.GetPath())
|
||||
// TODO: we should really eject the attach/detach out into its own control loop.
|
||||
detachDiskLogError(pd)
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user