Skip to content

Commit 65855d5

Browse files
Upgrade linter to 1.49.0 (dapr#1051)
* 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]>
1 parent eaca34b commit 65855d5

17 files changed

+52
-49
lines changed

.github/workflows/dapr_cli.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ${{ matrix.os }}
3131
env:
3232
GOVER: 1.18
33-
GOLANG_CI_LINT_VER: v1.46.2
33+
GOLANG_CI_LINT_VER: v1.49.0
3434
GOOS: ${{ matrix.target_os }}
3535
GOARCH: ${{ matrix.target_arch }}
3636
GOPROXY: https://proxy.golang.org
@@ -65,11 +65,10 @@ jobs:
6565
uses: golangci/[email protected]
6666
with:
6767
version: ${{ env.GOLANG_CI_LINT_VER }}
68-
only-new-issues: true
6968
skip-cache: true
70-
- name: Run make go.mod check-diff
69+
- name: Run make modtidy check-diff
7170
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
72-
run: make go.mod check-diff
71+
run: make modtidy check-diff
7372
- name: Parse release version and set REL_VERSION
7473
run: python ./.github/scripts/get_release_version.py
7574
- name: Setup test output

.golangci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,5 @@ linters:
260260
- varnamelen
261261
- forcetypeassert
262262
- ireturn
263-
- golint
263+
- golint
264+
- nosnakecase

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ test-e2e-sh: test-deps
184184
e2e-build-run-sh: build test-e2e-sh
185185

186186
################################################################################
187-
# Target: go.mod #
187+
# Target: modtidy #
188188
################################################################################
189-
.PHONY: go.mod
190-
go.mod:
189+
.PHONY: modtidy
190+
modtidy:
191191
go mod tidy -compat=1.18
192192

193193
################################################################################

cmd/annotate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ WARNING: If an app id is not provided, we will generate one using the format '<n
113113
if annotateTargetResource != "" {
114114
config = kubernetes.K8sAnnotatorConfig{
115115
TargetResource: &annotateTargetResource,
116-
} // nolint:exhaustivestruct
116+
} //nolint:exhaustivestruct
117117
if annotateTargetNamespace != "" {
118118
config.TargetNamespace = &annotateTargetNamespace
119119
}

