Skip to content

Commit

Permalink
golangci-lint: fix various issues from linters update
Browse files Browse the repository at this point in the history
Fix those issues:

	pkg/filters/caps.go:29:5                          gosimple  S1009: should omit nil check; len() for []github.com/cilium/tetragon/api/v1/tetragon.CapabilitiesType is defined as zero
	pkg/filters/caps.go:34:5                          gosimple  S1009: should omit nil check; len() for []github.com/cilium/tetragon/api/v1/tetragon.CapabilitiesType is defined as zero
	pkg/filters/caps.go:39:5                          gosimple  S1009: should omit nil check; len() for []github.com/cilium/tetragon/api/v1/tetragon.CapabilitiesType is defined as zero
	pkg/filters/caps.go:44:5                          gosimple  S1009: should omit nil check; len() for []github.com/cilium/tetragon/api/v1/tetragon.CapabilitiesType is defined as zero
	pkg/policyfilter/k8s_test.go:51:10                govet     printf: non-constant format string in call to (*testing.common).Logf
	pkg/sensors/exec/exec_test.go:367:13              govet     printf: non-constant format string in call to fmt.Printf
	pkg/sensors/exec/exec_test.go:496:13              govet     printf: non-constant format string in call to fmt.Printf
	pkg/tracingpolicy/generictracingpolicy.go:231:26  govet     printf: non-constant format string in call to fmt.Errorf

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Sep 2, 2024
1 parent 6f0a223 commit 539d050
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/filters/caps.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func filterSingleCapSet(caps []tetragon.CapabilitiesType, filters *tetragon.CapF
capset := mapset.NewSet[tetragon.CapabilitiesType]()
capset.Append(caps...)

if filters.Any != nil && len(filters.Any) > 0 {
if len(filters.Any) > 0 {
filterset.Append(filters.Any...)
return capset.ContainsAny(filterset.ToSlice()...)
}

if filters.All != nil && len(filters.All) > 0 {
if len(filters.All) > 0 {
filterset.Append(filters.All...)
return capset.Intersect(filterset).Equal(filterset)
}

if filters.Exactly != nil && len(filters.Exactly) > 0 {
if len(filters.Exactly) > 0 {
filterset.Append(filters.Exactly...)
return capset.Equal(filterset)
}

if filters.None != nil && len(filters.None) > 0 {
if len(filters.None) > 0 {
filterset.Append(filters.None...)
return capset.Intersect(filterset).IsEmpty()
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/policyfilter/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ import (

type tlog struct {
*testing.T
Log *logrus.Logger
Logger *logrus.Logger
}

func (tl tlog) Write(p []byte) (n int, err error) {
tl.Logf((string)(p))
tl.Log(string(p))
return len(p), nil
}

Expand Down Expand Up @@ -706,7 +706,7 @@ func TestK8s(t *testing.T) {

// NB: using testutils.CaptureLog causes import cycle
log := logger.GetLogger().(*logrus.Logger)
lc := &tlog{T: t, Log: log}
lc := &tlog{T: t, Logger: log}
log.SetOutput(lc)

oldEnablePolicyFilterValue := option.Config.EnablePolicyFilter
Expand Down
4 changes: 2 additions & 2 deletions pkg/sensors/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestEventExecveLongPath(t *testing.T) {
}

fmt.Printf("Path size: %d\n", len(testBin))
fmt.Printf("Test dir: " + testDir + "\n")
fmt.Printf("Test dir: %s\n", testDir)

// create directory
if err := os.MkdirAll(testDir, 0755); err != nil {
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestEventExecveLongPathLongArgs(t *testing.T) {
}

fmt.Printf("Path size: %d\n", len(testBin))
fmt.Printf("Test dir: " + testDir + "\n")
fmt.Printf("Test dir: %s\n", testDir)

// create directory
if err := os.MkdirAll(testDir, 0755); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tracingpolicy/generictracingpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func ValidateCRDSpec(policy K8sTracingPolicyObject) (*validate.Result, error) {

v, ok := validatorState.validators[policy.GetGroupVersionKind()]
if !ok {
return nil, fmt.Errorf("could not find validator for: " + policy.GetGroupVersionKind().String())
return nil, fmt.Errorf("could not find validator for: %s", policy.GetGroupVersionKind().String())
}

return v.Validate(policy), nil
Expand Down

0 comments on commit 539d050

Please sign in to comment.