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
e019addc
Unverified
Commit
e019addc
authored
Sep 29, 2018
by
k8s-ci-robot
Committed by
GitHub
Sep 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68931 from mlmhl/check_volume_attachment
extract volume attachment status checking operation as a common function when attaching a CSI volume
parents
0b3a5cd6
2ff6b7e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
csi_attacher.go
pkg/volume/csi/csi_attacher.go
+27
-24
No files found.
pkg/volume/csi/csi_attacher.go
View file @
e019addc
...
@@ -159,21 +159,13 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
...
@@ -159,21 +159,13 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
glog
.
Error
(
log
(
"attacher.WaitForAttach failed for volume [%s] (will continue to try): %v"
,
volumeHandle
,
err
))
glog
.
Error
(
log
(
"attacher.WaitForAttach failed for volume [%s] (will continue to try): %v"
,
volumeHandle
,
err
))
return
""
,
fmt
.
Errorf
(
"volume %v has GET error for volume attachment %v: %v"
,
volumeHandle
,
attachID
,
err
)
return
""
,
fmt
.
Errorf
(
"volume %v has GET error for volume attachment %v: %v"
,
volumeHandle
,
attachID
,
err
)
}
}
// if being deleted, fail fast
successful
,
err
:=
verifyAttachmentStatus
(
attach
,
volumeHandle
)
if
attach
.
GetDeletionTimestamp
()
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
log
(
"VolumeAttachment [%s] has deletion timestamp, will not continue to wait for attachment"
,
attachID
))
return
""
,
err
return
""
,
errors
.
New
(
"volume attachment is being deleted"
)
}
}
// attachment OK
if
successful
{
if
attach
.
Status
.
Attached
{
return
attachID
,
nil
return
attachID
,
nil
}
}
// driver reports attach error
attachErr
:=
attach
.
Status
.
AttachError
if
attachErr
!=
nil
{
glog
.
Error
(
log
(
"attachment for %v failed: %v"
,
volumeHandle
,
attachErr
.
Message
))
return
""
,
errors
.
New
(
attachErr
.
Message
)
}
watcher
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Watch
(
meta
.
SingleObject
(
meta
.
ObjectMeta
{
Name
:
attachID
,
ResourceVersion
:
attach
.
ResourceVersion
}))
watcher
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Watch
(
meta
.
SingleObject
(
meta
.
ObjectMeta
{
Name
:
attachID
,
ResourceVersion
:
attach
.
ResourceVersion
}))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -194,21 +186,13 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
...
@@ -194,21 +186,13 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
switch
event
.
Type
{
switch
event
.
Type
{
case
watch
.
Added
,
watch
.
Modified
:
case
watch
.
Added
,
watch
.
Modified
:
attach
,
_
:=
event
.
Object
.
(
*
storage
.
VolumeAttachment
)
attach
,
_
:=
event
.
Object
.
(
*
storage
.
VolumeAttachment
)
// if being deleted, fail fast
successful
,
err
:=
verifyAttachmentStatus
(
attach
,
volumeHandle
)
if
attach
.
GetDeletionTimestamp
()
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
log
(
"VolumeAttachment [%s] has deletion timestamp, will not continue to wait for attachment"
,
attachID
))
return
""
,
err
return
""
,
errors
.
New
(
"volume attachment is being deleted"
)
}
}
// attachment OK
if
successful
{
if
attach
.
Status
.
Attached
{
return
attachID
,
nil
return
attachID
,
nil
}
}
// driver reports attach error
attachErr
:=
attach
.
Status
.
AttachError
if
attachErr
!=
nil
{
glog
.
Error
(
log
(
"attachment for %v failed: %v"
,
volumeHandle
,
attachErr
.
Message
))
return
""
,
errors
.
New
(
attachErr
.
Message
)
}
case
watch
.
Deleted
:
case
watch
.
Deleted
:
// if deleted, fail fast
// if deleted, fail fast
glog
.
Error
(
log
(
"VolumeAttachment [%s] has been deleted, will not continue to wait for attachment"
,
attachID
))
glog
.
Error
(
log
(
"VolumeAttachment [%s] has been deleted, will not continue to wait for attachment"
,
attachID
))
...
@@ -226,6 +210,25 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
...
@@ -226,6 +210,25 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
}
}
}
}
func
verifyAttachmentStatus
(
attachment
*
storage
.
VolumeAttachment
,
volumeHandle
string
)
(
bool
,
error
)
{
// if being deleted, fail fast
if
attachment
.
GetDeletionTimestamp
()
!=
nil
{
glog
.
Error
(
log
(
"VolumeAttachment [%s] has deletion timestamp, will not continue to wait for attachment"
,
attachment
.
Name
))
return
false
,
errors
.
New
(
"volume attachment is being deleted"
)
}
// attachment OK
if
attachment
.
Status
.
Attached
{
return
true
,
nil
}
// driver reports attach error
attachErr
:=
attachment
.
Status
.
AttachError
if
attachErr
!=
nil
{
glog
.
Error
(
log
(
"attachment for %v failed: %v"
,
volumeHandle
,
attachErr
.
Message
))
return
false
,
errors
.
New
(
attachErr
.
Message
)
}
return
false
,
nil
}
func
(
c
*
csiAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
func
(
c
*
csiAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
glog
.
V
(
4
)
.
Info
(
log
(
"probing attachment status for %d volume(s) "
,
len
(
specs
)))
glog
.
V
(
4
)
.
Info
(
log
(
"probing attachment status for %d volume(s) "
,
len
(
specs
)))
...
...
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