@@ -105,7 +105,7 @@ func reclaimRemovedPeers(kube kubernetes.Interface, weave weaveClient, cml *conf
105
105
common .Log .Warnln ("[kube-peers] not removing myself" , peer )
106
106
continue
107
107
}
108
- changed , err := reclaimPeer (weave , cml , peer .PeerName , myPeerName )
108
+ changed , err := reclaimPeer (weave , cml , storedPeerList , peer .PeerName , myPeerName )
109
109
if err != nil {
110
110
return err
111
111
}
@@ -125,17 +125,32 @@ func reclaimRemovedPeers(kube kubernetes.Interface, weave weaveClient, cml *conf
125
125
// actions the reclaim.
126
126
// Return a bool to show whether we attempted to change anything,
127
127
// and an error if something went wrong.
128
- func reclaimPeer (weave weaveClient , cml * configMapAnnotations , peerName string , myPeerName string ) (changed bool , err error ) {
128
+ func reclaimPeer (weave weaveClient , cml * configMapAnnotations , storedPeerList * peerList , peerName string , myPeerName string ) (changed bool , err error ) {
129
129
common .Log .Debugln ("[kube-peers] Preparing to remove disappeared peer" , peerName )
130
130
okToRemove := false
131
+ nonExistentPeer := false
132
+
131
133
// 3. Check if there is an existing annotation with key X
132
- if existingAnnotation , found := cml .GetAnnotation (KubePeersPrefix + peerName ); found {
134
+ existingAnnotation , found := cml .GetAnnotation (KubePeersPrefix + peerName )
135
+ if found {
133
136
common .Log .Debugln ("[kube-peers] Existing annotation" , existingAnnotation )
134
137
// 4. If annotation already contains my identity, ok;
135
138
if existingAnnotation == myPeerName {
136
139
okToRemove = true
140
+ } else {
141
+ // handle an edge case where peer claimed to own the action to reclaim but no longer
142
+ // exists hence lock persists foever
143
+ peerExists := false
144
+ for _ , peer := range storedPeerList .Peers {
145
+ if existingAnnotation == peer .PeerName {
146
+ peerExists = true
147
+ break
148
+ }
149
+ }
150
+ nonExistentPeer = ! peerExists
137
151
}
138
- } else {
152
+ }
153
+ if ! found || nonExistentPeer {
139
154
// 5. If non-existent, write an annotation with key X and contents "my identity"
140
155
common .Log .Debugln ("[kube-peers] Noting I plan to remove " , peerName )
141
156
if err := cml .UpdateAnnotation (KubePeersPrefix + peerName , myPeerName ); err == nil {
0 commit comments