Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 golangci lint 1.48.0 #971

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.48.0

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
4 changes: 2 additions & 2 deletions pkg/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package admission
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/noobaa/noobaa-operator/v5/pkg/util"
Expand All @@ -28,7 +28,7 @@ func (gs *ServerHandler) serve(w http.ResponseWriter, r *http.Request) {
var arResponse admissionv1.AdmissionReview
var body []byte
if r.Body != nil {
if data, err := ioutil.ReadAll(r.Body); err == nil {
if data, err := io.ReadAll(r.Body); err == nil {
tangledbytes marked this conversation as resolved.
Show resolved Hide resolved
body = data
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/backingstore/backingstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package backingstore
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"time"

Expand Down Expand Up @@ -618,7 +618,7 @@ func RunCreateGoogleCloudStorage(cmd *cobra.Command, args []string) {

if secretName == "" {
privateKeyJSONFile := util.GetFlagStringOrPrompt(cmd, "private-key-json-file")
bytes, err := ioutil.ReadFile(privateKeyJSONFile)
bytes, err := os.ReadFile(privateKeyJSONFile)
if err != nil {
log.Fatalf("Failed to read file %q: %v", privateKeyJSONFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -44,7 +43,7 @@ func main() {
return nil
}
name := compiledNameRE.ReplaceAllString(path, "_")
bytes, err := ioutil.ReadFile(filepath.Clean(path))
bytes, err := os.ReadFile(filepath.Clean(path))
fatal(err)
sha256Bytes := sha256.Sum256(bytes)
sha256Hex := hex.EncodeToString(sha256Bytes[:])
Expand Down
4 changes: 2 additions & 2 deletions pkg/nb/rpc_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nb
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strconv"

Expand Down Expand Up @@ -57,7 +57,7 @@ func (c *RPCConnHTTP) Call(req *RPCMessage, res RPCResponse) error {
return err
}

resBytes, err := ioutil.ReadAll(httpResponse.Body)
resBytes, err := io.ReadAll(httpResponse.Body)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/nb/rpc_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"sync"
"time"

Expand Down Expand Up @@ -112,7 +111,7 @@ func (c *RPCConnWS) ConnectUnderLock() error {
}

logrus.Infof("RPC: Connecting websocket (%p) %+v", c, c)
dialCtx, dialCancel := context.WithTimeout(context.Background(), connectTimeout)
dialCtx, dialCancel := context.WithTimeout(context.Background(), connectTimeout)
defer dialCancel()
ws, _, err := websocket.Dial(dialCtx, c.Address, &websocket.DialOptions{HTTPClient: &c.RPC.HTTPClient})
if err != nil {
Expand Down Expand Up @@ -321,7 +320,7 @@ func (c *RPCConnWS) ReadMessage() (*RPCMessage, error) {

// Read message buffers if any
if msg.Buffers != nil && len(msg.Buffers) > 0 {
buffers, err := ioutil.ReadAll(reader)
buffers, err := io.ReadAll(reader)
tangledbytes marked this conversation as resolved.
Show resolved Hide resolved
// if err != nil && err.Error() != "failed to read: cannot use EOFed reader" {
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions pkg/olm/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package olm
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -206,7 +205,7 @@ func RunCatalog(cmd *cobra.Command, args []string) {

util.Panic(os.MkdirAll(versionDir, 0755))
if !forODF {
util.Panic(ioutil.WriteFile(dir+"noobaa-operator.package.yaml", pkgBytes, 0644))
util.Panic(os.WriteFile(dir+"noobaa-operator.package.yaml", pkgBytes, 0644))
}
util.Panic(util.WriteYamlFile(csvFileName, GenerateCSV(opConf, csvParams)))
crd.ForEachCRD(func(c *crd.CRD) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -751,7 +751,7 @@ func (r *Reconciler) prepareAWSSTSBackingStore() error {
if err != nil {
return err
}
bytes, err := ioutil.ReadFile(projectedServiceAccountTokenFile)
bytes, err := os.ReadFile(projectedServiceAccountTokenFile)
if err != nil {
r.Logger.Errorf("Failed to read file %q: %v", projectedServiceAccountTokenFile, err)
return err
Expand Down
25 changes: 12 additions & 13 deletions pkg/util/kms/kms_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kms

import (
"fmt"
"io/ioutil"
"os"

"github.com/noobaa/noobaa-operator/v5/pkg/util"
Expand All @@ -14,26 +13,26 @@ import (

// Vault authentication config options
const (
VaultAddr = "VAULT_ADDR"
VaultCaCert = "VAULT_CACERT"
VaultClientCert = "VAULT_CLIENT_CERT"
VaultClientKey = "VAULT_CLIENT_KEY"
VaultSkipVerify = "VAULT_SKIP_VERIFY"
VaultToken = "VAULT_TOKEN"
RootSecretPath = "NOOBAA_ROOT_SECRET_PATH"
VaultAddr = "VAULT_ADDR"
VaultCaCert = "VAULT_CACERT"
VaultClientCert = "VAULT_CLIENT_CERT"
VaultClientKey = "VAULT_CLIENT_KEY"
VaultSkipVerify = "VAULT_SKIP_VERIFY"
VaultToken = "VAULT_TOKEN"
RootSecretPath = "NOOBAA_ROOT_SECRET_PATH"
)

// Vault is a vault driver
type Vault struct {
UID string // NooBaa system UID
UID string // NooBaa system UID
}

// NewVault is vault driver constructor
func NewVault(
name string,
namespace string,
uid string,
) (Driver) {
) Driver {
return &Vault{uid}
}

Expand Down Expand Up @@ -104,7 +103,7 @@ func (v *Vault) DeleteContext() map[string]string {
//

// tlsConfig create temp files with TLS keys and certs
func tlsConfig(config map[string]interface{}, namespace string) (error) {
func tlsConfig(config map[string]interface{}, namespace string) error {
secret := &corev1.Secret{}
secret.Namespace = namespace

Expand Down Expand Up @@ -153,13 +152,13 @@ func writeCrtsToFile(secretName string, namespace string, secretValue []byte, en
}

// Generate a temp file
file, err := ioutil.TempFile("", "")
file, err := os.CreateTemp("", "")
baum marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return "", fmt.Errorf("failed to generate temp file for k8s secret %q content, %v", secretName, err)
}

// Write into a file
err = ioutil.WriteFile(file.Name(), secretValue, 0444)
err = os.WriteFile(file.Name(), secretValue, 0444)
if err != nil {
return "", fmt.Errorf("failed to write k8s secret %q content to a file %v", secretName, err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -133,7 +132,7 @@ func AddToRootCAs(localCertFile string) error {
}

// Read in the cert file
certs, err := ioutil.ReadFile(localCertFile)
certs, err := os.ReadFile(localCertFile)
if err != nil {
log.Errorf("Failed to append %q to RootCAs: %v", localCertFile, err)
return err
Expand Down Expand Up @@ -1198,7 +1197,7 @@ func DiscoverOAuthEndpoints() (*OAuth2Endpoints, error) {
return nil, err
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1528,7 +1527,7 @@ func DeleteStorageClass(sc *storagev1.StorageClass) error {
func LoadBucketReplicationJSON(replicationJSONFilePath string) (string, error) {

logrus.Infof("loading bucket replication %v", replicationJSONFilePath)
bytes, err := ioutil.ReadFile(replicationJSONFilePath)
bytes, err := os.ReadFile(replicationJSONFilePath)
if err != nil {
return "", fmt.Errorf("Failed to read file %q: %v", replicationJSONFilePath, err)
}
Expand Down