Skip to content

Commit 961207e

Browse files
committed
Adding a missed change after merge.
Refactoring constants into a separate package. Refactoring constants into a separate package.
1 parent b384410 commit 961207e

19 files changed

+228
-211
lines changed

pkg/azureutils/azure_disk_constants.go renamed to pkg/azureconstants/azure_constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package azureutils
17+
package azureconstants
1818

1919
import (
2020
"regexp"

pkg/azuredisk/azuredisk.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/klog/v2"
3333
"k8s.io/mount-utils"
3434

35+
azureconsts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
3536
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
3637
csicommon "sigs.k8s.io/azuredisk-csi-driver/pkg/csi-common"
3738
"sigs.k8s.io/azuredisk-csi-driver/pkg/mounter"
@@ -40,6 +41,7 @@ import (
4041
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
4142
consts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
4243
"sigs.k8s.io/cloud-provider-azure/pkg/provider"
44+
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
4345
)
4446

4547
// DriverOptions defines driver parameters specified in driver deployment
@@ -71,7 +73,7 @@ type DriverCore struct {
7173
cloudConfigSecretNamespace string
7274
customUserAgent string
7375
userAgentSuffix string
74-
cloud *provider.Cloud
76+
cloud *azure.Cloud
7577
mounter *mount.SafeFormatAndMount
7678
deviceHelper *optimization.SafeDeviceHelper
7779
nodeInfo *optimization.NodeInfo
@@ -184,9 +186,9 @@ func (d *Driver) Run(endpoint, kubeconfig string, disableAVSetNodes, testingMock
184186
}
185187

186188
func (d *Driver) isGetDiskThrottled() bool {
187-
cache, err := d.getDiskThrottlingCache.Get(azureutils.ThrottlingKey, azcache.CacheReadTypeDefault)
189+
cache, err := d.getDiskThrottlingCache.Get(azureconsts.ThrottlingKey, azcache.CacheReadTypeDefault)
188190
if err != nil {
189-
klog.Warningf("getDiskThrottlingCache(%s) return with error: %s", azureutils.ThrottlingKey, err)
191+
klog.Warningf("getDiskThrottlingCache(%s) return with error: %s", azureconsts.ThrottlingKey, err)
190192
return false
191193
}
192194
return cache != nil
@@ -210,9 +212,9 @@ func (d *Driver) checkDiskExists(ctx context.Context, diskURI string) (*compute.
210212

211213
disk, rerr := d.cloud.DisksClient.Get(ctx, resourceGroup, diskName)
212214
if rerr != nil {
213-
if strings.Contains(rerr.RawError.Error(), azureutils.RateLimited) {
215+
if strings.Contains(rerr.RawError.Error(), azureconsts.RateLimited) {
214216
klog.Warningf("checkDiskExists(%s) is throttled with error: %v", diskURI, rerr.Error())
215-
d.getDiskThrottlingCache.Set(azureutils.ThrottlingKey, "")
217+
d.getDiskThrottlingCache.Set(azureconsts.ThrottlingKey, "")
216218
return nil, nil
217219
}
218220
return nil, rerr.Error()
@@ -235,9 +237,9 @@ func (d *Driver) checkDiskCapacity(ctx context.Context, resourceGroup, diskName
235237
return false, status.Errorf(codes.AlreadyExists, "the request volume already exists, but its capacity(%v) is different from (%v)", *disk.DiskProperties.DiskSizeGB, requestGiB)
236238
}
237239
} else {
238-
if strings.Contains(rerr.RawError.Error(), azureutils.RateLimited) {
240+
if strings.Contains(rerr.RawError.Error(), azureconsts.RateLimited) {
239241
klog.Warningf("checkDiskCapacity(%s, %s) is throttled with error: %v", resourceGroup, diskName, rerr.Error())
240-
d.getDiskThrottlingCache.Set(azureutils.ThrottlingKey, "")
242+
d.getDiskThrottlingCache.Set(azureconsts.ThrottlingKey, "")
241243
}
242244
}
243245
return true, nil

pkg/azuredisk/azuredisk_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/golang/mock/gomock"
2727
"github.com/stretchr/testify/assert"
2828
"google.golang.org/grpc/status"
29-
constants "sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
29+
consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
3030
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/diskclient/mockdiskclient"
3131
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
3232
)
@@ -80,13 +80,13 @@ func TestRun(t *testing.T) {
8080
}
8181
}()
8282

83-
originalCredFile, ok := os.LookupEnv(constants.DefaultAzureCredentialFileEnv)
83+
originalCredFile, ok := os.LookupEnv(consts.DefaultAzureCredentialFileEnv)
8484
if ok {
85-
defer os.Setenv(constants.DefaultAzureCredentialFileEnv, originalCredFile)
85+
defer os.Setenv(consts.DefaultAzureCredentialFileEnv, originalCredFile)
8686
} else {
87-
defer os.Unsetenv(constants.DefaultAzureCredentialFileEnv)
87+
defer os.Unsetenv(consts.DefaultAzureCredentialFileEnv)
8888
}
89-
os.Setenv(constants.DefaultAzureCredentialFileEnv, fakeCredFile)
89+
os.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)
9090

9191
d, _ := NewFakeDriver(t)
9292
d.Run("tcp://127.0.0.1:0", "", true, true)
@@ -105,13 +105,13 @@ func TestRun(t *testing.T) {
105105
}
106106
}()
107107

108-
originalCredFile, ok := os.LookupEnv(constants.DefaultAzureCredentialFileEnv)
108+
originalCredFile, ok := os.LookupEnv(consts.DefaultAzureCredentialFileEnv)
109109
if ok {
110-
defer os.Setenv(constants.DefaultAzureCredentialFileEnv, originalCredFile)
110+
defer os.Setenv(consts.DefaultAzureCredentialFileEnv, originalCredFile)
111111
} else {
112-
defer os.Unsetenv(constants.DefaultAzureCredentialFileEnv)
112+
defer os.Unsetenv(consts.DefaultAzureCredentialFileEnv)
113113
}
114-
os.Setenv(constants.DefaultAzureCredentialFileEnv, fakeCredFile)
114+
os.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)
115115

116116
d, _ := NewFakeDriver(t)
117117
d.setCloud(&azure.Cloud{})

pkg/azuredisk/azuredisk_v1_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-12-01/compute"
2626
"github.com/golang/mock/gomock"
2727
"github.com/stretchr/testify/assert"
28-
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
28+
consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
2929
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/diskclient/mockdiskclient"
3030
)
3131

@@ -41,14 +41,14 @@ func TestCheckDiskCapacity_V1(t *testing.T) {
4141
}
4242
d.getCloud().DisksClient.(*mockdiskclient.MockInterface).EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(disk, nil).AnyTimes()
4343

44-
d.setDiskThrottlingCache(azureutils.ThrottlingKey, "")
44+
d.setDiskThrottlingCache(consts.ThrottlingKey, "")
4545
flag, _ := d.checkDiskCapacity(context.TODO(), resourceGroup, diskName, 11)
4646
assert.Equal(t, flag, true)
4747
}
4848

4949
func TestDriver_checkDiskExists_V1(t *testing.T) {
5050
d, _ := NewFakeDriver(t)
51-
d.setDiskThrottlingCache(azureutils.ThrottlingKey, "")
51+
d.setDiskThrottlingCache(consts.ThrottlingKey, "")
5252
_, err := d.checkDiskExists(context.TODO(), "testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/disks/name")
5353
assert.Equal(t, err, nil)
5454
}

0 commit comments

Comments
 (0)