Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Make robot client optional for lb client #37

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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