Skip to content

Commit 11dcf3f

Browse files
author
Albertone Quentin
committed
chores(exoscale): update user-agent
1 parent d4a3ca1 commit 11dcf3f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cluster-autoscaler/cloudprovider/exoscale/exoscale_manager.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"net/http"
2324
"os"
2425

2526
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
@@ -38,6 +39,20 @@ type exoscaleClient interface {
3839
ScaleSKSNodepool(context.Context, string, *egoscale.SKSCluster, *egoscale.SKSNodepool, int64) error
3940
}
4041

42+
// userAgentRoundTripper is a roundtripper which updates the user-agent header.
43+
// This roundtripper can be deleted with egoscale v3.
44+
type userAgentRoundTripper struct {
45+
next http.RoundTripper
46+
}
47+
48+
func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
49+
previousUseragent := req.Header.Get("user-agent")
50+
useragent := "k8s.io/cluster-auto-scaler " + previousUseragent
51+
req.Header.Add("User-Agent", useragent)
52+
53+
return rt.next.RoundTrip(req)
54+
}
55+
4156
const defaultAPIEnvironment = "api"
4257

4358
// Manager handles Exoscale communication and data caching of
@@ -75,7 +90,12 @@ func newManager(discoveryOpts cloudprovider.NodeGroupDiscoveryOptions) (*Manager
7590
apiEnvironment = defaultAPIEnvironment
7691
}
7792

78-
client, err := egoscale.NewClient(apiKey, apiSecret)
93+
client, err := egoscale.NewClient(
94+
apiKey, apiSecret,
95+
egoscale.ClientOptWithHTTPClient(&http.Client{
96+
Transport: &userAgentRoundTripper{next: http.DefaultTransport},
97+
}),
98+
)
7999
if err != nil {
80100
return nil, err
81101
}

0 commit comments

Comments
 (0)