Skip to content

Commit

Permalink
Merge pull request #37 from syself/optional-robotclient
Browse files Browse the repository at this point in the history
🐛 Make robot client optional for lb client
  • Loading branch information
kranurag7 authored Apr 24, 2024
2 parents 04b701b + abbd29a commit 39cfe65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 5 additions & 3 deletions hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {
client := hcloud.NewClient(opts...)
metadataClient := metadata.NewClient()

robotUserName, foundRobotUserName := os.LookupEnv(robotUserNameENVVar)
robotPassword, foundRobotPassword := os.LookupEnv(robotPasswordENVVar)
robotUserName := os.Getenv(robotUserNameENVVar)
robotPassword := os.Getenv(robotPasswordENVVar)

cacheTimeout, err := util.GetEnvDuration(CacheTimeout)
if err != nil {
Expand All @@ -160,14 +160,16 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {
}

var robotClient robotclient.Client
if foundRobotUserName && foundRobotPassword {
if robotUserName != "" && robotPassword != "" {
client := &http.Client{
Transport: &LoggingTransport{
roundTripper: http.DefaultTransport,
},
}
c := hrobot.NewBasicAuthClientWithCustomHttpClient(robotUserName, robotPassword, client)
robotClient = cache.NewClient(c, cacheTimeout)
} else {
klog.Infof("Hetzner robot is not support because of insufficient credentials. Robot user name specified: %v. Robot password specified: %v", robotUserName != "", robotPassword != "")
}

var networkID int64
Expand Down
13 changes: 9 additions & 4 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/syself/hetzner-cloud-controller-manager/internal/annotation"
"github.com/syself/hetzner-cloud-controller-manager/internal/metrics"
"github.com/syself/hetzner-cloud-controller-manager/internal/robot/client"
"github.com/syself/hrobot-go/models"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -640,10 +641,14 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(

// List all robot servers to check whether the ip targets of the load balancer
// correspond to a dedicated server
dedicatedServers, err := l.RobotClient.ServerGetList()
if err != nil {
HandleRateLimitExceededError(err, svc)
return changed, fmt.Errorf("%s: failed to get list of dedicated servers: %w", op, err)
var dedicatedServers []models.Server

if l.RobotClient != nil {
dedicatedServers, err = l.RobotClient.ServerGetList()
if err != nil {
HandleRateLimitExceededError(err, svc)
return changed, fmt.Errorf("%s: failed to get list of dedicated servers: %w", op, err)
}
}

for _, s := range dedicatedServers {
Expand Down

0 comments on commit 39cfe65

Please sign in to comment.