Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor fail-on-init-error when no resources are found #1031

Draft
wants to merge 3 commits into
base: release-0.15
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ linters-settings:
local-prefixes: github.com/NVIDIA/k8s-device-plugin

issues:
exclude:
# Exclude all integer overflow errors on this branch.
- "G115: integer overflow conversion"
exclude-rules:
# We use math/rand instead of crypto/rand for unique names in e2e tests.
- path: tests/e2e/
Expand Down
5 changes: 4 additions & 1 deletion cmd/gpu-feature-discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ func start(c *cli.Context, cfg *Config) error {
}
klog.Infof("\nRunning with config:\n%v", string(configJSON))

manager := resource.NewManager(config)
manager, err := resource.NewManager(config)
if err != nil {
return err
}
vgpul := vgpu.NewVGPULib(vgpu.NewNvidiaPCILib())

var clientSets flags.ClientSets
Expand Down
24 changes: 17 additions & 7 deletions internal/resource/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@
package resource

import (
"fmt"

"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"k8s.io/klog/v2"

spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
)

// NewManager is a factory method that creates a resource Manager based on the specified config.
func NewManager(config *spec.Config) Manager {
return WithConfig(getManager(), config)
func NewManager(config *spec.Config) (Manager, error) {
manager, err := getManager()
if err != nil {
if *config.Flags.FailOnInitError {
return nil, err
}
klog.ErrorS(err, "using empty manager")
return NewNullManager(), nil
}

return WithConfig(manager, config), nil
}

// WithConfig modifies a manager depending on the specified config.
Expand All @@ -39,7 +50,7 @@ func WithConfig(manager Manager, config *spec.Config) Manager {
}

// getManager returns the resource manager depending on the system configuration.
func getManager() Manager {
func getManager() (Manager, error) {
// logWithReason logs the output of the has* / is* checks from the info.Interface
logWithReason := func(f func() (bool, string), tag string) bool {
is, reason := f()
Expand All @@ -63,12 +74,11 @@ func getManager() Manager {

if hasNVML {
klog.Info("Using NVML manager")
return NewNVMLManager()
return NewNVMLManager(), nil
} else if isTegra {
klog.Info("Using CUDA manager")
return NewCudaManager()
return NewCudaManager(), nil
}

klog.Warning("No valid resources detected; using empty manager.")
return NewNullManager()
return nil, fmt.Errorf("no valid resource detected")
}
2 changes: 1 addition & 1 deletion tests/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (f *Framework) AfterEach(ctx context.Context) {
for namespaceKey, namespaceErr := range nsDeletionErrors {
messages = append(messages, fmt.Sprintf("Couldn't delete ns: %q: %s (%#v)", namespaceKey, namespaceErr, namespaceErr))
}
e2elog.Failf(strings.Join(messages, ","))
e2elog.Fail(strings.Join(messages, ","))
}
}()

Expand Down