updated linter and fixed deprecated stuff

This commit is contained in:
mslacken
2022-10-14 17:40:16 +02:00
parent b5d3de621b
commit ab0ee87629
21 changed files with 50 additions and 60 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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)
}

View File

@@ -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)
}
}
}

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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")
}

View File

@@ -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
}