# Creation and Deletion of Volumes ## Volume Creation Flow ![Katbox Create Flow](images/katboxCreate.png) A request is made to the kubernetes to create a pod. Kubernetes schedules a pod on a worker node in the cluster. The kubelet sees that there is a request for an ephemeral-inline volume from the driver `katbox.csi.paypal.com` so it looks through its registered plugins and finds Katbox. It creates a `NodePublishVolume` api requests through the Unix Domain Socket registered for Katbox by the CSI Node Registrar. Katbox receives the request and creates a folder in its working directory. By default, this directory is located at `/var/lib/csi-katbox`. Using the information provided by the request, a new folder is created in the working directory using the volume ID received: `$WORKDIR/` This newly created folder is then bind mounted to the mount location expected by the kubelet called the `targetPath`. By default this folder's location is in: `/var/lib/kubelet/pods//volumes/kubernetes.io-csi//mount` The pod UUID is generated by Kubernetes when the pod is created, while the volume name is the name given to the mount in the spec. Once the bind mount is successful, Katbox replies to the request as having succeeded. If for any reason katbox is unable to fulfill the request, an error is returned to the kubelet and the pod creation process fails. ## Volume Deletion Flow ![Katbox Delete Flow](images/katboxDelete.png) When a pod which uses a Katbox allocated volume is deleted, the kubelet sends a `NodeUnpublishVolume` api request to katbox via a previously registered Unix Domain Socket. Katbox unbinds the folder that was bound from katbox's working directory to the `targetPath`. Next, katbox adds the volume to its deletion queue and returns a successful deletion message to the kubelet. If for some reason katbox is unable to unmount the given folder, katbox will instead return an error to the kubelet which will then begin attempting to retry the deletion. The information given to the deletion queue includes the path of the folder used for the volume inside katbox's working directory, the time at which it was deleted, as well as a lifespan. An example of the information given to the queue looks like this: ``` { Path: "/var/lib/kubelet/csi-katbox//", Time: time.Now(), Lifespan: