Skip to content

Commit

Permalink
auto load kernel modules
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed May 8, 2023
1 parent 4c47bf4 commit a987188
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

"github.com/pmorjan/kmod"

Check failure on line 14 in clab/config.go

View workflow job for this annotation

GitHub Actions / staticcheck

no required module provides package github.com/pmorjan/kmod; to add it:

Check failure on line 14 in clab/config.go

View workflow job for this annotation

GitHub Actions / build-containerlab

no required module provides package github.com/pmorjan/kmod; to add it:

Check failure on line 14 in clab/config.go

View workflow job for this annotation

GitHub Actions / unit-test

no required module provides package github.com/pmorjan/kmod; to add it:
log "github.com/sirupsen/logrus"
"github.com/srl-labs/containerlab/labels"
"github.com/srl-labs/containerlab/nodes"
Expand Down Expand Up @@ -463,7 +464,21 @@ func (c *CLab) verifyKernelModulesLoaded() error {
return err
}
if !isLoaded {
log.Warnf("kernel module %s is not loaded", m)
log.Debugf("kernel module %q is not loaded. Trying to load", m)
// trying to load the kernel modules without actually throwing any more error.
// if we succeeed fine, if not we've already indicated modules are missing
km, err := kmod.New()
if err != nil {
log.Warnf("Unable to init kmod for automatic kernel module loading with %w. Hence, skipping", err)
return nil
}
err = km.Load(m, "", 0)
if err != nil {
log.Warnf("Unable to load kernel module %q automatically (%w)", m, err)
return nil
} else {
log.Debugf("kernel module %q loaded successfully", m)
}
}
}
return nil
Expand Down

0 comments on commit a987188

Please sign in to comment.