pkg/kubernetes/annotator.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (p *K8sAnnotator) processInput(input io.Reader, out io.Writer, opts Annotat
160160
if err != nil {
161161
return err
162162
}
163-
items = append(items, runtime.RawExtension{Raw: annotatedJSON}) // nolint:exhaustivestruct
163+
items = append(items, runtime.RawExtension{Raw: annotatedJSON}) //nolint:exhaustivestruct
164164
}
165165
sourceList.Items = items
166166
result, err = yaml.Marshal(sourceList)
@@ -235,7 +235,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
235235
kind := strings.ToLower(metaType.Kind)
236236
switch kind {
237237
case pod:
238-
pod := &corev1.Pod{} // nolint:exhaustivestruct
238+
pod := &corev1.Pod{} //nolint:exhaustivestruct
239239
if err := yaml.Unmarshal(input, pod); err != nil {
240240
return nil, false, err
241241
}
@@ -244,7 +244,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
244244
path = podAnnotationsPath
245245
ns = getNamespaceOrDefault(pod)
246246
case cronjob:
247-
cronjob := &batchv1beta1.CronJob{} // nolint:exhaustivestruct
247+
cronjob := &batchv1beta1.CronJob{} //nolint:exhaustivestruct
248248
if err := yaml.Unmarshal(input, cronjob); err != nil {
249249
return nil, false, err
250250
}
@@ -253,7 +253,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
253253
path = cronjobAnnotationsPath
254254
ns = getNamespaceOrDefault(cronjob)
255255
case deployment:
256-
deployment := &appsv1.Deployment{} // nolint:exhaustivestruct
256+
deployment := &appsv1.Deployment{} //nolint:exhaustivestruct
257257
if err := yaml.Unmarshal(input, deployment); err != nil {
258258
return nil, false, err
259259
}
@@ -262,7 +262,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
262262
path = templateAnnotationsPath
263263
ns = getNamespaceOrDefault(deployment)
264264
case replicaset:
265-
replicaset := &appsv1.ReplicaSet{} // nolint:exhaustivestruct
265+
replicaset := &appsv1.ReplicaSet{} //nolint:exhaustivestruct
266266
if err := yaml.Unmarshal(input, replicaset); err != nil {
267267
return nil, false, err
268268
}
@@ -271,7 +271,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
271271
path = templateAnnotationsPath
272272
ns = getNamespaceOrDefault(replicaset)
273273
case job:
274-
job := &batchv1.Job{} // nolint:exhaustivestruct
274+
job := &batchv1.Job{} //nolint:exhaustivestruct
275275
if err := yaml.Unmarshal(input, job); err != nil {
276276
return nil, false, err
277277
}
@@ -280,7 +280,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
280280
path = templateAnnotationsPath
281281
ns = getNamespaceOrDefault(job)
282282
case statefulset:
283-
statefulset := &appsv1.StatefulSet{} // nolint:exhaustivestruct
283+
statefulset := &appsv1.StatefulSet{} //nolint:exhaustivestruct
284284
if err := yaml.Unmarshal(input, statefulset); err != nil {
285285
return nil, false, err
286286
}
@@ -289,7 +289,7 @@ func (p *K8sAnnotator) annotateYAML(input []byte, config AnnotateOptions) ([]byt
289289
path = templateAnnotationsPath
290290
ns = getNamespaceOrDefault(statefulset)
291291
case daemonset:
292-
daemonset := &appsv1.DaemonSet{} // nolint:exhaustivestruct
292+
daemonset := &appsv1.DaemonSet{} //nolint:exhaustivestruct
293293
if err := yaml.Unmarshal(input, daemonset); err != nil {
294294
return nil, false, err
295295
}

pkg/kubernetes/annotator_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type AnnotateOptions struct {
4747
type AnnoteOption func(*AnnotateOptions)
4848

4949
func NewAnnotateOptions(opts ...AnnoteOption) AnnotateOptions {
50-
config := AnnotateOptions{} // nolint:exhaustivestruct
50+
config := AnnotateOptions{} //nolint:exhaustivestruct
5151
for _, opt := range opts {
5252
opt(&config)
5353
}

pkg/kubernetes/annotator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type annotation struct {
3434
optionFactory func() AnnotateOptions
3535
}
3636

37-
// nolint
37+
//nolint:maintidx
3838
func TestAnnotate(t *testing.T) {
3939
// Helper function used to order test documents.
4040
sortDocs := func(docs []string) {

pkg/kubernetes/kubernetes.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ func Init(config InitConfiguration) error {
5959

6060
stopSpinning := print.Spinner(os.Stdout, msg)
6161
defer stopSpinning(print.Failure)
62-
// nolint
63-
err := install(config)
64-
if err != nil {
62+
if err := install(config); err != nil {
6563
return err
6664
}
6765

pkg/kubernetes/mtls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
const (
3535
systemConfigName = "daprsystem"
36-
trustBundleSecretName = "dapr-trust-bundle" // nolint:gosec
36+
trustBundleSecretName = "dapr-trust-bundle" //nolint:gosec
3737
warningDaysForCertExpiry = 30 // in days.
3838
)
3939

pkg/kubernetes/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func applyCRDs(version string) error {
143143
for _, crd := range crds {
144144
url := fmt.Sprintf("https://raw.githubusercontent.com/dapr/dapr/%s/charts/dapr/crds/%s.yaml", version, crd)
145145

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

pkg/standalone/run.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (meta *DaprMeta) portExists(port int) bool {
189189
if port <= 0 {
190190
return false
191191
}
192-
// nolint
192+
//nolint
193193
_, ok := meta.ExistingPorts[port]
194194
if ok {
195195
return true
@@ -344,7 +344,7 @@ func getAppCommand(config *RunConfig) *exec.Cmd {
344344
}
345345

346346
func Run(config *RunConfig) (*RunOutput, error) {
347-
// nolint
347+
//nolint
348348
err := config.validate()
349349
if err != nil {
350350
return nil, err
@@ -355,7 +355,7 @@ func Run(config *RunConfig) (*RunOutput, error) {
355355
return nil, err
356356
}
357357

358-
// nolint
358+
//nolint
359359
var appCMD *exec.Cmd = getAppCommand(config)
360360
return &RunOutput{
361361
DaprCMD: daprCMD,

pkg/standalone/standalone.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ func createSlimConfiguration(wg *sync.WaitGroup, errorChan chan<- error, info in
696696
func makeDefaultComponentsDir() error {
697697
// Make default components directory.
698698
componentsDir := DefaultComponentsDirPath()
699-
// nolint
699+
//nolint
700700
_, err := os.Stat(componentsDir)
701701
if os.IsNotExist(err) {
702702
errDir := os.MkdirAll(componentsDir, 0o755)
@@ -821,7 +821,7 @@ func untar(reader io.Reader, targetDir string, binaryFilePrefix string) (string,
821821
foundBinary := ""
822822
for {
823823
header, err := tr.Next()
824-
// nolint
824+
//nolint
825825
if err == io.EOF {
826826
break
827827
} else if err != nil {
@@ -1068,7 +1068,7 @@ func downloadFile(dir string, url string) (string, error) {
10681068
},
10691069
}
10701070

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

10811081
defer resp.Body.Close()
10821082

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

pkg/standalone/testutils.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net"
2020
"net/http"
2121
"net/http/httptest"
22+
"time"
2223

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

4950
func getTestSocketServerFunc(handler http.Handler, appID, path string) (*http.Server, net.Listener) {
5051
s := &http.Server{
51-
Handler: handler,
52+
Handler: handler,
53+
ReadHeaderTimeout: time.Duration(5) * time.Second,
5254
}
5355

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

6264
func getTestSocketServer(expectedPath, resp, appID, path string) (*http.Server, net.Listener) {
6365
s := &http.Server{
64-
Handler: handlerTestPathResp(expectedPath, resp),
66+
Handler: handlerTestPathResp(expectedPath, resp),
67+
ReadHeaderTimeout: time.Duration(5) * time.Second,
6568
}
6669

6770
socket := utils.GetSocket(path, appID, "http")

pkg/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func GetDaprVersion() (string, error) {
7171
}
7272

7373
func GetVersionFromURL(releaseURL string, parseVersion func(body []byte) (string, error)) (string, error) {
74-
req, err := http.NewRequest("GET", releaseURL, nil)
74+
req, err := http.NewRequest(http.MethodGet, releaseURL, nil)
7575
if err != nil {
7676
return "", err
7777
}

pkg/version/version_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"net/http"
2020
"testing"
21+
"time"
2122

2223
"github.com/stretchr/testify/assert"
2324
)
@@ -163,7 +164,7 @@ func TestGetVersionsGithub(t *testing.T) {
163164
},
164165
}
165166
m := http.NewServeMux()
166-
s := http.Server{Addr: ":12345", Handler: m}
167+
s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
167168

168169
for _, tc := range tests {
169170
body := tc.ResponseBody
@@ -272,7 +273,7 @@ entries:
272273
},
273274
}
274275
m := http.NewServeMux()
275-
s := http.Server{Addr: ":12346", Handler: m}
276+
s := http.Server{Addr: ":12346", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
276277

277278
for _, tc := range tests {
278279
body := tc.ResponseBody

tests/e2e/upgrade/upgrade_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var supportedUpgradePaths = []upgradePath{
7777
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"},
7878
},
7979
},
80-
// test downgrade
80+
// test downgrade.
8181
{
8282
previous: common.VersionDetails{
8383
RuntimeVersion: "1.8.0",
@@ -121,13 +121,13 @@ func getTestsOnUpgrade(p upgradePath, installOpts, upgradeOpts common.TestOption
121121
details := p.next
122122

123123
tests = append(tests, []common.TestCase{
124-
{"upgrade to " + details.RuntimeVersion, common.UpgradeTest(details, upgradeOpts)},
125-
{"crds exist " + details.RuntimeVersion, common.CRDTest(details, upgradeOpts)},
126-
{"clusterroles exist " + details.RuntimeVersion, common.ClusterRolesTest(details, upgradeOpts)},
127-
{"clusterrolebindings exist " + details.RuntimeVersion, common.ClusterRoleBindingsTest(details, upgradeOpts)},
128-
{"previously applied components exist " + details.RuntimeVersion, common.ComponentsTestOnInstallUpgrade(upgradeOpts)},
129-
{"check mtls " + details.RuntimeVersion, common.MTLSTestOnInstallUpgrade(upgradeOpts)},
130-
{"status check " + details.RuntimeVersion, common.StatusTestOnInstallUpgrade(details, upgradeOpts)},
124+
{Name: "upgrade to " + details.RuntimeVersion, Callable: common.UpgradeTest(details, upgradeOpts)},
125+
{Name: "crds exist " + details.RuntimeVersion, Callable: common.CRDTest(details, upgradeOpts)},
126+
{Name: "clusterroles exist " + details.RuntimeVersion, Callable: common.ClusterRolesTest(details, upgradeOpts)},
127+
{Name: "clusterrolebindings exist " + details.RuntimeVersion, Callable: common.ClusterRoleBindingsTest(details, upgradeOpts)},
128+
{Name: "previously applied components exist " + details.RuntimeVersion, Callable: common.ComponentsTestOnInstallUpgrade(upgradeOpts)},
129+
{Name: "check mtls " + details.RuntimeVersion, Callable: common.MTLSTestOnInstallUpgrade(upgradeOpts)},
130+
{Name: "status check " + details.RuntimeVersion, Callable: common.StatusTestOnInstallUpgrade(details, upgradeOpts)},
131131
}...)
132132

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

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

147148
return tests
148149
}

utils/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func RunCmdAndWait(name string, args ...string) (string, error) {
118118
}
119119
errB, err := io.ReadAll(stderr)
120120
if err != nil {
121-
// nolint
121+
//nolint
122122
return "", nil
123123
}
124124

@@ -151,7 +151,7 @@ func CreateDirectory(dir string) error {
151151

152152
// IsDockerInstalled checks whether docker is installed/running.
153153
func IsDockerInstalled() bool {
154-
// nolint:staticcheck
154+
//nolint:staticcheck
155155
cli, err := client.NewEnvClient()
156156
if err != nil {
157157
return false

0 commit comments

Comments
 (0)