Skip to content

Can't define Default method for kinds watched by multiple controllers #483

@ekuefler

Description

@ekuefler

My manager installs multiple controllers for the same kind. If I define a Default() method for that kind, I get an error on startup:

2019-06-10T16:42:05.355-0700	INFO	controller-runtime.builder	Registering a mutating webhook	{"GVK": "my-group/v1alpha1, Kind=MyKind", "path": "/mutate-my-group-v1-alpha1-my-kind"}
panic: can't register duplicate path: /mutate-my-group-v1-alpha1-my-kind

goroutine 1 [running]:
sigs.k8s.io/controller-runtime/pkg/webhook.(*Server).Register(0xc0004510e0, 0xc0000e83c0, 0x41, 0x16f2dc0, 0xc0003f5110)
	/home/ekuefler/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/webhook/server.go:96 +0x25a
sigs.k8s.io/controller-runtime/pkg/builder.(*Builder).doWebhook(0xc000411300, 0x16f1360, 0xc0003f50b0)
	/home/ekuefler/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/builder/build.go:274 +0x89c
sigs.k8s.io/controller-runtime/pkg/builder.(*Builder).Build(0xc000411300, 0x16f1360, 0xc0003f50b0, 0x0, 0x1, 0xc000495180, 0x0)
	/home/ekuefler/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/builder/build.go:164 +0xcc
sigs.k8s.io/controller-runtime/pkg/builder.(*Builder).Complete(...)
	/home/ekuefler/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/builder/build.go:136
environments/controllers/localhost.(*ConfigMapReconciler).setupWithManager(0xc0003f50b0, 0x17478c0, 0xc0002fb680, 0x172ce60, 0xc0004aaf60)
	/home/ekuefler/environments/controllers/localhost/config_map_reconciler.go:91 +0xfd
environments/controllers/localhost.(*Reconciler).SetupWithManager(0xc000127ea8, 0x17478c0, 0xc0002fb680, 0x172ce60, 0xc0004aab40)
	/home/ekuefler/environments/controllers/localhost/reconciler.go:32 +0x1b8
main.main()
	/home/ekuefler/environments/main.go:55 +0x330

Presumably this is due to

blder.mgr.GetWebhookServer().Register(path, mwh)
, where the builder tries to register a new path in the manager every time a controller is created.

I may be doing something wrong, as the webhook stuff seems mostly undocumented and I'm just trying to figure it out by picking through code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.priority/critical-urgentHighest priority. Must be actively worked on as someone's top priority right now.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions