From ee7acdd58a114fc598439725b78132c6dc8195b2 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Fri, 1 Sep 2023 20:13:39 -0400 Subject: [PATCH] fix(inventory): put pvc into pending until all storage classes synced Signed-off-by: Artur Troian --- operator/inventory/rancher.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/operator/inventory/rancher.go b/operator/inventory/rancher.go index 34816fe0..c2c7d617 100644 --- a/operator/inventory/rancher.go +++ b/operator/inventory/rancher.go @@ -112,13 +112,11 @@ func (c *rancher) run() error { } sc, exists := scs[obj.Name] - if !exists { - sc = &rancherStorage{ - isRancher: obj.Provisioner == "rancher.io/local-path", - } + sc = &rancherStorage{} } + sc.isRancher = obj.Provisioner == "rancher.io/local-path" sc.isAkashManaged, _ = strconv.ParseBool(lblVal) scs[obj.Name] = sc @@ -140,7 +138,7 @@ func (c *rancher) run() error { } } case watch.Deleted: - // volumes can remain without storage class so to keep metrics wight when storage class suddenly + // volumes can remain without storage class so to keep metrics right when storage class suddenly // recreated we don't delete it default: break evtdone @@ -148,6 +146,11 @@ func (c *rancher) run() error { log.Info(msg, "name", obj.Name) case *corev1.PersistentVolume: + if !scSynced { + pendingPVs = append(pendingPVs, evt) + break evtdone + } + switch evt.Type { case watch.Added: pvCount++ @@ -158,17 +161,17 @@ func (c *rancher) run() error { break } - if params, exists := scs[obj.Name]; !exists { - scs[obj.Spec.StorageClassName] = &rancherStorage{ - allocated: uint64(resource.Value()), - } + if params, exists := scs[obj.Spec.StorageClassName]; !exists { + scSynced = false + pendingPVs = append(pendingPVs, evt) + break evtdone } else { params.allocated += uint64(resource.Value()) - } - pvList, _ := KubeClientFromCtx(c.ctx).CoreV1().PersistentVolumes().List(c.ctx, metav1.ListOptions{}) - if len(pvList.Items) == pvCount && !pvSynced { - pvSynced = true + pvList, _ := KubeClientFromCtx(c.ctx).CoreV1().PersistentVolumes().List(c.ctx, metav1.ListOptions{}) + if len(pvList.Items) == pvCount && !pvSynced { + pvSynced = true + } } case watch.Deleted: pvCount--