Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Improve comments and error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Sep 12, 2018
1 parent aa41ecb commit 1a0407d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions prog/kube-utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func getKubePeers(c kubernetes.Interface, includeWithNoIPAddr bool) ([]nodeInfo,
return addresses, nil
}

// (minimal, incomplete) interface so weaver can be mocked for testing.
type weaveClient interface {
RmPeer(peerName string) (string, error)
}
Expand Down Expand Up @@ -109,7 +110,12 @@ func reclaimRemovedPeers(kube kubernetes.Interface, weave weaveClient, cml *conf
return nil
}

func reclaimPeer(weave weaveClient, cml *configMapAnnotations, peerName string, myPeerName string) (bool, error) {
// Attempt to reclaim the IP addresses owned by peerName, using the
// Kubernetes api-server as a point of consensus so that only one peer
// actions the reclaim.
// Return a bool to show whether we attempted to change anything,
// and an error if something went wrong.
func reclaimPeer(weave weaveClient, cml *configMapAnnotations, peerName string, myPeerName string) (changed bool, err error) {
common.Log.Debugln("[kube-peers] Preparing to remove disappeared peer", peerName)
okToRemove := false
// 3. Check if there is an existing annotation with key X
Expand Down Expand Up @@ -137,7 +143,7 @@ func reclaimPeer(weave weaveClient, cml *configMapAnnotations, peerName string,
if err != nil {
return false, err
}
cml.LoopUpdate(func() error {
err = cml.LoopUpdate(func() error {
// 7aa. Remove any annotations Z* that have contents X
if err := cml.RemoveAnnotationsWithValue(peerName); err != nil {
return err
Expand All @@ -164,7 +170,7 @@ func reclaimPeer(weave weaveClient, cml *configMapAnnotations, peerName string,

// Question: Should we narrow step 2 by checking against Weave Net IPAM?
// i.e. If peer X owns any address space and is marked unreachable, we want to rmpeer X
return true, nil
return true, err
}

func main() {
Expand Down

0 comments on commit 1a0407d

Please sign in to comment.