Skip to content

Commit 39cfe65

Browse files
authored
Merge pull request #37 from syself/optional-robotclient
🐛 Make robot client optional for lb client
2 parents 04b701b + abbd29a commit 39cfe65

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

hcloud/cloud.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {
147147
client := hcloud.NewClient(opts...)
148148
metadataClient := metadata.NewClient()
149149

150-
robotUserName, foundRobotUserName := os.LookupEnv(robotUserNameENVVar)
151-
robotPassword, foundRobotPassword := os.LookupEnv(robotPasswordENVVar)
150+
robotUserName := os.Getenv(robotUserNameENVVar)
151+
robotPassword := os.Getenv(robotPasswordENVVar)
152152

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

162162
var robotClient robotclient.Client
163-
if foundRobotUserName && foundRobotPassword {
163+
if robotUserName != "" && robotPassword != "" {
164164
client := &http.Client{
165165
Transport: &LoggingTransport{
166166
roundTripper: http.DefaultTransport,
167167
},
168168
}
169169
c := hrobot.NewBasicAuthClientWithCustomHttpClient(robotUserName, robotPassword, client)
170170
robotClient = cache.NewClient(c, cacheTimeout)
171+
} else {
172+
klog.Infof("Hetzner robot is not support because of insufficient credentials. Robot user name specified: %v. Robot password specified: %v", robotUserName != "", robotPassword != "")
171173
}
172174

173175
var networkID int64

internal/hcops/load_balancer.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/syself/hetzner-cloud-controller-manager/internal/annotation"
1515
"github.com/syself/hetzner-cloud-controller-manager/internal/metrics"
1616
"github.com/syself/hetzner-cloud-controller-manager/internal/robot/client"
17+
"github.com/syself/hrobot-go/models"
1718
corev1 "k8s.io/api/core/v1"
1819
"k8s.io/client-go/tools/record"
1920
"k8s.io/klog/v2"
@@ -640,10 +641,14 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(
640641

641642
// List all robot servers to check whether the ip targets of the load balancer
642643
// correspond to a dedicated server
643-
dedicatedServers, err := l.RobotClient.ServerGetList()
644-
if err != nil {
645-
HandleRateLimitExceededError(err, svc)
646-
return changed, fmt.Errorf("%s: failed to get list of dedicated servers: %w", op, err)
644+
var dedicatedServers []models.Server
645+
646+
if l.RobotClient != nil {
647+
dedicatedServers, err = l.RobotClient.ServerGetList()
648+
if err != nil {
649+
HandleRateLimitExceededError(err, svc)
650+
return changed, fmt.Errorf("%s: failed to get list of dedicated servers: %w", op, err)
651+
}
647652
}
648653

649654
for _, s := range dedicatedServers {

0 commit comments

Comments
 (0)