Skip to content

Commit 1f7573b

Browse files
committed
Fix lint
1 parent d1ec8d8 commit 1f7573b

File tree

21 files changed

+58
-62
lines changed

21 files changed

+58
-62
lines changed

adopt/adopt.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ import (
2424
"context"
2525
"strings"
2626

27+
"github.com/go-logr/logr"
2728
"k8s.io/apimachinery/pkg/api/errors"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/types"
3132

32-
"github.com/go-logr/logr"
33-
3433
"github.com/authzed/controller-idioms/handler"
3534
"github.com/authzed/controller-idioms/queue"
3635
"github.com/authzed/controller-idioms/typed"

adopt/adopt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func TestSecretAdopterHandler(t *testing.T) {
346346
require.Equal(t, tt.expectCtxSecret, CtxSecret.Value(ctx))
347347
}, "testnext"),
348348
)
349-
ctx := CtxOwnerNN.WithValue(context.Background(), tt.cluster)
349+
ctx := CtxOwnerNN.WithValue(t.Context(), tt.cluster)
350350
ctx = CtxSecretNN.WithValue(ctx, types.NamespacedName{Namespace: "test", Name: tt.secretName})
351351
ctx = QueueOps.WithValue(ctx, ctrls)
352352
s.Handle(ctx)

bootstrap/resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3030
"k8s.io/apimachinery/pkg/util/yaml"
3131
"k8s.io/client-go/dynamic"
32-
"k8s.io/utils/pointer"
32+
"k8s.io/utils/ptr"
3333
)
3434

