Skip to content

Commit f33856d

Browse files
committed
chore(selectors/kernel): consolidate action verification checks
Signed-off-by: David Windsor <[email protected]>
1 parent 6a6bae6 commit f33856d

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

pkg/selectors/kernel.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,35 +1519,35 @@ func HasOverride(spec *v1alpha1.KProbeSpec) bool {
15191519
return false
15201520
}
15211521

1522-
func HasSigkillAction(kspec *v1alpha1.KProbeSpec) bool {
1523-
for i := range kspec.Selectors {
1524-
s := &kspec.Selectors[i]
1525-
for j := range s.MatchActions {
1526-
act := strings.ToLower(s.MatchActions[j].Action)
1527-
if act == "sigkill" {
1522+
// HasAction returns true if any selector in the KProbeSpec has the specified action
1523+
func HasAction(kspec *v1alpha1.KProbeSpec, actionName string) bool {
1524+
act := strings.ToLower(actionName)
1525+
for _, s := range kspec.Selectors {
1526+
for _, action := range s.MatchActions {
1527+
if strings.ToLower(action.Action) == act {
15281528
return true
15291529
}
15301530
}
15311531
}
15321532
return false
15331533
}
15341534

1535-
func HasFilter(selectors []v1alpha1.KProbeSelector, index uint32) bool {
1536-
for _, s := range selectors {
1537-
for _, a := range s.MatchArgs {
1538-
if a.Index == index {
1535+
// HasActionType returns true if any selector in the KProbeSpec has the specified action type
1536+
func HasActionType(kspec *v1alpha1.KProbeSpec, actionType int32) bool {
1537+
for _, s := range kspec.Selectors {
1538+
for _, action := range s.MatchActions {
1539+
if ActionTypeFromString(action.Action) == actionType {
15391540
return true
15401541
}
15411542
}
15421543
}
15431544
return false
15441545
}
15451546

1546-
// HasNotifyEnforcerAction returns true if any selector in the KProbeSpec has a NotifyEnforcer action
1547-
func HasNotifyEnforcerAction(kspec *v1alpha1.KProbeSpec) bool {
1548-
for _, s := range kspec.Selectors {
1549-
for _, action := range s.MatchActions {
1550-
if action.Action == "NotifyEnforcer" {
1547+
func HasFilter(selectors []v1alpha1.KProbeSelector, index uint32) bool {
1548+
for _, s := range selectors {
1549+
for _, a := range s.MatchArgs {
1550+
if a.Index == index {
15511551
return true
15521552
}
15531553
}

pkg/sensors/tracing/generickprobe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func preValidateKprobe(
466466
}
467467
}
468468

469-
if selectors.HasSigkillAction(f) && !config.EnableLargeProgs() {
469+
if selectors.HasActionType(f, selectors.ActionTypeSigKill) && !config.EnableLargeProgs() {
470470
return nil, errors.New("sigkill action requires kernel >= 5.3.0")
471471
}
472472

@@ -540,7 +540,7 @@ func preValidateKprobes(log logger.FieldLogger, kprobes []v1alpha1.KProbeSpec, l
540540

541541
// If the NotifyEnforcer action is specified, there must be at least one enforcer.
542542
for _, kprobe := range kprobes {
543-
if selectors.HasNotifyEnforcerAction(&kprobe) {
543+
if selectors.HasActionType(&kprobe, selectors.ActionTypeNotifyEnforcer) {
544544
if len(enforcers) == 0 {
545545
return nil, errors.New("NotifyEnforcer action specified, but spec contains no enforcers")
546546
}

0 commit comments

Comments
 (0)