Skip to content

Commit 2e8c770

Browse files
ryotaraiclaude
andcommitted
Update webhook registrations to use WebhookManagedBy for ResourceQuota and HierarchicalResourceQuota.
- Replace manual webhook registration with builder.WebhookManagedBy() pattern - Use NewResourceQuotaStatus constructor for ResourceQuota webhook - Use NewHRQ constructor for HierarchicalResourceQuota webhook - Add proper error handling for webhook creation - Remove old manual injection and registration code 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e260205 commit 2e8c770

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

internal/setup/webhooks.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,23 @@ func createWebhooks(mgr ctrl.Manager, f *forest.Forest, opts Options) error {
131131

132132
if opts.HRQ {
133133
// Create webhook for ResourceQuota status.
134-
{
135-
handler := &hrq.ResourceQuotaStatus{
136-
Log: ctrl.Log.WithName("validators").WithName("ResourceQuota"),
137-
Forest: f,
138-
}
139-
handler.InjectDecoder(decoder)
140-
handler.InjectClient(mgr.GetClient())
141-
mgr.GetWebhookServer().Register(hrq.ResourceQuotasStatusServingPath, &webhook.Admission{Handler: handler})
134+
rqStatusValidator := hrq.NewResourceQuotaStatus(f, mgr.GetClient())
135+
if err := builder.WebhookManagedBy(mgr).
136+
For(&corev1.ResourceQuota{}).
137+
WithCustomPath(hrq.ResourceQuotasStatusServingPath).
138+
WithValidator(rqStatusValidator).
139+
Complete(); err != nil {
140+
return fmt.Errorf("failed to create webhook for ResourceQuota status: %w", err)
142141
}
143142

144143
// Create webhook for HierarchicalResourceQuota spec.
145-
{
146-
handler := &hrq.HRQ{
147-
Log: ctrl.Log.WithName("validators").WithName("HierarchicalResourceQuota"),
148-
}
149-
handler.InjectDecoder(decoder)
150-
handler.InjectClient(mgr.GetClient())
151-
mgr.GetWebhookServer().Register(hrq.HRQServingPath, &webhook.Admission{Handler: handler})
144+
hrqValidator := hrq.NewHRQ(mgr.GetClient())
145+
if err := builder.WebhookManagedBy(mgr).
146+
For(&api.HierarchicalResourceQuota{}).
147+
WithCustomPath(hrq.HRQServingPath).
148+
WithValidator(hrqValidator).
149+
Complete(); err != nil {
150+
return fmt.Errorf("failed to create webhook for HierarchicalResourceQuota: %w", err)
152151
}
153152
}
154153

0 commit comments

Comments
 (0)