Skip to content

Commit 6ff696a

Browse files
committed
Add indirection of ImexManager through wrapping Controller abstraction
In the future, we plan to manage multiple components from this wrapping abstraction. Signed-off-by: Kevin Klues <[email protected]>
1 parent 5b926e2 commit 6ff696a

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2025 NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"fmt"
22+
)
23+
24+
type Controller struct {
25+
ImexManager *ImexManager
26+
}
27+
28+
// StartController starts a Controller.
29+
func StartController(ctx context.Context, config *Config) (*Controller, error) {
30+
if !config.flags.deviceClasses.Has(ImexChannelType) {
31+
return nil, nil
32+
}
33+
34+
imexManager, err := StartImexManager(ctx, config)
35+
if err != nil {
36+
return nil, fmt.Errorf("error starting IMEX manager: %w", err)
37+
}
38+
39+
m := &Controller{
40+
ImexManager: imexManager,
41+
}
42+
43+
return m, nil
44+
}
45+
46+
// Stop stops a running Controller.
47+
func (m *Controller) Stop() error {
48+
if m == nil {
49+
return nil
50+
}
51+
return m.ImexManager.Stop()
52+
}

cmd/nvidia-dra-controller/imex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type ImexManager struct {
6464
driverResources *resourceslice.DriverResources
6565
}
6666

67-
func StartIMEXManager(ctx context.Context, config *Config) (*ImexManager, error) {
67+
func StartImexManager(ctx context.Context, config *Config) (*ImexManager, error) {
6868
// Create a new set of DriverResources
6969
driverResources := &resourceslice.DriverResources{
7070
Pools: make(map[string]resourceslice.Pool),

cmd/nvidia-dra-controller/main.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,18 @@ func newApp() *cli.App {
159159
sigs := make(chan os.Signal, 1)
160160
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
161161

162-
var imexManager *ImexManager
162+
var controller *Controller
163163
ctx, cancel := context.WithCancel(c.Context)
164164
defer func() {
165165
cancel()
166-
if err := imexManager.Stop(); err != nil {
167-
klog.Errorf("Error stopping IMEX manager: %v", err)
166+
if err := controller.Stop(); err != nil {
167+
klog.Errorf("Error stopping controller: %v", err)
168168
}
169169
}()
170170

171-
if flags.deviceClasses.Has(ImexChannelType) {
172-
imexManager, err = StartIMEXManager(ctx, config)
173-
if err != nil {
174-
return fmt.Errorf("start IMEX manager: %w", err)
175-
}
171+
controller, err = StartController(ctx, config)
172+
if err != nil {
173+
return fmt.Errorf("start controller: %w", err)
176174
}
177175

178176
<-sigs

0 commit comments

Comments
 (0)