Skip to content

Commit

Permalink
run golangci-lint run --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Jan 10, 2025
1 parent 9f0d2f6 commit 25829c5
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 112 deletions.
24 changes: 11 additions & 13 deletions pkg/apis/networking/metadata_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ import (
"knative.dev/pkg/apis"
)

var (
allowedAnnotations = sets.New[string](
IngressClassAnnotationKey,
CertificateClassAnnotationKey,
DisableAutoTLSAnnotationKey,
DisableExternalDomainTLSAnnotationKey,
HTTPOptionAnnotationKey,

IngressClassAnnotationAltKey,
CertificateClassAnnotationAltKey,
DisableAutoTLSAnnotationAltKey,
HTTPProtocolAnnotationKey,
)
var allowedAnnotations = sets.New[string](
IngressClassAnnotationKey,
CertificateClassAnnotationKey,
DisableAutoTLSAnnotationKey,
DisableExternalDomainTLSAnnotationKey,
HTTPOptionAnnotationKey,

IngressClassAnnotationAltKey,
CertificateClassAnnotationAltKey,
DisableAutoTLSAnnotationAltKey,
HTTPProtocolAnnotationKey,
)

// ValidateAnnotations validates that `annotations` in `metadata` stanza of the
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/networking/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ const (
ServicePortNameHTTPS = "https"
)

var (
// AppProtocolH2C is the name of the external port of the service for HTTP/2, from https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/3726-standard-application-protocols#new-standard-protocols
AppProtocolH2C = "kubernetes.io/h2c"
)
// AppProtocolH2C is the name of the external port of the service for HTTP/2, from https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/3726-standard-application-protocols#new-standard-protocols
var AppProtocolH2C = "kubernetes.io/h2c"

// ServicePortName returns the port for the app level protocol.
func ServicePortName(proto ProtocolType) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestCertificateSpecValidation(t *testing.T) {
})
}
}

func TestCertificateValidation(t *testing.T) {
tests := []struct {
name string
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/networking/v1alpha1/domainclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ type ClusterDomainClaim struct {
Spec ClusterDomainClaimSpec `json:"spec,omitempty"`
}

var (
// Check that we can create OwnerReferences to a ClusterDomainClaim.
_ kmeta.OwnerRefable = (*ClusterDomainClaim)(nil)
)
// Check that we can create OwnerReferences to a ClusterDomainClaim.
var _ kmeta.OwnerRefable = (*ClusterDomainClaim)(nil)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/networking/v1alpha1/ingress_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"github.com/google/go-cmp/cmp"
)

var (
hosts = []string{"foo", "bar", "foo.bar"}
)
var hosts = []string{"foo", "bar", "foo.bar"}

func TestGetIngressTLSForVisibility(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/certificates/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import "strings"
const (
Organization = "knative.dev"

// nolint:all
//nolint:all
LegacyFakeDnsName = "data-plane." + Organization

// nolint:all
//nolint:all
// Deprecated: FakeDnsName is deprecated.
// Please use the DataPlaneRoutingSAN for calls to the Activator
// and the DataPlaneUserSAN function for calls to a Knative-Service via Queue-Proxy.
Expand Down
18 changes: 12 additions & 6 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@ func TestAnnotationsInDomainTemplate(t *testing.T) {
Name: "foo",
Namespace: "bar",
Annotations: map[string]string{
"sub": "sub1"},
Domain: "baz.com"},
"sub": "sub1",
},
Domain: "baz.com",
},
}, {
name: "network configuration without annotations in template",
wantErr: false,
Expand All @@ -561,7 +563,8 @@ func TestAnnotationsInDomainTemplate(t *testing.T) {
data: DomainTemplateValues{
Name: "foo",
Namespace: "bar",
Domain: "baz.com"},
Domain: "baz.com",
},
}}

