Skip to content

Commit 8c43f14

Browse files
authored
Merge pull request #211 from erikgb/enable-more-linters
Enable some additional golangci-lint linters
2 parents 31a571f + c45d35e commit 8c43f14

13 files changed

Lines changed: 41 additions & 34 deletions

File tree

.golangci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
version: "2"
22
linters:
3+
default: standard
4+
enable:
5+
- contextcheck
6+
- errorlint
7+
- gosec
8+
- misspell
9+
- modernize
10+
- nilnil
311
settings:
412
errcheck:
513
exclude-functions:

api/accurate/v1/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func TestFuzzyConversion(t *testing.T) {
1818
}))
1919
}
2020

21-
func SubNamespaceStatusFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
22-
return []interface{}{
21+
func SubNamespaceStatusFuzzFunc(_ runtimeserializer.CodecFactory) []any {
22+
return []any{
2323
SubNamespaceStatusFuzzer,
2424
}
2525
}

api/accurate/v2alpha1/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func TestFuzzyConversion(t *testing.T) {
1818
}))
1919
}
2020

21-
func SubNamespaceStatusFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
22-
return []interface{}{
21+
func SubNamespaceStatusFuzzFunc(_ runtimeserializer.CodecFactory) []any {
22+
return []any{
2323
SubNamespaceStatusFuzzer,
2424
}
2525
}

cmd/accurate-controller/sub/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ var rootCmd = &cobra.Command{
4242
cmd.SilenceUsage = true
4343
h, p, err := net.SplitHostPort(options.webhookAddr)
4444
if err != nil {
45-
return fmt.Errorf("invalid webhook address: %s, %v", options.webhookAddr, err)
45+
return fmt.Errorf("invalid webhook address: %s, %w", options.webhookAddr, err)
4646
}
4747
numPort, err := strconv.Atoi(p)
4848
if err != nil {
49-
return fmt.Errorf("invalid webhook address: %s, %v", options.webhookAddr, err)
49+
return fmt.Errorf("invalid webhook address: %s, %w", options.webhookAddr, err)
5050
}
5151
ns := os.Getenv("POD_NAMESPACE")
5252
if ns == "" {

cmd/accurate-controller/sub/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func subMain(ns, addr string, port int) error {
167167

168168
logger.Info("starting manager")
169169
if err := mgr.Start(ctx); err != nil {
170-
return fmt.Errorf("problem running manager: %s", err)
170+
return fmt.Errorf("problem running manager: %w", err)
171171
}
172172
return nil
173173
}

cmd/kubectl-accurate/sub/namespace_describe.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (o *nsDescribeOpts) Fill(streams genericiooptions.IOStreams, config *generi
5757
return nil
5858
}
5959

60-
func (o *nsDescribeOpts) printf(s string, args ...interface{}) {
60+
func (o *nsDescribeOpts) printf(s string, args ...any) {
6161
fmt.Fprintf(o.streams.Out, s, args...)
6262
}
6363

@@ -159,8 +159,7 @@ func (o *nsDescribeOpts) Run(ctx context.Context) error {
159159
for _, gvk := range cfg.Watches {
160160
o.printResource(ctx, w, gvk)
161161
}
162-
w.Flush()
163-
return nil
162+
return w.Flush()
164163
}
165164

166165
func (o *nsDescribeOpts) printResource(ctx context.Context, w io.Writer, gvk metav1.GroupVersionKind) {

controllers/namespace_controller_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ var _ = Describe("Namespace controller", func() {
113113
role1 := roleRes.DeepCopy()
114114
role1.SetNamespace("tmpl")
115115
role1.SetName("role1")
116-
role1.Object["rules"] = []interface{}{
117-
map[string]interface{}{
118-
"apiGroups": []interface{}{""},
119-
"resources": []interface{}{"pods"},
120-
"verbs": []interface{}{"get", "watch", "list"},
116+
role1.Object["rules"] = []any{
117+
map[string]any{
118+
"apiGroups": []any{""},
119+
"resources": []any{"pods"},
120+
"verbs": []any{"get", "watch", "list"},
121121
},
122122
}
123123
Expect(k8sClient.Create(ctx, role1)).To(Succeed())
@@ -126,19 +126,19 @@ var _ = Describe("Namespace controller", func() {
126126
role2.SetNamespace("tmpl")
127127
role2.SetName("role2")
128128
role2.SetAnnotations(map[string]string{constants.AnnPropagate: constants.PropagateCreate})
129-
role2.Object["rules"] = []interface{}{
130-
map[string]interface{}{
131-
"apiGroups": []interface{}{""},
132-
"resources": []interface{}{"pods"},
133-
"verbs": []interface{}{"get", "watch", "list"},
129+
role2.Object["rules"] = []any{
130+
map[string]any{
131+
"apiGroups": []any{""},
132+
"resources": []any{"pods"},
133+
"verbs": []any{"get", "watch", "list"},
134134
},
135135
}
136136
Expect(k8sClient.Create(ctx, role2)).To(Succeed())
137137

138138
secret := secretRes.DeepCopy()
139139
secret.SetNamespace("tmpl")
140140
secret.SetName("foo")
141-
secret.Object["data"] = map[string]interface{}{
141+
secret.Object["data"] = map[string]any{
142142
"foo": "MjAyMC0wOS0xM1QwNDozOToxMFo=",
143143
}
144144
secret.SetAnnotations(map[string]string{constants.AnnPropagate: constants.PropagateUpdate})
@@ -151,7 +151,7 @@ var _ = Describe("Namespace controller", func() {
151151
secret2 := secretRes.DeepCopy()
152152
secret2.SetNamespace("ns1")
153153
secret2.SetName("bar")
154-
secret2.Object["data"] = map[string]interface{}{
154+
secret2.Object["data"] = map[string]any{
155155
"bar": "MjAyMC0wOS0xM1QwNDozOToxMFo=",
156156
}
157157
secret2.SetAnnotations(map[string]string{constants.AnnPropagate: constants.PropagateUpdate})

controllers/subnamespace_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (r *SubNamespaceReconciler) finalize(ctx context.Context, sn *accuratev2.Su
9090
logger.Info("deleted namespace", "name", ns.Name)
9191
}
9292

93-
return r.removeFinalizer(context.Background(), sn)
93+
return r.removeFinalizer(ctx, sn)
9494
}
9595

9696
func (r *SubNamespaceReconciler) removeFinalizer(ctx context.Context, sn *accuratev2.SubNamespace) error {
@@ -102,8 +102,8 @@ func (r *SubNamespaceReconciler) removeFinalizer(ctx context.Context, sn *accura
102102
controllerutil.RemoveFinalizer(sn, constants.Finalizer)
103103

104104
// We'll use a JSON Merge Patch here to avoid removal of finalizers added by other controllers
105-
patch := map[string]interface{}{
106-
"metadata": map[string]interface{}{
105+
patch := map[string]any{
106+
"metadata": map[string]any{
107107
"finalizers": sn.GetFinalizers(),
108108
},
109109
}

e2e/run_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func kubectl(input []byte, args ...string) ([]byte, error) {
1212
stdout := new(bytes.Buffer)
1313
stderr := new(bytes.Buffer)
14-
cmd := exec.Command("kubectl", args...)
14+
cmd := exec.Command("kubectl", args...) // #nosec G204 -- args are static/test-controlled
1515
cmd.Stdout = stdout
1616
cmd.Stderr = stderr
1717
if input != nil {
@@ -21,7 +21,7 @@ func kubectl(input []byte, args ...string) ([]byte, error) {
2121
if err == nil {
2222
return stdout.Bytes(), nil
2323
}
24-
return nil, fmt.Errorf("kubectl failed with %s: stderr=%s", err, stderr)
24+
return nil, fmt.Errorf("kubectl failed with %w: stderr=%s", err, stderr.String())
2525
}
2626

2727
func kubectlSafe(input []byte, args ...string) []byte {

hooks/allow-cascade-delete/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var _ = BeforeSuite(func() {
119119
dialer := &net.Dialer{Timeout: time.Second}
120120
addrPort := fmt.Sprintf("%s:%d", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort)
121121
Eventually(func() error {
122-
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true})
122+
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true}) // #nosec G402 -- test environment with self-signed cert
123123
if err != nil {
124124
return err
125125
}

0 commit comments

Comments
 (0)