in clusterloader2/pkg/measurement/util/wait_for_pvcs.go [40:86]
func WaitForPVCs(clientSet clientset.Interface, stopCh <-chan struct{}, options *WaitForPVCOptions) error {
ps, err := NewPVCStore(clientSet, options.Selector)
if err != nil {
return fmt.Errorf("PVC store creation error: %v", err)
}
defer ps.Stop()
oldPVCs := ps.List()
scaling := uninitialized
var pvcsStatus PVCsStartupStatus
switch {
case len(oldPVCs) == options.DesiredPVCCount:
scaling = none
case len(oldPVCs) < options.DesiredPVCCount:
scaling = up
case len(oldPVCs) > options.DesiredPVCCount:
scaling = down
}
for {
select {
case <-stopCh:
return fmt.Errorf("timeout while waiting for %d PVCs to be running in namespace '%v' with labels '%v' and fields '%v' - only %d found bound",
options.DesiredPVCCount, options.Selector.Namespace, options.Selector.LabelSelector, options.Selector.FieldSelector, pvcsStatus.Bound)
case <-time.After(options.WaitForPVCsInterval):
pvcs := ps.List()
pvcsStatus = ComputePVCsStartupStatus(pvcs, options.DesiredPVCCount)
diff := DiffPVCs(oldPVCs, pvcs)
deletedPVCs := diff.DeletedPVCs()
if scaling != down && len(deletedPVCs) > 0 {
klog.Errorf("%s: %s: %d PVCs disappeared: %v", options.CallerName, options.Selector.String(), len(deletedPVCs), strings.Join(deletedPVCs, ", "))
}
addedPVCs := diff.AddedPVCs()
if scaling != up && len(addedPVCs) > 0 {
klog.Errorf("%s: %s: %d PVCs appeared: %v", options.CallerName, options.Selector.String(), len(deletedPVCs), strings.Join(deletedPVCs, ", "))
}
klog.V(2).Infof("%s: %s: %s", options.CallerName, options.Selector.String(), pvcsStatus.String())
// We wait until there is a desired number of PVCs bound and all other PVCs are pending.
if len(pvcs) == (pvcsStatus.Bound+pvcsStatus.Pending) && pvcsStatus.Bound == options.DesiredPVCCount {
return nil
}
oldPVCs = pvcs
}
}
}