Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Sep 24, 2024
1 parent 6f38bfb commit b252977
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 17 additions & 4 deletions images/sds-local-volume-scheduler-extender/src/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"sync"
"time"

snc "github.com/deckhouse/sds-node-configurator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -44,17 +45,29 @@ type pvcCache struct {

// NewCache initialize new cache.
func NewCache(logger logger.Logger) *Cache {
return &Cache{
ch := &Cache{
log: logger,
}

go func() {
duration := 2 * time.Second
timer := time.NewTimer(duration)

for {
select {
case <-timer.C:
fmt.Println("HELLO FROM TIMER")
timer.Reset(duration)
}
}
}()
return ch
}

// AddLVG adds selected LVMVolumeGroup resource to the cache. If it is already stored, does nothing.
func (c *Cache) AddLVG(lvg *snc.LVMVolumeGroup) {
_, loaded := c.lvgs.LoadOrStore(lvg.Name, &lvgCache{
lvg: lvg,
thickPVCs: sync.Map{},
thinPools: sync.Map{},
lvg: lvg,
})
if loaded {
c.log.Debug(fmt.Sprintf("[AddLVG] the LVMVolumeGroup %s has been already added to the cache", lvg.Name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ package controller
import (
"context"
"fmt"
"reflect"

snc "github.com/deckhouse/sds-node-configurator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/workqueue"
"reflect"
"sds-local-volume-scheduler-extender/pkg/cache"
"sds-local-volume-scheduler-extender/pkg/logger"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"sds-local-volume-scheduler-extender/pkg/cache"
"sds-local-volume-scheduler-extender/pkg/logger"
)

const (
Expand Down Expand Up @@ -90,7 +88,6 @@ func RunLVGWatcherCacheController(
log.Info(fmt.Sprintf("[RunCacheWatcherController] UpdateFunc starts the cache reconciliation for the LVMVolumeGroup %s", e.ObjectNew.GetName()))
oldLvg := e.ObjectOld
newLvg := e.ObjectNew

err := cache.UpdateLVG(newLvg)
if err != nil {
log.Error(err, fmt.Sprintf("[RunLVGWatcherCacheController] unable to update the LVMVolumeGroup %s cache", newLvg.Name))
Expand Down

0 comments on commit b252977

Please sign in to comment.