Skip to content

Commit b3e6b99

Browse files
committed
Fix linger issues
1 parent eaf2253 commit b3e6b99

20 files changed

Lines changed: 62 additions & 40 deletions

File tree

‎.golangci.yaml‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ linters:
7272
- gocritic
7373

7474
# See config below
75-
- gomodguard
75+
- gomodguard_v2
7676

7777
# Inspects source code for security problems.
7878
- gosec
@@ -154,27 +154,26 @@ linters:
154154
checks:
155155
- all
156156
- "-QF1008" # Disable https://staticcheck.dev/docs/checks/#QF1008
157-
gomodguard:
157+
gomodguard_v2:
158158
blocked:
159-
modules:
160-
- github.com/ghodss/yaml:
161-
recommendations:
162-
- sigs.k8s.io/yaml
163-
- go.uber.org/atomic:
164-
recommendations:
165-
- sync/atomic
166-
- io/ioutil:
167-
recommendations:
168-
- os
169-
- io
170-
- github.com/hashicorp/go-multierror:
171-
recommendations:
172-
- errors
173-
reason: use errors.Join
174-
- go.uber.org/multierr:
175-
recommendations:
176-
- errors
177-
reason: use errors.Join
159+
- module: github.com/ghodss/yaml
160+
recommendations:
161+
- sigs.k8s.io/yaml
162+
- module: go.uber.org/atomic
163+
recommendations:
164+
- sync/atomic
165+
- module: io/ioutil
166+
recommendations:
167+
- os
168+
- io
169+
- module: github.com/hashicorp/go-multierror
170+
recommendations:
171+
- errors
172+
reason: use errors.Join
173+
- module: go.uber.org/multierr
174+
recommendations:
175+
- errors
176+
reason: use errors.Join
178177
revive:
179178
rules:
180179
# use unparam linter instead - defaults are better
@@ -190,10 +189,15 @@ linters:
190189
rules:
191190
- linters:
192191
- staticcheck
193-
text: corev1.Endpoint.* is deprecated
192+
text: (corev1.Endpoint|k8s.io/api/core/v1.Endpoints).* is deprecated
194193
- linters:
195194
- staticcheck
196195
text: .*NewSimpleClientset is deprecated
196+
# These tests intentionally exercise fields marked as deprecated.
197+
- linters:
198+
- staticcheck
199+
text: 'is deprecated: This field is deprecated'
200+
path: _test\.go
197201
- linters:
198202
- gosec
199203
- noctx

