add small thread management library #40
                
     Merged
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
What this PR does / why we need it:
In the ClusterProvider: Gardener, we add watches to clusters during runtime, which essentially works by calling
Start(...)on that cluster's cache. This is a blocking method, so it has to run in a new go routine, and it can return an error, so we cannot simply dogo cache.Start(...), because then we would not notice if the watch failed somehow.This means that we need slightly more complex logic to handle the multiple go routines. Using the
errgrouppackage'sWait()method doesn't work either, because that one too blocks and returns an error, and furthermore stops when all go routines in the group have finished, which doesn't fit our use case, where having zero watches is something that could happen for some time.This PR adds a
ThreadManager. It manages multiple go routines and allows reacting to them being stopped. This enables the Gardener ClusterProvider to start multiple watches and react to failing ones by logging the error and restarting them.