Skip to content
Closed
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
168 changes: 98 additions & 70 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,107 @@
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
settings:
gomodguard:
blocked:
modules:
- io/ioutil:
recommendations:
- io
- os
reason: Deprecation of package ioutil in Go 1.16.
govet:
enable:
- shadow
settings:
shadow:
strict: false
misspell:
locale: US
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- errcheck
- gocyclo
path: _test\.go
- 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
- 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: true
goimports:
local-prefixes:
- sigs.k8s.io/gateway-api
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
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
4 changes: 2 additions & 2 deletions conformance/echo-basic/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ 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))
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPPort)) //nolint:noctx
if err != nil {
fmt.Printf("failed to listen: %v\n", err)
os.Exit(1)
Expand All @@ -200,7 +200,7 @@ 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))
secureListener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", config.HTTPSPort)) //nolint:noctx
if err != nil {
fmt.Printf("failed to listen: %v\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/gateway-static-addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func filterAddr(addrs []v1.GatewaySpecAddress, filter v1.GatewaySpecAddress) (ne
newAddrs = append(newAddrs, addr)
}
}
return
return //nolint:gofumpt
}

var finalExpectedListenerState = []v1.ListenerStatus{
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 @@ -241,7 +241,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/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,5 @@ func convertGatewayAddrsToPrimitives(gwaddrs []v1beta1.GatewaySpecAddress) (raw
"value": addr.Value,
})
}
return
return //nolint:gofumpt
}
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
30 changes: 15 additions & 15 deletions conformance/utils/suite/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ var (

type profileReportsMap map[ConformanceProfileName]confv1.ProfileReport

func (p profileReportsMap) list() (profileReports []confv1.ProfileReport) {
for _, profileReport := range p {
profileReports = append(profileReports, profileReport)
}
return //nolint:gofumpt
}

func newReports() profileReportsMap {
return make(profileReportsMap)
}
Expand All @@ -66,19 +73,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,23 +96,16 @@ 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)
}
}
p[conformanceProfile.Name] = report
}

func (p profileReportsMap) list() (profileReports []confv1.ProfileReport) {
for _, profileReport := range p {
profileReports = append(profileReports, profileReport)
}
return
}

func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformanceProfileName]FeaturesSet, unsupportedFeaturesMap map[ConformanceProfileName]FeaturesSet) {
for key, report := range p {
// report the overall result for core features
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.6.2"
readonly KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..

cd "${KUBE_ROOT}"
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/crd/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func executeKubectlCommand(t *testing.T, kubectl, kubeconfig string, args []stri
cacheDir := filepath.Dir(kubeconfig)
args = append([]string{"--cache-dir", cacheDir}, args...)

cmd := exec.Command(kubectl, args...)
cmd := exec.CommandContext(t.Context(), kubectl, args...)
cmd.Env = []string{
fmt.Sprintf("KUBECONFIG=%s", kubeconfig),
}
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