Skip to content

Commit

Permalink
sync with other branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Nov 13, 2024
1 parent 4618ff9 commit f22fc72
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cloud/linode/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type routeCache struct {
}

// RefreshCache checks if cache has expired and updates it accordingly
func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) error {
func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) {
rc.Mu.Lock()
defer rc.Mu.Unlock()

if time.Since(rc.lastUpdate) < rc.ttl {
return nil
return
}

vpcNodes := map[int][]linodego.VPCIP{}
Expand All @@ -54,7 +54,6 @@ func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) e

rc.routes = vpcNodes
rc.lastUpdate = time.Now()
return nil
}

type routes struct {
Expand Down Expand Up @@ -100,10 +99,7 @@ func (r *routes) instanceRoutesByID(id int) ([]linodego.VPCIP, error) {
// getInstanceRoutes returns routes for given instance id
// It refreshes routeCache if it has expired
func (r *routes) getInstanceRoutes(ctx context.Context, id int) ([]linodego.VPCIP, error) {
if err := r.routeCache.refreshRoutes(ctx, r.client); err != nil {
return nil, err
}

r.routeCache.refreshRoutes(ctx, r.client)
return r.instanceRoutesByID(id)
}

Expand Down

0 comments on commit f22fc72

Please sign in to comment.