Change:
Problem: An attachable volume referenced by a pod via a PVC object (instead of directly) is not detached if the pod is deleted via namespace deletion (i.e. deleting the pod's namespace instead of the pod object directly). Repro steps: a new volume a new namespace. - PV and PVC objects: - PV/PVC objects are in bound state - pod object that references the volume via PVC - pod gets into running state without issue (i.e. volume is attached) - the namespace - for pod to terminate if volume remains attached after a few minutes Expected: Volume is detached. Actual: Volume remains attached indefinitely. <detailsis: And is: </detailsWorkarounds: the pod object directly before deleting the namespace. In step 7 above do instead If the attachable volume is referenced by a pod using a PVC object, and the pod object is deleted directly (instead of the namespace first), the volume is correctly detached. volume directly in pod (without a PVC object). If the attachable volume is referenced by a pod directly (without a PVC object), namespace deletion results in the volume being correctly detached.
Root Cause: event for pod fails on Attach/Detach controller When a volume referenced via PVC is deleted by namespace, the PV/PVC objects are deleted before the pod object, therefore when the delete event is processed by the attach/detach controller, it fails because it cannot dereference the PVC object. was to ensure volumes are still detached even if a delete event is missed (or fails), however that has a bug in it (the value of is not checked): Proposed Fixes: attach/detach controller to cache PVC/PV so even if it is deleted, it can be recovered on pod deletion events. bug in to check so that it can delete pods even if the delete event is missed (or fails).

Discussion:
// desiredStateOfWorldPopulatorLoopSleepPeriod is the amount of time the // DesiredStateOfWorldPopulator loop waits between successive executions <del> desiredStateOfWorldPopulatorLoopSleepPeriod time.Duration = 5 * time.Minute </del> <ins> desiredStateOfWorldPopulatorLoopSleepPeriod time.Duration = 1 * time.Minute </ins> ) // AttachDetachController defines the operations supported by this controller.

glog.Errorf("MetaNamespaceKeyFunc failed for pod %q (UID %q) with: %v", dswPodKey, dswPodUID, err) continue } <del> // retrieve the pod object from pod informer with the namespace key informerPodObj, exists, err := dswp.podInformer.GetStore().GetByKey(dswPodKey) if err != nil || informerPodObj == nil { glog.Errorf("podInformer GetByKey failed for pod %q (UID %q) with %v", dswPodKey, dswPodUID, err) </del> <ins> // Retrieve the pod object from pod informer with the namespace key informerPodObj, exists, err := dswp.podInformer.GetStore().GetByKey(dswPodKey) if err != nil { glog.Errorf( "podInformer GetByKey failed for pod %q (UID %q) with %v", dswPodKey, dswPodUID, err) </ins> continue } <ins> if exists && informerPodObj == nil { glog.Info( "podInformer GetByKey found pod, but informerPodObj is nil for pod %q (UID %q)", dswPodKey, dswPodUID) continue } </ins> if exists { informerPod, ok := informerPodObj.(*api.Pod) if !ok {

continue } informerPodUID := volumehelper.GetUniquePodName(informerPod) <del> // Check whether the unique idenfier of the pod from dsw matches the one retrived from pod informer </del> <ins> // Check whether the unique identifier of the pod from dsw matches the one retrieved from pod informer </ins> if informerPodUID == dswPodUID { glog.V(10).Infof( "Verified pod %q (UID %q) from dsw exists in pod informer.", dswPodKey, dswPodUID)

} } <del> // the pod from dsw does not exist in pod informer, or it does not match the unique idenfier retrieved </del> <ins> // the pod from dsw does not exist in pod informer, or it does not match the unique identifer retrieved </ins> // from the informer, delete it from dsw glog.V(1).Infof( "Removing pod %q (UID %q) from dsw because it does not exist in pod informer.", dswPodKey, dswPodUID)