diff --git a/pkg/azurefile/azure.go b/pkg/azurefile/azure.go index f2923158d3..0835c865a6 100644 --- a/pkg/azurefile/azure.go +++ b/pkg/azurefile/azure.go @@ -43,7 +43,7 @@ var ( ) // getCloudProvider get Azure Cloud Provider -func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace string) (*azureprovider.Cloud, error) { +func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent string) (*azureprovider.Cloud, error) { az := &azureprovider.Cloud{ InitSecretConfig: azureprovider.InitSecretConfig{ SecretName: secretName, @@ -51,6 +51,7 @@ func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace string) (* CloudConfigKey: "cloud-config", }, } + az.UserAgent = userAgent kubeClient, err := getKubeClient(kubeconfig) if err != nil && !os.IsNotExist(err) && err != rest.ErrNotInCluster { return az, fmt.Errorf("failed to get KubeClient: %v", err) diff --git a/pkg/azurefile/azure_test.go b/pkg/azurefile/azure_test.go index 4e85b0ddab..96b85d4f37 100644 --- a/pkg/azurefile/azure_test.go +++ b/pkg/azurefile/azure_test.go @@ -154,7 +154,7 @@ users: } os.Setenv(DefaultAzureCredentialFileEnv, fakeCredFile) } - _, err := getCloudProvider(test.kubeconfig, "", "", "") + _, err := getCloudProvider(test.kubeconfig, "", "", "", "") if !testutil.AssertError(err, &test.expectedErr) { t.Errorf("desc: %s,\n input: %q, getCloudProvider err: %v, expectedErr: %v", test.desc, test.kubeconfig, err, test.expectedErr) } diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index e431face8e..b64ebdec44 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -220,7 +220,9 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) { } klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta) - d.cloud, err = getCloudProvider(kubeconfig, d.NodeID, d.cloudConfigSecretName, d.cloudConfigSecretNamespace) + userAgent := GetUserAgent(d.Name) + klog.V(2).Infof("driver userAgent: %s", userAgent) + d.cloud, err = getCloudProvider(kubeconfig, d.NodeID, d.cloudConfigSecretName, d.cloudConfigSecretNamespace, userAgent) if err != nil { klog.Fatalf("failed to get Azure Cloud Provider, error: %v", err) } diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go index f737aac645..d033ac5d1f 100644 --- a/pkg/azurefile/controllerserver.go +++ b/pkg/azurefile/controllerserver.go @@ -28,7 +28,6 @@ import ( "github.com/Azure/azure-storage-file-go/azfile" "github.com/Azure/go-autorest/autorest/to" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/protobuf/ptypes" "github.com/pborman/uuid" "google.golang.org/grpc/codes" @@ -37,6 +36,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient" azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache" "sigs.k8s.io/cloud-provider-azure/pkg/metrics" @@ -691,9 +691,9 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ } if exists { klog.V(2).Infof("snapshot(%s) already exists", snapshotName) - tp, err := ptypes.TimestampProto(item.Properties.LastModified) - if err != nil { - return nil, status.Errorf(codes.Internal, "Failed to covert creation timestamp: %v", err) + tp := timestamppb.New(item.Properties.LastModified) + if tp == nil { + return nil, status.Errorf(codes.Internal, "Failed to convert timestamp(%v)", item.Properties.LastModified) } return &csi.CreateSnapshotResponse{ Snapshot: &csi.Snapshot{ @@ -724,9 +724,9 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ return nil, status.Errorf(codes.Internal, "failed to get snapshot properties from (%s): %v", snapshotShare.Snapshot(), err) } - tp, err := ptypes.TimestampProto(properties.LastModified()) - if err != nil { - return nil, status.Errorf(codes.Internal, "Failed to covert creation timestamp: %v", err) + tp := timestamppb.New(properties.LastModified()) + if tp == nil { + return nil, status.Errorf(codes.Internal, "Failed to convert timestamp(%v)", properties.LastModified()) } createResp := &csi.CreateSnapshotResponse{ diff --git a/pkg/azurefile/version.go b/pkg/azurefile/version.go index 02830a44c9..79f69a1090 100644 --- a/pkg/azurefile/version.go +++ b/pkg/azurefile/version.go @@ -65,3 +65,8 @@ func GetVersionYAML(driverName string) (string, error) { } return strings.TrimSpace(string(marshalled)), nil } + +// GetUserAgent returns user agent of the driver +func GetUserAgent(driverName string) string { + return fmt.Sprintf("%s/%s %s/%s (%s-%s) %s/%s", driverName, driverVersion, runtime.Compiler, runtime.Version(), runtime.GOARCH, runtime.GOOS, gitCommit, buildDate) +}