Skip to content

Commit ee7dc0b

Browse files
committed
raname hooks to handlers
1 parent 4e908f1 commit ee7dc0b

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

apiexport/provider.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242

4343
apisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
4444

45-
"github.com/kcp-dev/multicluster-provider/internal/hooks"
45+
"github.com/kcp-dev/multicluster-provider/internal/handlers"
4646
"github.com/kcp-dev/multicluster-provider/internal/provider"
4747
)
4848

@@ -61,8 +61,8 @@ type Provider struct {
6161
providersLock sync.RWMutex
6262
providers map[string]*provider.Provider
6363

64-
log logr.Logger
65-
hooks hooks.Hooks
64+
log logr.Logger
65+
handlers handlers.Handlers
6666

6767
config *rest.Config
6868
scheme *runtime.Scheme
@@ -88,9 +88,9 @@ type Options struct {
8888
// the same endpoint semantics.
8989
ObjectToWatch client.Object
9090

91-
// Hooks are lifecycle hook, ran for each logical cluster in the provider represented
91+
// Handlers are lifecycle handlers, ran for each logical cluster in the provider represented
9292
// by apibinding object.
93-
Hooks hooks.Hooks
93+
Handlers handlers.Handlers
9494
}
9595

9696
// New creates a new kcp virtual workspace provider. The provided [rest.Config]
@@ -133,8 +133,8 @@ func New(cfg *rest.Config, endpointSliceName string, options Options) (*Provider
133133
object: options.ObjectToWatch,
134134
cache: c,
135135

136-
log: *options.Log,
137-
hooks: options.Hooks,
136+
log: *options.Log,
137+
handlers: options.Handlers,
138138
}, nil
139139
}
140140

