k8s.io/kubernetes@v1.29.3/pkg/kubelet/volumemanager/reconciler/reconciler_new.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 // TODO: move to reconciler.go and remove old code there when NewVolumeManagerReconstruction is GA 25 26 // TODO: Replace Run() when NewVolumeManagerReconstruction is GA 27 func (rc *reconciler) runNew(stopCh <-chan struct{}) { 28 rc.reconstructVolumes() 29 klog.InfoS("Reconciler: start to sync state") 30 wait.Until(rc.reconcileNew, rc.loopSleepDuration, stopCh) 31 } 32 33 func (rc *reconciler) reconcileNew() { 34 readyToUnmount := rc.readyToUnmount() 35 if readyToUnmount { 36 // Unmounts are triggered before mounts so that a volume that was 37 // referenced by a pod that was deleted and is now referenced by another 38 // pod is unmounted from the first pod before being mounted to the new 39 // pod. 40 rc.unmountVolumes() 41 } 42 43 // Next we mount required volumes. This function could also trigger 44 // attach if kubelet is responsible for attaching volumes. 45 // If underlying PVC was resized while in-use then this function also handles volume 46 // resizing. 47 rc.mountOrAttachVolumes() 48 49 // Unmount volumes only when DSW and ASW are fully populated to prevent unmounting a volume 50 // that is still needed, but it did not reach DSW yet. 51 if readyToUnmount { 52 // Ensure devices that should be detached/unmounted are detached/unmounted. 53 rc.unmountDetachDevices() 54 55 // Clean up any orphan volumes that failed reconstruction. 56 rc.cleanOrphanVolumes() 57 } 58 59 if len(rc.volumesNeedUpdateFromNodeStatus) != 0 { 60 rc.updateReconstructedFromNodeStatus() 61 } 62 if len(rc.volumesNeedUpdateFromNodeStatus) == 0 { 63 // ASW is fully populated only after both devicePaths and uncertain volume attach-ability 64 // were reconstructed from the API server. 65 // This will start reconciliation of node.status.volumesInUse. 66 rc.updateLastSyncTime() 67 } 68 69 if len(rc.volumesNeedReportedInUse) != 0 && rc.populatorHasAddedPods() { 70 // Once DSW is populated, mark all reconstructed as reported in node.status, 71 // so they can proceed with MountDevice / SetUp. 72 rc.desiredStateOfWorld.MarkVolumesReportedInUse(rc.volumesNeedReportedInUse) 73 rc.volumesNeedReportedInUse = nil 74 } 75 }