k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/kubelet/volumemanager/reconciler/reconciler.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package reconciler 18 19 import ( 20 "k8s.io/apimachinery/pkg/util/wait" 21 "k8s.io/klog/v2" 22 ) 23 24 func (rc *reconciler) Run(stopCh <-chan struct{}) { 25 rc.reconstructVolumes() 26 klog.InfoS("Reconciler: start to sync state") 27 wait.Until(rc.reconcile, rc.loopSleepDuration, stopCh) 28 } 29 30 func (rc *reconciler) reconcile() { 31 readyToUnmount := rc.readyToUnmount() 32 if readyToUnmount { 33 // Unmounts are triggered before mounts so that a volume that was 34 // referenced by a pod that was deleted and is now referenced by another 35 // pod is unmounted from the first pod before being mounted to the new 36 // pod. 37 rc.unmountVolumes() 38 } 39 40 // Next we mount required volumes. This function could also trigger 41 // attach if kubelet is responsible for attaching volumes. 42 // If underlying PVC was resized while in-use then this function also handles volume 43 // resizing. 44 rc.mountOrAttachVolumes() 45 46 // Unmount volumes only when DSW and ASW are fully populated to prevent unmounting a volume 47 // that is still needed, but it did not reach DSW yet. 48 if readyToUnmount { 49 // Ensure devices that should be detached/unmounted are detached/unmounted. 50 rc.unmountDetachDevices() 51 52 // Clean up any orphan volumes that failed reconstruction. 53 rc.cleanOrphanVolumes() 54 } 55 56 if len(rc.volumesNeedUpdateFromNodeStatus) != 0 { 57 rc.updateReconstructedFromNodeStatus() 58 } 59 if len(rc.volumesNeedUpdateFromNodeStatus) == 0 { 60 // ASW is fully populated only after both devicePaths and uncertain volume attach-ability 61 // were reconstructed from the API server. 62 // This will start reconciliation of node.status.volumesInUse. 63 rc.updateLastSyncTime() 64 } 65 66 if len(rc.volumesNeedReportedInUse) != 0 && rc.populatorHasAddedPods() { 67 // Once DSW is populated, mark all reconstructed as reported in node.status, 68 // so they can proceed with MountDevice / SetUp. 69 rc.desiredStateOfWorld.MarkVolumesReportedInUse(rc.volumesNeedReportedInUse) 70 rc.volumesNeedReportedInUse = nil 71 } 72 }