for _, tt := range networkConfigTests {
Expand Down Expand Up @@ -602,8 +605,10 @@ func TestLabelsInDomainTemplate(t *testing.T) {
Name: "foo",
Namespace: "bar",
Labels: map[string]string{
"sub": "sub1"},
Domain: "baz.com"},
"sub": "sub1",
},
Domain: "baz.com",
},
}, {
name: "network configuration without labels in template",
wantErr: false,
Expand All @@ -615,7 +620,8 @@ func TestLabelsInDomainTemplate(t *testing.T) {
templateValue: DomainTemplateValues{
Name: "foo",
Namespace: "bar",
Domain: "baz.com"},
Domain: "baz.com",
},
}}

for _, tt := range networkConfigTests {
Expand Down
4 changes: 2 additions & 2 deletions pkg/http/probe/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func BenchmarkProbeHandlerNoProbeHeader(b *testing.B) {
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)

b.Run("sequential-no-header", func(b *testing.B) {
for j := 0; j < b.N; j++ {
for range b.N {
h.ServeHTTP(resp, req)
}
})
Expand All @@ -131,7 +131,7 @@ func BenchmarkProbeHandlerWithProbeHeader(b *testing.B) {
h = NewHandler(h)
b.Run("sequential-probe-header", func(b *testing.B) {
resp := httptest.NewRecorder()
for j := 0; j < b.N; j++ {
for range b.N {
h.ServeHTTP(resp, req)
}
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ingress

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -46,7 +47,7 @@ func InsertProbe(ing *v1alpha1.Ingress) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to compute the hash of the Ingress: %w", err)
}
hash := fmt.Sprintf("%x", bytes)
hash := hex.EncodeToString(bytes[:])

for _, rule := range ing.Spec.Rules {
if rule.HTTP == nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package status
import (
"context"
"crypto/tls"
"encoding/hex"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -58,10 +59,8 @@ const (
initialDelay = 200 * time.Millisecond
)

var (
// probeMaxRetryDelay defines the maximum delay between retries in the backoff of probing
probeMaxRetryDelay = 30 * time.Second
)
// probeMaxRetryDelay defines the maximum delay between retries in the backoff of probing
var probeMaxRetryDelay = 30 * time.Second

func init() {
if val, ok := os.LookupEnv("PROBE_MAX_RETRY_DELAY_SECONDS"); ok {
Expand Down Expand Up @@ -151,7 +150,8 @@ type Prober struct {
func NewProber(
logger *zap.SugaredLogger,
targetLister ProbeTargetLister,
readyCallback func(*v1alpha1.Ingress)) *Prober {
readyCallback func(*v1alpha1.Ingress),
) *Prober {
return &Prober{
logger: logger,
ingressStates: make(map[types.NamespacedName]*ingressState),
Expand Down Expand Up @@ -183,7 +183,7 @@ func (m *Prober) IsReady(ctx context.Context, ing *v1alpha1.Ingress) (bool, erro
if err != nil {
return false, fmt.Errorf("failed to compute the hash of the Ingress: %w", err)
}
hash := fmt.Sprintf("%x", bytes)
hash := hex.EncodeToString(bytes[:])

if ready, ok := func() (bool, bool) {
m.mu.Lock()
Expand Down Expand Up @@ -297,11 +297,11 @@ func (m *Prober) Start(done <-chan struct{}) chan struct{} {
var wg sync.WaitGroup

// Start the worker goroutines
for i := 0; i < m.probeConcurrency; i++ {
for range m.probeConcurrency {
wg.Add(1)
go func() {
defer wg.Done()
//nolint:all

for m.processWorkItem() {
}
}()
Expand Down
41 changes: 19 additions & 22 deletions pkg/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
ingTemplate = &v1alpha1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "whatever",
},
Spec: v1alpha1.IngressSpec{
Rules: []v1alpha1.IngressRule{{
Hosts: []string{
"foo.bar.com",
},
Visibility: v1alpha1.IngressVisibilityExternalIP,
HTTP: &v1alpha1.HTTPIngressRuleValue{},
}},
},
}
)
var ingTemplate = &v1alpha1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "whatever",
},
Spec: v1alpha1.IngressSpec{
Rules: []v1alpha1.IngressRule{{
Hosts: []string{
"foo.bar.com",
},
Visibility: v1alpha1.IngressVisibilityExternalIP,
HTTP: &v1alpha1.HTTPIngressRuleValue{},
}},
},
}

func TestProbeAllHosts(t *testing.T) {
const hostA = "foo.bar.com"
Expand All @@ -73,7 +71,7 @@ func TestProbeAllHosts(t *testing.T) {
failedRequests := make(chan *http.Request)
failHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
failedRequests <- r
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
})

// Actual probe handler used in Activator and Queue-Proxy
Expand Down Expand Up @@ -163,7 +161,6 @@ func TestProbeAllHosts(t *testing.T) {

// Just drain the requests in the channel to not block the handler
go func() {
//nolint:all
for range probeRequests {
}
}()
Expand Down Expand Up @@ -197,7 +194,7 @@ func TestProbeLifecycle(t *testing.T) {
failedRequests := make(chan *http.Request)
failHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
failedRequests <- r
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
})

// Actual probe handler used in Activator and Queue-Proxy
Expand Down Expand Up @@ -260,7 +257,7 @@ func TestProbeLifecycle(t *testing.T) {
const expHostHeader = "foo.bar.com"

// Wait for the first (failing) and second (success) requests to be executed and validate Host header
for i := 0; i < 2; i++ {
for range 2 {
req := <-probeRequests
if req.Host != expHostHeader {
t.Fatalf("Host header = %q, want %q", req.Host, expHostHeader)
Expand All @@ -275,7 +272,7 @@ func TestProbeLifecycle(t *testing.T) {
}

// The subsequent calls to IsReady must succeed and return true
for i := 0; i < 5; i++ {
for range 5 {
if ok, err = prober.IsReady(context.Background(), ing); err != nil {
t.Fatal("IsReady failed:", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/testing/status/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestIsReadyCallCount(t *testing.T) {
ingress2 := v1alpha1.Ingress{ObjectMeta: metav1.ObjectMeta{Namespace: "ns2", Name: "name2"}}
ingress3 := v1alpha1.Ingress{ObjectMeta: metav1.ObjectMeta{Namespace: "ns3", Name: "name3"}}

for i := 0; i < 10; i++ {
for range 10 {
statusManager.IsReady(context.Background(), &ingress1)
}

for i := 0; i < 5; i++ {
for range 5 {
statusManager.IsReady(context.Background(), &ingress2)
}

Expand Down
4 changes: 2 additions & 2 deletions test/conformance/ingress/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestIngressClass(t *testing.T) {
}}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

Expand All @@ -70,7 +69,8 @@ func TestIngressClass(t *testing.T) {
}

func verifyIngressWithAnnotations(ctx context.Context, t *testing.T, clients *test.Clients,
annotations map[string]string, backend *v1alpha1.IngressBackend) {
annotations map[string]string, backend *v1alpha1.IngressBackend,
) {
t.Helper()

// createIngress internally sets hooks to delete the ingress,
Expand Down
6 changes: 3 additions & 3 deletions test/conformance/ingress/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestGRPC(t *testing.T) {
t.Fatal("PingStream() =", err)
}

for i := 0; i < 100; i++ {
for range 100 {
checkGRPCRoundTrip(t, stream, suffix)
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestGRPCSplit(t *testing.T) {

const maxRequests = 100
got := sets.New[string]()
for i := 0; i < maxRequests; i++ {
for range maxRequests {
stream, err := pc.PingStream(ctx)
if err != nil {
t.Error("PingStream() =", err)
Expand All @@ -164,7 +164,7 @@ func TestGRPCSplit(t *testing.T) {
}
got.Insert(suffix)

for j := 0; j < 10; j++ {
for range 10 {
checkGRPCRoundTrip(t, stream, suffix)
}

Expand Down
Loading

0 comments on commit 25829c5

Please sign in to comment.