metacontroller / metacontroller

Writing kubernetes controllers can be simple
https://metacontroller.github.io/metacontroller
Apache License 2.0
857 stars 89 forks source link

Panic when only using the finalize hook in decorator #948

Open Shashankft9 opened 7 months ago

Shashankft9 commented 7 months ago

I have a usecase where i want to a hook to be called only when the resource is being deleted, with the assumption that nothing has to be done for create/update operations.

So, if i mention only the finalize hook, I see a runtime panic error in the logs of metacontroller:

image

Decorator looks something like this:

apiVersion: metacontroller.k8s.io/v1alpha1
kind: DecoratorController
metadata:
  name: call-removal-api
spec:
  hooks:
    finalize:
      version: v1
      webhook:
        url: http://call-removal-api.metacontroller.svc.cluster.local?type=delete    
  resources:
  - apiVersion: helm.toolkit.fluxcd.io/v2beta1
    resource: helmreleases

Should this be a supported use case in metacontroller?

grzesuav commented 7 months ago

@Shashankft9 which version do you use ? I remember it was reported already, and I was under impression it is fixed already

Shashankft9 commented 5 months ago

hey @grzesuav, I am using version 4.10.0, let me try the latest version and see if this feature is there - thanks!

Shashankft9 commented 3 months ago

@grzesuav I checked with the latest metacontroller, seems like this issue is present there as well, in this line: https://github.com/metacontroller/metacontroller/blob/master/pkg/controller/decorator/hooks.go#L60, here c.syncHook will be nil which will cause a panic. Couldn't this be fixed by just doing a check like c.syncHook.IsEnabled() ?