Skip to content

Commit 87020aa

Browse files
committed
Fix golang-ci lint errors
1 parent cb21626 commit 87020aa

File tree

7 files changed

+73
-76
lines changed

7 files changed

+73
-76
lines changed

pkg/reconciler/ingress/config/gateway_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ package config
1919
import (
2020
"testing"
2121

22-
. "knative.dev/pkg/configmap/testing"
22+
ktesting "knative.dev/pkg/configmap/testing"
2323
)
2424

2525
func TestGateway(t *testing.T) {
26-
cm, example := ConfigMapsFromTestFile(t, GatewayConfigName)
26+
cm, example := ktesting.ConfigMapsFromTestFile(t, GatewayConfigName)
2727

2828
if _, err := NewGatewayFromConfigMap(cm); err != nil {
2929
t.Error("NewContourFromConfigMap(actual) =", err)

pkg/reconciler/ingress/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import (
3232
_ "knative.dev/networking/pkg/client/injection/informers/networking/v1alpha1/ingress/fake"
3333
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/endpoints/fake"
3434

35-
. "knative.dev/pkg/reconciler/testing"
35+
ktesting "knative.dev/pkg/reconciler/testing"
3636
)
3737

3838
func TestNew(t *testing.T) {
39-
ctx, _ := SetupFakeContext(t)
39+
ctx, _ := ktesting.SetupFakeContext(t)
4040

4141
c := NewController(ctx, configmap.NewStaticWatcher(&corev1.ConfigMap{
4242
ObjectMeta: metav1.ObjectMeta{

pkg/reconciler/ingress/ingress_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/apimachinery/pkg/runtime"
2929
"k8s.io/apimachinery/pkg/types"
3030
clientgotesting "k8s.io/client-go/testing"
31-
"k8s.io/utils/pointer"
31+
"k8s.io/utils/ptr"
3232

3333
fakegwapiclientset "knative.dev/net-gateway-api/pkg/client/injection/client/fake"
3434
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
@@ -46,8 +46,8 @@ import (
4646

4747
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
4848

49-
. "knative.dev/net-gateway-api/pkg/reconciler/testing"
50-
. "knative.dev/pkg/reconciler/testing"
49+
gwtesting "knative.dev/net-gateway-api/pkg/reconciler/testing"
50+
ktesting "knative.dev/pkg/reconciler/testing"
5151
)
5252

5353
var (
@@ -57,9 +57,9 @@ var (
5757
privateSvc = network.GetServiceHostname(privateName, testNamespace)
5858

5959
gatewayRef = gatewayapi.ParentReference{
60-
Group: (*gatewayapi.Group)(pointer.String("gateway.networking.k8s.io")),
61-
Kind: (*gatewayapi.Kind)(pointer.String("Gateway")),
62-
Namespace: (*gatewayapi.Namespace)(pointer.String("istio-system")),
60+
Group: (*gatewayapi.Group)(ptr.To("gateway.networking.k8s.io")),
61+
Kind: (*gatewayapi.Kind)(ptr.To("Gateway")),
62+
Namespace: (*gatewayapi.Namespace)(ptr.To("istio-system")),
6363
Name: gatewayapi.ObjectName("istio-gateway"),
6464
}
6565
)
@@ -137,7 +137,7 @@ var (
137137

138138
// TODO: Add more tests - e.g. invalid ingress, delete ingress, etc.
139139
func TestReconcile(t *testing.T) {
140-
table := TableTest{{
140+
table := ktesting.TableTest{{
141141
Name: "bad workqueue key",
142142
Key: "too/many/parts",
143143
}, {
@@ -187,8 +187,8 @@ func TestReconcile(t *testing.T) {
187187
Patch: []byte(`{"metadata":{"finalizers":["ingresses.networking.internal.knative.dev"],"resourceVersion":""}}`),
188188
}},
189189
WantEvents: []string{
190-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
191-
Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
190+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
191+
ktesting.Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
192192
},
193193
}, {
194194
Name: "reconcile ready ingress",
@@ -200,7 +200,7 @@ func TestReconcile(t *testing.T) {
200200
// no extra update
201201
}}
202202

203-
table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
203+
table.Test(t, gwtesting.MakeFactory(func(ctx context.Context, listers *gwtesting.Listers, _ configmap.Watcher) controller.Reconciler {
204204
r := &Reconciler{
205205
gwapiclient: fakegwapiclientset.Get(ctx),
206206
// Listers index properties about resources
@@ -225,7 +225,7 @@ func TestReconcile(t *testing.T) {
225225
}
226226

227227
func TestReconcileProberNotReady(t *testing.T) {
228-
table := TableTest{{
228+
table := ktesting.TableTest{{
229229
Name: "first reconcile basic ingress wth prober",
230230
Key: "ns/name",
231231
Objects: append([]runtime.Object{
@@ -246,12 +246,12 @@ func TestReconcileProberNotReady(t *testing.T) {
246246
Patch: []byte(`{"metadata":{"finalizers":["ingresses.networking.internal.knative.dev"],"resourceVersion":""}}`),
247247
}},
248248
WantEvents: []string{
249-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
250-
Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
249+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
250+
ktesting.Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
251251
},
252252
}}
253253

254-
table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
254+
table.Test(t, gwtesting.MakeFactory(func(ctx context.Context, listers *gwtesting.Listers, _ configmap.Watcher) controller.Reconciler {
255255
r := &Reconciler{
256256
gwapiclient: fakegwapiclientset.Get(ctx),
257257
// Listers index properties about resources
@@ -277,7 +277,7 @@ func TestReconcileTLS(t *testing.T) {
277277
secretName := "name-WE-STICK-A-LONG-UID-HERE"
278278
nsName := "ns"
279279
deleteTime := time.Now().Add(-10 * time.Second)
280-
table := TableTest{{
280+
table := ktesting.TableTest{{
281281
Name: "Happy TLS",
282282
Key: "ns/name",
283283
Objects: []runtime.Object{
@@ -312,8 +312,8 @@ func TestReconcileTLS(t *testing.T) {
312312
}),
313313
}},
314314
WantEvents: []string{
315-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
316-
Eventf(corev1.EventTypeNormal, "Created", `Created HTTPRoute "example.com"`),
315+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
316+
ktesting.Eventf(corev1.EventTypeNormal, "Created", `Created HTTPRoute "example.com"`),
317317
},
318318
}, {
319319
Name: "Already Configured",
@@ -390,10 +390,10 @@ func TestReconcileTLS(t *testing.T) {
390390
}),
391391
}},
392392
WantEvents: []string{
393-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
394-
Eventf(corev1.EventTypeNormal, "Created", `Created HTTPRoute "example.com"`),
395-
Eventf(corev1.EventTypeWarning, "GatewayMissing", `Unable to update Gateway istio-system/istio-gateway`),
396-
Eventf(corev1.EventTypeWarning, "InternalError", `Gateway istio-system/istio-gateway does not exist: gateway.gateway.networking.k8s.io "istio-gateway" not found`),
393+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
394+
ktesting.Eventf(corev1.EventTypeNormal, "Created", `Created HTTPRoute "example.com"`),
395+
ktesting.Eventf(corev1.EventTypeWarning, "GatewayMissing", `Unable to update Gateway istio-system/istio-gateway`),
396+
ktesting.Eventf(corev1.EventTypeWarning, "InternalError", `Gateway istio-system/istio-gateway does not exist: gateway.gateway.networking.k8s.io "istio-gateway" not found`),
397397
},
398398
}, {
399399
Name: "TLS ingress with httpOption redirected",
@@ -432,13 +432,13 @@ func TestReconcileTLS(t *testing.T) {
432432
Patch: []byte(`{"metadata":{"finalizers":["ingresses.networking.internal.knative.dev"],"resourceVersion":""}}`),
433433
}},
434434
WantEvents: []string{
435-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
436-
Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
437-
Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com-redirect\""),
435+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
436+
ktesting.Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
437+
ktesting.Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com-redirect\""),
438438
},
439439
}}
440440

441-
table.Test(t, GatewayFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, tr *TableRow) controller.Reconciler {
441+
table.Test(t, GatewayFactory(func(ctx context.Context, listers *gwtesting.Listers, _ configmap.Watcher, tr *ktesting.TableRow) controller.Reconciler {
442442
r := &Reconciler{
443443
gwapiclient: fakegwapiclientset.Get(ctx),
444444
httprouteLister: listers.GetHTTPRouteLister(),
@@ -475,7 +475,7 @@ func TestReconcileTLS(t *testing.T) {
475475
func TestReconcileProbeError(t *testing.T) {
476476
theError := errors.New("this is the error")
477477

478-
table := TableTest{{
478+
table := ktesting.TableTest{{
479479
Name: "first reconcile basic ingress",
480480
Key: "ns/name",
481481
WantErr: true,
@@ -497,13 +497,13 @@ func TestReconcileProbeError(t *testing.T) {
497497
Patch: []byte(`{"metadata":{"finalizers":["ingresses.networking.internal.knative.dev"],"resourceVersion":""}}`),
498498
}},
499499
WantEvents: []string{
500-
Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
501-
Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
502-
Eventf(corev1.EventTypeWarning, "InternalError", fmt.Sprintf("failed to probe Ingress: %v", theError)),
500+
ktesting.Eventf(corev1.EventTypeNormal, "FinalizerUpdate", `Updated "name" finalizers`),
501+
ktesting.Eventf(corev1.EventTypeNormal, "Created", "Created HTTPRoute \"example.com\""),
502+
ktesting.Eventf(corev1.EventTypeWarning, "InternalError", fmt.Sprintf("failed to probe Ingress: %v", theError)),
503503
},
504504
}}
505505

506-
table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
506+
table.Test(t, gwtesting.MakeFactory(func(ctx context.Context, listers *gwtesting.Listers, _ configmap.Watcher) controller.Reconciler {
507507
r := &Reconciler{
508508
gwapiclient: fakegwapiclientset.Get(ctx),
509509
// Listers index properties about resources
@@ -562,7 +562,7 @@ type HTTPRouteOption func(h *gatewayapi.HTTPRoute)
562562

563563
func withSectionName(sectionName string) HTTPRouteOption {
564564
return func(h *gatewayapi.HTTPRoute) {
565-
h.Spec.CommonRouteSpec.ParentRefs[0].SectionName = (*gatewayapi.SectionName)(pointer.String(sectionName))
565+
h.Spec.CommonRouteSpec.ParentRefs[0].SectionName = (*gatewayapi.SectionName)(ptr.To(sectionName))
566566
}
567567
}
568568

@@ -589,14 +589,14 @@ func (t *testConfigStore) ToContext(ctx context.Context) context.Context {
589589
}
590590

591591
// We need to inject the row's `Objects` to work-around improper pluralization in UnsafeGuessKindToResource
592-
func GatewayFactory(ctor func(context.Context, *Listers, configmap.Watcher, *TableRow) controller.Reconciler) Factory {
593-
return func(t *testing.T, r *TableRow) (
594-
controller.Reconciler, ActionRecorderList, EventList,
592+
func GatewayFactory(ctor func(context.Context, *gwtesting.Listers, configmap.Watcher, *ktesting.TableRow) controller.Reconciler) ktesting.Factory {
593+
return func(t *testing.T, r *ktesting.TableRow) (
594+
controller.Reconciler, ktesting.ActionRecorderList, ktesting.EventList,
595595
) {
596-
shim := func(c context.Context, l *Listers, cw configmap.Watcher) controller.Reconciler {
596+
shim := func(c context.Context, l *gwtesting.Listers, cw configmap.Watcher) controller.Reconciler {
597597
return ctor(c, l, cw, r)
598598
}
599-
return MakeFactory(shim)(t, r)
599+
return gwtesting.MakeFactory(shim)(t, r)
600600
}
601601
}
602602

@@ -634,18 +634,18 @@ func tlsListener(hostname, nsName, secretName string) GatewayOption {
634634
Port: 443,
635635
Protocol: "HTTPS",
636636
TLS: &gatewayapi.GatewayTLSConfig{
637-
Mode: (*gatewayapi.TLSModeType)(pointer.String("Terminate")),
637+
Mode: (*gatewayapi.TLSModeType)(ptr.To("Terminate")),
638638
CertificateRefs: []gatewayapi.SecretObjectReference{{
639-
Group: (*gatewayapi.Group)(pointer.String("")),
640-
Kind: (*gatewayapi.Kind)(pointer.String("Secret")),
639+
Group: (*gatewayapi.Group)(ptr.To("")),
640+
Kind: (*gatewayapi.Kind)(ptr.To("Secret")),
641641
Name: gatewayapi.ObjectName(secretName),
642642
Namespace: (*gatewayapi.Namespace)(&nsName),
643643
}},
644644
Options: map[gatewayapi.AnnotationKey]gatewayapi.AnnotationValue{},
645645
},
646646
AllowedRoutes: &gatewayapi.AllowedRoutes{
647647
Namespaces: &gatewayapi.RouteNamespaces{
648-
From: (*gatewayapi.FromNamespaces)(pointer.String("Selector")),
648+
From: (*gatewayapi.FromNamespaces)(ptr.To("Selector")),
649649
Selector: &metav1.LabelSelector{
650650
MatchLabels: map[string]string{
651651
"kubernetes.io/metadata.name": nsName,

pkg/reconciler/ingress/lister_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"knative.dev/networking/pkg/status"
3434
"knative.dev/pkg/kmeta"
3535

36-
. "knative.dev/net-gateway-api/pkg/reconciler/testing"
36+
ingress "knative.dev/net-gateway-api/pkg/reconciler/testing"
3737
)
3838

3939
var (
@@ -142,7 +142,7 @@ func TestListProbeTargets(t *testing.T) {
142142

143143
for _, test := range tests {
144144
t.Run(test.name, func(t *testing.T) {
145-
tl := NewListers(test.objects)
145+
tl := ingress.NewListers(test.objects)
146146

147147
l := &gatewayPodTargetLister{
148148
endpointsLister: tl.GetEndpointsLister(),

pkg/reconciler/ingress/reconcile_resources.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
apierrs "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/types"
28-
"k8s.io/utils/pointer"
2928
"k8s.io/utils/ptr"
3029
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
3130
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
@@ -46,7 +45,7 @@ func (c *Reconciler) reconcileWorkloadRoute(
4645
gatewayConfig := config.FromContext(ctx).Gateway.Gateways[rule.Visibility]
4746
gatewayRef := gatewayapi.ParentReference{
4847
Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group),
49-
Kind: (*gatewayapi.Kind)(pointer.String("Gateway")),
48+
Kind: (*gatewayapi.Kind)(ptr.To("Gateway")),
5049
Namespace: (*gatewayapi.Namespace)(&gatewayConfig.Gateway.Namespace),
5150
Name: gatewayapi.ObjectName(gatewayConfig.Gateway.Name),
5251
}
@@ -79,7 +78,7 @@ func (c *Reconciler) reconcileRedirectHTTPRoute(
7978
gatewayConfig := config.FromContext(ctx).Gateway.Gateways[rule.Visibility]
8079
gatewayRef := gatewayapi.ParentReference{
8180
Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group),
82-
Kind: (*gatewayapi.Kind)(pointer.String("Gateway")),
81+
Kind: (*gatewayapi.Kind)(ptr.To("Gateway")),
8382
Namespace: (*gatewayapi.Namespace)(&gatewayConfig.Gateway.Namespace),
8483
Name: gatewayapi.ObjectName(gatewayConfig.Gateway.Name),
8584

@@ -114,25 +113,25 @@ func (c *Reconciler) reconcileHTTPRoute(ctx context.Context,
114113
return httpRoute, nil
115114
} else if err != nil {
116115
return nil, err
117-
} else {
118-
if !equality.Semantic.DeepEqual(httpRoute.Spec, desired.Spec) ||
119-
!equality.Semantic.DeepEqual(httpRoute.Annotations, desired.Annotations) ||
120-
!equality.Semantic.DeepEqual(httpRoute.Labels, desired.Labels) {
121-
122-
// Don't modify the informers copy.
123-
origin := httpRoute.DeepCopy()
124-
origin.Spec = desired.Spec
125-
origin.Annotations = desired.Annotations
126-
origin.Labels = desired.Labels
127-
128-
updated, err := c.gwapiclient.GatewayV1beta1().HTTPRoutes(origin.Namespace).Update(
129-
ctx, origin, metav1.UpdateOptions{})
130-
if err != nil {
131-
recorder.Eventf(ing, corev1.EventTypeWarning, "UpdateFailed", "Failed to update HTTPRoute: %v", err)
132-
return nil, fmt.Errorf("failed to update HTTPRoute: %w", err)
133-
}
134-
return updated, nil
116+
}
117+
118+
if !equality.Semantic.DeepEqual(httpRoute.Spec, desired.Spec) ||
119+
!equality.Semantic.DeepEqual(httpRoute.Annotations, desired.Annotations) ||
120+
!equality.Semantic.DeepEqual(httpRoute.Labels, desired.Labels) {
121+
122+
// Don't modify the informers copy.
123+
origin := httpRoute.DeepCopy()
124+
origin.Spec = desired.Spec
125+
origin.Annotations = desired.Annotations
126+
origin.Labels = desired.Labels
127+
128+
updated, err := c.gwapiclient.GatewayV1beta1().HTTPRoutes(origin.Namespace).Update(
129+
ctx, origin, metav1.UpdateOptions{})
130+
if err != nil {
131+
recorder.Eventf(ing, corev1.EventTypeWarning, "UpdateFailed", "Failed to update HTTPRoute: %v", err)
132+
return nil, fmt.Errorf("failed to update HTTPRoute: %w", err)
135133
}
134+
return updated, nil
136135
}
137136

138137
return httpRoute, err

pkg/reconciler/ingress/resources/httproute.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"net/http"
2121
"sort"
2222

23-
"k8s.io/utils/pointer"
2423
"knative.dev/pkg/kmap"
2524

2625
corev1 "k8s.io/api/core/v1"
@@ -244,7 +243,7 @@ func matchesFromRulePath(path netv1alpha1.HTTPIngressPath) []gatewayapi.HTTPRout
244243
}
245244
pathMatch := gatewayapi.HTTPPathMatch{
246245
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
247-
Value: pointer.String(pathPrefix),
246+
Value: ptr.To(pathPrefix),
248247
}
249248

250249
var headerMatchList []gatewayapi.HTTPHeaderMatch

0 commit comments

Comments
 (0)