From ab0ee87629dfa8106a3063a5fa22124e6bff4b2f Mon Sep 17 00:00:00 2001 From: mslacken Date: Fri, 14 Oct 2022 17:40:16 +0200 Subject: [PATCH] updated linter and fixed deprecated stuff --- Makefile | 2 +- cmd/update_configuration/update_configuration.go | 5 ++--- internal/app/api/wwapic/wwapic.go | 6 +++--- internal/app/api/wwapid/wwapid.go | 3 +-- internal/app/api/wwapird/wwapird.go | 9 +++++---- internal/app/wwclient/root.go | 3 +-- internal/app/wwctl/node/edit/main.go | 3 +-- internal/app/wwctl/overlay/show/main.go | 3 +-- internal/app/wwctl/profile/edit/main.go | 3 +-- internal/pkg/api/apiconfig/client.go | 7 ++++--- internal/pkg/api/apiconfig/client_server.go | 7 ++++--- internal/pkg/api/apiconfig/server.go | 7 ++++--- internal/pkg/container/util.go | 3 +-- internal/pkg/kernel/kernel.go | 7 +++---- internal/pkg/node/constructors.go | 6 +++--- internal/pkg/oci/puller.go | 3 +-- internal/pkg/overlay/funcmap.go | 5 ++--- internal/pkg/overlay/overlay.go | 6 ++---- internal/pkg/pidfile/pidfile.go | 5 ++--- internal/pkg/warewulfconf/constructors.go | 4 ++-- internal/pkg/warewulfd/daemon.go | 13 ++++++------- 21 files changed, 50 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index add0a600..44c2ed49 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ CONFIG := $(shell pwd) GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN)/, $(notdir $(GO_TOOLS))) GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS)) GOLANGCI_LINT := $(TOOLS_BIN)/golangci-lint -GOLANGCI_LINT_VERSION := v1.45.2 +GOLANGCI_LINT_VERSION := v1.50.0 # use GOPROXY for older git clients and speed up downloads GOPROXY ?= https://proxy.golang.org diff --git a/cmd/update_configuration/update_configuration.go b/cmd/update_configuration/update_configuration.go index 2ddd79ae..c64de182 100644 --- a/cmd/update_configuration/update_configuration.go +++ b/cmd/update_configuration/update_configuration.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "os" "reflect" @@ -44,7 +43,7 @@ func saveConf(conf interface{}) { os.Exit(1) } myprintf("writing configuration file %s as type %s\n", confFile, reflect.TypeOf(conf)) - err = ioutil.WriteFile(confFile, out, info.Mode()) + err = os.WriteFile(confFile, out, info.Mode()) if err != nil { myprintf("Could not write file: %s\n", err) os.Exit(1) @@ -136,7 +135,7 @@ func main() { os.Exit(1) } myprintf("Opening node configuration file: %s\n", confFile) - data, err := ioutil.ReadFile(confFile) + data, err := os.ReadFile(confFile) if err != nil { myprintf("Could open file %v\n", err) os.Exit(1) diff --git a/internal/app/api/wwapic/wwapic.go b/internal/app/api/wwapic/wwapic.go index f4c09a63..65cd85b5 100644 --- a/internal/app/api/wwapic/wwapic.go +++ b/internal/app/api/wwapic/wwapic.go @@ -5,8 +5,8 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "log" + "os" "path" "time" @@ -42,7 +42,7 @@ func main() { // Load the CA cert. var cacert []byte - cacert, err = ioutil.ReadFile(config.TlsConfig.CaCert) + cacert, err = os.ReadFile(config.TlsConfig.CaCert) if err != nil { log.Fatalf("Failed to load cacert. err: %s\n", err) } @@ -86,4 +86,4 @@ func main() { } log.Printf("Version Response: %v\n", response) -} \ No newline at end of file +} diff --git a/internal/app/api/wwapid/wwapid.go b/internal/app/api/wwapid/wwapid.go index 7d6a1de4..1cea854f 100644 --- a/internal/app/api/wwapid/wwapid.go +++ b/internal/app/api/wwapid/wwapid.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "log" "net" "os" @@ -60,7 +59,7 @@ func main() { // Load the CA cert. var cacert []byte - cacert, err = ioutil.ReadFile(config.TlsConfig.CaCert) + cacert, err = os.ReadFile(config.TlsConfig.CaCert) if err != nil { log.Fatalf("Failed to load cacert. err: %s\n", err) } diff --git a/internal/app/api/wwapird/wwapird.go b/internal/app/api/wwapird/wwapird.go index d7984914..dcbaecf1 100644 --- a/internal/app/api/wwapird/wwapird.go +++ b/internal/app/api/wwapird/wwapird.go @@ -4,11 +4,11 @@ import ( "context" "crypto/tls" "crypto/x509" + "os" "flag" "fmt" "log" - "io/ioutil" "net/http" "github.com/golang/glog" @@ -21,8 +21,9 @@ import ( gw "github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1" - "github.com/hpcng/warewulf/internal/pkg/buildconfig" "path" + + "github.com/hpcng/warewulf/internal/pkg/buildconfig" ) func run() error { @@ -56,7 +57,7 @@ func run() error { // Load the CA cert. var cacert []byte - cacert, err = ioutil.ReadFile(config.ClientTlsConfig.CaCert) + cacert, err = os.ReadFile(config.ClientTlsConfig.CaCert) if err != nil { log.Fatalf("Failed to load cacert. err: %s\n", err) } @@ -109,4 +110,4 @@ func main() { if err := run(); err != nil { glog.Fatal(err) } -} \ No newline at end of file +} diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index 01807a28..dc06e684 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -3,7 +3,6 @@ package wwclient import ( "errors" "fmt" - "io/ioutil" "log" "net" "net/http" @@ -122,7 +121,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { x := smbiosDump.SystemEnclosure() tag := strings.ReplaceAll(x.AssetTagNumber(), " ", "_") - cmdline, err := ioutil.ReadFile("/proc/cmdline") + cmdline, err := os.ReadFile("/proc/cmdline") if err != nil { wwlog.Error("Could not read from /proc/cmdline: %s", err) os.Exit(1) diff --git a/internal/app/wwctl/node/edit/main.go b/internal/app/wwctl/node/edit/main.go index 9307edef..0683f931 100644 --- a/internal/app/wwctl/node/edit/main.go +++ b/internal/app/wwctl/node/edit/main.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "os" "strings" @@ -39,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { nodeMap := make(map[string]*node.NodeConf) // got proper yaml back _ = yaml.Unmarshal([]byte(nodeListMsg.NodeConfMapYaml), nodeMap) - file, err := ioutil.TempFile("/tmp", "ww4NodeEdit*.yaml") + file, err := os.CreateTemp(os.TempDir(), "ww4NodeEdit*.yaml") if err != nil { wwlog.Error("Could not create temp file:%s \n", err) } diff --git a/internal/app/wwctl/overlay/show/main.go b/internal/app/wwctl/overlay/show/main.go index 9e132fc5..d1a27958 100644 --- a/internal/app/wwctl/overlay/show/main.go +++ b/internal/app/wwctl/overlay/show/main.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -38,7 +37,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NodeName == "" { - f, err := ioutil.ReadFile(overlayFile) + f, err := os.ReadFile(overlayFile) if err != nil { wwlog.Error("Could not read file: %s", err) os.Exit(1) diff --git a/internal/app/wwctl/profile/edit/main.go b/internal/app/wwctl/profile/edit/main.go index a5694e5d..97d5a3ad 100644 --- a/internal/app/wwctl/profile/edit/main.go +++ b/internal/app/wwctl/profile/edit/main.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "os" "strings" @@ -39,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { profileMap := make(map[string]*node.NodeConf) // got proper yaml back _ = yaml.Unmarshal([]byte(profileListMsg.NodeConfMapYaml), profileMap) - file, err := ioutil.TempFile("/tmp", "ww4ProfileEdit*.yaml") + file, err := os.CreateTemp(os.TempDir(), "ww4ProfileEdit*.yaml") if err != nil { wwlog.Error("Could not create temp file:%s \n", err) } diff --git a/internal/pkg/api/apiconfig/client.go b/internal/pkg/api/apiconfig/client.go index df397975..595409e8 100644 --- a/internal/pkg/api/apiconfig/client.go +++ b/internal/pkg/api/apiconfig/client.go @@ -1,9 +1,10 @@ package apiconfig import ( - "gopkg.in/yaml.v2" - "io/ioutil" "log" + "os" + + "gopkg.in/yaml.v2" ) // ClientApiConfig contains configuration parameters for an API server. @@ -26,7 +27,7 @@ func NewClient(configFilePath string) (config ClientConfig, err error) { log.Printf("Loading api client configuration from: %v\n", configFilePath) var fileBytes []byte - fileBytes, err = ioutil.ReadFile(configFilePath) + fileBytes, err = os.ReadFile(configFilePath) if err != nil { return } diff --git a/internal/pkg/api/apiconfig/client_server.go b/internal/pkg/api/apiconfig/client_server.go index 89e035ca..c227e224 100644 --- a/internal/pkg/api/apiconfig/client_server.go +++ b/internal/pkg/api/apiconfig/client_server.go @@ -1,9 +1,10 @@ package apiconfig import ( - "gopkg.in/yaml.v2" - "io/ioutil" "log" + "os" + + "gopkg.in/yaml.v2" ) // ClientServerConfig is the full client server configuration. @@ -22,7 +23,7 @@ func NewClientServer(configFilePath string) (config ClientServerConfig, err erro log.Printf("Loading api client server configuration from: %v\n", configFilePath) var fileBytes []byte - fileBytes, err = ioutil.ReadFile(configFilePath) + fileBytes, err = os.ReadFile(configFilePath) if err != nil { return } diff --git a/internal/pkg/api/apiconfig/server.go b/internal/pkg/api/apiconfig/server.go index 80f7006c..85be2bce 100644 --- a/internal/pkg/api/apiconfig/server.go +++ b/internal/pkg/api/apiconfig/server.go @@ -1,9 +1,10 @@ package apiconfig import ( - "gopkg.in/yaml.v2" - "io/ioutil" "log" + "os" + + "gopkg.in/yaml.v2" ) // ServerApiConfig contains configuration parameters for an API server. @@ -28,7 +29,7 @@ func NewServer(configFilePath string) (config ServerConfig, err error) { log.Printf("Loading api server configuration from: %v\n", configFilePath) var fileBytes []byte - fileBytes, err = ioutil.ReadFile(configFilePath) + fileBytes, err = os.ReadFile(configFilePath) if err != nil { return } diff --git a/internal/pkg/container/util.go b/internal/pkg/container/util.go index 3d741a10..48211710 100644 --- a/internal/pkg/container/util.go +++ b/internal/pkg/container/util.go @@ -1,7 +1,6 @@ package container import ( - "io/ioutil" "os" "github.com/pkg/errors" @@ -27,7 +26,7 @@ func ListSources() ([]string, error) { } wwlog.Debug("Searching for VNFS Rootfs directories: %s", SourceParentDir()) - sources, err := ioutil.ReadDir(SourceParentDir()) + sources, err := os.ReadDir(SourceParentDir()) if err != nil { return ret, err } diff --git a/internal/pkg/kernel/kernel.go b/internal/pkg/kernel/kernel.go index 4fae2ea9..9983572e 100644 --- a/internal/pkg/kernel/kernel.go +++ b/internal/pkg/kernel/kernel.go @@ -4,7 +4,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -51,7 +50,7 @@ func GetKernelVersion(kernelName string) string { wwlog.Error("Kernel Name is not defined") return "" } - kernelVersion, err := ioutil.ReadFile(KernelVersionFile(kernelName)) + kernelVersion, err := os.ReadFile(KernelVersionFile(kernelName)) if err != nil { return "" } @@ -96,7 +95,7 @@ func ListKernels() ([]string, error) { wwlog.Debug("Searching for Kernel image directories: %s", KernelImageTopDir()) - kernels, err := ioutil.ReadDir(KernelImageTopDir()) + kernels, err := os.ReadDir(KernelImageTopDir()) if err != nil { return ret, err } @@ -198,7 +197,7 @@ func Build(kernelVersion, kernelName, root string) (string, error) { driversDestination, []string{ "." + kernelDriversRelative, - "./lib/firmware" }, + "./lib/firmware"}, []string{}, // ignore cross-device files true, diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index cb3ab52d..fec425fa 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -2,7 +2,7 @@ package node import ( "errors" - "io/ioutil" + "os" "path" "sort" "strings" @@ -48,7 +48,7 @@ func New() (NodeYaml, error) { var ret NodeYaml wwlog.Verbose("Opening node configuration file: %s", ConfigFile) - data, err := ioutil.ReadFile(ConfigFile) + data, err := os.ReadFile(ConfigFile) if err != nil { return ret, err } @@ -79,7 +79,7 @@ func (config *NodeYaml) FindAllNodes() ([]NodeInfo, error) { */ var defConf map[string]*NodeConf wwlog.Verbose("Opening defaults failed %s\n", DefaultConfig) - defData, err := ioutil.ReadFile(DefaultConfig) + defData, err := os.ReadFile(DefaultConfig) if err != nil { wwlog.Verbose("Couldn't read DefaultConfig :%s\n", err) } diff --git a/internal/pkg/oci/puller.go b/internal/pkg/oci/puller.go index 9acae792..1ad4e700 100644 --- a/internal/pkg/oci/puller.go +++ b/internal/pkg/oci/puller.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -139,7 +138,7 @@ func (p *puller) Pull(ctx context.Context, uri, dst string) (err error) { } // defaults to $TMPDIR or /tmp - tmpDir, err := ioutil.TempDir(p.tmpDirPath, "oci-bundle-") + tmpDir, err := os.MkdirTemp(p.tmpDirPath, "oci-bundle-") if err != nil { return err } diff --git a/internal/pkg/overlay/funcmap.go b/internal/pkg/overlay/funcmap.go index 9ecf632f..49b50d3d 100644 --- a/internal/pkg/overlay/funcmap.go +++ b/internal/pkg/overlay/funcmap.go @@ -2,7 +2,6 @@ package overlay import ( "bufio" - "io/ioutil" "os" "path" "strings" @@ -23,7 +22,7 @@ func templateFileInclude(inc string) string { inc = path.Join(buildconfig.SYSCONFDIR(), "warewulf", inc) } wwlog.Debug("Including file into template: %s", inc) - content, err := ioutil.ReadFile(inc) + content, err := os.ReadFile(inc) if err != nil { wwlog.Verbose("Could not include file into template: %s", err) } @@ -93,7 +92,7 @@ func templateContainerFileInclude(containername string, filepath string) string return "" } - content, err := ioutil.ReadFile(path.Join(containerDir, filepath)) + content, err := os.ReadFile(path.Join(containerDir, filepath)) if err != nil { wwlog.Error("Template include failed: %s", err) diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index b0d56d37..fc2cb41f 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -5,7 +5,6 @@ import ( "bytes" "fmt" "io/fs" - "io/ioutil" "os" "path" "path/filepath" @@ -105,10 +104,9 @@ Get all overlays present in warewulf */ func FindOverlays() ([]string, error) { var ret []string - var files []os.FileInfo dotfilecheck, _ := regexp.Compile(`^\..*`) - files, err := ioutil.ReadDir(OverlaySourceTopDir()) + files, err := os.ReadDir(OverlaySourceTopDir()) if err != nil { return ret, errors.Wrap(err, "could not get list of overlays") } @@ -156,7 +154,7 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayNames []string) error { wwlog.Debug("Created directory for %s: %s", name, overlayImageDir) - buildDir, err := ioutil.TempDir(os.TempDir(), ".wwctl-overlay-") + buildDir, err := os.MkdirTemp(os.TempDir(), ".wwctl-overlay-") if err != nil { return errors.Wrapf(err, "Failed to create temporary directory for %s", name) } diff --git a/internal/pkg/pidfile/pidfile.go b/internal/pkg/pidfile/pidfile.go index 9541ea99..25565340 100644 --- a/internal/pkg/pidfile/pidfile.go +++ b/internal/pkg/pidfile/pidfile.go @@ -5,7 +5,6 @@ package pidfile import ( "errors" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -47,11 +46,11 @@ func WriteControl(filename string, pid int, overwrite bool) (int, error) { } // We're clear to (over)write the file - return pid, ioutil.WriteFile(filename, []byte(fmt.Sprintf("%d\n", pid)), 0644) + return pid, os.WriteFile(filename, []byte(fmt.Sprintf("%d\n", pid)), 0644) } func pidfileContents(filename string) (int, error) { - contents, err := ioutil.ReadFile(filename) + contents, err := os.ReadFile(filename) if err != nil { return 0, err } diff --git a/internal/pkg/warewulfconf/constructors.go b/internal/pkg/warewulfconf/constructors.go index 1d68564a..3935f60c 100644 --- a/internal/pkg/warewulfconf/constructors.go +++ b/internal/pkg/warewulfconf/constructors.go @@ -3,8 +3,8 @@ package warewulfconf import ( "errors" "fmt" - "io/ioutil" "net" + "os" "path" "github.com/brotherpowers/ipsubnet" @@ -43,7 +43,7 @@ func New() (ControllerConf, error) { // Check if cached config is old before re-reading config file if !cachedConf.current { wwlog.Debug("Opening Warewulf configuration file: %s", ConfigFile) - data, err := ioutil.ReadFile(ConfigFile) + data, err := os.ReadFile(ConfigFile) if err != nil { wwlog.Warn("Error reading Warewulf configuration file") } diff --git a/internal/pkg/warewulfd/daemon.go b/internal/pkg/warewulfd/daemon.go index 4eec8c21..2ed57ed4 100644 --- a/internal/pkg/warewulfd/daemon.go +++ b/internal/pkg/warewulfd/daemon.go @@ -2,7 +2,6 @@ package warewulfd import ( "fmt" - "io/ioutil" "log/syslog" "os" "os/exec" @@ -41,7 +40,7 @@ func DaemonInitLogging() error { if err == nil { wwlog.SetLogLevel(level) } - }else{ + } else { wwlog.SetLogLevel(wwlog.SERV) } @@ -86,7 +85,7 @@ func DaemonStart() error { logLevel := wwlog.GetLogLevel() if logLevel == wwlog.INFO { os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(wwlog.SERV)) - }else{ + } else { os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(logLevel)) } @@ -124,7 +123,7 @@ func DaemonStatus() error { return errors.New("Warewulf server is not running") } - dat, err := ioutil.ReadFile(WAREWULFD_PIDFILE) + dat, err := os.ReadFile(WAREWULFD_PIDFILE) if err != nil { return errors.Wrap(err, "could not read Warewulfd PID file") } @@ -150,7 +149,7 @@ func DaemonReload() error { return errors.New("Warewulf server is not running") } - dat, err := ioutil.ReadFile(WAREWULFD_PIDFILE) + dat, err := os.ReadFile(WAREWULFD_PIDFILE) if err != nil { return errors.Wrap(err, "could not read Warewulfd PID file") } @@ -169,7 +168,7 @@ func DaemonReload() error { logLevel := wwlog.GetLogLevel() if logLevel == wwlog.INFO { os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(wwlog.SERV)) - }else{ + } else { os.Setenv("WAREWULFD_LOGLEVEL", strconv.Itoa(logLevel)) } @@ -182,7 +181,7 @@ func DaemonStop() error { return nil } - dat, err := ioutil.ReadFile(WAREWULFD_PIDFILE) + dat, err := os.ReadFile(WAREWULFD_PIDFILE) if err != nil { return err }