-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detach the volume when pod is terminated #45286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,11 +281,7 @@ func (adc *attachDetachController) populateActualStateOfWorld() error { | |
continue | ||
} | ||
adc.processVolumesInUse(nodeName, node.Status.VolumesInUse, true /* forceUnmount */) | ||
if _, exists := node.Annotations[volumehelper.ControllerManagedAttachAnnotation]; exists { | ||
// Node specifies annotation indicating it should be managed by | ||
// attach detach controller. Add it to desired state of world. | ||
adc.desiredStateOfWorld.AddNode(types.NodeName(node.Name)) // Needed for DesiredStateOfWorld population | ||
} | ||
adc.addNodeToDswp(node, types.NodeName(node.Name)) | ||
} | ||
} | ||
return nil | ||
|
@@ -385,7 +381,12 @@ func (adc *attachDetachController) podAdd(obj interface{}) { | |
return | ||
} | ||
|
||
util.ProcessPodVolumes(pod, true, /* addVolumes */ | ||
volumeActionFlag := util.DetermineVolumeAction( | ||
pod, | ||
adc.desiredStateOfWorld, | ||
true /* default volume action */) | ||
|
||
util.ProcessPodVolumes(pod, volumeActionFlag, /* addVolumes */ | ||
adc.desiredStateOfWorld, &adc.volumePluginMgr, adc.pvcLister, adc.pvLister) | ||
} | ||
|
||
|
@@ -395,8 +396,22 @@ func (adc *attachDetachController) GetDesiredStateOfWorld() cache.DesiredStateOf | |
} | ||
|
||
func (adc *attachDetachController) podUpdate(oldObj, newObj interface{}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. podUpdate still only happens once every 12 hours though right? I think we have to do it in one of the reconciler loops There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assume that, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, regardless of this event though - I have also updated DSWP to remove the pod from DSW if pod is terminated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah...brain fart my b 🥇 |
||
// The flow for update is the same as add. | ||
adc.podAdd(newObj) | ||
pod, ok := newObj.(*v1.Pod) | ||
if pod == nil || !ok { | ||
return | ||
} | ||
if pod.Spec.NodeName == "" { | ||
// Ignore pods without NodeName, indicating they are not scheduled. | ||
return | ||
} | ||
|
||
volumeActionFlag := util.DetermineVolumeAction( | ||
pod, | ||
adc.desiredStateOfWorld, | ||
true /* default volume action */) | ||
|
||
util.ProcessPodVolumes(pod, volumeActionFlag, /* addVolumes */ | ||
adc.desiredStateOfWorld, &adc.volumePluginMgr, adc.pvcLister, adc.pvLister) | ||
} | ||
|
||
func (adc *attachDetachController) podDelete(obj interface{}) { | ||
|
@@ -433,11 +448,7 @@ func (adc *attachDetachController) nodeUpdate(oldObj, newObj interface{}) { | |
} | ||
|
||
nodeName := types.NodeName(node.Name) | ||
if _, exists := node.Annotations[volumehelper.ControllerManagedAttachAnnotation]; exists { | ||
// Node specifies annotation indicating it should be managed by attach | ||
// detach controller. Add it to desired state of world. | ||
adc.desiredStateOfWorld.AddNode(nodeName) | ||
} | ||
adc.addNodeToDswp(node, nodeName) | ||
adc.processVolumesInUse(nodeName, node.Status.VolumesInUse, false /* forceUnmount */) | ||
} | ||
|
||
|
@@ -539,3 +550,17 @@ func (adc *attachDetachController) GetSecretFunc() func(namespace, name string) | |
return nil, fmt.Errorf("GetSecret unsupported in attachDetachController") | ||
} | ||
} | ||
|
||
func (adc *attachDetachController) addNodeToDswp(node *v1.Node, nodeName types.NodeName) { | ||
if _, exists := node.Annotations[volumehelper.ControllerManagedAttachAnnotation]; exists { | ||
keepTerminatedPodVolumes := false | ||
|
||
if t, ok := node.Annotations[volumehelper.KeepTerminatedPodVolumesAnnotation]; ok { | ||
keepTerminatedPodVolumes = (t == "true") | ||
} | ||
|
||
// Node specifies annotation indicating it should be managed by attach | ||
// detach controller. Add it to desired state of world. | ||
adc.desiredStateOfWorld.AddNode(nodeName, keepTerminatedPodVolumes) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this defaulting to true? i don't think you should do this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i see below it was defaulting to true previously... i think that was a mistake... can we make that false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derekwaynecarr I think that change should be a part of #45615