This docs contain e2e testing steps for kubernetes-csi/csi-driver-host-path#569
- Build the project and push CSI hostpath plugin image to private repo
$ make push-multiarch PULL_BASE_REF=master REGISTRY_NAME=prasadg193 BUILD_PLATFORMS="linux amd64 amd64"
# This builds and pushes image prasadg193/hostpathplugin:canary
-
Deploy CSI hostpath plugin with external-snapshot-metadata sidecar
a. Manual steps:
Steps to generate certs and required manifest are given here: https://github.com/PrasadG193/csi-driver-host-path/tree/snapshot-metadata-service-deploy/examples/external-snapshot-metadata
b. Using deploy.sh script
Alternatively, one can use updated
deploy.shscript from repo:i. clone the branch
update-deploy-scriptfrom forked repo PrasadG193/csi-driver-host-pathii. Execute deploy script to setup hostpath plugin driver with external-snapshot-metadata change
$ SNAPSHOT_METADATA_TESTS=true ./deploy/kubernetes-1.27/deploy.sh -
Create CSI Hostpath storageclass
$ kubectl create -f examples/csi-storageclass.yaml
We will be using sample client to interact with external-snapshot-metadata service to query changed block metadata information between two CSI snapshots on Kubernetes.: https://github.com/PrasadG193/external-snapshot-metadata-client
The client with all necessary permissions can be deployed using manifest from: https://github.com/PrasadG193/external-snapshot-metadata-client/tree/main/deploy
This client performs following actions as recommended in KEP:
- Find Driver name for the snapshot
- Discover
SnapshotMetadataServiceresource for the driver which contains endpoint, audience and CA cert - Create SA Token with expected audience and permissions
- Make gRPC call
GetMetadataAllocatedandGetMetadataDeltawith appropriate params fromSnapshotMetadataServiceresource , generated SA token - Stream response and print on console
- Create a volume with Block mode access
kubectl apply -f - <<EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-raw
spec:
accessModes:
- ReadWriteOnce
storageClassName: csi-hostpath-sc
volumeMode: Block
resources:
requests:
storage: 10Mi
EOF
- Mount the PVC to a pod
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: pod-raw
labels:
name: busybox-test
spec:
restartPolicy: Always
containers:
- image: gcr.io/google_containers/busybox
command: ["/bin/sh", "-c"]
args: [ "tail -f /dev/null" ]
name: busybox
volumeDevices:
- name: vol
devicePath: /dev/loop3 # This device path needs to be replaced with the site specific
volumes:
- name: vol
persistentVolumeClaim:
claimName: pvc-raw
EOF
- Snapshot PVC
pvc-raw
kubectl apply -f - <<EOF
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: raw-pvc-snap-1
spec:
volumeSnapshotClassName: csi-hostpath-snapclass
source:
persistentVolumeClaimName: pvc-raw
EOF
Wait for snapshot to be ready
$ kg vs snapshot-1
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
snapshot-1 true pvc-raw 10Mi csi-hostpath-snapclass snapcontent-70b40b27-80d4-448b-bd9a-a87079c1a248 28s 29s
- Using
external-snapshot-metadata-clientwhich usesGetMetadataAllocatedgRPC to allocated blocks metadata
$ kubectl exec -ti cbt-client-fdc8f549c-stql2 -n cbt-client -- /external-snapshot-metadata-client -client-namespace cbt-client -service-account cbt-client -snapshot-1 raw-pvc-snap-1
.
.
.
.
## Response received from external-snapshot-metadata service:
{"blockMetadataType":"FIXED_LENGTH", "volumeCapacityBytes":"10485760", "blockMetadata":[{"sizeBytes":"4096"}, {"byteOffset":"4096", "sizeBytes":"4096"}, {"byteOffset"
:"8192", "sizeBytes":"4096"}, {"byteOffset":"12288", "sizeBytes":"4096"}, {"byteOffset":"16384", "sizeBytes":"4096"}, {"byteOffset":"20480", "sizeBytes":"4096"}, {"by
teOffset":"24576", "sizeBytes":"4096"}, {"byteOffset":"28672", "sizeBytes":"4096"}, {"byteOffset":"32768", "sizeBytes":"4096"}, {"byteOffset":"36864", "sizeBytes":"40
96"}, {"byteOffset":"40960", "sizeBytes":"4096"}, {"byteOffset":"45056", "sizeBytes":"4096"}, {"byteOffset":"49152", "sizeBytes":"4096"}, {"byteOffset":"53248", "size
Bytes":"4096"}, {"byteOffset":"57344", "sizeBytes":"4096"}, {"byteOffset":"6144
.
.
.
.
":"4096"}, {"byteOffset":"10440704", "sizeBytes":"4096"}, {"byteOffset":"10444800", "sizeBytes":"4096"}, {"byteOffset":"10448896", "sizeBytes":"4096"}, {"byteOffset":"10452992", "sizeBytes":"4096"}, {"byteOffset":"10457088", "sizeBytes":"4096"}, {"byteOffset":"10461184", "sizeBytes":"4096"}, {"byteOffset":"10465280", "sizeBytes":"4096"}, {"byteOffset":"10469376", "sizeBytes":"4096"}, {"byteOffset":"10473472", "sizeBytes":"4096"}, {"byteOffset":"10477568", "sizeBytes":"4096"}, {"byteOffset":"10481664", "sizeBytes":"4096"}]}
2024/12/09 12:42:34 finished
- Change couple of blocks in the mounted device file in
pod-rawPod
$ kubectl exec -ti pod-raw -- sh
### change blocks 12, 13, 15 and 20
/ # dd if=/dev/urandom of=/dev/loop3 bs=4K count=1 seek=12 conv=notrunc
1+0 records in
1+0 records out
/ # dd if=/dev/urandom of=/dev/loop3 bs=4K count=1 seek=13 conv=notrunc
1+0 records in
1+0 records out
/ # dd if=/dev/urandom of=/dev/loop3 bs=4K count=1 seek=15 conv=notrunc
1+0 records in
1+0 records out
/ # dd if=/dev/urandom of=/dev/loop3 bs=4K count=1 seek=20 conv=notrunc
1+0 records in
1+0 records out
- Snapshot
pvc-rawagain
kubectl apply -f - <<EOF
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: raw-pvc-snap-2
spec:
volumeSnapshotClassName: csi-hostpath-snapclass
source:
persistentVolumeClaimName: pvc-raw
EOF
Wait for snapshot to be ready
$ kubectl get vs
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
raw-pvc-snap-1 true pvc-raw 10Mi csi-hostpath-snapclass snapcontent-ef10f725-4261-4e80-af37-906708796700 7m40s 7m40s
raw-pvc-snap-2 true pvc-raw 10Mi csi-hostpath-snapclass snapcontent-188562cb-03b3-4b70-b12d-28900527bca8 23s 23s
- Using
external-snapshot-metadata-clientwhich usesGetMetadataDeltagRPC to allocated blocks metadata
$ kubectl exec -ti cbt-client-fdc8f549c-stql2 -n cbt-client -- /external-snapshot-metadata-client -client-namespace cbt-client -service-account cbt-client -snapshot-1 raw-pvc-snap-1 -snapshot-2 raw-pvc-snap-2
.
.
.
.
## Response received from external-snapshot-metadata service:
{"blockMetadataType":"FIXED_LENGTH", "volumeCapacityBytes":"10485760", "blockMetadata":[{"byteOffset":"49152", "sizeBytes":"4096"}, {"byteOffset":"53248", "sizeBytes":"4096"}, {"byteOffset":"61440", "sizeBytes":"4096"}, {"byteOffset":"81920", "sizeBytes":"4096"}]}
2024/12/09 12:51:36 finished