From 150ef391f534c77f4dbcc3bfd82a23231a38387d Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 2 Jul 2024 09:53:03 +0200 Subject: [PATCH] chore(cmd/driver,pkg/driver): allow to disable kernel headers automatic download. Signed-off-by: Federico Di Pierro --- cmd/driver/driver_linux.go | 2 ++ cmd/driver/install/install.go | 8 +++++--- cmd/driver/install/install_test.go | 1 + pkg/driver/distro/distro.go | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/driver/driver_linux.go b/cmd/driver/driver_linux.go index 9b735234..f4858fad 100644 --- a/cmd/driver/driver_linux.go +++ b/cmd/driver/driver_linux.go @@ -138,6 +138,8 @@ func NewDriverCmd(ctx context.Context, opt *options.Common) *cobra.Command { return err } allowedDriverTypes = append(allowedDriverTypes, drvType) + opt.Printer.Logger.Debug("Allowed driver", + opt.Printer.Logger.Args("type", drvType)) } // Step 2: fetch system info (kernel release/version and distro) diff --git a/cmd/driver/install/install.go b/cmd/driver/install/install.go index 87bfc734..43c5b655 100644 --- a/cmd/driver/install/install.go +++ b/cmd/driver/install/install.go @@ -41,8 +41,9 @@ type driverDownloadOptions struct { type driverInstallOptions struct { *options.Common *options.Driver - Download bool - Compile bool + Download bool + Compile bool + DownloadHeaders bool driverDownloadOptions } @@ -77,6 +78,7 @@ func NewDriverInstallCmd(ctx context.Context, opt *options.Common, driver *optio cmd.Flags().BoolVar(&o.Download, "download", true, "Whether to enable download of prebuilt drivers") cmd.Flags().BoolVar(&o.Compile, "compile", true, "Whether to enable local compilation of drivers") + cmd.Flags().BoolVar(&o.DownloadHeaders, "download-headers", true, "Whether to enable automatic kernel headers download where supported") cmd.Flags().BoolVar(&o.InsecureDownload, "http-insecure", false, "Whether you want to allow insecure downloads or not") cmd.Flags().DurationVar(&o.HTTPTimeout, "http-timeout", 60*time.Second, "Timeout for each http try") cmd.Flags().StringVar(&o.HTTPHeaders, "http-headers", @@ -191,7 +193,7 @@ func (o *driverInstallOptions) RunDriverInstall(ctx context.Context) (string, er if !o.Printer.DisableStyling { o.Printer.Spinner, _ = o.Printer.Spinner.Start("Trying to build the driver") } - dest, err = driverdistro.Build(ctx, o.Distro, o.Printer.WithWriter(&buf), o.Kr, o.Driver.Name, o.Driver.Type, o.Driver.Version) + dest, err = driverdistro.Build(ctx, o.Distro, o.Printer.WithWriter(&buf), o.Kr, o.Driver.Name, o.Driver.Type, o.Driver.Version, o.DownloadHeaders) if o.Printer.Spinner != nil { _ = o.Printer.Spinner.Stop() } diff --git a/cmd/driver/install/install_test.go b/cmd/driver/install/install_test.go index e8eb6e3c..18a971fc 100644 --- a/cmd/driver/install/install_test.go +++ b/cmd/driver/install/install_test.go @@ -34,6 +34,7 @@ Usage: Flags: --compile Whether to enable local compilation of drivers (default true) --download Whether to enable download of prebuilt drivers (default true) + --download-headers Whether to enable automatic kernel headers download where supported (default true) -h, --help help for install --http-headers string Optional comma-separated list of headers for the http GET request (e.g. --http-headers='x-emc-namespace: default,Proxy-Authenticate: Basic'). Not necessary if default repo is used --http-insecure Whether you want to allow insecure downloads or not diff --git a/pkg/driver/distro/distro.go b/pkg/driver/distro/distro.go index 8f6778b6..0eb51e1c 100644 --- a/pkg/driver/distro/distro.go +++ b/pkg/driver/distro/distro.go @@ -169,6 +169,7 @@ func Build(ctx context.Context, driverName string, driverType drivertype.DriverType, driverVer string, + downloadHeaders bool, ) (string, error) { printer.Logger.Info("Trying to compile the requested driver") driverFileName := toFilename(d, &kr, driverName, driverType) @@ -190,7 +191,6 @@ func Build(ctx context.Context, // Disable automatic kernel headers fetching // if customizeBuild already retrieved kernel headers for us // (and has set the KernelDirEnv key) - downloadHeaders := true if _, ok := env[drivertype.KernelDirEnv]; ok { downloadHeaders = false }