Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Jun 18, 2024
1 parent cdee11f commit 9223992
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 8 additions & 3 deletions cloud/linode/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package client

import (
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/linode/linodego"
Expand Down Expand Up @@ -56,8 +58,11 @@ type Client interface {
// linodego.Client implements Client
var _ Client = (*linodego.Client)(nil)

// New creates a new linode client with a given token, userAgent, and API URL
func New(token, userAgent, apiURL string, timeout time.Duration) (*linodego.Client, error) {
// New creates a new linode client with a given token and default timeout
func New(token string, timeout time.Duration) (*linodego.Client, error) {
userAgent := fmt.Sprintf("linode-cloud-controller-manager %s", linodego.DefaultUserAgent)
apiURL := os.Getenv("LINODE_URL")

tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
oauth2Client := &http.Client{
Transport: &oauth2.Transport{
Expand All @@ -72,6 +77,6 @@ func New(token, userAgent, apiURL string, timeout time.Duration) (*linodego.Clie
}
client.SetUserAgent(userAgent)

klog.V(3).Infof("Linode client created with default timeout of %v seconds", timeout)
klog.V(3).Infof("Linode client created with default timeout of %v", timeout)
return client, nil
}
9 changes: 2 additions & 7 deletions cloud/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"
"time"

"github.com/linode/linodego"
"github.com/spf13/pflag"
"golang.org/x/exp/slices"
"k8s.io/client-go/informers"
Expand All @@ -22,7 +21,6 @@ const (
ProviderName = "linode"
accessTokenEnv = "LINODE_API_TOKEN"
regionEnv = "LINODE_REGION"
urlEnv = "LINODE_URL"
ciliumLBType = "cilium-bgp"
nodeBalancerLBType = "nodebalancer"
)
Expand Down Expand Up @@ -97,18 +95,15 @@ func newCloud() (cloudprovider.Interface, error) {
return nil, fmt.Errorf("%s must be set in the environment (use a k8s secret)", regionEnv)
}

url := os.Getenv(urlEnv)
ua := fmt.Sprintf("linode-cloud-controller-manager %s", linodego.DefaultUserAgent)

// set timeout used by linodeclient for API calls
timeout := client.DefaultClientTimeout
if raw, ok := os.LookupEnv("LINODE_REQUEST_TIMEOUT_SECONDS"); ok {
if t, _ := strconv.Atoi(raw); t > 0 {
if t, err := strconv.Atoi(raw); err == nil && t > 0 {
timeout = time.Duration(t) * time.Second
}
}

linodeClient, err := client.New(apiToken, ua, url, timeout)
linodeClient, err := client.New(apiToken, timeout)
if err != nil {
return nil, fmt.Errorf("client was not created succesfully: %w", err)
}
Expand Down

0 comments on commit 9223992

Please sign in to comment.