@@ -239,7 +239,7 @@ func (p *Provider) update(es *apisv1alpha1.APIExportEndpointSlice) {
239239
ObjectToWatch: p.object,
240240
Scheme: p.scheme,
241241
Log: &logger,
242-
Hooks: p.hooks,
242+
Handlers: p.handlers,
243243
})
244244
if err != nil {
245245
p.log.Error(err, "failed to create provider")
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package hooks
17+
package handlers
1818

1919
import (
2020
"sigs.k8s.io/controller-runtime/pkg/client"
2121
)
2222

23-
// Hooks is a collection of Hook.
24-
type Hooks []Hook
23+
// Handlers is a collection of Handler.
24+
type Handlers []Handler
2525

26-
// Hook are lifecycle hook for logical clusters managed by a provider and presented as
26+
// Handler are lifecycle hook for logical clusters managed by a provider and presented as
2727
// apibindings via APIExport virtual workspace.
2828
// It allows to react to addition, update and deletion of apibindings (consumers) in the provider.
29-
// Hooks should be implemented with care to avoid blocking the main reconciliation loop.
30-
type Hook interface {
29+
// Handlers should be implemented with care to avoid blocking the main reconciliation loop.
30+
type Handler interface {
3131
// OnAdd is called when a new logical cluster is added.
3232
OnAdd(obj client.Object)
3333

@@ -38,23 +38,23 @@ type Hook interface {
3838
OnDelete(obj client.Object)
3939
}
4040

41-
// RunOnAdd runs OnAdd on all hooks.
42-
func (h Hooks) RunOnAdd(obj client.Object) {
43-
for _, hook := range h {
44-
hook.OnAdd(obj)
41+
// RunOnAdd runs OnAdd on all handlers.
42+
func (h Handlers) RunOnAdd(obj client.Object) {
43+
for _, handler := range h {
44+
handler.OnAdd(obj)
4545
}
4646
}
4747

48-
// RunOnUpdate runs OnUpdate on all hooks.
49-
func (h Hooks) RunOnUpdate(oldObj, newObj client.Object) {
50-
for _, hook := range h {
51-
hook.OnUpdate(oldObj, newObj)
48+
// RunOnUpdate runs OnUpdate on all handlers.
49+
func (h Handlers) RunOnUpdate(oldObj, newObj client.Object) {
50+
for _, handler := range h {
51+
handler.OnUpdate(oldObj, newObj)
5252
}
5353
}
5454

55-
// RunOnDelete runs OnDelete on all hooks.
56-
func (h Hooks) RunOnDelete(obj client.Object) {
57-
for _, hook := range h {
58-
hook.OnDelete(obj)
55+
// RunOnDelete runs OnDelete on all handlers.
56+
func (h Handlers) RunOnDelete(obj client.Object) {
57+
for _, handler := range h {
58+
handler.OnDelete(obj)
5959
}
6060
}

internal/provider/provider.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444

4545
mcpcache "github.com/kcp-dev/multicluster-provider/internal/cache"
4646
mcrecorder "github.com/kcp-dev/multicluster-provider/internal/events/recorder"
47-
"github.com/kcp-dev/multicluster-provider/internal/hooks"
47+
"github.com/kcp-dev/multicluster-provider/internal/handlers"
4848
)
4949

5050
// Clusters is an alias for clusters.Clusters[cluster.Cluster].
@@ -68,7 +68,7 @@ type Provider struct {
6868
aware multicluster.Aware
6969
clusters *Clusters
7070
cancelFns map[logicalcluster.Name]context.CancelFunc
71-
hooks hooks.Hooks
71+
handlers handlers.Handlers
7272

7373
recorderProvider *mcrecorder.Provider
7474
}
@@ -85,7 +85,7 @@ type Options struct {
8585

8686
// ObjectToWatch is the object type that the provider watches via a /clusters/*
8787
// wildcard endpoint to extract information about logical clusters joining and
88-
// leaving the "fleet" of (logical) clusters in kcp. If this is nil, it defaults
88+
// leaving the "fleet" of (logical) clustergit pushs in kcp. If this is nil, it defaults
8989
// to [apisv1alpha1.APIBinding]. This might be useful when using this provider
9090
// against custom virtual workspaces that are not the APIExport one but share
9191
// the same endpoint semantics.
@@ -100,9 +100,9 @@ type Options struct {
100100
// stopped with the manager.
101101
makeBroadcaster mcrecorder.EventBroadcasterProducer
102102

103-
// Hooks are lifecycle hooks for logical clusters managed by this provider represented
103+
// Handlers are lifecycle handlers for logical clusters managed by this provider represented
104104
// by apibinding object.
105-
Hooks hooks.Hooks
105+
Handlers handlers.Handlers
106106
}
107107

108108
// New creates a new kcp virtual workspace provider. The provided [rest.Config]
@@ -148,12 +148,12 @@ func New(cfg *rest.Config, clusters *Clusters, options Options) (*Provider, erro
148148
}
149149

150150
return &Provider{
151-
config: cfg,
152-
scheme: options.Scheme,
153-
cache: options.WildcardCache,
154-
object: options.ObjectToWatch,
155-
hooks: options.Hooks,
156-
log: *options.Log,
151+
config: cfg,
152+
scheme: options.Scheme,
153+
cache: options.WildcardCache,
154+
object: options.ObjectToWatch,
155+
handlers: options.Handlers,
156+
log: *options.Log,
157157

158158
cancelFns: map[logicalcluster.Name]context.CancelFunc{},
159159
clusters: clusters,
@@ -206,15 +206,15 @@ func (p *Provider) Start(ctx context.Context, aware multicluster.Aware) error {
206206
return
207207
}
208208
p.cancelFns[clusterName] = cancel
209-
p.hooks.RunOnAdd(cobj)
209+
p.handlers.RunOnAdd(cobj)
210210
},
211211
UpdateFunc: func(oldObj, newObj interface{}) {
212212
cobj, ok := newObj.(client.Object)
213213
if !ok {
214214
klog.Errorf("unexpected object type %T", newObj)
215215
return
216216
}
217-
p.hooks.RunOnUpdate(oldObj.(client.Object), cobj)
217+
p.handlers.RunOnUpdate(oldObj.(client.Object), cobj)
218218
},
219219
DeleteFunc: func(obj any) {
220220
cobj, ok := obj.(client.Object)
@@ -253,7 +253,7 @@ func (p *Provider) Start(ctx context.Context, aware multicluster.Aware) error {
253253
cancel()
254254
delete(p.cancelFns, clusterName)
255255
p.clusters.Remove(clusterName.String())
256-
p.hooks.RunOnDelete(cobj)
256+
p.handlers.RunOnDelete(cobj)
257257
}
258258
}
259259
},

path-aware/provider.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import (
2929
kcpcore "github.com/kcp-dev/sdk/apis/core"
3030

3131
provider "github.com/kcp-dev/multicluster-provider/apiexport"
32-
"github.com/kcp-dev/multicluster-provider/internal/hooks"
32+
"github.com/kcp-dev/multicluster-provider/internal/handlers"
3333
"github.com/kcp-dev/multicluster-provider/internal/paths"
3434
)
3535

3636
var _ multicluster.Provider = &Provider{}
3737
var _ multicluster.ProviderRunnable = &Provider{}
38-
var _ hooks.Hook = &pathHook{}
38+
var _ handlers.Handler = &pathHandler{}
3939

4040
// Provider is a [sigs.k8s.io/multicluster-runtime/pkg/multicluster.Provider] that represents each [logical cluster]
4141
// (in the kcp sense) exposed via a APIExport virtual workspace as a cluster in the [sigs.k8s.io/multicluster-runtime] sense.
@@ -55,10 +55,10 @@ type Provider struct {
5555
func New(cfg *rest.Config, endpointSliceName string, options provider.Options) (*Provider, error) {
5656
store := paths.New()
5757

58-
h := &pathHook{
58+
h := &pathHandler{
5959
pathStore: store,
6060
}
61-
options.Hooks = append(options.Hooks, h)
61+
options.Handlers = append(options.Handlers, h)
6262

6363
p, err := provider.New(cfg, endpointSliceName, options)
6464
if err != nil {
@@ -91,11 +91,11 @@ func (p *Provider) Start(ctx context.Context, aware multicluster.Aware) error {
9191
return p.Provider.Start(ctx, aware)
9292
}
9393

94-
type pathHook struct {
94+
type pathHandler struct {
9595
pathStore *paths.Store
9696
}
9797

98-
func (p *pathHook) OnAdd(obj client.Object) {
98+
func (p *pathHandler) OnAdd(obj client.Object) {
9999
cluster := logicalcluster.From(obj)
100100

101101
path := obj.GetAnnotations()[kcpcore.LogicalClusterPathAnnotationKey]
@@ -106,11 +106,11 @@ func (p *pathHook) OnAdd(obj client.Object) {
106106
p.pathStore.Add(path, cluster)
107107
}
108108

109-
func (p *pathHook) OnUpdate(oldObj, newObj client.Object) {
109+
func (p *pathHandler) OnUpdate(oldObj, newObj client.Object) {
110110
// Not used.
111111
}
112112

113-
func (p *pathHook) OnDelete(obj client.Object) {
113+
func (p *pathHandler) OnDelete(obj client.Object) {
114114
path, ok := obj.GetAnnotations()[kcpcore.LogicalClusterPathAnnotationKey]
115115
if !ok {
116116
return

0 commit comments

Comments
 (0)