@startuml
(*) -->[ **user** creates PVC ] "PVC exists"
-->[ **PV controller** checks storage class and existing PVs ] ==B1==

==B1== -->[= __immediate binding:__\lif necessary, **PV controller** sets the\l""volume.beta.kubernetes.io/storage-provisioner""\lannotation] "PVC ready for provisioning" as PVC_READY_IMMEDIATE
  -->"CreateVolume for all nodes" as CREATE_VOLUME_ALL
  -->[failure] "PVC_READY_IMMEDIATE"
  CREATE_VOLUME_ALL -->[success] ==B2==

==B1== -->[= __late binding__] "wait for pod" as POD
  -->[ **scheduler** tentatively chooses a node for the pod\lwhich uses the volume and sets the\l""volume.beta.kubernetes.io/selected-node""\lannotation ] "PVC with selected node" as PVC_SELECTED
  -->[if necessary, **PV controller** sets the\l""volume.beta.kubernetes.io/storage-provisioner""\lannotation ] "PVC with selected node ready for provisioning" as PVC_SELECTED_READY
  --> "CreateVolume for selected node" as CREATE_VOLUME_SELECTED
  -->[""ResourceExhausted"":\l**external-provisioner**\lunsets the\l""selected-node"" annotation] "POD"
  CREATE_VOLUME_SELECTED -->[failure] "PVC_SELECTED_READY"
  CREATE_VOLUME_SELECTED -->[success] ==B2==

==B2== --> "volume exists" as VOLUME_EXISTS
-->[ **external-provisioner** creates PV ] "PV ready for binding"
-->[ **PV controller** sets\l* ""PV.Status.Phase: Bound"" ] "PV bound"
-->[ **PV controller** sets\l* ""pv.kubernetes.io/bind-completed: yes""\l* ""pv.kubernetes.io/bound-by-controller: yes""\l* ""PVC.Spec.VolumeName""] "PVC almost bound"
-->[ **PV controller** sets\l* ""PVC.Status.Phase: Bound""\l* ""PVC.Status.Capacity"" ] "PVC bound"
-->[ **user** deletes PVC ] "PVC marked for deletion"
-->[ **PVC protection controller** determines that PVC is not in use ] "PVC deleted, PV orphaned" as VOLUME_READY_FOR_DELETION
--> "DeleteVolume"
DeleteVolume -->[failure] VOLUME_READY_FOR_DELETION
DeleteVolume -->[success] "volume deleted"
-->[ **external-provisioner** set ""PV.Status.Phase: Released"" ] "PV ready for deletion" as PV_READY_FOR_DELETION
-->[ **external-provisioner** deletes PV ] "PV marked for deletion"
-->[ **PV controller** checks the volume one last time\l and removes the pv protection finalizer ] "PV deleted"
--> (*)
@enduml
