From 72d744e4ad3785fa60be669814acfdf88d0b9f2f Mon Sep 17 00:00:00 2001 From: Sky Singh <114267538+Akash-Singh04@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:03:30 +0530 Subject: [PATCH] [feature]: Added Validate() function to check if the linux kernel version is lower than 5.15 (#1828) * Added Validate function to check if the linux kernel version is lower than 5.15 Signed-off-by: Akash Singh * Integrated github.com/moby/moby/pkg/parsers/kernel for kernel level check Signed-off-by: Akash Singh * Refactored var name Signed-off-by: Akash Singh --------- Signed-off-by: Akash Singh --- cli/provider/cmd.go | 13 +++++++++++++ cli/record.go | 2 +- cli/service.go | 1 + cli/test.go | 2 +- go.mod | 3 +++ go.sum | 7 +++++++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/provider/cmd.go b/cli/provider/cmd.go index be1d46a10..184154928 100644 --- a/cli/provider/cmd.go +++ b/cli/provider/cmd.go @@ -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" @@ -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()) diff --git a/cli/record.go b/cli/record.go index 40727c555..ea6fda187 100755 --- a/cli/record.go +++ b/cli/record.go @@ -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()) diff --git a/cli/service.go b/cli/service.go index edf027d23..8e0f815ac 100644 --- a/cli/service.go +++ b/cli/service.go @@ -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 } diff --git a/cli/test.go b/cli/test.go index c616a03d8..c3a6dd769 100755 --- a/cli/test.go +++ b/cli/test.go @@ -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()) diff --git a/go.mod b/go.mod index 9f8646aee..52594349f 100755 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index e46ba168b..656c0cd46 100755 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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=