Skip to content

Commit

Permalink
Merge pull request #1554 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 31, 2024
2 parents 18b73a8 + 6046abf commit 86cb9ad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/blob/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/blob/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down
32 changes: 16 additions & 16 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
//
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 @@ -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 (
Expand Down Expand Up @@ -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),
},
},
}
Expand Down Expand Up @@ -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),
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions test/utils/azure/authorization_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
})
}
Expand Down

0 comments on commit 86cb9ad

Please sign in to comment.