Skip to content

Commit cc5735f

Browse files
authored
Merge pull request #485 from andyzhangx/useragent
feat: add driver userAgent in ARM request
2 parents fcaeb59 + 124f95f commit cc5735f

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

pkg/blob/azure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ func IsAzureStackCloud(cloud *azureprovider.Cloud) bool {
4949
}
5050

5151
// getCloudProvider get Azure Cloud Provider
52-
func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace string) (*azureprovider.Cloud, error) {
52+
func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent string) (*azureprovider.Cloud, error) {
5353
az := &azureprovider.Cloud{
5454
InitSecretConfig: azureprovider.InitSecretConfig{
5555
SecretName: secretName,
5656
SecretNamespace: secretNamespace,
5757
CloudConfigKey: "cloud-config",
5858
},
5959
}
60+
az.UserAgent = userAgent
6061
kubeClient, err := getKubeClient(kubeconfig)
6162
if err != nil && !os.IsNotExist(err) && err != rest.ErrNotInCluster {
6263
return az, fmt.Errorf("failed to get KubeClient: %v", err)

pkg/blob/azure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ users:
150150
}
151151
os.Setenv(DefaultAzureCredentialFileEnv, fakeCredFile)
152152
}
153-
cloud, err := getCloudProvider(test.kubeconfig, test.nodeID, "", "")
153+
cloud, err := getCloudProvider(test.kubeconfig, test.nodeID, "", "", "")
154154
if !reflect.DeepEqual(err, test.expectedErr) {
155155
t.Errorf("desc: %s,\n input: %q, GetCloudProvider err: %v, expectedErr: %v", test.desc, test.kubeconfig, err, test.expectedErr)
156156
}

pkg/blob/blob.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) {
161161
}
162162
klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
163163

164-
d.cloud, err = getCloudProvider(kubeconfig, d.NodeID, d.cloudConfigSecretName, d.cloudConfigSecretNamespace)
164+
userAgent := GetUserAgent(d.Name)
165+
klog.V(2).Infof("driver userAgent: %s", userAgent)
166+
d.cloud, err = getCloudProvider(kubeconfig, d.NodeID, d.cloudConfigSecretName, d.cloudConfigSecretNamespace, userAgent)
165167
if err != nil {
166168
klog.Fatalf("failed to get Azure Cloud Provider, error: %v", err)
167169
}

pkg/blob/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ func GetVersionYAML(driverName string) (string, error) {
6565
}
6666
return strings.TrimSpace(string(marshalled)), nil
6767
}
68+
69+
// GetUserAgent returns user agent of the driver
70+
func GetUserAgent(driverName string) string {
71+
return fmt.Sprintf("%s/%s %s/%s (%s-%s) %s/%s", driverName, driverVersion, runtime.Compiler, runtime.Version(), runtime.GOARCH, runtime.GOOS, gitCommit, buildDate)
72+
}

0 commit comments

Comments
 (0)