Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug by passing fstype correctly #335

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/kubernetes/static-provisioning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Static Provisioning
This example shows how to create and consume persistence volume from exising EBS using static provisioning.

## Usage
1. Edit the PersistentVolume spec in [example manifest](./specs/example.yaml). Update `volumeHandle` with EBS volume ID that you are going to use, and update the `fsType` with the filesystem type of the volume. In this example, I have a pre-created EBS volume in us-east-1c availability zone and it is formatted with xfs filesystem.

```
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-pv
spec:
capacity:
storage: 50Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
csi:
driver: ebs.csi.aws.com
volumeHandle: {volumeId}
fsType: xfs
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: topology.ebs.csi.aws.com/zone
operator: In
values:
- us-east-1c
```
Note that node affinity is used here since EBS volume is created in us-east-1c, hence only node in the same AZ can consume this persisence volume.

2. Deploy the example:
```sh
kubectl apply -f specs/
```

3. Verify application pod is running:
```sh
kubectl describe po app
```

4. Validate the pod successfully wrote data to the volume:
```sh
kubectl exec -it app cat /data/out.txt
```

5. Cleanup resources:
```sh
kubectl delete -f specs/
```
61 changes: 61 additions & 0 deletions examples/kubernetes/static-provisioning/specs/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-sc
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-pv
spec:
capacity:
storage: 50Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
csi:
driver: ebs.csi.aws.com
volumeHandle: vol-05786ec9ec9526b67
fsType: xfs
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: topology.ebs.csi.aws.com/zone
operator: In
values:
- us-east-1c
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
resources:
requests:
storage: 50Gi
---
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: ebs-claim
2 changes: 1 addition & 1 deletion examples/kubernetes/storageclass/specs/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
parameters:
fsType: xfs
csi.storage.k8s.io/fstype: xfs
type: io1
iopsPerGB: "50"
encrypted: "true"
Expand Down
19 changes: 10 additions & 9 deletions hack/run-e2e-test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -uo pipefail
set -euo pipefail

OS_ARCH=$(go env GOOS)-amd64
TEST_ID=$RANDOM
Expand Down Expand Up @@ -47,6 +47,15 @@ chmod +x $KOPS_PATH

helm::install

echo "Build and push test driver image"
eval $(aws ecr get-login --region $REGION --no-include-email)
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG=$TEST_ID
IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/aws-ebs-csi-driver
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG

set +e
echo "Creating cluster $CLUSTER_NAME"
CLUSTER_YAML_PATH=$TEST_DIR/$CLUSTER_NAME.yaml
SSH_KEY_PATH=$TEST_DIR/id_rsa
Expand Down Expand Up @@ -77,14 +86,6 @@ while [[ 1 ]]; do
fi
done;

# Push test driver image
eval $(aws ecr get-login --region $REGION --no-include-email)
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG=$TEST_ID
IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/aws-ebs-csi-driver
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG

echo "Deploying driver"
helm::init
helm::wait_tiller
Expand Down
1 change: 0 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ type Disk struct {
VolumeID string
CapacityGiB int64
AvailabilityZone string
FsType string
}

// DiskOptions represents parameters to create an EBS volume
Expand Down
3 changes: 0 additions & 3 deletions pkg/driver/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const (

// constants of keys in volume parameters
const (
// FsTypeKey represents key for filesystem type
FsTypeKey = "fstype"

// VolumeTypeKey represents key for volume type
VolumeTypeKey = "type"

Expand Down
11 changes: 3 additions & 8 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
}

var (
fsType string
volumeType string
iopsPerGB int
isEncrypted bool
Expand All @@ -112,8 +111,8 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol

for key, value := range req.GetParameters() {
switch strings.ToLower(key) {
case FsTypeKey:
fsType = value
case "fstype":
klog.Warning("\"fstype\" is deprecated, please use \"csi.storage.k8s.io/fstype\" instead")
case VolumeTypeKey:
volumeType = value
case IopsPerGBKey:
Expand All @@ -136,7 +135,6 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol

// volume exists already
if disk != nil {
disk.FsType = fsType
return newCreateVolumeResponse(disk), nil
}

Expand Down Expand Up @@ -172,7 +170,6 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
}
return nil, status.Errorf(errCode, "Could not create volume %q: %v", volName, err)
}
disk.FsType = fsType
return newCreateVolumeResponse(disk), nil
}

Expand Down Expand Up @@ -488,9 +485,7 @@ func newCreateVolumeResponse(disk *cloud.Disk) *csi.CreateVolumeResponse {
Volume: &csi.Volume{
VolumeId: disk.VolumeID,
CapacityBytes: util.GiBToBytes(disk.CapacityGiB),
VolumeContext: map[string]string{
FsTypeKey: disk.FsType,
},
VolumeContext: map[string]string{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK: external-provisioner will fill in volume.spec.csi.fstype for us

AccessibleTopology: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: disk.AvailabilityZone},
Expand Down
Loading