@@ -41,9 +41,11 @@ import (
4141 utilnet "k8s.io/apimachinery/pkg/util/net"
4242 "k8s.io/apimachinery/pkg/util/validation"
4343 "k8s.io/client-go/transport"
44+ "k8s.io/klog/v2"
4445 "k8s.io/utils/ptr"
4546 ctrl "sigs.k8s.io/controller-runtime"
4647 ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
48+ "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
4749
4850 runtimehooksv1 "sigs.k8s.io/cluster-api/api/runtime/hooks/v1alpha1"
4951 runtimev1 "sigs.k8s.io/cluster-api/api/runtime/v1beta2"
@@ -172,21 +174,25 @@ func (c *client) Unregister(extensionConfig *runtimev1.ExtensionConfig) error {
172174 return nil
173175}
174176
175- func (c * client ) GetAllExtensions (ctx context.Context , hook runtimecatalog.Hook , forObject metav1 .Object ) ([]string , error ) {
177+ func (c * client ) GetAllExtensions (ctx context.Context , hook runtimecatalog.Hook , forObject ctrlclient .Object ) ([]string , error ) {
176178 hookName := runtimecatalog .HookName (hook )
177179 log := ctrl .LoggerFrom (ctx ).WithValues ("hook" , hookName )
178180 ctx = ctrl .LoggerInto (ctx , log )
179181 gvh , err := c .catalog .GroupVersionHook (hook )
180182 if err != nil {
181183 return nil , errors .Wrapf (err , "failed to get extension handlers for hook %q: failed to compute GroupVersionHook" , hookName )
182184 }
185+ forObjectGVK , err := apiutil .GVKForObject (forObject , c .client .Scheme ())
186+ if err != nil {
187+ return nil , errors .Wrapf (err , "failed to get extension handlers for hook %q: failed to get GroupVersionKind for the object the hook is executed for" , hookName )
188+ }
183189
184190 registrations , err := c .registry .List (gvh .GroupHook ())
185191 if err != nil {
186192 return nil , errors .Wrapf (err , "failed to get extension handlers for hook %q" , gvh .GroupHook ())
187193 }
188194
189- log .V (4 ).Info (fmt .Sprintf ("Getting all extensions of hook %q" , hookName ))
195+ log .V (4 ).Info (fmt .Sprintf ("Getting all extensions of hook %q for %s %s " , hookName , forObjectGVK . Kind , klog . KObj ( forObject ) ))
190196 matchingRegistrations := []string {}
191197 for _ , registration := range registrations {
192198 // Compute whether the object the get is being made for matches the namespaceSelector
@@ -210,14 +216,18 @@ func (c *client) GetAllExtensions(ctx context.Context, hook runtimecatalog.Hook,
210216// This ensures we don't end up waiting for timeout from multiple unreachable Extensions.
211217// See CallExtension for more details on when an ExtensionHandler returns an error.
212218// The aggregated result of the ExtensionHandlers is updated into the response object passed to the function.
213- func (c * client ) CallAllExtensions (ctx context.Context , hook runtimecatalog.Hook , forObject metav1 .Object , request runtimehooksv1.RequestObject , response runtimehooksv1.ResponseObject ) error {
219+ func (c * client ) CallAllExtensions (ctx context.Context , hook runtimecatalog.Hook , forObject ctrlclient .Object , request runtimehooksv1.RequestObject , response runtimehooksv1.ResponseObject ) error {
214220 hookName := runtimecatalog .HookName (hook )
215221 log := ctrl .LoggerFrom (ctx ).WithValues ("hook" , hookName )
216222 ctx = ctrl .LoggerInto (ctx , log )
217223 gvh , err := c .catalog .GroupVersionHook (hook )
218224 if err != nil {
219225 return errors .Wrapf (err , "failed to call extension handlers for hook %q: failed to compute GroupVersionHook" , hookName )
220226 }
227+ forObjectGVK , err := apiutil .GVKForObject (forObject , c .client .Scheme ())
228+ if err != nil {
229+ return errors .Wrapf (err , "failed to call extension handlers for hook %q: failed to get GroupVersionKind for the object the hook is executed for" , hookName )
230+ }
221231 // Make sure the request is compatible with the hook.
222232 if err := c .catalog .ValidateRequest (gvh , request ); err != nil {
223233 return errors .Wrapf (err , "failed to call extension handlers for hook %q: request object is invalid for hook" , gvh .GroupHook ())
@@ -232,7 +242,7 @@ func (c *client) CallAllExtensions(ctx context.Context, hook runtimecatalog.Hook
232242 return errors .Wrapf (err , "failed to call extension handlers for hook %q" , gvh .GroupHook ())
233243 }
234244
235- log .V (4 ).Info (fmt .Sprintf ("Calling all extensions of hook %q" , hookName ))
245+ log .V (4 ).Info (fmt .Sprintf ("Calling all extensions of hook %q for %s %s " , hookName , forObjectGVK . Kind , klog . KObj ( forObject ) ))
236246 responses := []runtimehooksv1.ResponseObject {}
237247 for _ , registration := range registrations {
238248 // Creates a new instance of the response parameter.
@@ -304,7 +314,7 @@ func aggregateSuccessfulResponses(aggregatedResponse runtimehooksv1.ResponseObje
304314// Nb. FailurePolicy does not affect the following kinds of errors:
305315// - Internal errors. Examples: hooks is incompatible with ExtensionHandler, ExtensionHandler information is missing.
306316// - Error when ExtensionHandler returns a response with `Status` set to `Failure`.
307- func (c * client ) CallExtension (ctx context.Context , hook runtimecatalog.Hook , forObject metav1 .Object , name string , request runtimehooksv1.RequestObject , response runtimehooksv1.ResponseObject , opts ... runtimeclient.CallExtensionOption ) error {
317+ func (c * client ) CallExtension (ctx context.Context , hook runtimecatalog.Hook , forObject ctrlclient .Object , name string , request runtimehooksv1.RequestObject , response runtimehooksv1.ResponseObject , opts ... runtimeclient.CallExtensionOption ) error {
308318 // Calculate the options.
309319 options := & runtimeclient.CallExtensionOptions {}
310320 for _ , opt := range opts {
0 commit comments