Skip to content

Commit

Permalink
Merge pull request #2081 from Zhupku/mengzezhu/ptr
Browse files Browse the repository at this point in the history
chore: Replace deprecated k8s.io/utils/pointer with k8s.io/utils/ptr
  • Loading branch information
k8s-ci-robot authored Aug 30, 2024
2 parents 05ad2d8 + 5b58f41 commit 0066ec3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions pkg/azurefile/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
certutil "k8s.io/client-go/util/cert"
"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"
Expand Down Expand Up @@ -258,7 +258,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
Expand Down
8 changes: 4 additions & 4 deletions pkg/azurefile/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"sigs.k8s.io/azurefile-csi-driver/test/utils/testutil"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/subnetclient/mocksubnetclient"
Expand Down Expand Up @@ -263,7 +263,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)
Expand All @@ -280,7 +280,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()
Expand All @@ -302,7 +302,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()
Expand Down
40 changes: 20 additions & 20 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"google.golang.org/grpc/status"

"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

timestamppb "google.golang.org/protobuf/types/known/timestamppb"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient"
Expand Down Expand Up @@ -92,7 +92,7 @@ var (
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
}
skipMatchingTag = map[string]*string{azure.SkipMatchingTag: pointer.String("")}
skipMatchingTag = map[string]*string{azure.SkipMatchingTag: ptr.To("")}
)

// CreateVolume provisions an azure file
Expand Down Expand Up @@ -138,7 +138,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
var vnetResourceGroup, vnetName, subnetName, shareNamePrefix, fsGroupChangePolicy string
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess *bool
// set allowBlobPublicAccess as false by default
allowBlobPublicAccess := pointer.Bool(false)
allowBlobPublicAccess := ptr.To(false)

fileShareNameReplaceMap := map[string]string{}
// store account key to k8s secret by default
Expand Down Expand Up @@ -347,7 +347,7 @@ 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)
}
var vnetResourceIDs []string
if fsType == nfs || protocol == nfs {
Expand All @@ -366,7 +366,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
// reset protocol field (compatible with "fsType: nfs")
setKeyValueInMap(parameters, protocolField, protocol)

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 {
Expand All @@ -375,7 +375,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
}

if pointer.BoolDeref(isMultichannelEnabled, false) {
if ptr.Deref(isMultichannelEnabled, false) {
if sku != "" && !strings.HasPrefix(strings.ToLower(sku), premium) {
return nil, status.Errorf(codes.InvalidArgument, "smb multichannel is only supported with premium account, current account type: %s", sku)
}
Expand All @@ -384,7 +384,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
}

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")
}

Expand Down Expand Up @@ -492,8 +492,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
accountName = v.(string)
} else {
lockKey = fmt.Sprintf("%s%s%s%s%s%s%s%v%v%v%v%v", sku, accountKind, resourceGroup, location, protocol, subsID, accountAccessTier,
pointer.BoolDeref(createPrivateEndpoint, false), pointer.BoolDeref(allowBlobPublicAccess, false), pointer.BoolDeref(requireInfraEncryption, false),
pointer.BoolDeref(enableLFS, false), pointer.BoolDeref(disableDeleteRetentionPolicy, false))
ptr.Deref(createPrivateEndpoint, false), ptr.Deref(allowBlobPublicAccess, false), ptr.Deref(requireInfraEncryption, false),
ptr.Deref(enableLFS, false), ptr.Deref(disableDeleteRetentionPolicy, false))
// search in cache first
cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault)
if err != nil {
Expand Down Expand Up @@ -537,7 +537,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
}

if pointer.BoolDeref(createPrivateEndpoint, false) {
if ptr.Deref(createPrivateEndpoint, false) {
setKeyValueInMap(parameters, serverNameField, fmt.Sprintf("%s.privatelink.file.%s", accountName, storageEndpointSuffix))
}

Expand Down Expand Up @@ -565,7 +565,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
RequestGiB: fileShareSize,
AccessTier: shareAccessTier,
RootSquash: rootSquashType,
Metadata: map[string]*string{createdByMetadata: pointer.String(d.Name)},
Metadata: map[string]*string{createdByMetadata: ptr.To(d.Name)},
}

