Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 106 additions & 70 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,115 @@
version: "2"
run:
timeout: 10m
modules-download-mode: readonly
issues-exit-code: 1
tests: true
modules-download-mode: readonly
allow-parallel-runners: false

linters:
fast: false
enable:
- errcheck
- copyloopvar
- gocritic
- gofumpt
- goimports
- gomodguard
- gosec
- govet
- misspell
- revive
- unconvert
- unparam
- unused
- whitespace
disable-all: false
presets:
- bugs
- unused

# all available settings of specific linters
linters-settings:
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goimports:
local-prefixes: sigs.k8s.io/gateway-api
govet:
enable:
- shadow
settings:
shadow:
# Whether to be strict about shadowing; can be noisy.
strict: false
misspell:
locale: US
ignore-words: []
gomodguard:
blocked:
# List of blocked modules.
modules:
- io/ioutil:
recommendations:
- io
- os
reason: "Deprecation of package ioutil in Go 1.16."

- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- durationcheck
- errchkjson
- errorlint
- exhaustive
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
- gomodguard
- gosec
- gosmopolitan
- loggercheck
- makezero
- misspell
- musttag
- nilerr
- nilnesserr
- noctx
- protogetter
- reassign
- recvcheck
- revive
- rowserrcheck
- spancheck
- sqlclosecheck
- testifylint
- unconvert
- unparam
- whitespace
- zerologlint
# all available settings of specific linters
settings:
gomodguard:
blocked:
# List of blocked modules.
modules:
- io/ioutil:
recommendations:
- io
- os
reason: Deprecation of package ioutil in Go 1.16.
govet:
enable:
- shadow
settings:
shadow:
# Whether to be strict about shadowing; can be noisy.
strict: false
misspell:
locale: US
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
# Exclude some linters from running on tests files.
- linters:
- dupl
- errcheck
- gocyclo
path: _test\.go
# Too many false positives - for examples see: https://github.com/Antonboom/testifylint/issues/67
- linters:
- testifylint
text: require must only be used in the goroutine running the test function
- linters:
- testifylint
text: contains assertions that must only be used in the goroutine running the test function
# It is valid usage to wrap errors without using %w to not make them part of
# the API contract.
- linters:
- errorlint
text: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
- path: (.+)\.go$
text: Using the variable on range scope `tc` in function literal
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
# Too many false positives - for examples see: https://github.com/Antonboom/testifylint/issues/67
- linters:
- testifylint
text: "require must only be used in the goroutine running the test function"
- linters:
- testifylint
text: "contains assertions that must only be used in the goroutine running the test function"
# It is valid usage to wrap errors without using %w to not make them part of
# the API contract.
- linters: ["errorlint"]
text: "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
exclude:
- Using the variable on range scope `tc` in function literal
formatters:
enable:
- gofumpt
- goimports
settings:
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goimports:
local-prefixes:
- sigs.k8s.io/gateway-api
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
1 change: 1 addition & 0 deletions apis/v1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ const (
//
// Note: This condition is not really "deprecated", but rather "reserved"; however, deprecated triggers Go linters
// to alert about usage.
//
// Deprecated: Ready is reserved for future use
GatewayConditionReady GatewayConditionType = "Ready"

Expand Down
4 changes: 2 additions & 2 deletions conformance/echo-basic/echo-basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func TestEchoHandler(t *testing.T) {

// Test RequestAssertions struct contains expected context namespace
expectedNamespace := context.Namespace
if responseAssertions.Context.Namespace != expectedNamespace {
t.Errorf("Expected X-Content-Type-Options header %s, but got %s", expectedNamespace, responseAssertions.Context.Namespace)
if responseAssertions.Namespace != expectedNamespace {
t.Errorf("Expected X-Content-Type-Options header %s, but got %s", expectedNamespace, responseAssertions.Namespace)
}
}

Expand Down
10 changes: 6 additions & 4 deletions conformance/echo-basic/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *echoServer) EchoTwo(ctx context.Context, in *pb.EchoRequest) (*pb.EchoR
return s.doEcho("EchoTwo", ctx, in)
}

func runServer(config serverConfig) (int, int) { //nolint:unparam
func runServer(ctx context.Context, config serverConfig) (int, int) { //nolint:unparam
svcs := pb.File_grpcecho_proto.Services()
svcd := svcs.ByName("GrpcEcho")
if svcd == nil {
Expand All @@ -173,7 +173,8 @@ func runServer(config serverConfig) (int, int) { //nolint:unparam
fullService := string(svcd.FullName())

// Set up plaintext server.
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPPort))
plc := net.ListenConfig{}
lis, err := plc.Listen(ctx, "tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPPort))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of my curiosity, was this a bug or a linter complain?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in this PR is done to fix new linter complains. In this case, ListenConfig is introduced to add a Listen function accepting a context.

if err != nil {
fmt.Printf("failed to listen: %v\n", err)
os.Exit(1)
Expand All @@ -200,7 +201,8 @@ func runServer(config serverConfig) (int, int) { //nolint:unparam
fmt.Printf("failed to create credentials: %v\n", err)
os.Exit(1)
}
secureListener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPSPort))
slc := net.ListenConfig{}
secureListener, err := slc.Listen(ctx, "tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPSPort))
if err != nil {
fmt.Printf("failed to listen: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -262,7 +264,7 @@ func Main() {
TLSServerPrivKey: os.Getenv("TLS_SERVER_PRIV_KEY"),
HTTPSPort: httpsPort,
}
runServer(config)
runServer(context.Background(), config)
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
<-done
Expand Down
2 changes: 1 addition & 1 deletion conformance/echo-basic/grpc/grpcechoserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func clientAndServer(t *testing.T) (pb.GrpcEchoClient, serverConfig, string) {
HTTPPort: ServerHTTPPort,
PodContext: podContext,
}
httpPort, _ := runServer(config)
httpPort, _ := runServer(t.Context(), config)

dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}

Expand Down
5 changes: 2 additions & 3 deletions conformance/tests/httproute-request-percentage-mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ var HTTPRouteRequestPercentageMirror = suite.ConformanceTest{
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expected)

// Override to not have more requests than expected
var dedicatedTimeoutConfig config.TimeoutConfig
dedicatedTimeoutConfig = suite.TimeoutConfig
dedicatedTimeoutConfig := suite.TimeoutConfig
dedicatedTimeoutConfig.RequiredConsecutiveSuccesses = 1
// used to limit number of parallel go routines
semaphore := make(chan struct{}, concurrentRequests)
Expand Down Expand Up @@ -225,7 +224,7 @@ func testMirroredRequestsDistribution(t *testing.T, suite *suite.ConformanceTest
tlog.Logf(t, "Pod: %s, Expected: %f (min: %f, max: %f), Actual: %f", mirrorPod.Name, expected, minExpected, maxExpected, actual)

if actual < minExpected || actual > maxExpected {
errs = append(errs, fmt.Errorf("Pod %s did not meet the mirroring percentage within tolerance. Expected between %f and %f, but got %f", mirrorPod.Name, minExpected, maxExpected, actual))
errs = append(errs, fmt.Errorf("pod %s did not meet the mirroring percentage within tolerance. Expected between %f and %f, but got %f", mirrorPod.Name, minExpected, maxExpected, actual))
}
}
if len(errs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion conformance/utils/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func AwaitConvergence(t *testing.T, threshold int, maxTimeToConsistency time.Dur
default:
}

completed := fn(time.Now().Sub(start))
completed := fn(time.Since(start))
attempts++
if completed {
successes++
Expand Down
2 changes: 1 addition & 1 deletion conformance/utils/http/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package http
package http //nolint:revive

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion conformance/utils/kubernetes/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ spec:
resources, err := tc.applier.prepareResources(t, decoder)

require.NoError(t, err, "unexpected error preparing resources")
require.EqualValues(t, tc.expected, resources)
require.Equal(t, tc.expected, resources)
})
}
}
2 changes: 1 addition & 1 deletion conformance/utils/kubernetes/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNewGatewayRef(t *testing.T) {
require.IsType(t, GatewayRef{}, ref)
if test.listenerNames == nil {
require.Len(t, ref.listenerNames, 1)
assert.Equal(t, "", string(*ref.listenerNames[0]))
assert.Empty(t, string(*ref.listenerNames[0]))
} else {
require.Len(t, ref.listenerNames, len(test.listenerNames))
for i := 0; i < len(ref.listenerNames); i++ {
Expand Down
16 changes: 8 additions & 8 deletions conformance/utils/suite/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ func (p profileReportsMap) addTestResults(conformanceProfile ConformanceProfile,
if report.Extended == nil {
report.Extended = &confv1.ExtendedStatus{}
}
report.Extended.Statistics.Passed++
report.Extended.Passed++
} else {
report.Core.Statistics.Passed++
report.Core.Passed++
}
case testFailed:
if testIsExtended {
if report.Extended == nil {
report.Extended = &confv1.ExtendedStatus{}
}
report.Extended.FailedTests = append(report.Extended.FailedTests, result.test.ShortName)
report.Extended.Statistics.Failed++
report.Extended.Failed++
} else {
report.Core.Statistics.Failed++
report.Core.Failed++
if report.Core.FailedTests == nil {
report.Core.FailedTests = []string{}
}
Expand All @@ -89,10 +89,10 @@ func (p profileReportsMap) addTestResults(conformanceProfile ConformanceProfile,
if report.Extended == nil {
report.Extended = &confv1.ExtendedStatus{}
}
report.Extended.Statistics.Skipped++
report.Extended.Skipped++
report.Extended.SkippedTests = append(report.Extended.SkippedTests, result.test.ShortName)
} else {
report.Core.Statistics.Skipped++
report.Core.Skipped++
report.Core.SkippedTests = append(report.Core.SkippedTests, result.test.ShortName)
}
}
Expand Down Expand Up @@ -196,9 +196,9 @@ func buildReportSummary(status confv1.Status) string {
case confv1.Success:
message = "succeeded"
case confv1.Partial:
message = fmt.Sprintf("partially succeeded with %d test skips", status.Statistics.Skipped)
message = fmt.Sprintf("partially succeeded with %d test skips", status.Skipped)
case confv1.Failure:
message = fmt.Sprintf("failed with %d test failures", status.Statistics.Failed)
message = fmt.Sprintf("failed with %d test failures", status.Failed)
}
return message
}
2 changes: 1 addition & 1 deletion hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -o errexit
set -o nounset
set -o pipefail

readonly VERSION="v1.64.8"
readonly VERSION="v2.7.2"
readonly KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..

cd "${KUBE_ROOT}"
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ParseDuration(s string) (*time.Duration, error) {
See https://gateway-api.sigs.k8s.io/geps/gep-2257/ for more details.
*/
if !re.MatchString(s) {
return nil, errors.New("Invalid duration format")
return nil, errors.New("invalid duration format")
}
parsedTime, err := time.ParseDuration(s)
if err != nil {
Expand Down Expand Up @@ -72,17 +72,17 @@ func FormatDuration(duration time.Duration) (string, error) {

// check if a negative value
if duration < 0 {
return "", errors.New("Invalid duration format. Cannot have negative durations")
return "", errors.New("invalid duration format. Cannot have negative durations")
}
// check for the maximum value allowed to be expressed
if duration > maxDuration {
return "", errors.New("Invalid duration format. Duration larger than maximum expression allowed in GEP-2257")
return "", errors.New("invalid duration format. Duration larger than maximum expression allowed in GEP-2257")
}
// time.Duration allows for floating point ms, which is not allowed in GEP-2257
durationMicroseconds := duration.Microseconds()

if durationMicroseconds%1000 != 0 {
return "", errors.New("Cannot express sub-milliseconds precision in GEP-2257")
return "", errors.New("cannot express sub-milliseconds precision in GEP-2257")
}

output := ""
Expand Down
Loading