Skip to content

Commit

Permalink
added some working comments
Browse files Browse the repository at this point in the history
Signed-off-by: nicklesimba <[email protected]>
  • Loading branch information
nicklesimba committed May 27, 2022
1 parent a0f4d90 commit 1052d80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/controlloop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func main() {

http.Handle("/metrics", promhttp.Handler())

// TODO: i want to generalize this - use random ip address instead of a specific one
go func() {
log.Fatal(http.ListenAndServe(":1337", nil)) // ListenAndServe is a blocking call.
log.Fatal(http.ListenAndServe(":1984", nil)) // ListenAndServe is a blocking call.
}()

// here's where my for { select {} } loop should go - and use tickers
Expand Down
24 changes: 6 additions & 18 deletions cmd/reconciler/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package reconciler

import (
"context"
"errors"
"time"

"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
Expand All @@ -15,30 +14,19 @@ const (
// reconcilerTimeout = flag.Int("timeout", defaultReconcilerTimeout, "the value for a request timeout in seconds.") // what about this is not constant? >:(
)

// TODO: get ip_test.go working with this - currently idk if it does...
func InvokeIPReconciler(returnErr chan error) {
go func() {
doInvokeIPReconciler(returnErr)
}()
select {
case <-time.After(5 * time.Minute):
returnErr <- errors.New("ip reconciler timed out")
return
case <-returnErr:
logging.Verbosef("finishing ip reconciler run")
return
}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(defaultReconcilerTimeout*time.Second))
defer cancel()

// TODO: get ip_test.go working with this - currently idk if it does...
func doInvokeIPReconciler(returnErr chan error) {
ipReconcileLoop, err := reconciler.NewReconcileLooper(context.Background(), defaultReconcilerTimeout)
ipReconcileLoop, err := reconciler.NewReconcileLooper(ctx, defaultReconcilerTimeout)
if err != nil {
_ = logging.Errorf("failed to create the reconcile looper: %v", err)
returnErr <- err
return
}

cleanedUpIps, err := ipReconcileLoop.ReconcileIPPools(context.Background())
cleanedUpIps, err := ipReconcileLoop.ReconcileIPPools(ctx)
if err != nil {
_ = logging.Errorf("failed to clean up IP for allocations: %v", err)
returnErr <- err
Expand All @@ -51,7 +39,7 @@ func doInvokeIPReconciler(returnErr chan error) {
logging.Debugf("no IP addresses to cleanup")
}

if err := ipReconcileLoop.ReconcileOverlappingIPAddresses(context.Background()); err != nil {
if err := ipReconcileLoop.ReconcileOverlappingIPAddresses(ctx); err != nil {
returnErr <- err
return
}
Expand Down

0 comments on commit 1052d80

Please sign in to comment.