-
Notifications
You must be signed in to change notification settings - Fork 59
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
new: driver selection logic #484
Conversation
…ogic. `Driver.Type` will now be a slice in config. Then, cmd/driver_linux will take care of discovering, given the list of allowed driver types loaded from the config, the correct driver to be used. This has multple consequencies: * enforcing a single `--type` works like the existing behavior * allowed driver types are in descending priority order Signed-off-by: Federico Di Pierro <[email protected]>
/milestone v0.8.0 |
// type Tracing, attachType AttachTraceRawTp program availability. | ||
// | ||
//go:linkname probeProgram github.com/cilium/ebpf/features.probeProgram | ||
func probeProgram(spec *ebpf.ProgramSpec) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid fully rewriting the function, we "unsafely" import it using go:linkname
.
I think this is better than copying the function locally, because then we get any change probeProgram
might get with new versions, and if probeProgram
changes signature/name, our build will fail while bumping the library dep.
This way, we always know if something has changed.
// err := features.HaveProgramType(ebpf.Tracing) | ||
// Therefore, we need to manually build a feature test. | ||
// Empty tracing program that just returns 0 | ||
progSpec := &ebpf.ProgramSpec{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass a prog spec with correct AttachType
type.
@@ -162,11 +183,22 @@ func NewDriverCmd(ctx context.Context, opt *options.Common) *cobra.Command { | |||
}, | |||
} | |||
|
|||
cmd.PersistentFlags().Var(driverTypes, "type", "Driver type to be used "+driverTypes.Allowed()) | |||
cmd.PersistentFlags().StringSliceVar(&driverTypesStr, "type", config.DefaultDriver.Type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
is now a slice.
cmd.PersistentFlags().StringVar(&driver.Version, "version", config.DefaultDriver.Version, "Driver version to be used.") | ||
cmd.PersistentFlags().StringSliceVar(&driver.Repos, "repo", config.DefaultDriver.Repos, "Driver repo to be used.") | ||
cmd.PersistentFlags().StringVar(&driver.Name, "name", config.DefaultDriver.Name, "Driver name to be used.") | ||
cmd.PersistentFlags().StringVar(&driver.HostRoot, "host-root", config.DefaultDriver.HostRoot, "Driver host root to be used.") | ||
cmd.PersistentFlags().StringVar(&driverKernelRelease, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved --kernelrelease
and --kernelversion
CLI options directly to driver
root command.
return fmt.Errorf("automatic driver selection failed") | ||
// Step 2: fetch system info (kernel release/version and distro) | ||
var err error | ||
driver.Kr, err = driverkernel.FetchInfo(driverKernelRelease, driverKernelVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.Driver
now holds run kernelrelease and distro too.
This way, we discover them just once, here, and then pass the driver options down to all driver related commands, without needing to discover distro or kernel infos twice.
} else { | ||
return "", fmt.Errorf("detected an unsupported target system, please get in touch with the Falco community") | ||
} | ||
if o.Distro.String() == driverdistro.UndeterminedDistro && o.Compile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check is now a bit different because we are not discovering the distro here anymore; instead we receive a distro from driver
root command.
We need to check if ErrUnsupported
was returned, ie: if the distro is UndeterminedDistro
.
Signed-off-by: Federico Di Pierro <[email protected]>
…dern bpf support. Signed-off-by: Federico Di Pierro <[email protected]>
…md/driver_linux root command. Signed-off-by: Federico Di Pierro <[email protected]>
Signed-off-by: Federico Di Pierro <[email protected]>
…ogram type check. Signed-off-by: Federico Di Pierro <[email protected]>
…version. Moreover, added a version for others OS. Signed-off-by: Federico Di Pierro <[email protected]>
8f33dbc
to
2a56cf9
Compare
func probeProgram(spec *ebpf.ProgramSpec) error | ||
|
||
//nolint:gocritic // the method shall not be able to modify kr | ||
func (m *modernBpf) Supported(_ kernelrelease.KernelRelease) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: modern bpf will check directly against running kernel, to see if all required features are supported.
This means that we cannot check against "foreign" kernel releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First quick look. I really like the new UX! 🤩
It SGTM already, still I'd like to get a second opinion before approving.
cc @alacuku
Also, allow `FetchInfo` to override kernelrelease/version if only one of them is enforced. Signed-off-by: Federico Di Pierro <[email protected]>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, leogr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
when a
Any specific area of the project related to this PR?
/area library
/area cli
What this PR does / why we need it:
This PR expands the driver automatic selection logic, in this way:
--type
CLI option/type
config key/FALCOCTL_DRIVER_TYPE
env var do now support multiple driver types to be specifiedtype
is specified, we retain the old behaviortype
s are passed, the automatic selection logic will choose the best-fit given:New default is to enable all drivers in this order:
modern_ebpf,ebpf,kmod
.COS
target does now specializePreferredDriver
method since it does not supportkmod
.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer: