Skip to content

Commit 238e64e

Browse files
authored
Merge pull request #28 from authzed/k8s-1-26
2 parents b7c14e3 + 841f199 commit 238e64e

File tree

5 files changed

+211
-178
lines changed

5 files changed

+211
-178
lines changed

fileinformer/file_informer.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type FileSharedIndexInformer struct {
145145
handlers []cache.ResourceEventHandler
146146
}
147147

148-
var _ cache.SharedIndexInformer = &FileSharedIndexInformer{}
148+
var _ cache.SharedIndexInformer = (*FileSharedIndexInformer)(nil)
149149

150150
// NewFileSharedIndexInformer creates a new informer watching the file
151151
// Note that currently all event handlers share the default resync period.
@@ -159,11 +159,13 @@ func NewFileSharedIndexInformer(log logr.Logger, fileName string, watcher *fsnot
159159
}
160160
}
161161

162-
func (f *FileSharedIndexInformer) AddEventHandler(handler cache.ResourceEventHandler) {
163-
f.AddEventHandlerWithResyncPeriod(handler, f.defaultEventHandlerResyncPeriod)
162+
func (f *FileSharedIndexInformer) IsStopped() bool { return !f.started }
163+
164+
func (f *FileSharedIndexInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error) {
165+
return f.AddEventHandlerWithResyncPeriod(handler, f.defaultEventHandlerResyncPeriod)
164166
}
165167

166-
func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) {
168+
func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error) {
167169
f.RLock()
168170
if f.started {
169171
panic("cannot add event handlers after informer has started")
@@ -173,6 +175,14 @@ func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.
173175
defer f.Unlock()
174176
f.handlers = append(f.handlers, handler)
175177
// TODO: non-default resync period
178+
179+
return nil, nil
180+
}
181+
182+
// RemoveEventHandler implements cache.SharedInformer
183+
func (*FileSharedIndexInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error {
184+
// TODO implement me
185+
panic("unimplemented")
176186
}
177187

178188
func (f *FileSharedIndexInformer) GetStore() cache.Store {
@@ -240,24 +250,22 @@ func (f *FileSharedIndexInformer) Run(stopCh <-chan struct{}) {
240250
continue
241251
}
242252
f.log.V(4).Info("filewatcher got event", "event", event.String(), "event_name", event.Name)
243-
if event.Op&fsnotify.Write == fsnotify.Write ||
244-
event.Op&fsnotify.Create == fsnotify.Create {
253+
if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) {
245254
f.RLock()
246255
for _, h := range f.handlers {
247256
h.OnAdd(fileName)
248257
}
249258
f.RUnlock()
250259
}
251260
// chmod is the event from a configmap reload in kube
252-
if event.Op&fsnotify.Rename == fsnotify.Rename ||
253-
event.Op&fsnotify.Chmod == fsnotify.Chmod {
261+
if event.Has(fsnotify.Rename) || event.Has(fsnotify.Chmod) {
254262
f.RLock()
255263
for _, h := range f.handlers {
256264
h.OnUpdate(fileName, fileName)
257265
}
258266
f.RUnlock()
259267
}
260-
if event.Op&fsnotify.Remove == fsnotify.Remove {
268+
if event.Has(fsnotify.Remove) {
261269
f.RLock()
262270
for _, h := range f.handlers {
263271
h.OnDelete(fileName)

fileinformer/file_informer_test.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ func TestFileInformer(t *testing.T) {
3232
eventHandlers2.On("OnAdd", file2.Name()).Return()
3333

3434
inf := informerFactory.ForResource(FileGroupVersion.WithResource(file.Name())).Informer()
35-
inf.AddEventHandler(eventHandlers)
35+
_, err = inf.AddEventHandler(eventHandlers)
36+
require.NoError(t, err)
3637
inf2 := informerFactory.ForResource(FileGroupVersion.WithResource(file2.Name())).Informer()
37-
inf2.AddEventHandler(eventHandlers2)
38+
_, err = inf2.AddEventHandler(eventHandlers2)
39+
require.NoError(t, err)
3840

3941
ctx, cancel := context.WithCancel(context.Background())
4042
informerFactory.Start(ctx.Done())
@@ -75,7 +77,14 @@ func TestFileInformer(t *testing.T) {
7577
require.Eventually(t, func() bool {
7678
eventHandlers.Lock()
7779
defer eventHandlers.Unlock()
78-
return len(eventHandlers.Calls) == 4
80+
81+
foundDelete := false
82+
for _, call := range eventHandlers.Calls {
83+
if call.Method == "OnDelete" {
84+
foundDelete = true
85+
}
86+
}
87+
return foundDelete
7988
}, 500*time.Millisecond, 10*time.Millisecond)
8089

8190
cancel()

go.mod

+51-48
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,103 @@ go 1.19
55
require (
66
github.com/cespare/xxhash/v2 v2.1.2
77
github.com/davecgh/go-spew v1.1.1
8-
github.com/fsnotify/fsnotify v1.5.4
8+
github.com/fsnotify/fsnotify v1.6.0
99
github.com/go-logr/logr v1.2.3
1010
github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0
11-
github.com/prometheus/client_golang v1.13.0
11+
github.com/prometheus/client_golang v1.14.0
1212
github.com/stretchr/testify v1.8.0
1313
golang.org/x/exp v0.0.0-20220823124025-807a23277127
1414
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde
15-
k8s.io/api v0.25.0
16-
k8s.io/apiextensions-apiserver v0.25.0
17-
k8s.io/apimachinery v0.25.0
18-
k8s.io/apiserver v0.25.0
19-
k8s.io/client-go v0.25.0
20-
k8s.io/component-base v0.25.0
21-
k8s.io/controller-manager v0.25.0
22-
k8s.io/klog/v2 v2.80.0
23-
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73
15+
k8s.io/api v0.26.0
16+
k8s.io/apiextensions-apiserver v0.26.0
17+
k8s.io/apimachinery v0.26.0
18+
k8s.io/apiserver v0.26.0
19+
k8s.io/client-go v0.26.0
20+
k8s.io/component-base v0.26.0
21+
k8s.io/controller-manager v0.26.0
22+
k8s.io/klog/v2 v2.80.1
23+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
2424
mvdan.cc/gofumpt v0.3.1
25-
sigs.k8s.io/controller-runtime v0.12.3
25+
sigs.k8s.io/controller-runtime v0.14.1
2626
)
2727

2828
require (
2929
github.com/NYTimes/gziphandler v1.1.1 // indirect
30-
github.com/PuerkitoBio/purell v1.1.1 // indirect
31-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
30+
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
3231
github.com/beorn7/perks v1.0.1 // indirect
3332
github.com/blang/semver/v4 v4.0.0 // indirect
33+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
3434
github.com/coreos/go-semver v0.3.0 // indirect
3535
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
36-
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
36+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
3737
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
38-
github.com/felixge/httpsnoop v1.0.1 // indirect
38+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
39+
github.com/felixge/httpsnoop v1.0.3 // indirect
40+
github.com/go-logr/stdr v1.2.2 // indirect
3941
github.com/go-openapi/jsonpointer v0.19.5 // indirect
40-
github.com/go-openapi/jsonreference v0.19.5 // indirect
42+
github.com/go-openapi/jsonreference v0.20.0 // indirect
4143
github.com/go-openapi/swag v0.19.14 // indirect
4244
github.com/gogo/protobuf v1.3.2 // indirect
4345
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4446
github.com/golang/protobuf v1.5.2 // indirect
47+
github.com/google/cel-go v0.12.5 // indirect
4548
github.com/google/gnostic v0.5.7-v3refs // indirect
46-
github.com/google/go-cmp v0.5.8 // indirect
49+
github.com/google/go-cmp v0.5.9 // indirect
4750
github.com/google/gofuzz v1.1.0 // indirect
4851
github.com/google/uuid v1.1.2 // indirect
4952
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
50-
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
53+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
5154
github.com/imdario/mergo v0.3.12 // indirect
52-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
55+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
5356
github.com/josharian/intern v1.0.0 // indirect
5457
github.com/json-iterator/go v1.1.12 // indirect
5558
github.com/mailru/easyjson v0.7.6 // indirect
56-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
59+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
5760
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5861
github.com/modern-go/reflect2 v1.0.2 // indirect
5962
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6063
github.com/pkg/errors v0.9.1 // indirect
6164
github.com/pmezard/go-difflib v1.0.0 // indirect
62-
github.com/prometheus/client_model v0.2.0 // indirect
65+
github.com/prometheus/client_model v0.3.0 // indirect
6366
github.com/prometheus/common v0.37.0 // indirect
6467
github.com/prometheus/procfs v0.8.0 // indirect
65-
github.com/spf13/cobra v1.4.0 // indirect
68+
github.com/spf13/cobra v1.6.0 // indirect
6669
github.com/spf13/pflag v1.0.5 // indirect
70+
github.com/stoewer/go-strcase v1.2.0 // indirect
6771
github.com/stretchr/objx v0.4.0 // indirect
68-
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
69-
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
70-
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
71-
go.opentelemetry.io/contrib v0.20.0 // indirect
72-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 // indirect
73-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
74-
go.opentelemetry.io/otel v0.20.0 // indirect
75-
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
76-
go.opentelemetry.io/otel/metric v0.20.0 // indirect
77-
go.opentelemetry.io/otel/sdk v0.20.0 // indirect
78-
go.opentelemetry.io/otel/sdk/export/metric v0.20.0 // indirect
79-
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
80-
go.opentelemetry.io/otel/trace v0.20.0 // indirect
81-
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
72+
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
73+
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
74+
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
75+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 // indirect
76+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.0 // indirect
77+
go.opentelemetry.io/otel v1.10.0 // indirect
78+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
79+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect
80+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 // indirect
81+
go.opentelemetry.io/otel/metric v0.31.0 // indirect
82+
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
83+
go.opentelemetry.io/otel/trace v1.10.0 // indirect
84+
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
8285
go.uber.org/atomic v1.7.0 // indirect
8386
go.uber.org/multierr v1.6.0 // indirect
84-
go.uber.org/zap v1.19.1 // indirect
85-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
86-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
87+
go.uber.org/zap v1.24.0 // indirect
88+
golang.org/x/mod v0.6.0 // indirect
89+
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
8790
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
88-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
89-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
90-
golang.org/x/text v0.3.7 // indirect
91-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
92-
golang.org/x/tools v0.1.12 // indirect
91+
golang.org/x/sys v0.3.0 // indirect
92+
golang.org/x/term v0.3.0 // indirect
93+
golang.org/x/text v0.5.0 // indirect
94+
golang.org/x/time v0.3.0 // indirect
95+
golang.org/x/tools v0.2.0 // indirect
9396
google.golang.org/appengine v1.6.7 // indirect
9497
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
95-
google.golang.org/grpc v1.47.0 // indirect
98+
google.golang.org/grpc v1.49.0 // indirect
9699
google.golang.org/protobuf v1.28.1 // indirect
97100
gopkg.in/inf.v0 v0.9.1 // indirect
98101
gopkg.in/yaml.v2 v2.4.0 // indirect
99102
gopkg.in/yaml.v3 v3.0.1 // indirect
100-
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
101-
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.32 // indirect
103+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
104+
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33 // indirect
102105
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
103106
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
104107
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)