Skip to content

Commit

Permalink
Upgrade linter to 1.49.0 (dapr#1051)
Browse files Browse the repository at this point in the history
* Upgrade linter to 1.49.0

Signed-off-by: Mukundan Sundararajan <[email protected]>

* fix linter error

Signed-off-by: Mukundan Sundararajan <[email protected]>

Signed-off-by: Mukundan Sundararajan <[email protected]>
  • Loading branch information
mukundansundar authored Aug 25, 2022
1 parent eaca34b commit 65855d5
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 49 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/dapr_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
GOVER: 1.18
GOLANG_CI_LINT_VER: v1.46.2
GOLANG_CI_LINT_VER: v1.49.0
GOOS: ${{ matrix.target_os }}
GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org
Expand Down Expand Up @@ -65,11 +65,10 @@ jobs:
uses: golangci/[email protected]
with:
version: ${{ env.GOLANG_CI_LINT_VER }}
only-new-issues: true
skip-cache: true
- name: Run make go.mod check-diff
- name: Run make modtidy check-diff
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: make go.mod check-diff
run: make modtidy check-diff
- name: Parse release version and set REL_VERSION
run: python ./.github/scripts/get_release_version.py
- name: Setup test output
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ linters:
- varnamelen
- forcetypeassert
- ireturn
- golint
- golint
- nosnakecase
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ test-e2e-sh: test-deps
e2e-build-run-sh: build test-e2e-sh

################################################################################
# Target: go.mod #
# Target: modtidy #
################################################################################
.PHONY: go.mod
go.mod:
.PHONY: modtidy
modtidy:
go mod tidy -compat=1.18

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion cmd/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ WARNING: If an app id is not provided, we will generate one using the format '<n
if annotateTargetResource != "" {
config = kubernetes.K8sAnnotatorConfig{
TargetResource: &annotateTargetResource,
} // nolint:exhaustivestruct
} //nolint:exhaustivestruct
if annotateTargetNamespace != "" {
config.TargetNamespace = &annotateTargetNamespace
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/kubernetes/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (p *K8sAnnotator) processInput(input io.Reader, out io.Writer, opts Annotat
if err != nil {
return err
}
items = append(items, runtime.RawExtension{Raw: annotatedJSON}) // nolint:exhaustivestruct
items = append(items, runtime.RawExtension{Raw: annotatedJSON}) //nolint:exhaustivestruct
}
sourceList.Items = items
result, err = yaml.Marshal(sourceList)
Expand Down Expand Up @@ -235,7 +235,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
kind := strings.ToLower(metaType.Kind)
switch kind {
case pod:
pod := &corev1.Pod{} // nolint:exhaustivestruct
pod := &corev1.Pod{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, pod); err != nil {
return nil, false, err
}
Expand All @@ -244,7 +244,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = podAnnotationsPath
ns = getNamespaceOrDefault(pod)
case cronjob:
cronjob := &batchv1beta1.CronJob{} // nolint:exhaustivestruct
cronjob := &batchv1beta1.CronJob{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, cronjob); err != nil {
return nil, false, err
}
Expand All @@ -253,7 +253,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = cronjobAnnotationsPath
ns = getNamespaceOrDefault(cronjob)
case deployment:
deployment := &appsv1.Deployment{} // nolint:exhaustivestruct
deployment := &appsv1.Deployment{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, deployment); err != nil {
return nil, false, err
}
Expand All @@ -262,7 +262,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = templateAnnotationsPath
ns = getNamespaceOrDefault(deployment)
case replicaset:
replicaset := &appsv1.ReplicaSet{} // nolint:exhaustivestruct
replicaset := &appsv1.ReplicaSet{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, replicaset); err != nil {
return nil, false, err
}
Expand All @@ -271,7 +271,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = templateAnnotationsPath
ns = getNamespaceOrDefault(replicaset)
case job:
job := &batchv1.Job{} // nolint:exhaustivestruct
job := &batchv1.Job{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, job); err != nil {
return nil, false, err
}
Expand All @@ -280,7 +280,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = templateAnnotationsPath
ns = getNamespaceOrDefault(job)
case statefulset:
statefulset := &appsv1.StatefulSet{} // nolint:exhaustivestruct
statefulset := &appsv1.StatefulSet{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, statefulset); err != nil {
return nil, false, err
}
Expand All @@ -289,7 +289,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
path = templateAnnotationsPath
ns = getNamespaceOrDefault(statefulset)
case daemonset:
daemonset := &appsv1.DaemonSet{} // nolint:exhaustivestruct
daemonset := &appsv1.DaemonSet{} //nolint:exhaustivestruct
if err := yaml.Unmarshal(input, daemonset); err != nil {
return nil, false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/annotator_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AnnotateOptions struct {
type AnnoteOption func(*AnnotateOptions)

func NewAnnotateOptions(opts ...AnnoteOption) AnnotateOptions {
config := AnnotateOptions{} // nolint:exhaustivestruct
config := AnnotateOptions{} //nolint:exhaustivestruct
for _, opt := range opts {
opt(&config)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/annotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type annotation struct {
optionFactory func() AnnotateOptions
}

// nolint
//nolint:maintidx
func TestAnnotate(t *testing.T) {
// Helper function used to order test documents.
sortDocs := func(docs []string) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func Init(config InitConfiguration) error {

stopSpinning := print.Spinner(os.Stdout, msg)
defer stopSpinning(print.Failure)
// nolint
err := install(config)
if err != nil {
if err := install(config); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/mtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

const (
systemConfigName = "daprsystem"
trustBundleSecretName = "dapr-trust-bundle" // nolint:gosec
trustBundleSecretName = "dapr-trust-bundle" //nolint:gosec
warningDaysForCertExpiry = 30 // in days.
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func applyCRDs(version string) error {
for _, crd := range crds {
url := fmt.Sprintf("https://raw.githubusercontent.com/dapr/dapr/%s/charts/dapr/crds/%s.yaml", version, crd)

resp, _ := http.Get(url) // nolint:gosec
resp, _ := http.Get(url) //nolint:gosec
if resp != nil && resp.StatusCode == 200 {
defer resp.Body.Close()

Expand Down
6 changes: 3 additions & 3 deletions pkg/standalone/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (meta *DaprMeta) portExists(port int) bool {
if port <= 0 {
return false
}
// nolint
//nolint
_, ok := meta.ExistingPorts[port]
if ok {
return true
Expand Down Expand Up @@ -344,7 +344,7 @@ func getAppCommand(config *RunConfig) *exec.Cmd {
}

func Run(config *RunConfig) (*RunOutput, error) {
// nolint
//nolint
err := config.validate()
if err != nil {
return nil, err
Expand All @@ -355,7 +355,7 @@ func Run(config *RunConfig) (*RunOutput, error) {
return nil, err
}

// nolint
//nolint
var appCMD *exec.Cmd = getAppCommand(config)
return &RunOutput{
DaprCMD: daprCMD,
Expand Down
10 changes: 5 additions & 5 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func createSlimConfiguration(wg *sync.WaitGroup, errorChan chan<- error, info in
func makeDefaultComponentsDir() error {
// Make default components directory.
componentsDir := DefaultComponentsDirPath()
// nolint
//nolint
_, err := os.Stat(componentsDir)
if os.IsNotExist(err) {
errDir := os.MkdirAll(componentsDir, 0o755)
Expand Down Expand Up @@ -821,7 +821,7 @@ func untar(reader io.Reader, targetDir string, binaryFilePrefix string) (string,
foundBinary := ""
for {
header, err := tr.Next()
// nolint
//nolint
if err == io.EOF {
break
} else if err != nil {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ func downloadFile(dir string, url string) (string, error) {
},
}

req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err
}
Expand All @@ -1080,9 +1080,9 @@ func downloadFile(dir string, url string) (string, error) {

defer resp.Body.Close()

if resp.StatusCode == 404 {
if resp.StatusCode == http.StatusNotFound {
return "", fmt.Errorf("version not found from url: %s", url)
} else if resp.StatusCode != 200 {
} else if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("download failed with %d", resp.StatusCode)
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/standalone/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"time"

"github.com/dapr/cli/utils"
)
Expand Down Expand Up @@ -48,7 +49,8 @@ func getTestServer(expectedPath, resp string) (*httptest.Server, int) {

func getTestSocketServerFunc(handler http.Handler, appID, path string) (*http.Server, net.Listener) {
s := &http.Server{
Handler: handler,
Handler: handler,
ReadHeaderTimeout: time.Duration(5) * time.Second,
}

socket := utils.GetSocket(path, appID, "http")
Expand All @@ -61,7 +63,8 @@ func getTestSocketServerFunc(handler http.Handler, appID, path string) (*http.Se

func getTestSocketServer(expectedPath, resp, appID, path string) (*http.Server, net.Listener) {
s := &http.Server{
Handler: handlerTestPathResp(expectedPath, resp),
Handler: handlerTestPathResp(expectedPath, resp),
ReadHeaderTimeout: time.Duration(5) * time.Second,
}

socket := utils.GetSocket(path, appID, "http")
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func GetDaprVersion() (string, error) {
}

func GetVersionFromURL(releaseURL string, parseVersion func(body []byte) (string, error)) (string, error) {
req, err := http.NewRequest("GET", releaseURL, nil)
req, err := http.NewRequest(http.MethodGet, releaseURL, nil)
if err != nil {
return "", err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestGetVersionsGithub(t *testing.T) {
},
}
m := http.NewServeMux()
s := http.Server{Addr: ":12345", Handler: m}
s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}

for _, tc := range tests {
body := tc.ResponseBody
Expand Down Expand Up @@ -272,7 +273,7 @@ entries:
},
}
m := http.NewServeMux()
s := http.Server{Addr: ":12346", Handler: m}
s := http.Server{Addr: ":12346", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}

for _, tc := range tests {
body := tc.ResponseBody
Expand Down
21 changes: 11 additions & 10 deletions tests/e2e/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var supportedUpgradePaths = []upgradePath{
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"},
},
},
// test downgrade
// test downgrade.
{
previous: common.VersionDetails{
RuntimeVersion: "1.8.0",
Expand Down Expand Up @@ -121,13 +121,13 @@ func getTestsOnUpgrade(p upgradePath, installOpts, upgradeOpts common.TestOption
details := p.next

tests = append(tests, []common.TestCase{
{"upgrade to " + details.RuntimeVersion, common.UpgradeTest(details, upgradeOpts)},
{"crds exist " + details.RuntimeVersion, common.CRDTest(details, upgradeOpts)},
{"clusterroles exist " + details.RuntimeVersion, common.ClusterRolesTest(details, upgradeOpts)},
{"clusterrolebindings exist " + details.RuntimeVersion, common.ClusterRoleBindingsTest(details, upgradeOpts)},
{"previously applied components exist " + details.RuntimeVersion, common.ComponentsTestOnInstallUpgrade(upgradeOpts)},
{"check mtls " + details.RuntimeVersion, common.MTLSTestOnInstallUpgrade(upgradeOpts)},
{"status check " + details.RuntimeVersion, common.StatusTestOnInstallUpgrade(details, upgradeOpts)},
{Name: "upgrade to " + details.RuntimeVersion, Callable: common.UpgradeTest(details, upgradeOpts)},
{Name: "crds exist " + details.RuntimeVersion, Callable: common.CRDTest(details, upgradeOpts)},
{Name: "clusterroles exist " + details.RuntimeVersion, Callable: common.ClusterRolesTest(details, upgradeOpts)},
{Name: "clusterrolebindings exist " + details.RuntimeVersion, Callable: common.ClusterRoleBindingsTest(details, upgradeOpts)},
{Name: "previously applied components exist " + details.RuntimeVersion, Callable: common.ComponentsTestOnInstallUpgrade(upgradeOpts)},
{Name: "check mtls " + details.RuntimeVersion, Callable: common.MTLSTestOnInstallUpgrade(upgradeOpts)},
{Name: "status check " + details.RuntimeVersion, Callable: common.StatusTestOnInstallUpgrade(details, upgradeOpts)},
}...)

// uninstall.
Expand All @@ -141,8 +141,9 @@ func getTestsOnUpgrade(p upgradePath, installOpts, upgradeOpts common.TestOption
})...)

// delete CRDs if exist.
tests = append(tests, common.TestCase{"delete CRDs " + p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)})
tests = append(tests, common.TestCase{"delete CRDs " + p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)})
tests = append(tests,
common.TestCase{Name: "delete CRDs " + p.previous.RuntimeVersion, Callable: common.DeleteCRD(p.previous.CustomResourceDefs)},
common.TestCase{Name: "delete CRDs " + p.next.RuntimeVersion, Callable: common.DeleteCRD(p.next.CustomResourceDefs)})

return tests
}
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func RunCmdAndWait(name string, args ...string) (string, error) {
}
errB, err := io.ReadAll(stderr)
if err != nil {
// nolint
//nolint
return "", nil
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func CreateDirectory(dir string) error {

// IsDockerInstalled checks whether docker is installed/running.
func IsDockerInstalled() bool {
// nolint:staticcheck
//nolint:staticcheck
cli, err := client.NewEnvClient()
if err != nil {
return false
Expand Down

0 comments on commit 65855d5

Please sign in to comment.