Skip to content

Commit bd57df7

Browse files
authored
Merge pull request #864 from andyzhangx/context-refine
cleanup: remove context.TODO
2 parents 07f79d4 + a210490 commit bd57df7

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

pkg/blob/blob.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
460460
if secretName != "" && !strings.EqualFold(azureStorageAuthType, "msi") {
461461
// read from k8s secret first
462462
var name string
463-
name, accountKey, err = d.GetStorageAccountFromSecret(secretName, secretNamespace)
463+
name, accountKey, err = d.GetStorageAccountFromSecret(ctx, secretName, secretNamespace)
464464
if name != "" {
465465
accountName = name
466466
}
@@ -695,7 +695,7 @@ func getContainerReference(containerName string, secrets map[string]string, env
695695
return container, nil
696696
}
697697

698-
func setAzureCredentials(kubeClient kubernetes.Interface, accountName, accountKey, secretNamespace string) (string, error) {
698+
func setAzureCredentials(ctx context.Context, kubeClient kubernetes.Interface, accountName, accountKey, secretNamespace string) (string, error) {
699699
if kubeClient == nil {
700700
klog.Warningf("could not create secret: kubeClient is nil")
701701
return "", nil
@@ -715,7 +715,7 @@ func setAzureCredentials(kubeClient kubernetes.Interface, accountName, accountKe
715715
},
716716
Type: "Opaque",
717717
}
718-
_, err := kubeClient.CoreV1().Secrets(secretNamespace).Create(context.TODO(), secret, metav1.CreateOptions{})
718+
_, err := kubeClient.CoreV1().Secrets(secretNamespace).Create(ctx, secret, metav1.CreateOptions{})
719719
if errors.IsAlreadyExists(err) {
720720
err = nil
721721
}
@@ -738,7 +738,7 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
738738
if secretName == "" {
739739
secretName = fmt.Sprintf(secretNameTemplate, accountOptions.Name)
740740
}
741-
_, accountKey, err := d.GetStorageAccountFromSecret(secretName, secretNamespace)
741+
_, accountKey, err := d.GetStorageAccountFromSecret(ctx, secretName, secretNamespace)
742742
if err != nil {
743743
klog.V(2).Infof("could not get account(%s) key from secret(%s) namespace(%s), error: %v, use cluster identity to get account key instead", accountOptions.Name, secretName, secretNamespace, err)
744744
accountKey, err = d.cloud.GetStorageAccesskey(ctx, accountOptions.SubscriptionID, accountOptions.Name, accountOptions.ResourceGroup)
@@ -748,12 +748,12 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
748748

749749
// GetStorageAccountFromSecret get storage account key from k8s secret
750750
// return <accountName, accountKey, error>
751-
func (d *Driver) GetStorageAccountFromSecret(secretName, secretNamespace string) (string, string, error) {
751+
func (d *Driver) GetStorageAccountFromSecret(ctx context.Context, secretName, secretNamespace string) (string, string, error) {
752752
if d.cloud.KubeClient == nil {
753753
return "", "", fmt.Errorf("could not get account key from secret(%s): KubeClient is nil", secretName)
754754
}
755755

756-
secret, err := d.cloud.KubeClient.CoreV1().Secrets(secretNamespace).Get(context.TODO(), secretName, metav1.GetOptions{})
756+
secret, err := d.cloud.KubeClient.CoreV1().Secrets(secretNamespace).Get(ctx, secretName, metav1.GetOptions{})
757757
if err != nil {
758758
return "", "", fmt.Errorf("could not get secret(%v): %w", secretName, err)
759759
}

pkg/blob/blob_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func TestSetAzureCredentials(t *testing.T) {
945945
}
946946

947947
for _, test := range tests {
948-
result, err := setAzureCredentials(test.kubeClient, test.accountName, test.accountKey, test.secretNamespace)
948+
result, err := setAzureCredentials(context.TODO(), test.kubeClient, test.accountName, test.accountKey, test.secretNamespace)
949949
if result != test.expectedName || !reflect.DeepEqual(err, test.expectedErr) {
950950
t.Errorf("desc: %s,\n input: kubeClient(%v), accountName(%v), accountKey(%v),\n setAzureCredentials result: %v, expectedName: %v err: %v, expectedErr: %v",
951951
test.desc, test.kubeClient, test.accountName, test.accountKey, result, test.expectedName, err, test.expectedErr)
@@ -1047,7 +1047,7 @@ func TestGetStorageAccountFromSecret(t *testing.T) {
10471047
d.cloud.KubeClient = nil
10481048
secretName := "foo"
10491049
secretNamespace := "bar"
1050-
_, _, err := d.GetStorageAccountFromSecret(secretName, secretNamespace)
1050+
_, _, err := d.GetStorageAccountFromSecret(context.TODO(), secretName, secretNamespace)
10511051
expectedErr := fmt.Errorf("could not get account key from secret(%s): KubeClient is nil", secretName)
10521052
if assert.Error(t, err) {
10531053
assert.Equal(t, expectedErr, err)
@@ -1062,7 +1062,7 @@ func TestGetStorageAccountFromSecret(t *testing.T) {
10621062
d.cloud.KubeClient = fakeClient
10631063
secretName := ""
10641064
secretNamespace := ""
1065-
_, _, err := d.GetStorageAccountFromSecret(secretName, secretNamespace)
1065+
_, _, err := d.GetStorageAccountFromSecret(context.TODO(), secretName, secretNamespace)
10661066
// expectedErr := fmt.Errorf("could not get secret(%v): %w", secretName, err)
10671067
assert.Error(t, err) // could not check what type of error, needs fix
10681068
/*if assert.Error(t, err) {
@@ -1095,7 +1095,7 @@ func TestGetStorageAccountFromSecret(t *testing.T) {
10951095
if secretCreateErr != nil {
10961096
t.Error("failed to create secret")
10971097
}
1098-
an, ak, err := d.GetStorageAccountFromSecret(secretName, secretNamespace)
1098+
an, ak, err := d.GetStorageAccountFromSecret(context.TODO(), secretName, secretNamespace)
10991099
assert.Equal(t, accountName, an, "accountName's should match")
11001100
assert.Equal(t, accountKey, ak, "accountKey's should match")
11011101
assert.Equal(t, nil, err, "error should be nil")

pkg/blob/controllerserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
391391
}
392392
}
393393

394-
secretName, err := setAzureCredentials(d.cloud.KubeClient, accountName, accountKey, secretNamespace)
394+
secretName, err := setAzureCredentials(ctx, d.cloud.KubeClient, accountName, accountKey, secretNamespace)
395395
if err != nil {
396396
return nil, status.Errorf(codes.Internal, "failed to store storage account key: %v", err)
397397
}

pkg/blob/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
145145
return &csi.NodePublishVolumeResponse{}, nil
146146
}
147147

148-
func (d *Driver) mountBlobfuseWithProxy(args string, protocol string, authEnv []string) (string, error) {
148+
func (d *Driver) mountBlobfuseWithProxy(args, protocol string, authEnv []string) (string, error) {
149149
var resp *mount_azure_blob.MountAzureBlobResponse
150150
var output string
151151
connectionTimout := time.Duration(d.blobfuseProxyConnTimout) * time.Second

0 commit comments

Comments
 (0)