Skip to content

Commit

Permalink
fix(inventory): put pvc into pending until all storage classes synced
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Sep 2, 2023
1 parent 907e061 commit ee7acdd
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions operator/inventory/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -140,14 +138,19 @@ 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
}

log.Info(msg, "name", obj.Name)
case *corev1.PersistentVolume:
if !scSynced {
pendingPVs = append(pendingPVs, evt)
break evtdone
}

switch evt.Type {
case watch.Added:
pvCount++
Expand All @@ -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--
Expand Down

0 comments on commit ee7acdd

Please sign in to comment.