Skip to content

Commit

Permalink
syntax fix
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Shipkov <[email protected]>
  • Loading branch information
grem-li committed Dec 2, 2024
1 parent 264713a commit 6014630
Showing 1 changed file with 55 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,62 +83,71 @@ func NewLinstorResourcesWatcher(
time.Sleep(time.Second * time.Duration(interval))
log.Info("[NewLinstorResourcesWatcher] starts reconcile")

scs, err := GetStorageClasses(ctx, cl)
if err != nil {
log.Error(err, "[NewLinstorResourcesWatcher] unable to get Kubernetes Storage Classes")
continue
}
runLinstorResourcesReconcile(ctx, log, cl, lc)

scMap := make(map[string]v1.StorageClass, len(scs))
for _, sc := range scs {
scMap[sc.Name] = sc
}
log.Info("[NewLinstorResourcesWatcher] ends reconcile")
}
}()
}

rds, err := lc.ResourceDefinitions.GetAll(ctx, lapi.RDGetAllRequest{})
if err != nil {
log.Error(err, "[NewLinstorResourcesWatcher] unable to get Linstor Resource Definitions")
continue
}
func runLinstorResourcesReconcile(
ctx context.Context,
log logger.Logger,
cl client.Client,
lc *lapi.Client,
) {
scs, err := GetStorageClasses(ctx, cl)
if err != nil {
log.Error(err, "[runLinstorResourcesReconcile] unable to get Kubernetes Storage Classes")
return
}

rdMap := make(map[string]lapi.ResourceDefinitionWithVolumeDefinition, len(rds))
for _, rd := range rds {
rdMap[rd.Name] = rd
}
scMap := make(map[string]v1.StorageClass, len(scs))
for _, sc := range scs {
scMap[sc.Name] = sc
}

rgs, err := lc.ResourceGroups.GetAll(ctx)
if err != nil {
log.Error(err, "[NewLinstorResourcesWatcher] unable to get Linstor Resource Groups")
continue
}
rds, err := lc.ResourceDefinitions.GetAll(ctx, lapi.RDGetAllRequest{})
if err != nil {
log.Error(err, "[runLinstorResourcesReconcile] unable to get Linstor Resource Definitions")
return
}

rgMap := make(map[string]lapi.ResourceGroup, len(rgs))
for _, rg := range rgs {
rgMap[rg.Name] = rg
}
rdMap := make(map[string]lapi.ResourceDefinitionWithVolumeDefinition, len(rds))
for _, rd := range rds {
rdMap[rd.Name] = rd
}

pvList, err := GetListPV(ctx, cl)
if err != nil {
log.Error(err, "[NewLinstorResourcesWatcher] unable to get Persistent Volumes")
continue
}
rgs, err := lc.ResourceGroups.GetAll(ctx)
if err != nil {
log.Error(err, "[runLinstorResourcesReconcile] unable to get Linstor Resource Groups")
return
}

resMap := make(map[string][]lapi.Resource, len(rdMap))
for name := range rdMap {
res, err := lc.Resources.GetAll(ctx, name)
if err != nil {
log.Error(err, fmt.Sprintf("[NewLinstorResourcesWatcher] unable to get Linstor Resources, name: %s", name))
continue
}
resMap[name] = res
}
rgMap := make(map[string]lapi.ResourceGroup, len(rgs))
for _, rg := range rgs {
rgMap[rg.Name] = rg
}

ReconcileParams(ctx, log, cl, lc, scMap, rdMap, rgMap, pvList)
ReconcileTieBreaker(ctx, log, lc, rdMap, rgMap, resMap)
ReconcilePVReplicas(ctx, log, cl, lc, rdMap, rgMap, resMap, pvList)
pvList, err := GetListPV(ctx, cl)
if err != nil {
log.Error(err, "[runLinstorResourcesReconcile] unable to get Persistent Volumes")
return
}

log.Info("[NewLinstorResourcesWatcher] ends reconcile")
resMap := make(map[string][]lapi.Resource, len(rdMap))
for name := range rdMap {
res, err := lc.Resources.GetAll(ctx, name)
if err != nil {
log.Error(err, fmt.Sprintf("[runLinstorResourcesReconcile] unable to get Linstor Resources, name: %s", name))
return
}
}()
resMap[name] = res
}

ReconcileParams(ctx, log, cl, lc, scMap, rdMap, rgMap, pvList)
ReconcileTieBreaker(ctx, log, lc, rdMap, rgMap, resMap)
ReconcilePVReplicas(ctx, log, cl, lc, rdMap, rgMap, resMap, pvList)
}

func ReconcileParams(
Expand Down

0 comments on commit 6014630

Please sign in to comment.