Skip to content

Commit

Permalink
feat: include useragent in volumesnapshot creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kassarl committed Sep 2, 2021
1 parent 97e4079 commit 2347058
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/driver-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ perfProfile | [disk device performance profile](../docs/enhancements/feat-add-ab
networkAccessPolicy | NetworkAccessPolicy property to prevent anybody from generating the SAS URI for a disk or a snapshot | `AllowAll`, `DenyAll`, `AllowPrivate` | No | `AllowAll`
diskAccessID | ARM id of the DiskAccess resource for using private endpoints on disks | | No | ``
enableBursting | [enable on-demand bursting](https://docs.microsoft.com/en-us/azure/virtual-machines/disk-bursting) beyond the provisioned performance target of the disk. On-demand bursting only be applied to Premium disk, disk size > 512GB, Ultra & shared disk is not supported. Bursting is disabled by default. | `true`, `false` | No | `false`
useragent | Useragent that can be set to allow for customer attribution | | No | Generated Useragent formatted `driverName/driverVersion compiler/version (GOARCH-GOOS) gitCommit/buildDate`
useragent | User agent used for [customer usage attribution](https://docs.microsoft.com/en-us/azure/marketplace/azure-partner-customer-usage-attribution)| | No | Generated Useragent formatted `driverName/driverVersion compiler/version (GOARCH-GOOS) gitCommit/buildDate`


- disk created by dynamic provisioning
Expand Down Expand Up @@ -51,3 +51,4 @@ volumeAttributes.cachingMode | [disk host cache setting](https://docs.microsoft.
resourceGroup | resource group for storing snapshot shots | EXISTING RESOURCE GROUP | No | If not specified, snapshot will be stored in the same resource group as source Azure disk
incremental | take [full or incremental snapshot](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/incremental-snapshots) | `true`, `false` | No | `true`
tags | azure disk [tags](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources) | tag format: 'key1=val1,key2=val2' | No | ""
useragent | User agent used for [customer usage attribution](https://docs.microsoft.com/en-us/azure/marketplace/azure-partner-customer-usage-attribution) | | No | Generated Useragent formatted `driverName/driverVersion compiler/version (GOARCH-GOOS) gitCommit/buildDate`
24 changes: 15 additions & 9 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
diskAccessID string
maxShares int
enableBursting *bool
localCloud *azure.Cloud
)

localCloud = d.cloud
localCloud := d.cloud
tags := make(map[string]string)
parameters := req.GetParameters()
if parameters == nil {
Expand Down Expand Up @@ -177,8 +176,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
newUserAgent := v
localCloud, err = azureutils.GetCloudProvider(d.kubeconfig, d.cloudConfigSecretName, d.cloudConfigSecretNamespace, newUserAgent)
if err != nil {
klog.V(2).Infof("Unable to create new cloud for UserAgent, err: (%s)", err)
localCloud = d.cloud
return nil, fmt.Errorf("create cloud with UserAgent(%s) failed with: (%s)", newUserAgent, err)
}
default:
return nil, fmt.Errorf("invalid parameter %s in storage class", k)
Expand Down Expand Up @@ -207,7 +205,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
diskName = azureutils.CreateValidDiskName(diskName)

if resourceGroup == "" {
resourceGroup = localCloud.ResourceGroup
resourceGroup = d.cloud.ResourceGroup
}

// normalize values
Expand All @@ -226,7 +224,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}

requirement := req.GetAccessibilityRequirements()
diskZone := azureutils.PickAvailabilityZone(requirement, localCloud.Location, topologyKey)
diskZone := azureutils.PickAvailabilityZone(requirement, d.cloud.Location, topologyKey)
accessibleTopology := []*csi.Topology{}
if skuName == compute.StandardSSDZRS || skuName == compute.PremiumZRS {
klog.V(2).Infof("diskZone(%s) is reset as empty since disk(%s) is ZRS(%s)", diskZone, diskName, skuName)
Expand Down Expand Up @@ -260,7 +258,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, err
}

mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_create_volume", localCloud.ResourceGroup, localCloud.SubscriptionID, d.Name)
mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_create_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
isOperationSucceeded := false
defer func() {
mc.ObserveOperationWithResult(isOperationSucceeded)
Expand Down Expand Up @@ -835,6 +833,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
incremental := true
var resourceGroup string
var err error
localCloud := d.cloud

parameters := req.GetParameters()
for k, v := range parameters {
Expand All @@ -847,12 +846,19 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
}
case consts.ResourceGroupField:
resourceGroup = v
case consts.UserAgentField:
newUserAgent := v
localCloud, err = azureutils.GetCloudProvider(d.kubeconfig, d.cloudConfigSecretName, d.cloudConfigSecretNamespace, newUserAgent)
if err != nil {
return nil, fmt.Errorf("create cloud with UserAgent(%s) failed with: (%s)", newUserAgent, err)

}
default:
return nil, fmt.Errorf("AzureDisk - invalid option %s in VolumeSnapshotClass", k)
}
}

if azureutils.IsAzureStackCloud(d.cloud.Config.Cloud, d.cloud.Config.DisableAzureStackCloud) {
if azureutils.IsAzureStackCloud(localCloud.Config.Cloud, localCloud.Config.DisableAzureStackCloud) {
klog.V(2).Info("Use full snapshot instead as Azure Stack does not support incremental snapshot.")
incremental = false
}
Expand Down Expand Up @@ -892,7 +898,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
}()

klog.V(2).Infof("begin to create snapshot(%s, incremental: %v) under rg(%s)", snapshotName, incremental, resourceGroup)
rerr := d.cloud.SnapshotsClient.CreateOrUpdate(ctx, resourceGroup, snapshotName, snapshot)
rerr := localCloud.SnapshotsClient.CreateOrUpdate(ctx, resourceGroup, snapshotName, snapshot)
if rerr != nil {
if strings.Contains(rerr.Error().Error(), "existing disk") {
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", snapshotName, resourceGroup, rerr.Error()))
Expand Down

0 comments on commit 2347058

Please sign in to comment.