Skip to content

Commit

Permalink
style: Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshmprabhu committed Sep 18, 2024
1 parent fd432e6 commit 90c4ae3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cns/nodesubnet/ip_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/pkg/errors"
)

var ErrorRefreshSkipped = errors.New("refresh skipped due to throttling")
var ErrRefreshSkipped = errors.New("refresh skipped due to throttling")

// This interface is implemented by the NMAgent Client, and also a mock client for testing
// InterfaceRetriever is an interface is implemented by the NMAgent Client, and also a mock client for testing.
type InterfaceRetriever interface {
GetInterfaceIPInfo(ctx context.Context) (nmagent.Interfaces, error)
}
Expand All @@ -32,10 +32,10 @@ func NewIPFetcher(nmaClient InterfaceRetriever, queryInterval time.Duration) *IP
}
}

// If secondaryIPQueryInterval has elapsed since the last fetch, fetch secondary IPs
func (c *IPFetcher) RefreshSecondaryIPsIfNeeded(ctx context.Context) (ips []net.IP, err error) {
// If secondaryIPQueryInterval has elapsed since the last fetch, fetch secondary IPs
if time.Since(c.secondaryIPLastRefreshTime) < c.secondaryIPQueryInterval {
return nil, ErrorRefreshSkipped
return nil, ErrRefreshSkipped
}

c.secondaryIPLastRefreshTime = time.Now()
Expand Down
4 changes: 2 additions & 2 deletions cns/nodesubnet/ip_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func TestRefreshSecondaryIPsIfNeeded(t *testing.T) {
_, err := fetcher.RefreshSecondaryIPsIfNeeded(ctx)

if test.shouldCall {
if err != nil && errors.Is(err, nodesubnet.ErrorRefreshSkipped) {
if err != nil && errors.Is(err, nodesubnet.ErrRefreshSkipped) {
t.Error("refresh expected, but didn't happen")
}

checkErr(t, err, false)
} else if err == nil || !errors.Is(err, nodesubnet.ErrorRefreshSkipped) {
} else if err == nil || !errors.Is(err, nodesubnet.ErrRefreshSkipped) {
t.Error("refresh not expected, but happened")
}
})
Expand Down
1 change: 1 addition & 0 deletions nmagent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (c *Client) GetHomeAz(ctx context.Context) (AzResponse, error) {
return homeAzResponse, nil
}

// GetInterfaceIPInfo fetches the node's interface IP information from nmagent
func (c *Client) GetInterfaceIPInfo(ctx context.Context) (Interfaces, error) {
req, err := c.buildRequest(ctx, &GetSecondaryIPsRequest{})
var out Interfaces
Expand Down

0 comments on commit 90c4ae3

Please sign in to comment.