‎apis/deprecated.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func getPrefixedNamedFieldValues(prefix string, obj interface{}) (map[string]ref
116116
// getInterface returns the interface value of the reflected object.
117117
func getInterface(a reflect.Value) interface{} {
118118
switch a.Kind() {
119-
case reflect.Ptr:
119+
case reflect.Pointer:
120120
if a.IsNil() {
121121
return nil
122122
}
@@ -137,7 +137,7 @@ func getInterface(a reflect.Value) interface{} {
137137
// nonZero returns true if a is nil or reflect.Zero.
138138
func nonZero(a reflect.Value) bool {
139139
switch a.Kind() {
140-
case reflect.Ptr:
140+
case reflect.Pointer:
141141
if a.IsNil() {
142142
return false
143143
}
@@ -168,7 +168,7 @@ func differ(a, b reflect.Value) bool {
168168
}
169169

170170
switch a.Kind() {
171-
case reflect.Ptr:
171+
case reflect.Pointer:
172172
if a.IsNil() || b.IsNil() {
173173
return a.IsNil() != b.IsNil()
174174
}

‎configmap/hash-gen/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func main() {
3838
// processFile reads the ConfigMap manifest from a file and adds or updates the label
3939
// containing the checksum of it's _example data if present.
4040
func processFile(fileName string) error {
41+
//nolint:gosec // This build-time tool reads ConfigMap manifests passed as CLI args; path traversal is not a concern.
4142
in, err := os.ReadFile(fileName)
4243
if err != nil {
4344
return fmt.Errorf("failed to read file: %w", err)

‎configmap/load.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func Load(p string) (map[string]string, error) {
4646
if info.IsDir() {
4747
return nil
4848
}
49+
//nolint:gosec // Reading files from a trusted mounted ConfigMap volume; symlink traversal is not a concern.
4950
b, err := os.ReadFile(p)
5051
if err != nil {
5152
return err

‎injection/config.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func ParseAndGetRESTConfigOrDie() *rest.Config {
4040
}
4141

4242
// GetRESTConfig returns a rest.Config to be used for kubernetes client creation.
43+
//
4344
// Deprecated: use environment.ClientConfig package
4445
func GetRESTConfig(serverURL, kubeconfig string) (*rest.Config, error) {
4546
env := environment.ClientConfig{

‎injection/sharedmain/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func GetObservabilityConfig(ctx context.Context) (*observability.Config, error)
142142

143143
// EnableInjectionOrDie enables Knative Injection and starts the informers.
144144
// Both Context and Config are optional.
145+
//
145146
// Deprecated: use injection.EnableInjectionOrDie
146147
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) context.Context {
147148
ctx, startInformers := injection.EnableInjectionOrDie(ctx, cfg)

‎kmeta/map.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ package kmeta
1919
import "knative.dev/pkg/kmap"
2020

2121
// CopyMap makes a copy of the map.
22+
//
2223
// Deprecated: use kmap.Copy
2324
var CopyMap = kmap.Copy
2425

2526
// UnionMaps returns a map constructed from the union of input maps.
2627
// where values from latter maps win.
28+
//
2729
// Deprecated: use kmap.Union
2830
var UnionMaps = kmap.Union
2931

3032
// FilterMap creates a copy of the provided map, filtering out the elements
3133
// that match `filter`.
3234
// nil `filter` is accepted.
35+
//
3336
// Deprecated: use kmap.Filter
3437
var FilterMap = kmap.Filter

‎kmp/reporters_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type testStruct struct {
3030
StructField childStruct `json:"child"`
3131
Omit string `json:"omit,omitempty"`
3232
Ignore string `json:"-"`
33-
Dash string `json:"-,"`
33+
//nolint:staticcheck // We actually want to test this broken json option works.
34+
Dash string `json:"-,"`
3435
//nolint:staticcheck // We actually want to test this broken json options work
3536
MultiComma string `json:"multi,omitempty,somethingelse"`
3637
}

‎network/h2c.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ import (
2424
"time"
2525

2626
"golang.org/x/net/http2"
27-
"golang.org/x/net/http2/h2c"
2827
)
2928

3029
// NewServer returns a new HTTP Server with HTTP2 handler.
3130
func NewServer(addr string, h http.Handler) *http.Server {
3231
h1s := &http.Server{
3332
Addr: addr,
34-
Handler: h2c.NewHandler(h, &http2.Server{}),
33+
Handler: h,
3534
ReadHeaderTimeout: time.Minute, // https://medium.com/a-journey-with-go/go-understand-and-mitigate-slowloris-attack-711c1b1403f6
35+
Protocols: new(http.Protocols),
3636
}
37+
// Serve HTTP/1.1 alongside unencrypted HTTP/2 (h2c) using the standard
38+
// library instead of the deprecated golang.org/x/net/http2/h2c handler.
39+
h1s.Protocols.SetHTTP1(true)
40+
h1s.Protocols.SetUnencryptedHTTP2(true)
3741

3842
return h1s
3943
}
@@ -50,9 +54,8 @@ func newH2CTransport(disableCompression bool) http.RoundTripper {
5054
return &http2.Transport{
5155
AllowHTTP: true,
5256
DisableCompression: disableCompression,
53-
DialTLS: func(netw, addr string, _ *tls.Config) (net.Conn, error) {
54-
return DialWithBackOff(context.Background(),
55-
netw, addr)
57+
DialTLSContext: func(ctx context.Context, netw, addr string, _ *tls.Config) (net.Conn, error) {
58+
return DialWithBackOff(ctx, netw, addr)
5659
},
5760
}
5861
}

‎network/transports.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ func dialBackOffHelper(ctx context.Context, network, address string, bo wait.Bac
8585
dialer := &net.Dialer{
8686
Timeout: bo.Duration, // Initial duration.
8787
KeepAlive: 5 * time.Second,
88-
DualStack: true,
8988
}
9089
start := time.Now()
9190
for {

0 commit comments

Comments
 (0)