klog.V(2).Infof("begin to create file share(%s) on account(%s) type(%s) subID(%s) rg(%s) location(%s) size(%d) protocol(%s)", validFileShareName, accountName, sku, subsID, resourceGroup, location, fileShareSize, shareProtocol)
Expand Down Expand Up @@ -919,7 +919,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ

itemSnapshot = snapshotShare.SnapshotTime.Format(snapshotTimeFormat)
itemSnapshotTime = snapshotShare.SnapshotTime.Time
itemSnapshotQuota = pointer.Int32Deref(snapshotShare.ShareQuota, 0)
itemSnapshotQuota = ptr.Deref(snapshotShare.ShareQuota, 0)
}

klog.V(2).Infof("created share snapshot: %s, time: %v, quota: %dGiB", itemSnapshot, itemSnapshotTime, itemSnapshotQuota)
Expand All @@ -928,7 +928,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get file share(%s) quota: %v", fileShareName, err)
}
itemSnapshotQuota = pointer.Int32Deref(fileshare.ShareQuota, defaultAzureFileQuota)
itemSnapshotQuota = ptr.Deref(fileshare.ShareQuota, defaultAzureFileQuota)
}
createResp := &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{
Expand Down Expand Up @@ -1294,17 +1294,17 @@ func (d *Driver) snapshotExists(ctx context.Context, sourceVolumeID, snapshotNam
continue
}
shareSnapshotTime := share.SnapshotTime.Format(snapshotTimeFormat)
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, pointer.StringDeref(share.Name, ""), shareSnapshotTime)
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, ptr.Deref(share.Name, ""), shareSnapshotTime)
if err != nil {
klog.V(2).Infof("get share(%s) snapshot(%s) error(%s)", pointer.StringDeref(share.Name, ""), shareSnapshotTime, err)
klog.V(2).Infof("get share(%s) snapshot(%s) error(%s)", ptr.Deref(share.Name, ""), shareSnapshotTime, err)
return false, "", time.Time{}, 0, nil
}
if fileshare.Metadata != nil && pointer.StringDeref(fileshare.Metadata[snapshotNameKey], "") == snapshotName {
if pointer.StringDeref(fileshare.Name, "") == fileShareName {
klog.V(2).Infof("found share(%s) snapshot(%s) Metadata(%v)", pointer.StringDeref(fileshare.Name, ""), shareSnapshotTime, fileshare.Metadata)
return true, shareSnapshotTime, share.SnapshotTime.Time, pointer.Int32Deref(share.ShareQuota, 0), nil
if fileshare.Metadata != nil && ptr.Deref(fileshare.Metadata[snapshotNameKey], "") == snapshotName {
if ptr.Deref(fileshare.Name, "") == fileShareName {
klog.V(2).Infof("found share(%s) snapshot(%s) Metadata(%v)", ptr.Deref(fileshare.Name, ""), shareSnapshotTime, fileshare.Metadata)
return true, shareSnapshotTime, share.SnapshotTime.Time, ptr.Deref(share.ShareQuota, 0), nil
}
return true, "", time.Time{}, 0, fmt.Errorf("snapshot(%s) already exists, while the current file share name(%s) does not equal to %s, SourceVolumeId(%s)", snapshotName, pointer.StringDeref(share.Name, ""), fileShareName, sourceVolumeID)
return true, "", time.Time{}, 0, fmt.Errorf("snapshot(%s) already exists, while the current file share name(%s) does not equal to %s, SourceVolumeId(%s)", snapshotName, ptr.Deref(share.Name, ""), fileShareName, sourceVolumeID)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient/mockfileclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/storageaccountclient/mockstorageaccountclient"
Expand Down Expand Up @@ -1026,7 +1026,7 @@ func TestCreateVolume(t *testing.T) {
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes()
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: pointer.Int32(1)}}, nil).AnyTimes()
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: ptr.To(int32(1))}}, nil).AnyTimes()

