Skip to content

Commit 0f6d178

Browse files
authored
Merge pull request kubernetes#8921 from quentinalbertone/exoscale-update-client-user-agent
chores(exoscale): update user-agent
2 parents 41d87a6 + 938075f commit 0f6d178

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

cluster-autoscaler/cloudprovider/exoscale/exoscale_manager.go

Lines changed: 19 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,18 @@ 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+
req.Header.Add("User-Agent", "k8s.io/cluster-auto-scaler "+egoscale.UserAgent)
50+
51+
return rt.next.RoundTrip(req)
52+
}
53+
4154
const defaultAPIEnvironment = "api"
4255

4356
// Manager handles Exoscale communication and data caching of
@@ -75,7 +88,12 @@ func newManager(discoveryOpts cloudprovider.NodeGroupDiscoveryOptions) (*Manager
7588
apiEnvironment = defaultAPIEnvironment
7689
}
7790

78-
client, err := egoscale.NewClient(apiKey, apiSecret)
91+
client, err := egoscale.NewClient(
92+
apiKey, apiSecret,
93+
egoscale.ClientOptWithHTTPClient(&http.Client{
94+
Transport: &userAgentRoundTripper{next: http.DefaultTransport},
95+
}),
96+
)
7997
if err != nil {
8098
return nil, err
8199
}

0 commit comments

Comments
 (0)