Skip to content

Commit

Permalink
[feature]: Added Validate() function to check if the linux kernel ver…
Browse files Browse the repository at this point in the history
…sion is lower than 5.15 (keploy#1828)

* Added Validate function to check if the linux kernel version is lower than 5.15

Signed-off-by: Akash Singh <[email protected]>

* Integrated github.com/moby/moby/pkg/parsers/kernel for kernel level check

Signed-off-by: Akash Singh <[email protected]>

* Refactored var name

Signed-off-by: Akash Singh <[email protected]>

---------

Signed-off-by: Akash Singh <[email protected]>
  • Loading branch information
SkySingh04 authored Apr 20, 2024
1 parent 3239e98 commit 72d744e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cli/provider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/moby/moby/pkg/parsers/kernel"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.keploy.io/server/v2/config"
Expand Down Expand Up @@ -240,6 +241,18 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command) error {
return nil
}

func (c *CmdConfigurator) Validate(ctx context.Context, cmd *cobra.Command) error {
//check if the version of the kernel is above 5.15 for eBPF support
isValid := kernel.CheckKernelVersion(5, 15, 0)
if !isValid {
errMsg := "Kernel version is below 5.15. Keploy requires kernel version 5.15 or above"
utils.LogError(c.logger, nil, errMsg)
return errors.New(errMsg)
}

return c.ValidateFlags(ctx, cmd)
}

func (c *CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command) error {
// used to bind common flags for commands like record, test. For eg: PATH, PORT, COMMAND etc.
err := viper.BindPFlags(cmd.Flags())
Expand Down
2 changes: 1 addition & 1 deletion cli/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Record(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFa
Short: "record the keploy testcases from the API calls",
Example: `keploy record -c "/path/to/user/app"`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
return cmdConfigurator.ValidateFlags(ctx, cmd)
return cmdConfigurator.Validate(ctx, cmd)
},
RunE: func(cmd *cobra.Command, _ []string) error {
svc, err := serviceFactory.GetService(ctx, cmd.Name())
Expand Down
1 change: 1 addition & 0 deletions cli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ type ServiceFactory interface {
type CmdConfigurator interface {
AddFlags(cmd *cobra.Command) error
ValidateFlags(ctx context.Context, cmd *cobra.Command) error
Validate(ctx context.Context, cmd *cobra.Command) error
}
2 changes: 1 addition & 1 deletion cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test(ctx context.Context, logger *zap.Logger, cfg *config.Config, serviceFa
Short: "run the recorded testcases and execute assertions",
Example: `keploy test -c "/path/to/user/app" --delay 6`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
return cmdConfigurator.ValidateFlags(ctx, cmd)
return cmdConfigurator.Validate(ctx, cmd)
},
RunE: func(cmd *cobra.Command, _ []string) error {
svc, err := serviceFactory.GetService(ctx, cmd.Name())
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
)

require (
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -55,6 +56,7 @@ require (
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sosodev/duration v1.2.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand Down Expand Up @@ -139,6 +141,7 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/moby v26.0.2+incompatible
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/cilium/ebpf v0.13.2 h1:uhLimLX+jF9BTPPvoCUYh/mBeoONkjgaJ9w9fn0mRj4=
github.com/cilium/ebpf v0.13.2/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso=
github.com/cloudflare/cfssl v1.6.4 h1:NMOvfrEjFfC63K3SGXgAnFdsgkmiq4kATme5BfcqrO8=
github.com/cloudflare/cfssl v1.6.4/go.mod h1:8b3CQMxfWPAeom3zBnGJ6sd+G1NkL5TXqmDXacb+1J0=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -169,6 +171,8 @@ github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo=
github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/moby v26.0.2+incompatible h1:t41TD3nRvK8E6bZFJdKrmNlH8Xe3epTmdNXf/mnfLKk=
github.com/moby/moby v26.0.2+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
Expand Down Expand Up @@ -232,6 +236,8 @@ github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sosodev/duration v1.2.0 h1:pqK/FLSjsAADWY74SyWDCjOcd5l7H8GSnnOGEB9A1Us=
github.com/sosodev/duration v1.2.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down Expand Up @@ -390,6 +396,7 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit 72d744e

Please sign in to comment.