3535
// KubeResourceObject is satisfied by any standard kube object.
@@ -40,7 +40,7 @@ type KubeResourceObject interface {
4040

4141
// ResourceFromFile creates a KubeResourceObject with the given config file
4242
func ResourceFromFile[O KubeResourceObject](ctx context.Context, fieldManager string, gvr schema.GroupVersionResource, dclient dynamic.Interface, configPath string, lastHash uint64) (uint64, error) {
43-
if len(configPath) <= 0 {
43+
if len(configPath) == 0 {
4444
logr.FromContextOrDiscard(ctx).V(4).Info("bootstrap file path not specified")
4545
return 0, nil
4646
}
@@ -86,7 +86,7 @@ func ResourceFromFile[O KubeResourceObject](ctx context.Context, fieldManager st
8686
_, err = dclient.
8787
Resource(gvr).
8888
Namespace(objectDef.GetNamespace()).
89-
Patch(ctx, objectDef.GetName(), types.ApplyPatchType, data, metav1.PatchOptions{FieldManager: fieldManager, Force: pointer.Bool(true)})
89+
Patch(ctx, objectDef.GetName(), types.ApplyPatchType, data, metav1.PatchOptions{FieldManager: fieldManager, Force: ptr.To(true)})
9090
if err != nil {
9191
return hash, err
9292
}

bootstrap/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"k8s.io/apimachinery/pkg/util/yaml"
1515
"k8s.io/client-go/dynamic/fake"
1616
"k8s.io/client-go/testing"
17-
"k8s.io/klog/v2/klogr"
17+
"k8s.io/klog/v2/textlogger"
1818
)
1919

2020
func ExampleResourceFromFile() {
21-
ctx, cancel := context.WithCancel(logr.NewContext(context.Background(), klogr.New()))
21+
ctx, cancel := context.WithCancel(logr.NewContext(context.Background(), textlogger.NewLogger(textlogger.NewConfig())))
2222
defer cancel()
2323

2424
secretGVR := corev1.SchemeGroupVersion.WithResource("secrets")

component/ensure_component_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type MyObject struct {
3535
}
3636
type MyObjectStatus struct {
3737
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
38-
conditions.StatusConditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
38+
conditions.StatusConditions `json:"conditions,omitempty" patchMergeKey:"type" patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
3939
}
4040

4141
func TestEnsureServiceHandler(t *testing.T) {
@@ -108,7 +108,7 @@ func TestEnsureServiceHandler(t *testing.T) {
108108
}
109109
for _, tt := range tests {
110110
t.Run(tt.name, func(t *testing.T) {
111-
ctx, cancel := context.WithCancel(context.Background())
111+
ctx, cancel := context.WithCancel(t.Context())
112112
defer cancel()
113113

114114
ctrls := &fake.FakeInterface{}

conditions/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type StatusConditions struct {
1313
// Conditions for the current state of the resource.
1414
// +optional
15-
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
15+
Conditions []metav1.Condition `json:"conditions,omitempty" patchMergeKey:"type" patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
1616
}
1717

1818
// GetStatusConditions returns a pointer to all status conditions.

fileinformer/file_informer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (f *FileSharedIndexInformer) AddEventHandler(handler cache.ResourceEventHan
170170
})
171171
}
172172

173-
func (f *FileSharedIndexInformer) AddEventHandlerWithOptions(handler cache.ResourceEventHandler, options cache.HandlerOptions) (cache.ResourceEventHandlerRegistration, error) {
173+
func (f *FileSharedIndexInformer) AddEventHandlerWithOptions(handler cache.ResourceEventHandler, _ cache.HandlerOptions) (cache.ResourceEventHandlerRegistration, error) {
174174
f.RLock()
175175
if f.started {
176176
panic("cannot add event handlers after informer has started")
@@ -323,7 +323,7 @@ func (f *FileSharedIndexInformer) SetWatchErrorHandler(_ cache.WatchErrorHandler
323323
panic("implement me")
324324
}
325325

326-
func (f *FileSharedIndexInformer) SetWatchErrorHandlerWithContext(handler cache.WatchErrorHandlerWithContext) error {
326+
func (f *FileSharedIndexInformer) SetWatchErrorHandlerWithContext(_ cache.WatchErrorHandlerWithContext) error {
327327
// TODO implement me
328328
panic("implement me")
329329
}

fileinformer/file_informer_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
"github.com/stretchr/testify/mock"
1111
"github.com/stretchr/testify/require"
1212
"k8s.io/client-go/tools/cache"
13-
"k8s.io/klog/v2/klogr"
13+
"k8s.io/klog/v2/textlogger"
1414
)
1515

1616
func TestFileInformer(t *testing.T) {
17-
informerFactory, err := NewFileInformerFactory(klogr.New())
17+
informerFactory, err := NewFileInformerFactory(textlogger.NewLogger(textlogger.NewConfig()))
1818
require.NoError(t, err)
1919

20-
file, err := os.CreateTemp("", "watched-file")
20+
file, err := os.CreateTemp(t.TempDir(), "watched-file")
2121
require.NoError(t, err)
2222

23-
file2, err := os.CreateTemp("", "watched-file")
23+
file2, err := os.CreateTemp(t.TempDir(), "watched-file")
2424
require.NoError(t, err)
2525
defer require.NoError(t, file2.Close())
2626

@@ -38,15 +38,15 @@ func TestFileInformer(t *testing.T) {
3838
_, err = inf2.AddEventHandler(eventHandlers2)
3939
require.NoError(t, err)
4040

41-
ctx, cancel := context.WithCancel(context.Background())
41+
ctx, cancel := context.WithCancel(t.Context())
4242
informerFactory.Start(ctx.Done())
4343
informerFactory.WaitForCacheSync(ctx.Done())
4444

4545
eventHandlers.Lock()
46-
require.Equal(t, len(eventHandlers.Calls), 1)
46+
require.Len(t, eventHandlers.Calls, 1)
4747
eventHandlers.Unlock()
4848
eventHandlers2.Lock()
49-
require.Equal(t, len(eventHandlers2.Calls), 1)
49+
require.Len(t, len(eventHandlers2.Calls), 1)
5050
eventHandlers2.Unlock()
5151

5252
// expect an OnAdd when the file is written

hash/hash.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func SecureObject(obj interface{}) string {
7171
// xxhash's hasher.Write never returns an error, so we can safely ignore
7272
// the error here tpp
7373
_, _ = xxhasher.Write(hasher.Sum(nil))
74-
return rand.SafeEncodeString(fmt.Sprint(xxhasher.Sum(nil)))
74+
return rand.SafeEncodeString(fmt.Sprint(string(xxhasher.Sum(nil))))
7575
}
7676

7777
// SecureEqual compares hashes safely
@@ -92,7 +92,7 @@ func Object(obj interface{}) string {
9292
// xxhash's hasher.Write never returns an error, and Fprintf just passes up
9393
// the underlying Write call's error, so we can safely ignore the error here
9494
_, _ = printer.Fprintf(hasher, "%#v", obj)
95-
return rand.SafeEncodeString(fmt.Sprint(hasher.Sum(nil)))
95+
return rand.SafeEncodeString(fmt.Sprint(string(hasher.Sum(nil))))
9696
}
9797

9898
// Equal compares hashes safely

hash/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type MyObject struct {
2121

2222
type MyObjectStatus struct {
2323
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
24-
conditions.StatusConditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
24+
conditions.StatusConditions `json:"conditions,omitempty" patchMergeKey:"type" patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
2525
}
2626

2727
// This test uses complex non-comparable objects to confirm the hashing behavior,

0 commit comments

Comments
 (0)