Skip to content

Commit

Permalink
Merge pull request #608 from rquitales/update-golangci-lint
Browse files Browse the repository at this point in the history
chore: Bump golangci-lint version
  • Loading branch information
k8s-ci-robot authored Nov 2, 2022
2 parents c10935a + 49981f7 commit 57ba470
Show file tree
Hide file tree
Showing 34 changed files with 191 additions and 191 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -31,14 +30,12 @@ linters:
- misspell
- nakedret
- staticcheck
- structcheck
- stylecheck
- revive
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace


Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: generate license fix vet fmt test lint tidy
go install github.com/google/[email protected]

"$(MYGOBIN)/golangci-lint":
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0

"$(MYGOBIN)/deepcopy-gen":
go install k8s.io/code-generator/cmd/[email protected]
Expand Down
3 changes: 1 addition & 2 deletions cmd/diff/cmddiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package diff

import (
"io/ioutil"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -104,7 +103,7 @@ func Initialize(o *diff.DiffOptions, f util.Factory, args []string) (func(), err
func createTempDir() (string, error) {
// Create a temporary file with the passed prefix in
// the default temporary directory.
tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
tmpDir, err := os.MkdirTemp("", tmpDirPrefix)
if err != nil {
return "", err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/apply/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"testing"
Expand Down Expand Up @@ -240,20 +240,20 @@ func (g *genericHandler) handle(t *testing.T, req *http.Request) (*http.Response

if req.URL.Path == singlePath && req.Method == http.MethodGet {
if r.exists {
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.StringBody("")}, true, nil
}

if req.URL.Path == singlePath && req.Method == http.MethodPatch {
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}

if req.URL.Path == singlePath && req.Method == http.MethodDelete {
if r.exists {
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}

Expand All @@ -271,12 +271,12 @@ func (g *genericHandler) handle(t *testing.T, req *http.Request) (*http.Response
Kind: r.resource.GetKind(),
},
}
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, result)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, result)))
return &http.Response{StatusCode: status, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}

if req.URL.Path == allPath && req.Method == http.MethodPost {
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func (n *nsHandler) handle(t *testing.T, req *http.Request) (*http.Response, boo
Name: nsName,
},
}
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, &ns)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, &ns)))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
}
return nil, false, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/apply/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

// Type determines the type of events that are available.
//
//go:generate stringer -type=Type
type Type int

Expand Down
1 change: 1 addition & 0 deletions pkg/apply/prune/event-factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func CreateEventFactory(isDelete bool, groupName string) EventFactory {

// PruneEventFactory implements EventFactory interface as a concrete
// representation of for prune events.
//
//nolint:revive // stuttering ok because Prune is a type of PruneEvent
type PruneEventFactory struct {
groupName string
Expand Down
11 changes: 6 additions & 5 deletions pkg/apply/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ type Options struct {
// automatically prune/delete).
//
// Parameters:
// objs - objects to prune (delete)
// pruneFilters - list of filters for deletion permission
// taskContext - task for apply/prune
// taskName - name of the parent task group, for events
// opts - options for dry-run
//
// objs - objects to prune (delete)
// pruneFilters - list of filters for deletion permission
// taskContext - task for apply/prune
// taskName - name of the parent task group, for events
// opts - options for dry-run
func (p *Pruner) Prune(
objs object.UnstructuredSet,
pruneFilters []filter.ValidationFilter,
Expand Down
6 changes: 3 additions & 3 deletions pkg/apply/task/apply_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -192,8 +192,8 @@ func newApplyOptions(taskName string, eventChannel chan<- event.Event, serverSid
OpenAPIPatch: true, // Normally set in apply.NewApplyOptions
Recorder: genericclioptions.NoopRecorder{},
IOStreams: genericclioptions.IOStreams{
Out: ioutil.Discard,
ErrOut: ioutil.Discard, // TODO: Warning for no lastConfigurationAnnotation
Out: io.Discard,
ErrOut: io.Discard, // TODO: Warning for no lastConfigurationAnnotation
// is printed directly to stderr in ApplyOptions. We
// should turn that into a warning on the event channel.
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/apply/taskrunner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ type Options struct {
//
// The tasks run in a loop where a single goroutine will process events from
// three different channels.
// - taskQueue is read to allow updating the task queue at runtime.
// - statusChannel is read to allow updates to the resource cache and triggering
// validation of wait conditions.
// - eventChannel is written to with events based on status updates, if
// emitStatusEvents is true.
// - taskQueue is read to allow updating the task queue at runtime.
// - statusChannel is read to allow updates to the resource cache and triggering
// validation of wait conditions.
// - eventChannel is written to with events based on status updates, if
// emitStatusEvents is true.
func (tsr *TaskStatusRunner) Run(
ctx context.Context,
taskContext *TaskContext,
Expand Down
1 change: 1 addition & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
)

// ClientDryRun returns true if input drs is DryRunClient
//
//nolint:stylecheck // Prevent lint errors on receiver names caused by string generation above
func (drs DryRunStrategy) ClientDryRun() bool {
return drs == DryRunClient
Expand Down
5 changes: 2 additions & 3 deletions pkg/common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package common
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -94,11 +93,11 @@ func ExpandPackageDir(f genericclioptions.FileNameFlags) (genericclioptions.File
// an error if one occurs.
func FilterInputFile(in io.Reader, tmpDir string) error {
// Copy the config from "in" into a local temp file.
dir, err := ioutil.TempDir("", tmpDirPrefix)
dir, err := os.MkdirTemp("", tmpDirPrefix)
if err != nil {
return err
}
tmpFile, err := ioutil.TempFile(dir, fileRegexp)
tmpFile, err := os.CreateTemp(dir, fileRegexp)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/common/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package common

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -201,7 +200,7 @@ func TestFilterInputFile(t *testing.T) {
t.Fatalf("Unexpected error in FilterInputFile: %s", err)
}
// Retrieve the files from the test filesystem.
actualFiles, err := ioutil.ReadDir(tf.GetRootDir())
actualFiles, err := os.ReadDir(tf.GetRootDir())
if err != nil {
t.Fatalf("Error reading test filesystem directory: %s", err)
}
Expand All @@ -215,7 +214,7 @@ func TestFilterInputFile(t *testing.T) {
if len(actualFiles) != 0 {
actualFilename := (actualFiles[0]).Name()
defer os.Remove(actualFilename)
actual, err := ioutil.ReadFile(actualFilename)
actual, err := os.ReadFile(actualFilename)
if err != nil {
t.Fatalf("Error reading created file (%s): %s", actualFilename, err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/config/initoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func FindNamespace(loader namespaceLoader, dir string) (string, error) {
// passed directory or an error. This function cleans up paths
// such as current directory (.), relative directories (..), or
// multiple separators.
//
func NormalizeDir(dirPath string) (string, error) {
if !common.IsDir(dirPath) {
return "", fmt.Errorf("invalid directory argument: %s", dirPath)
Expand Down
7 changes: 3 additions & 4 deletions pkg/config/initoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand All @@ -19,7 +18,7 @@ import (

// writeFile writes a file under the test directory
func writeFile(t *testing.T, path string, value []byte) {
err := ioutil.WriteFile(path, value, 0600)
err := os.WriteFile(path, value, 0600)
if !assert.NoError(t, err) {
assert.FailNow(t, err.Error())
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestComplete(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
var err error
dir, err := ioutil.TempDir("", "test-dir")
dir, err := os.MkdirTemp("", "test-dir")
if !assert.NoError(t, err) {
assert.FailNow(t, err.Error())
}
Expand Down Expand Up @@ -222,7 +221,7 @@ func TestFindNamespace(t *testing.T) {
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
var err error
dir, err := ioutil.TempDir("", "test-dir")
dir, err := os.MkdirTemp("", "test-dir")
if !assert.NoError(t, err) {
assert.FailNow(t, err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/flowcontrol/flowcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package flowcontrol
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -37,7 +36,7 @@ func TestIsEnabled(t *testing.T) {
return &http.Response{
StatusCode: 200,
Header: headers,
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Body: io.NopCloser(bytes.NewReader(nil)),
}
},
expectedEnabled: true,
Expand All @@ -49,7 +48,7 @@ func TestIsEnabled(t *testing.T) {
return &http.Response{
StatusCode: 200,
Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Body: io.NopCloser(bytes.NewReader(nil)),
}
},
expectedEnabled: false,
Expand Down
9 changes: 4 additions & 5 deletions pkg/inventory/configmap/cm-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ package configmap
// Template for ConfigMap inventory object. The following fields
// must be filled in for this to be valid:
//
// <DATETIME>: The time this is auto-generated
// <NAMESPACE>: The namespace to place this inventory object
// <RANDOMSUFFIX>: The random suffix added to the end of the name
// <INVENTORYID>: The label value to retrieve this inventory object
//
// <DATETIME>: The time this is auto-generated
// <NAMESPACE>: The namespace to place this inventory object
// <RANDOMSUFFIX>: The random suffix added to the end of the name
// <INVENTORYID>: The label value to retrieve this inventory object
const ConfigMapTemplate = `# NOTE: auto-generated. Some fields should NOT be modified.
# Date: <DATETIME>
#
Expand Down
8 changes: 4 additions & 4 deletions pkg/inventory/fake-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package inventory

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"regexp"

Expand Down Expand Up @@ -65,7 +65,7 @@ func fakeClient(objs object.ObjMetadataSet) resource.FakeClientFunc {
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
if req.Method == "POST" && cmPathRegex.Match([]byte(req.URL.Path)) {
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
Expand All @@ -74,7 +74,7 @@ func fakeClient(objs object.ObjMetadataSet) resource.FakeClientFunc {
if err != nil {
return nil, err
}
bodyRC := ioutil.NopCloser(bytes.NewReader(b))
bodyRC := io.NopCloser(bytes.NewReader(b))
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
}
if req.Method == "GET" && cmPathRegex.Match([]byte(req.URL.Path)) {
Expand All @@ -97,7 +97,7 @@ func fakeClient(objs object.ObjMetadataSet) resource.FakeClientFunc {
Data: objs.ToStringMap(),
}
cmList.Items = append(cmList.Items, cm)
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(&cmList)))
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(&cmList)))
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, nil
}
return nil, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/inventory/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// can go through for a resource based on the comparison
// the inventory-id value in the package and the owning-inventory
// annotation in the live object.
//
//go:generate stringer -type=Policy -linecomment
type Policy int

Expand Down Expand Up @@ -72,6 +73,7 @@ const OwningInventoryKey = "config.k8s.io/owning-inventory"

// IDMatchStatus represents the result of comparing the
// id from current inventory info and the inventory-id from a live object.
//
//go:generate stringer -type=IDMatchStatus
type IDMatchStatus int

Expand Down
1 change: 1 addition & 0 deletions pkg/inventory/status-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package inventory
// StatusPolicy specifies whether the inventory client should apply status to
// the inventory object. The status contains the actuation and reconcile stauts
// of each object in the inventory.
//
//go:generate stringer -type=StatusPolicy -linecomment
type StatusPolicy int

Expand Down
Loading

0 comments on commit 57ba470

Please sign in to comment.