expectedErr := status.Errorf(codes.AlreadyExists, "request file share(random-vol-name-crete-file-error) already exists, but its capacity 1 is smaller than 100")
_, err := d.CreateVolume(ctx, req)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
imageutils "k8s.io/kubernetes/test/utils/image"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -684,7 +684,7 @@ func NewTestPod(c clientset.Interface, ns *v1.Namespace, command string, isWindo
},
RestartPolicy: v1.RestartPolicyNever,
Volumes: make([]v1.Volume, 0),
AutomountServiceAccountToken: pointer.Bool(false),
AutomountServiceAccountToken: ptr.To(false),
},
},
}
Expand Down Expand Up @@ -845,7 +845,7 @@ func (t *TestPod) SetupCSIInlineVolume(name, mountPath, secretName, shareName, s
"server": server,
"mountOptions": "dir_mode=0755,file_mode=0721,cache=singleclient",
},
ReadOnly: pointer.Bool(readOnly),
ReadOnly: ptr.To(readOnly),
},
},
}
Expand Down
36 changes: 18 additions & 18 deletions test/utils/azure/azure_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
network "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4"
resources "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
storage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/accountclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/fileshareclient"
Expand Down Expand Up @@ -167,29 +167,29 @@ func (az *Client) EnsureVirtualMachine(ctx context.Context, groupName, location,
groupName,
vmName,
compute.VirtualMachine{
Location: pointer.String(location),
Location: ptr.To(location),
Properties: &compute.VirtualMachineProperties{
HardwareProfile: &compute.HardwareProfile{
VMSize: to.Ptr(compute.VirtualMachineSizeTypesStandardDS2V2),
},
StorageProfile: &compute.StorageProfile{
ImageReference: &compute.ImageReference{
Publisher: pointer.String("Canonical"),
Offer: pointer.String("UbuntuServer"),
SKU: pointer.String("16.04.0-LTS"),
Version: pointer.String("latest"),
Publisher: ptr.To("Canonical"),
Offer: ptr.To("UbuntuServer"),
SKU: ptr.To("16.04.0-LTS"),
Version: ptr.To("latest"),
},
},
OSProfile: &compute.OSProfile{
ComputerName: pointer.String(vmName),
AdminUsername: pointer.String("azureuser"),
AdminPassword: pointer.String("Azureuser1234"),
ComputerName: ptr.To(vmName),
AdminUsername: ptr.To("azureuser"),
AdminPassword: ptr.To("Azureuser1234"),
LinuxConfiguration: &compute.LinuxConfiguration{
DisablePasswordAuthentication: pointer.Bool(true),
DisablePasswordAuthentication: ptr.To(true),
SSH: &compute.SSHConfiguration{
PublicKeys: []*compute.SSHPublicKey{
{
Path: pointer.String("/home/azureuser/.ssh/authorized_keys"),
Path: ptr.To("/home/azureuser/.ssh/authorized_keys"),
KeyData: &publicKey,
},
},
Expand All @@ -201,7 +201,7 @@ func (az *Client) EnsureVirtualMachine(ctx context.Context, groupName, location,
{
ID: nic.ID,
Properties: &compute.NetworkInterfaceReferenceProperties{
Primary: pointer.Bool(true),
Primary: ptr.To(true),
},
},
},
Expand Down Expand Up @@ -232,12 +232,12 @@ func (az *Client) EnsureNIC(ctx context.Context, groupName, location, nicName, v
groupName,
nicName,
network.Interface{
Name: pointer.String(nicName),
Location: pointer.String(location),
Name: ptr.To(nicName),
Location: ptr.To(location),
Properties: &network.InterfacePropertiesFormat{
IPConfigurations: []*network.InterfaceIPConfiguration{
{
Name: pointer.String("ipConfig1"),
Name: ptr.To("ipConfig1"),
Properties: &network.InterfaceIPConfigurationPropertiesFormat{
Subnet: subnet,
PrivateIPAllocationMethod: to.Ptr(network.IPAllocationMethodDynamic),
Expand All @@ -260,16 +260,16 @@ func (az *Client) EnsureVirtualNetworkAndSubnet(ctx context.Context, groupName,
groupName,
vnetName,
network.VirtualNetwork{
Location: pointer.String(location),
Location: ptr.To(location),
Properties: &network.VirtualNetworkPropertiesFormat{
AddressSpace: &network.AddressSpace{
AddressPrefixes: []*string{to.Ptr("10.0.0.0/8")},
},
Subnets: []*network.Subnet{
{
Name: pointer.String(subnetName),
Name: ptr.To(subnetName),
Properties: &network.SubnetPropertiesFormat{
AddressPrefix: pointer.String("10.0.0.0/16"),
AddressPrefix: ptr.To("10.0.0.0/16"),
},
},
},
Expand Down

0 comments on commit 0066ec3

Please sign in to comment.