Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Jan 17, 2025
1 parent 6b4d5e1 commit dba0e55
Show file tree
Hide file tree
Showing 13 changed files with 900 additions and 612 deletions.
60 changes: 14 additions & 46 deletions cmd/nvidia-dra-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,22 @@ import (
"context"
"fmt"
"sync"
"time"

"k8s.io/client-go/informers"

"github.com/NVIDIA/k8s-dra-driver/pkg/flags"
nvinformers "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions"
"github.com/NVIDIA/k8s-dra-driver/pkg/workqueue"
)

type ManagerConfig struct {
clientsets flags.ClientSets
nvInformerFactory nvinformers.SharedInformerFactory
coreInformerFactory informers.SharedInformerFactory
workQueue *workqueue.WorkQueue
driverName string
driverNamespace string
clientsets flags.ClientSets
workQueue *workqueue.WorkQueue
}

type OwnerExistsFunc func(ctx context.Context, uid string) (bool, error)

type Controller struct {
waitGroup sync.WaitGroup

ImexManager *ImexManager
waitGroup sync.WaitGroup
MultiNodeEnvironmentManager *MultiNodeEnvironmentManager
}

Expand All @@ -52,19 +46,12 @@ func StartController(ctx context.Context, config *Config) (*Controller, error) {
}

workQueue := workqueue.New(workqueue.DefaultControllerRateLimiter())
nvInformerFactory := nvinformers.NewSharedInformerFactory(config.clientsets.Nvidia, 30*time.Second)
coreInformerFactory := informers.NewSharedInformerFactory(config.clientsets.Core, 30*time.Second)

managerConfig := &ManagerConfig{
clientsets: config.clientsets,
nvInformerFactory: nvInformerFactory,
coreInformerFactory: coreInformerFactory,
workQueue: workQueue,
}

imexManager, err := StartImexManager(ctx, config)
if err != nil {
return nil, fmt.Errorf("error starting IMEX manager: %w", err)
driverName: config.driverName,
driverNamespace: config.flags.namespace,
clientsets: config.clientsets,
workQueue: workQueue,
}

mneManager, err := NewMultiNodeEnvironmentManager(ctx, managerConfig)
Expand All @@ -73,42 +60,23 @@ func StartController(ctx context.Context, config *Config) (*Controller, error) {
}

c := &Controller{
ImexManager: imexManager,
MultiNodeEnvironmentManager: mneManager,
}

c.waitGroup.Add(3)
go func() {
defer c.waitGroup.Done()
nvInformerFactory.Start(ctx.Done())
}()
go func() {
defer c.waitGroup.Done()
coreInformerFactory.Start(ctx.Done())
}()
c.waitGroup.Add(1)
go func() {
defer c.waitGroup.Done()
workQueue.Run(ctx)
}()

if err := c.MultiNodeEnvironmentManager.WaitForCacheSync(ctx); err != nil {
return nil, fmt.Errorf("error syncing cache: %w", err)
}

return c, nil
}

// Stop stops a running Controller.
func (m *Controller) Stop() error {
if m == nil {
return nil
func (c *Controller) Stop(ctx context.Context) error {
if err := c.MultiNodeEnvironmentManager.Shutdown(ctx); err != nil {
return fmt.Errorf("error shutting down MultiNodeEnvironment manager: %w", err)
}

m.waitGroup.Wait()

if err := m.ImexManager.Stop(); err != nil {
return fmt.Errorf("error stopping IMEX manager: %w", err)
}

c.waitGroup.Wait()
return nil
}
Loading

0 comments on commit dba0e55

Please sign in to comment.