From 6046abf4a307e82282b31f35f27b211d52bea7e3 Mon Sep 17 00:00:00 2001 From: mengze zhu Date: Wed, 28 Aug 2024 16:17:39 +0800 Subject: [PATCH] chore: Replace deprecated k8s.io/utils/pointer with k8s.io/utils/ptr --- pkg/blob/azure.go | 4 +-- pkg/blob/azure_test.go | 8 +++--- pkg/blob/controllerserver.go | 32 ++++++++++++------------ test/e2e/testsuites/testsuites.go | 6 ++--- test/utils/azure/authorization_helper.go | 6 ++--- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pkg/blob/azure.go b/pkg/blob/azure.go index d566e365b..009bbabd9 100644 --- a/pkg/blob/azure.go +++ b/pkg/blob/azure.go @@ -29,7 +29,7 @@ import ( "golang.org/x/net/context" "k8s.io/client-go/kubernetes" "k8s.io/klog/v2" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader" azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache" azure "sigs.k8s.io/cloud-provider-azure/pkg/provider" @@ -263,7 +263,7 @@ func (d *Driver) updateSubnetServiceEndpoints(ctx context.Context, vnetResourceG } serviceEndpoints := *subnet.SubnetPropertiesFormat.ServiceEndpoints for _, v := range serviceEndpoints { - if strings.HasPrefix(pointer.StringDeref(v.Service, ""), storageService) { + if strings.HasPrefix(ptr.Deref(v.Service, ""), storageService) { storageServiceExists = true klog.V(4).Infof("serviceEndpoint(%s) is already in subnet(%s)", storageService, sn) break diff --git a/pkg/blob/azure_test.go b/pkg/blob/azure_test.go index 4a701f774..b20973071 100644 --- a/pkg/blob/azure_test.go +++ b/pkg/blob/azure_test.go @@ -32,7 +32,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" "k8s.io/client-go/kubernetes" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/blob-csi-driver/pkg/util" "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/subnetclient/mocksubnetclient" @@ -344,7 +344,7 @@ func TestUpdateSubnetServiceEndpoints(t *testing.T) { testFunc: func(t *testing.T) { fakeSubnet := network.Subnet{ SubnetPropertiesFormat: &network.SubnetPropertiesFormat{}, - Name: pointer.String("subnetName"), + Name: ptr.To("subnetName"), } mockSubnetClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnet, nil).Times(1) @@ -361,7 +361,7 @@ func TestUpdateSubnetServiceEndpoints(t *testing.T) { SubnetPropertiesFormat: &network.SubnetPropertiesFormat{ ServiceEndpoints: &[]network.ServiceEndpointPropertiesFormat{}, }, - Name: pointer.String("subnetName"), + Name: ptr.To("subnetName"), } mockSubnetClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnet, nil).AnyTimes() @@ -383,7 +383,7 @@ func TestUpdateSubnetServiceEndpoints(t *testing.T) { }, }, }, - Name: pointer.String("subnetName"), + Name: ptr.To("subnetName"), } mockSubnetClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnet, nil).AnyTimes() diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index 2ff3c3a02..98af4b231 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -40,7 +40,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/blob-csi-driver/pkg/util" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/blobcontainerclient" @@ -99,7 +99,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) var vnetResourceIDs []string var err error // set allowBlobPublicAccess as false by default - allowBlobPublicAccess := pointer.Bool(false) + allowBlobPublicAccess := ptr.To(false) containerNameReplaceMap := map[string]string{} @@ -138,7 +138,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) secretNamespace = v case isHnsEnabledField: if strings.EqualFold(v, trueValue) { - isHnsEnabled = pointer.Bool(true) + isHnsEnabled = ptr.To(true) } case softDeleteBlobsField: days, err := parseDays(v) @@ -153,7 +153,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } softDeleteContainers = days case enableBlobVersioningField: - enableBlobVersioning = pointer.Bool(strings.EqualFold(v, trueValue)) + enableBlobVersioning = ptr.To(strings.EqualFold(v, trueValue)) case storeAccountKeyField: if strings.EqualFold(v, falseValue) { storeAccountKey = false @@ -164,17 +164,17 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } case allowBlobPublicAccessField: if strings.EqualFold(v, trueValue) { - allowBlobPublicAccess = pointer.Bool(true) + allowBlobPublicAccess = ptr.To(true) } case allowSharedKeyAccessField: var boolValue bool if boolValue, err = strconv.ParseBool(v); err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in volume context", allowSharedKeyAccessField, v) } - allowSharedKeyAccess = pointer.Bool(boolValue) + allowSharedKeyAccess = ptr.To(boolValue) case requireInfraEncryptionField: if strings.EqualFold(v, trueValue) { - requireInfraEncryption = pointer.Bool(true) + requireInfraEncryption = ptr.To(true) } case pvcNamespaceKey: pvcNamespace = v @@ -221,8 +221,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } } - if pointer.BoolDeref(enableBlobVersioning, false) { - if isNFSProtocol(protocol) || pointer.BoolDeref(isHnsEnabled, false) { + if ptr.Deref(enableBlobVersioning, false) { + if isNFSProtocol(protocol) || ptr.Deref(isHnsEnabled, false) { return nil, status.Errorf(codes.InvalidArgument, "enableBlobVersioning is not supported for NFS protocol or HNS enabled account") } } @@ -269,15 +269,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) if strings.Contains(subnetName, ",") { return nil, status.Errorf(codes.InvalidArgument, "subnetName(%s) can only contain one subnet for private endpoint", subnetName) } - createPrivateEndpoint = pointer.BoolPtr(true) + createPrivateEndpoint = ptr.To(true) } accountKind := string(armstorage.KindStorageV2) if isNFSProtocol(protocol) { - isHnsEnabled = pointer.Bool(true) - enableNfsV3 = pointer.Bool(true) + isHnsEnabled = ptr.To(true) + enableNfsV3 = ptr.To(true) // NFS protocol does not need account key storeAccountKey = false - if !pointer.BoolDeref(createPrivateEndpoint, false) { + if !ptr.Deref(createPrivateEndpoint, false) { // set VirtualNetworkResourceIDs for storage account firewall setting var err error if vnetResourceIDs, err = d.updateSubnetServiceEndpoints(ctx, vnetResourceGroup, vnetName, subnetName); err != nil { @@ -305,7 +305,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) storageEndpointSuffix = d.getStorageEndPointSuffix() } - if storeAccountKey && !pointer.BoolDeref(allowSharedKeyAccess, true) { + if storeAccountKey && !ptr.Deref(allowSharedKeyAccess, true) { return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled") } @@ -382,7 +382,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) if v, ok := d.volMap.Load(volName); ok { accountName = v.(string) } else { - lockKey := fmt.Sprintf("%s%s%s%s%s%v", storageAccountType, accountKind, resourceGroup, location, protocol, pointer.BoolDeref(createPrivateEndpoint, false)) + lockKey := fmt.Sprintf("%s%s%s%s%s%v", storageAccountType, accountKind, resourceGroup, location, protocol, ptr.Deref(createPrivateEndpoint, false)) // search in cache first cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault) if err != nil { @@ -411,7 +411,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } } - if pointer.BoolDeref(createPrivateEndpoint, false) && isNFSProtocol(protocol) { + if ptr.Deref(createPrivateEndpoint, false) && isNFSProtocol(protocol) { // As for blobfuse/blobfuse2, serverName, i.e.,AZURE_STORAGE_BLOB_ENDPOINT env variable can't include // "privatelink", issue: https://github.com/Azure/azure-storage-fuse/issues/1014 // diff --git a/test/e2e/testsuites/testsuites.go b/test/e2e/testsuites/testsuites.go index 70b649f86..95b522d1e 100644 --- a/test/e2e/testsuites/testsuites.go +++ b/test/e2e/testsuites/testsuites.go @@ -48,7 +48,7 @@ import ( e2epv "k8s.io/kubernetes/test/e2e/framework/pv" testutil "k8s.io/kubernetes/test/utils" imageutils "k8s.io/kubernetes/test/utils/image" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) const ( @@ -452,7 +452,7 @@ func NewTestPod(c clientset.Interface, ns *v1.Namespace, command string) *TestPo }, RestartPolicy: v1.RestartPolicyNever, Volumes: make([]v1.Volume, 0), - AutomountServiceAccountToken: pointer.Bool(false), + AutomountServiceAccountToken: ptr.To(false), }, }, } @@ -561,7 +561,7 @@ func (t *TestPod) SetupInlineVolume(name, mountPath, secretName, containerName s "containerName": containerName, "mountOptions": "-o allow_other --file-cache-timeout-in-seconds=240", }, - ReadOnly: pointer.Bool(readOnly), + ReadOnly: ptr.To(readOnly), }, }, } diff --git a/test/utils/azure/authorization_helper.go b/test/utils/azure/authorization_helper.go index 031f4728f..fa849f453 100644 --- a/test/utils/azure/authorization_helper.go +++ b/test/utils/azure/authorization_helper.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/blob-csi-driver/test/utils/credentials" "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization" @@ -65,8 +65,8 @@ func (a *AuthorizationClient) AssignRole(ctx context.Context, resourceID, princi uuid.NewV1().String(), authorization.RoleAssignmentCreateParameters{ RoleAssignmentProperties: &authorization.RoleAssignmentProperties{ - PrincipalID: pointer.String(principalID), - RoleDefinitionID: pointer.String(roleDefID), + PrincipalID: ptr.To(principalID), + RoleDefinitionID: ptr.To(roleDefID), }, }) }