Update local copy of annotations even after error
e.g. if we get a clash because someone else has updated the data, it returns the new data so we should work off that next time. Also re-fetch the Annotations every time round the main loop for safety.
This commit is contained in:
1 parent
ea76185873
commit
832fe2f0b0
2 files changed
+19
-22
No files matched your search
@@ -130,46 +130,40 @@ func (cml *configMapAnnotations) UpdatePeerList(list peerList) error {
|
|||||||
return cml.UpdateAnnotation(KubePeersAnnotationKey, string(recordBytes))
|
return cml.UpdateAnnotation(KubePeersAnnotationKey, string(recordBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cml *configMapAnnotations) UpdateAnnotation(key, value string) error {
|
func (cml *configMapAnnotations) UpdateAnnotation(key, value string) (err error) {
|
||||||
if cml.cm == nil {
|
if cml.cm == nil {
|
||||||
return errors.New("endpoint not initialized, call Init first")
|
return errors.New("endpoint not initialized, call Init first")
|
||||||
}
|
}
|
||||||
cm := cml.cm
|
// speculatively change the state, then replace with whatever comes back
|
||||||
cm.Annotations[key] = value
|
// from Update(), which will be the latest on the server whatever happened
|
||||||
cm, err := cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
cml.cm.Annotations[key] = value
|
||||||
if err == nil {
|
cml.cm, err = cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
||||||
cml.cm = cm
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cml *configMapAnnotations) RemoveAnnotation(key string) error {
|
func (cml *configMapAnnotations) RemoveAnnotation(key string) (err error) {
|
||||||
if cml.cm == nil {
|
if cml.cm == nil {
|
||||||
return errors.New("endpoint not initialized, call Init first")
|
return errors.New("endpoint not initialized, call Init first")
|
||||||
}
|
}
|
||||||
cm := cml.cm
|
// speculatively change the state, then replace with whatever comes back
|
||||||
delete(cm.Annotations, key)
|
// from Update(), which will be the latest on the server whatever happened
|
||||||
cm, err := cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
delete(cml.cm.Annotations, key)
|
||||||
if err == nil {
|
cml.cm, err = cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
||||||
cml.cm = cm
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cml *configMapAnnotations) RemoveAnnotationsWithValue(valueToRemove string) error {
|
func (cml *configMapAnnotations) RemoveAnnotationsWithValue(valueToRemove string) (err error) {
|
||||||
if cml.cm == nil {
|
if cml.cm == nil {
|
||||||
return errors.New("endpoint not initialized, call Init first")
|
return errors.New("endpoint not initialized, call Init first")
|
||||||
}
|
}
|
||||||
cm := cml.cm
|
// speculatively change the state, then replace with whatever comes back
|
||||||
for key, value := range cm.Annotations {
|
// from Update(), which will be the latest on the server whatever happened
|
||||||
|
for key, value := range cml.cm.Annotations {
|
||||||
if value == valueToRemove {
|
if value == valueToRemove {
|
||||||
delete(cm.Annotations, key)
|
delete(cml.cm.Annotations, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cm, err := cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
cml.cm, err = cml.Client.ConfigMaps(cml.Namespace).Update(cml.cm)
|
||||||
if err == nil {
|
|
||||||
cml.cm = cm
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ func checkIamInPeerList(cml *configMapAnnotations, c *kubernetes.Clientset, peer
|
|||||||
// Kubernetes, remove it from Weave IPAM
|
// Kubernetes, remove it from Weave IPAM
|
||||||
func reclaimRemovedPeers(weave *weaveapi.Client, cml *configMapAnnotations, nodes []nodeInfo, myPeerName string) error {
|
func reclaimRemovedPeers(weave *weaveapi.Client, cml *configMapAnnotations, nodes []nodeInfo, myPeerName string) error {
|
||||||
for {
|
for {
|
||||||
|
if err := cml.Init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// 1. Compare peers stored in the peerList against all peers reported by k8s now.
|
// 1. Compare peers stored in the peerList against all peers reported by k8s now.
|
||||||
storedPeerList, err := cml.GetPeerList()
|
storedPeerList, err := cml.GetPeerList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user