Documentation ¶
Overview ¶
Package cache implements data structures used by the attach/detach controller to keep track of volumes, the nodes they are attached to, and the pods that reference them.
Package cache implements data structures used by the attach/detach controller to keep track of volumes, the nodes they are attached to, and the pods that reference them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActualStateOfWorld ¶
type ActualStateOfWorld interface { // ActualStateOfWorld must implement the methods required to allow // operationexecutor to interact with it. operationexecutor.ActualStateOfWorldAttacherUpdater // AddVolumeNode adds the given volume and node to the underlying store. // If attached is set to true, it indicates the specified volume is already // attached to the specified node. If attached set to false, it means that // the volume is not confirmed to be attached to the node yet. // A unique volume name is generated from the volumeSpec and returned on // success. // If volumeSpec is not an attachable volume plugin, an error is returned. // If no volume with the name volumeName exists in the store, the volume is // added. // If no node with the name nodeName exists in list of attached nodes for // the specified volume, the node is added. AddVolumeNode(logger klog.Logger, uniqueName v1.UniqueVolumeName, volumeSpec *volume.Spec, nodeName types.NodeName, devicePath string, attached bool) (v1.UniqueVolumeName, error) // SetVolumesMountedByNode sets all the volumes mounted by the given node. // These volumes should include attached volumes, not-yet-attached volumes, // and may also include non-attachable volumes. // When present in the volumeNames parameter, the volume // is mounted by the given node, indicating it may not be safe to detach. // Otherwise, the volume is not mounted by the given node. SetVolumesMountedByNode(logger klog.Logger, volumeNames []v1.UniqueVolumeName, nodeName types.NodeName) // SetNodeStatusUpdateNeeded sets statusUpdateNeeded for the specified // node to true indicating the AttachedVolume field in the Node's Status // object needs to be updated by the node updater again. // If the specified node does not exist in the nodesToUpdateStatusFor list, // log the error and return SetNodeStatusUpdateNeeded(logger klog.Logger, nodeName types.NodeName) // ResetDetachRequestTime resets the detachRequestTime to 0 which indicates there is no detach // request any more for the volume ResetDetachRequestTime(logger klog.Logger, volumeName v1.UniqueVolumeName, nodeName types.NodeName) // SetDetachRequestTime sets the detachRequestedTime to current time if this is no // previous request (the previous detachRequestedTime is zero) and return the time elapsed // since last request SetDetachRequestTime(logger klog.Logger, volumeName v1.UniqueVolumeName, nodeName types.NodeName) (time.Duration, error) // DeleteVolumeNode removes the given volume and node from the underlying // store indicating the specified volume is no longer attached to the // specified node. // If the volume/node combo does not exist, this is a no-op. // If after deleting the node, the specified volume contains no other child // nodes, the volume is also deleted. DeleteVolumeNode(volumeName v1.UniqueVolumeName, nodeName types.NodeName) // GetAttachState returns the attach state for the given volume-node // combination. // Returns AttachStateAttached if the specified volume/node combo exists in // the underlying store indicating the specified volume is attached to the // specified node, AttachStateDetached if the combo does not exist, or // AttachStateUncertain if the attached state is marked as uncertain. GetAttachState(volumeName v1.UniqueVolumeName, nodeName types.NodeName) AttachState // GetAttachedVolumes generates and returns a list of volumes/node pairs // reflecting which volumes might attached to which nodes based on the // current actual state of the world. This list includes all the volumes which return successful // attach and also the volumes which return errors during attach. GetAttachedVolumes() []AttachedVolume // GetAttachedVolumesForNode generates and returns a list of volumes that added to // the specified node reflecting which volumes are/or might be attached to that node // based on the current actual state of the world. This function is currently used by // attach_detach_controller to process VolumeInUse GetAttachedVolumesForNode(nodeName types.NodeName) []AttachedVolume // GetAttachedVolumesPerNode generates and returns a map of nodes and volumes that added to // the specified node reflecting which volumes are attached to that node // based on the current actual state of the world. This function is currently used by // reconciler to verify whether the volume is still attached to the node. GetAttachedVolumesPerNode() map[types.NodeName][]operationexecutor.AttachedVolume // GetNodesForAttachedVolume returns the nodes on which the volume is attached. // This function is used by reconciler for multi-attach check. GetNodesForAttachedVolume(volumeName v1.UniqueVolumeName) []types.NodeName // GetVolumesToReportAttached returns a map containing the set of nodes for // which the VolumesAttached Status field in the Node API object should be // updated. The key in this map is the name of the node to update and the // value is list of volumes that should be reported as attached (note that // this may differ from the actual list of attached volumes for the node // since volumes should be removed from this list as soon a detach operation // is considered, before the detach operation is triggered). GetVolumesToReportAttached(logger klog.Logger) map[types.NodeName][]v1.AttachedVolume // GetVolumesToReportAttachedForNode returns the list of volumes that should be reported as // attached for the given node. It reports a boolean indicating if there is an update for that // node and the corresponding attachedVolumes list. GetVolumesToReportAttachedForNode(logger klog.Logger, name types.NodeName) (bool, []v1.AttachedVolume) // GetNodesToUpdateStatusFor returns the map of nodeNames to nodeToUpdateStatusFor GetNodesToUpdateStatusFor() map[types.NodeName]nodeToUpdateStatusFor }
ActualStateOfWorld defines a set of thread-safe operations supported on the attach/detach controller's actual state of the world cache. This cache contains volumes->nodes i.e. a set of all volumes and the nodes the attach/detach controller believes are successfully attached. Note: This is distinct from the ActualStateOfWorld implemented by the kubelet volume manager. They both keep track of different objects. This contains attach/detach controller specific state.
func NewActualStateOfWorld ¶
func NewActualStateOfWorld(volumePluginMgr *volume.VolumePluginMgr) ActualStateOfWorld
NewActualStateOfWorld returns a new instance of ActualStateOfWorld.
type AttachState ¶ added in v1.18.16
type AttachState int
AttachState represents the attach state of a volume to a node known to the Actual State of World. This type is used as external representation of attach state (specifically as the return type of GetAttachState only); the state is represented differently in the internal cache implementation.
const ( // AttachStateAttached represents the state in which the volume is attached to // the node. AttachStateAttached AttachState = iota // AttachStateUncertain represents the state in which the Actual State of World // does not know whether the volume is attached to the node. AttachStateUncertain // AttachStateDetached represents the state in which the volume is not // attached to the node. AttachStateDetached )
func (AttachState) String ¶ added in v1.18.16
func (s AttachState) String() string
type AttachedVolume ¶
type AttachedVolume struct { operationexecutor.AttachedVolume // MountedByNode indicates that this volume has been mounted by the node and // is unsafe to detach. // The value is set and unset by SetVolumesMountedByNode(...). MountedByNode bool // DetachRequestedTime is used to capture the desire to detach this volume. // When the volume is newly created this value is set to time zero. // It is set to current time, when SetDetachRequestTime(...) is called, if it // was previously set to zero (other wise its value remains the same). // It is reset to zero on ResetDetachRequestTime(...) calls. DetachRequestedTime time.Time }
AttachedVolume represents a volume that is attached to a node.
type DesiredStateOfWorld ¶
type DesiredStateOfWorld interface { // AddNode adds the given node to the list of nodes managed by the attach/ // detach controller. // If the node already exists this is a no-op. AddNode(nodeName k8stypes.NodeName) // AddPod adds the given pod to the list of pods that reference the // specified volume and is scheduled to the specified node. // A unique volumeName is generated from the volumeSpec and returned on // success. // If the pod already exists under the specified volume, this is a no-op. // If volumeSpec is not an attachable volume plugin, an error is returned. // If no volume with the name volumeName exists in the list of volumes that // should be attached to the specified node, the volume is implicitly added. // If no node with the name nodeName exists in list of nodes managed by the // attach/detach attached controller, an error is returned. AddPod(podName types.UniquePodName, pod *v1.Pod, volumeSpec *volume.Spec, nodeName k8stypes.NodeName) (v1.UniqueVolumeName, error) // DeleteNode removes the given node from the list of nodes managed by the // attach/detach controller. // If the node does not exist this is a no-op. // If the node exists but has 1 or more child volumes, an error is returned. DeleteNode(nodeName k8stypes.NodeName) error // DeletePod removes the given pod from the list of pods that reference the // specified volume and are scheduled to the specified node. // If no pod exists in the list of pods that reference the specified volume // and are scheduled to the specified node, this is a no-op. // If a node with the name nodeName does not exist in the list of nodes // managed by the attach/detach attached controller, this is a no-op. // If no volume with the name volumeName exists in the list of managed // volumes under the specified node, this is a no-op. // If after deleting the pod, the specified volume contains no other child // pods, the volume is also deleted. DeletePod(podName types.UniquePodName, volumeName v1.UniqueVolumeName, nodeName k8stypes.NodeName) // NodeExists returns true if the node with the specified name exists in // the list of nodes managed by the attach/detach controller. NodeExists(nodeName k8stypes.NodeName) bool // VolumeExists returns true if the volume with the specified name exists // in the list of volumes that should be attached to the specified node by // the attach detach controller. VolumeExists(volumeName v1.UniqueVolumeName, nodeName k8stypes.NodeName) bool // GetVolumesToAttach generates and returns a list of volumes to attach // and the nodes they should be attached to based on the current desired // state of the world. GetVolumesToAttach() []VolumeToAttach // GetPodToAdd generates and returns a map of pods based on the current desired // state of world GetPodToAdd() map[types.UniquePodName]PodToAdd // Mark multi-attach error as reported to prevent spamming multiple // events for same error SetMultiAttachError(v1.UniqueVolumeName, k8stypes.NodeName) // GetPodsOnNodes returns list of pods ("namespace/name") that require // given volume on given nodes. GetVolumePodsOnNodes(nodes []k8stypes.NodeName, volumeName v1.UniqueVolumeName) []*v1.Pod }
DesiredStateOfWorld defines a set of thread-safe operations supported on the attach/detach controller's desired state of the world cache. This cache contains nodes->volumes->pods where nodes are all the nodes managed by the attach/detach controller, volumes are all the volumes that should be attached to the specified node, and pods are the pods that reference the volume and are scheduled to that node. Note: This is distinct from the DesiredStateOfWorld implemented by the kubelet volume manager. They both keep track of different objects. This contains attach/detach controller specific state.
func NewDesiredStateOfWorld ¶
func NewDesiredStateOfWorld(volumePluginMgr *volume.VolumePluginMgr) DesiredStateOfWorld
NewDesiredStateOfWorld returns a new instance of DesiredStateOfWorld.
type PodToAdd ¶
type PodToAdd struct { // pod contains the api object of pod Pod *v1.Pod // volumeName contains the unique identifier for this volume. VolumeName v1.UniqueVolumeName // nodeName contains the name of this node. NodeName k8stypes.NodeName }
PodToAdd represents a pod that references the underlying volume and is scheduled to the underlying node.
type VolumeToAttach ¶
type VolumeToAttach struct {
operationexecutor.VolumeToAttach
}
VolumeToAttach represents a volume that should be attached to a node.