Skip to content

Commit b98da97

Browse files
authored
Merge pull request #75 from ecordell/bumpkube
bump kube to 1.33.1 and update informer interfaces
2 parents 5257c63 + 0db1d12 commit b98da97

29 files changed

+890
-1195
lines changed

.github/workflows/build-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on: # yamllint disable-line rule:truthy
88
branches:
99
- "*"
1010
env:
11-
GO_VERSION: "~1.20.7"
11+
GO_VERSION: "~1.24"
1212
jobs:
1313
unit:
1414
name: "Unit"

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on: # yamllint disable-line rule:truthy
88
pull_request:
99
branches: ["*"]
1010
env:
11-
GO_VERSION: "~1.20.7"
11+
GO_VERSION: "~1.24"
1212
jobs:
1313
go-lint:
1414
name: "Lint Go"

.golangci.yaml

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
---
2+
version: "2"
23
run:
3-
timeout: "5m"
4-
output:
5-
sort-results: true
4+
allow-parallel-runners: true
65
linters:
76
enable:
87
- "bidichk"
98
- "bodyclose"
109
- "errcheck"
1110
- "errname"
1211
- "errorlint"
13-
- "gofumpt"
14-
- "goimports"
12+
- "gocritic"
1513
- "goprintffuncname"
1614
- "gosec"
17-
- "gosimple"
1815
- "govet"
1916
- "importas"
2017
- "ineffassign"
@@ -24,11 +21,45 @@ linters:
2421
- "promlinter"
2522
- "revive"
2623
- "rowserrcheck"
24+
- "spancheck"
2725
- "staticcheck"
28-
- "stylecheck"
29-
- "tenv"
30-
- "typecheck"
26+
- "tagalign"
27+
- "testifylint"
28+
- "tparallel"
3129
- "unconvert"
32-
- "unused"
30+
- "usetesting"
3331
- "wastedassign"
3432
- "whitespace"
33+
- "unused"
34+
settings:
35+
staticcheck:
36+
checks:
37+
- "all"
38+
exclusions:
39+
generated: "lax"
40+
presets:
41+
- "comments"
42+
- "common-false-positives"
43+
- "legacy"
44+
- "std-error-handling"
45+
formatters:
46+
enable:
47+
- "gci"
48+
- "gofumpt"
49+
- "goimports"
50+
settings:
51+
gci:
52+
sections:
53+
- "standard"
54+
- "default"
55+
- "prefix(github.com/authzed)"
56+
- "localmodule"
57+
goimports:
58+
local-prefixes:
59+
- "github.com/authzed/controller-idioms"
60+
exclusions:
61+
generated: "lax"
62+
paths:
63+
- "third_party$"
64+
- "builtin$"
65+
- "examples$"

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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package component
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/stretchr/testify/require"
@@ -35,7 +36,7 @@ type MyObject struct {
3536
}
3637
type MyObjectStatus struct {
3738
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"`
39+
conditions.StatusConditions `json:"conditions,omitempty" patchMergeKey:"type" patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
3940
}
4041

4142
func TestEnsureServiceHandler(t *testing.T) {
@@ -78,7 +79,7 @@ func TestEnsureServiceHandler(t *testing.T) {
7879
"example.com/component": "the-main-service-component",
7980
},
8081
Annotations: map[string]string{
81-
hashKey: "n649h58dh598h654hc4hc9hbbh689q",
82+
hashKey: "76251aaa1ff6c84f",
8283
},
8384
}},
8485
},
@@ -93,7 +94,7 @@ func TestEnsureServiceHandler(t *testing.T) {
9394
"example.com/component": "the-main-service-component",
9495
},
9596
Annotations: map[string]string{
96-
hashKey: "n649h58dh598h654hc4hc9hbbh689q",
97+
hashKey: "76251aaa1ff6c84f",
9798
},
9899
},
99100
}, &corev1.Service{ObjectMeta: metav1.ObjectMeta{
@@ -108,7 +109,7 @@ func TestEnsureServiceHandler(t *testing.T) {
108109
}
109110
for _, tt := range tests {
110111
t.Run(tt.name, func(t *testing.T) {
111-
ctx, cancel := context.WithCancel(context.Background())
112+
ctx, cancel := context.WithCancel(t.Context())
112113
defer cancel()
113114

114115
ctrls := &fake.FakeInterface{}
@@ -145,8 +146,9 @@ func TestEnsureServiceHandler(t *testing.T) {
145146
hash.NewObjectHash(), hashKey),
146147
ctxOwner,
147148
queueOps,
148-
func(_ context.Context, _ *applycorev1.ServiceApplyConfiguration) (*corev1.Service, error) {
149+
func(_ context.Context, sac *applycorev1.ServiceApplyConfiguration) (*corev1.Service, error) {
149150
applyCalled = true
151+
fmt.Print(sac.Annotations)
150152
return nil, nil
151153
},
152154
func(_ context.Context, _ types.NamespacedName) error {

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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ func NewFileSharedIndexInformer(log logr.Logger, fileName string, watcher *fsnot
165165
func (f *FileSharedIndexInformer) IsStopped() bool { return !f.started }
166166

167167
func (f *FileSharedIndexInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error) {
168-
return f.AddEventHandlerWithResyncPeriod(handler, f.defaultEventHandlerResyncPeriod)
168+
return f.AddEventHandlerWithOptions(handler, cache.HandlerOptions{
169+
ResyncPeriod: &f.defaultEventHandlerResyncPeriod,
170+
})
169171
}
170172

171-
func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, _ time.Duration) (cache.ResourceEventHandlerRegistration, error) {
173+
func (f *FileSharedIndexInformer) AddEventHandlerWithOptions(handler cache.ResourceEventHandler, _ cache.HandlerOptions) (cache.ResourceEventHandlerRegistration, error) {
172174
f.RLock()
173175
if f.started {
174176
panic("cannot add event handlers after informer has started")
@@ -182,6 +184,12 @@ func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.
182184
return nil, nil
183185
}
184186

187+
func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, _ time.Duration) (cache.ResourceEventHandlerRegistration, error) {
188+
return f.AddEventHandlerWithOptions(handler, cache.HandlerOptions{
189+
ResyncPeriod: &f.defaultEventHandlerResyncPeriod,
190+
})
191+
}
192+
185193
// RemoveEventHandler implements cache.SharedInformer
186194
func (*FileSharedIndexInformer) RemoveEventHandler(_ cache.ResourceEventHandlerRegistration) error {
187195
// TODO implement me
@@ -198,6 +206,10 @@ func (f *FileSharedIndexInformer) GetController() cache.Controller {
198206
panic("implement me")
199207
}
200208

209+
func (f *FileSharedIndexInformer) RunWithContext(ctx context.Context) {
210+
f.Run(ctx.Done())
211+
}
212+
201213
func (f *FileSharedIndexInformer) Run(stopCh <-chan struct{}) {
202214
f.Do(func() {
203215
defer utilruntime.HandleCrash()
@@ -311,6 +323,11 @@ func (f *FileSharedIndexInformer) SetWatchErrorHandler(_ cache.WatchErrorHandler
311323
panic("implement me")
312324
}
313325

326+
func (f *FileSharedIndexInformer) SetWatchErrorHandlerWithContext(_ cache.WatchErrorHandlerWithContext) error {
327+
// TODO implement me
328+
panic("implement me")
329+
}
330+
314331
func (f *FileSharedIndexInformer) AddIndexers(_ cache.Indexers) error {
315332
// TODO implement me
316333
panic("implement me")

0 commit comments

Comments
 (0)