Skip to content

Commit

Permalink
🌱 enable robot api debug, only if ROBOT_DEBUG is set. (#41)
Browse files Browse the repository at this point in the history
* 🌱 enable robot api debug, only if ROBOT_DEBUG is set.

* ... more explicit log message, and explicit default of "false" in yaml.
  • Loading branch information
guettli authored Jun 18, 2024
1 parent d8076ad commit a5282a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion deploy/ccm-bare-metal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@ spec:
key: robot-password
- name: HCLOUD_DEBUG
value: "false"
- name: ROBOT_DEBUG
value: "false"
- name: HCLOUD_LOAD_BALANCERS_ENABLED
value: "true"
value: "true"
20 changes: 14 additions & 6 deletions hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
hcloudEndpointENVVar = "HCLOUD_ENDPOINT"
hcloudNetworkENVVar = "HCLOUD_NETWORK"
hcloudDebugENVVar = "HCLOUD_DEBUG"
robotDebugENVVar = "ROBOT_DEBUG"

robotUserNameENVVar = "ROBOT_USER_NAME"
robotPasswordENVVar = "ROBOT_PASSWORD"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (lt *LoggingTransport) RoundTrip(req *http.Request) (resp *http.Response, e
klog.InfoS("hetzner robot API. Error.", "err", err, "method", req.Method, "url", req.URL, "stack", stack)
return resp, err
}
klog.InfoS("hetzner robot API called.", "statusCode", resp.StatusCode, "method", req.Method, "url", req.URL, "stack", stack)
klog.V(1).InfoS("hetzner robot API called.", "statusCode", resp.StatusCode, "method", req.Method, "url", req.URL, "stack", stack)
return resp, nil
}

Expand Down Expand Up @@ -161,12 +162,19 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {

var robotClient robotclient.Client
if robotUserName != "" && robotPassword != "" {
client := &http.Client{
Transport: &LoggingTransport{
roundTripper: http.DefaultTransport,
},
var c hrobot.RobotClient
if os.Getenv(robotDebugENVVar) == "true" {
client := &http.Client{
Transport: &LoggingTransport{
roundTripper: http.DefaultTransport,
},
}
c = hrobot.NewBasicAuthClientWithCustomHttpClient(robotUserName, robotPassword, client)
klog.Info("Enabled robot API debugging")
} else {
c = hrobot.NewBasicAuthClient(robotUserName, robotPassword)
klog.Infof("Not enabling robot API debugging. Set env var %s=true to enable it.", robotDebugENVVar)
}
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 != "")
Expand Down

0 comments on commit a5282a4

Please sign in to comment.