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
8edae9b3
Commit
8edae9b3
authored
Sep 08, 2017
by
Hemant Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always populate volume status from node
parent
ed154988
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
29 deletions
+30
-29
attach_detach_controller.go
...ontroller/volume/attachdetach/attach_detach_controller.go
+5
-6
actual_state_of_world.go
...roller/volume/attachdetach/cache/actual_state_of_world.go
+2
-7
actual_state_of_world_test.go
...r/volume/attachdetach/cache/actual_state_of_world_test.go
+19
-12
reconciler_test.go
...troller/volume/attachdetach/reconciler/reconciler_test.go
+4
-4
No files found.
pkg/controller/volume/attachdetach/attach_detach_controller.go
View file @
8edae9b3
...
@@ -294,7 +294,7 @@ func (adc *attachDetachController) populateActualStateOfWorld() error {
...
@@ -294,7 +294,7 @@ func (adc *attachDetachController) populateActualStateOfWorld() error {
glog
.
Errorf
(
"Failed to mark the volume as attached: %v"
,
err
)
glog
.
Errorf
(
"Failed to mark the volume as attached: %v"
,
err
)
continue
continue
}
}
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
,
true
/* forceUnmount */
)
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
)
adc
.
addNodeToDswp
(
node
,
types
.
NodeName
(
node
.
Name
))
adc
.
addNodeToDswp
(
node
,
types
.
NodeName
(
node
.
Name
))
}
}
}
}
...
@@ -463,7 +463,7 @@ func (adc *attachDetachController) nodeUpdate(oldObj, newObj interface{}) {
...
@@ -463,7 +463,7 @@ func (adc *attachDetachController) nodeUpdate(oldObj, newObj interface{}) {
nodeName
:=
types
.
NodeName
(
node
.
Name
)
nodeName
:=
types
.
NodeName
(
node
.
Name
)
adc
.
addNodeToDswp
(
node
,
nodeName
)
adc
.
addNodeToDswp
(
node
,
nodeName
)
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
,
false
/* forceUnmount */
)
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
)
}
}
func
(
adc
*
attachDetachController
)
nodeDelete
(
obj
interface
{})
{
func
(
adc
*
attachDetachController
)
nodeDelete
(
obj
interface
{})
{
...
@@ -478,7 +478,7 @@ func (adc *attachDetachController) nodeDelete(obj interface{}) {
...
@@ -478,7 +478,7 @@ func (adc *attachDetachController) nodeDelete(obj interface{}) {
glog
.
Infof
(
"error removing node %q from desired-state-of-world: %v"
,
nodeName
,
err
)
glog
.
Infof
(
"error removing node %q from desired-state-of-world: %v"
,
nodeName
,
err
)
}
}
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
,
false
/* forceUnmount */
)
adc
.
processVolumesInUse
(
nodeName
,
node
.
Status
.
VolumesInUse
)
}
}
// processVolumesInUse processes the list of volumes marked as "in-use"
// processVolumesInUse processes the list of volumes marked as "in-use"
...
@@ -486,7 +486,7 @@ func (adc *attachDetachController) nodeDelete(obj interface{}) {
...
@@ -486,7 +486,7 @@ func (adc *attachDetachController) nodeDelete(obj interface{}) {
// corresponding volume in the actual state of the world to indicate that it is
// corresponding volume in the actual state of the world to indicate that it is
// mounted.
// mounted.
func
(
adc
*
attachDetachController
)
processVolumesInUse
(
func
(
adc
*
attachDetachController
)
processVolumesInUse
(
nodeName
types
.
NodeName
,
volumesInUse
[]
v1
.
UniqueVolumeName
,
forceUnmount
bool
)
{
nodeName
types
.
NodeName
,
volumesInUse
[]
v1
.
UniqueVolumeName
)
{
glog
.
V
(
4
)
.
Infof
(
"processVolumesInUse for node %q"
,
nodeName
)
glog
.
V
(
4
)
.
Infof
(
"processVolumesInUse for node %q"
,
nodeName
)
for
_
,
attachedVolume
:=
range
adc
.
actualStateOfWorld
.
GetAttachedVolumesForNode
(
nodeName
)
{
for
_
,
attachedVolume
:=
range
adc
.
actualStateOfWorld
.
GetAttachedVolumesForNode
(
nodeName
)
{
mounted
:=
false
mounted
:=
false
...
@@ -496,8 +496,7 @@ func (adc *attachDetachController) processVolumesInUse(
...
@@ -496,8 +496,7 @@ func (adc *attachDetachController) processVolumesInUse(
break
break
}
}
}
}
err
:=
adc
.
actualStateOfWorld
.
SetVolumeMountedByNode
(
err
:=
adc
.
actualStateOfWorld
.
SetVolumeMountedByNode
(
attachedVolume
.
VolumeName
,
nodeName
,
mounted
)
attachedVolume
.
VolumeName
,
nodeName
,
mounted
,
forceUnmount
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Warningf
(
glog
.
Warningf
(
"SetVolumeMountedByNode(%q, %q, %q) returned an error: %v"
,
"SetVolumeMountedByNode(%q, %q, %q) returned an error: %v"
,
...
...
pkg/controller/volume/attachdetach/cache/actual_state_of_world.go
View file @
8edae9b3
...
@@ -68,7 +68,7 @@ type ActualStateOfWorld interface {
...
@@ -68,7 +68,7 @@ type ActualStateOfWorld interface {
// returned.
// returned.
// If no node with the name nodeName exists in list of attached nodes for
// If no node with the name nodeName exists in list of attached nodes for
// the specified volume, an error is returned.
// the specified volume, an error is returned.
SetVolumeMountedByNode
(
volumeName
v1
.
UniqueVolumeName
,
nodeName
types
.
NodeName
,
mounted
bool
,
forceUnmount
bool
)
error
SetVolumeMountedByNode
(
volumeName
v1
.
UniqueVolumeName
,
nodeName
types
.
NodeName
,
mounted
bool
)
error
// SetNodeStatusUpdateNeeded sets statusUpdateNeeded for the specified
// SetNodeStatusUpdateNeeded sets statusUpdateNeeded for the specified
// node to true indicating the AttachedVolume field in the Node's Status
// node to true indicating the AttachedVolume field in the Node's Status
...
@@ -331,7 +331,7 @@ func (asw *actualStateOfWorld) AddVolumeNode(
...
@@ -331,7 +331,7 @@ func (asw *actualStateOfWorld) AddVolumeNode(
}
}
func
(
asw
*
actualStateOfWorld
)
SetVolumeMountedByNode
(
func
(
asw
*
actualStateOfWorld
)
SetVolumeMountedByNode
(
volumeName
v1
.
UniqueVolumeName
,
nodeName
types
.
NodeName
,
mounted
bool
,
forceUnmount
bool
)
error
{
volumeName
v1
.
UniqueVolumeName
,
nodeName
types
.
NodeName
,
mounted
bool
)
error
{
asw
.
Lock
()
asw
.
Lock
()
defer
asw
.
Unlock
()
defer
asw
.
Unlock
()
...
@@ -343,11 +343,6 @@ func (asw *actualStateOfWorld) SetVolumeMountedByNode(
...
@@ -343,11 +343,6 @@ func (asw *actualStateOfWorld) SetVolumeMountedByNode(
if
mounted
{
if
mounted
{
// Increment set count
// Increment set count
nodeObj
.
mountedByNodeSetCount
=
nodeObj
.
mountedByNodeSetCount
+
1
nodeObj
.
mountedByNodeSetCount
=
nodeObj
.
mountedByNodeSetCount
+
1
}
else
{
// Do not allow value to be reset unless it has been set at least once
if
nodeObj
.
mountedByNodeSetCount
==
0
&&
!
forceUnmount
{
return
nil
}
}
}
nodeObj
.
mountedByNode
=
mounted
nodeObj
.
mountedByNode
=
mounted
...
...
pkg/controller/volume/attachdetach/cache/actual_state_of_world_test.go
View file @
8edae9b3
...
@@ -506,8 +506,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSet(t *testing.T) {
...
@@ -506,8 +506,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSet(t *testing.T) {
}
}
// Act
// Act
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
// Assert
// Assert
if
setVolumeMountedErr1
!=
nil
{
if
setVolumeMountedErr1
!=
nil
{
...
@@ -527,7 +527,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSet(t *testing.T) {
...
@@ -527,7 +527,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSet(t *testing.T) {
// Populates data struct with one volume/node entry.
// Populates data struct with one volume/node entry.
// Calls SetVolumeMountedByNode once, setting mounted to false.
// Calls SetVolumeMountedByNode once, setting mounted to false.
// Verifies mountedByNode is
still true (since there was no SetVolumeMountedByNode to true call first)
// Verifies mountedByNode is
false because value is overwritten
func
Test_SetVolumeMountedByNode_Positive_UnsetWithoutInitialSet
(
t
*
testing
.
T
)
{
func
Test_SetVolumeMountedByNode_Positive_UnsetWithoutInitialSet
(
t
*
testing
.
T
)
{
// Arrange
// Arrange
volumePluginMgr
,
_
:=
volumetesting
.
GetTestVolumePluginMgr
(
t
)
volumePluginMgr
,
_
:=
volumetesting
.
GetTestVolumePluginMgr
(
t
)
...
@@ -541,20 +541,27 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithoutInitialSet(t *testing.T) {
...
@@ -541,20 +541,27 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithoutInitialSet(t *testing.T) {
t
.
Fatalf
(
"AddVolumeNode failed. Expected: <no error> Actual: <%v>"
,
addErr
)
t
.
Fatalf
(
"AddVolumeNode failed. Expected: <no error> Actual: <%v>"
,
addErr
)
}
}
attachedVolumes
:=
asw
.
GetAttachedVolumes
()
if
len
(
attachedVolumes
)
!=
1
{
t
.
Fatalf
(
"len(attachedVolumes) Expected: <1> Actual: <%v>"
,
len
(
attachedVolumes
))
}
verifyAttachedVolume
(
t
,
attachedVolumes
,
generatedVolumeName
,
string
(
volumeName
),
nodeName
,
devicePath
,
true
/* expectedMountedByNode */
,
false
/* expectNonZeroDetachRequestedTime */
)
// Act
// Act
setVolumeMountedErr
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
// Assert
// Assert
if
setVolumeMountedErr
!=
nil
{
if
setVolumeMountedErr
!=
nil
{
t
.
Fatalf
(
"SetVolumeMountedByNode failed. Expected <no error> Actual: <%v>"
,
setVolumeMountedErr
)
t
.
Fatalf
(
"SetVolumeMountedByNode failed. Expected <no error> Actual: <%v>"
,
setVolumeMountedErr
)
}
}
attachedVolumes
:
=
asw
.
GetAttachedVolumes
()
attachedVolumes
=
asw
.
GetAttachedVolumes
()
if
len
(
attachedVolumes
)
!=
1
{
if
len
(
attachedVolumes
)
!=
1
{
t
.
Fatalf
(
"len(attachedVolumes) Expected: <1> Actual: <%v>"
,
len
(
attachedVolumes
))
t
.
Fatalf
(
"len(attachedVolumes) Expected: <1> Actual: <%v>"
,
len
(
attachedVolumes
))
}
}
verifyAttachedVolume
(
t
,
attachedVolumes
,
generatedVolumeName
,
string
(
volumeName
),
nodeName
,
devicePath
,
tru
e
/* expectedMountedByNode */
,
false
/* expectNonZeroDetachRequestedTime */
)
verifyAttachedVolume
(
t
,
attachedVolumes
,
generatedVolumeName
,
string
(
volumeName
),
nodeName
,
devicePath
,
fals
e
/* expectedMountedByNode */
,
false
/* expectNonZeroDetachRequestedTime */
)
}
}
// Populates data struct with one volume/node entry.
// Populates data struct with one volume/node entry.
...
@@ -575,8 +582,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetAddVolumeNodeNotRes
...
@@ -575,8 +582,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetAddVolumeNodeNotRes
}
}
// Act
// Act
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
generatedVolumeName
,
addErr
=
asw
.
AddVolumeNode
(
volumeName
,
volumeSpec
,
nodeName
,
devicePath
)
generatedVolumeName
,
addErr
=
asw
.
AddVolumeNode
(
volumeName
,
volumeSpec
,
nodeName
,
devicePath
)
// Assert
// Assert
...
@@ -625,8 +632,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetVerifyDetachRequest
...
@@ -625,8 +632,8 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetVerifyDetachRequest
expectedDetachRequestedTime
:=
asw
.
GetAttachedVolumes
()[
0
]
.
DetachRequestedTime
expectedDetachRequestedTime
:=
asw
.
GetAttachedVolumes
()[
0
]
.
DetachRequestedTime
// Act
// Act
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
// Assert
// Assert
if
setVolumeMountedErr1
!=
nil
{
if
setVolumeMountedErr1
!=
nil
{
...
@@ -767,8 +774,8 @@ func Test_RemoveVolumeFromReportAsAttached_Positive_UnsetWithInitialSetVolumeMou
...
@@ -767,8 +774,8 @@ func Test_RemoveVolumeFromReportAsAttached_Positive_UnsetWithInitialSetVolumeMou
if
addErr
!=
nil
{
if
addErr
!=
nil
{
t
.
Fatalf
(
"AddVolumeNode failed. Expected: <no error> Actual: <%v>"
,
addErr
)
t
.
Fatalf
(
"AddVolumeNode failed. Expected: <no error> Actual: <%v>"
,
addErr
)
}
}
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr1
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
/* force unmount */
)
setVolumeMountedErr2
:=
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
if
setVolumeMountedErr1
!=
nil
{
if
setVolumeMountedErr1
!=
nil
{
t
.
Fatalf
(
"SetVolumeMountedByNode1 failed. Expected <no error> Actual: <%v>"
,
setVolumeMountedErr1
)
t
.
Fatalf
(
"SetVolumeMountedByNode1 failed. Expected <no error> Actual: <%v>"
,
setVolumeMountedErr1
)
}
}
...
...
pkg/controller/volume/attachdetach/reconciler/reconciler_test.go
View file @
8edae9b3
...
@@ -170,8 +170,8 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithUnmountedVolume(t *te
...
@@ -170,8 +170,8 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithUnmountedVolume(t *te
generatedVolumeName
,
generatedVolumeName
,
nodeName
)
nodeName
)
}
}
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
// Assert
// Assert
waitForNewDetacherCallCount
(
t
,
1
/* expectedCallCount */
,
fakePlugin
)
waitForNewDetacherCallCount
(
t
,
1
/* expectedCallCount */
,
fakePlugin
)
...
@@ -304,8 +304,8 @@ func Test_Run_Negative_OneDesiredVolumeAttachThenDetachWithUnmountedVolumeUpdate
...
@@ -304,8 +304,8 @@ func Test_Run_Negative_OneDesiredVolumeAttachThenDetachWithUnmountedVolumeUpdate
generatedVolumeName
,
generatedVolumeName
,
nodeName
)
nodeName
)
}
}
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
,
false
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
true
/* mounted */
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
,
false
)
asw
.
SetVolumeMountedByNode
(
generatedVolumeName
,
nodeName
,
false
/* mounted */
)
// Assert
// Assert
verifyNewDetacherCallCount
(
t
,
true
/* expectZeroNewDetacherCallCount */
,
fakePlugin
)
verifyNewDetacherCallCount
(
t
,
true
/* expectZeroNewDetacherCallCount */
,
fakePlugin
)
...
...
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