Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#564 from kubernetes-sigs/fix-nfs-f…
Browse files Browse the repository at this point in the history
…stype

fix: incorrect protocol and fsType combination
  • Loading branch information
andyzhangx authored Feb 23, 2021
2 parents 0e8d99d + 2c41b8f commit 4944cf5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
7 changes: 7 additions & 0 deletions hack/verify-helm-chart-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
set -euo pipefail

echo "begin to verify chart tgz files ..."
git config core.filemode false

# verify whether chart config has changed
diff=`git diff`
Expand Down Expand Up @@ -46,3 +47,9 @@ if [[ -n "${diff}" ]]; then
fi

echo "chart tgz files verified."

echo "verify helm chart index ..."
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm repo add azurefile-csi-driver https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/charts
helm search repo -l azurefile-csi-driver
echo "helm chart index verified."
4 changes: 4 additions & 0 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, status.Errorf(codes.InvalidArgument, "protocol(%s) is not supported, supported protocol list: %v", protocol, supportedProtocolList)
}

if protocol == nfs && fsType != "" && fsType != nfs {
return nil, status.Errorf(codes.InvalidArgument, "fsType(%s) is not supported with protocol(%s)", fsType, protocol)
}

enableHTTPSTrafficOnly := true
shareProtocol := storage.SMB
var vnetResourceIDs []string
Expand Down
44 changes: 42 additions & 2 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"net/http"
"net/url"
"reflect"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/subnetclient/mocksubnetclient"
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/subnetclient/mocksubnetclient"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-30/compute"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
azure2 "github.com/Azure/go-autorest/autorest/azure"
Expand Down Expand Up @@ -281,6 +282,45 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "Invalid protocol & fsType combination",
testFunc: func(t *testing.T) {
allParam := map[string]string{
protocolField: "nfs",
fsTypeField: "ext4",
}

req := &csi.CreateVolumeRequest{
Name: "random-vol-name-vol-cap-invalid",
CapacityRange: stdCapRange,
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Block{
Block: nil,
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
Parameters: allParam,
}

ctx := context.Background()
d := NewFakeDriver()

d.AddControllerServiceCapabilities(
[]csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
})

expectedErr := status.Errorf(codes.InvalidArgument, "fsType(ext4) is not supported with protocol(nfs)")
_, err := d.CreateVolume(ctx, req)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected error: %v", err)
}
},
},
{
name: "Failed to update subnet service endpoints",
testFunc: func(t *testing.T) {
Expand Down

0 comments on commit 4944cf5

Please sign in to comment.