GoogleCloudPlatform / metacontroller

Lightweight Kubernetes controllers as a service
https://metacontroller.app/
Apache License 2.0
791 stars 104 forks source link

panic when testing the decorator controller #39

Closed raffaelespazzoli closed 6 years ago

raffaelespazzoli commented 6 years ago

hi, I am getting this error when using the decorator controller:


I0321 03:40:45.050706       1 main.go:55] Discovery cache flush interval: 10s
--
  | I0321 03:40:45.056929       1 main.go:56] API server object cache flush interval: 30m0s
  | I0321 03:40:45.058576       1 reflector.go:202] Starting reflector *v1alpha1.CompositeController (30m0s) from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.058604       1 reflector.go:240] Listing and watching *v1alpha1.CompositeController from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.058753       1 reflector.go:202] Starting reflector *v1alpha1.ControllerRevision (30m0s) from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.058763       1 reflector.go:240] Listing and watching *v1alpha1.ControllerRevision from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.060036       1 metacontroller.go:92] Starting CompositeController metacontroller
  | I0321 03:40:45.060052       1 controller.go:32] Waiting for caches to sync for CompositeController controller
  | I0321 03:40:45.060111       1 metacontroller.go:85] Starting DecoratorController metacontroller
  | I0321 03:40:45.060130       1 reflector.go:202] Starting reflector *v1alpha1.DecoratorController (30m0s) from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.060141       1 reflector.go:240] Listing and watching *v1alpha1.DecoratorController from k8s.io/metacontroller/client/generated/informer/externalversions/factory.go:74
  | I0321 03:40:45.060141       1 controller.go:32] Waiting for caches to sync for DecoratorController controller
  | I0321 03:40:45.160202       1 shared_informer.go:123] caches populated
  | I0321 03:40:45.160225       1 controller.go:39] Caches are synced for CompositeController controller
  | I0321 03:40:45.160328       1 shared_informer.go:123] caches populated
  | I0321 03:40:45.160337       1 controller.go:39] Caches are synced for DecoratorController controller
  | I0321 03:40:45.160371       1 metacontroller.go:141] sync DecoratorController microsegmentation
  | I0321 03:40:45.160582       1 factory.go:104] Starting shared informer for services in v1
  | I0321 03:40:45.160661       1 asm_amd64.s:573] Shutting down DecoratorController metacontroller
  | E0321 03:40:45.160733       1 runtime.go:66] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:72
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:65
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:51
  | /usr/local/google/home/enisoc/.gvm/gos/go1.10/src/runtime/asm_amd64.s:573
  | /usr/local/google/home/enisoc/.gvm/gos/go1.10/src/runtime/panic.go:505
  | /usr/local/google/home/enisoc/.gvm/gos/go1.10/src/runtime/panic.go:63
  | /usr/local/google/home/enisoc/.gvm/gos/go1.10/src/runtime/signal_unix.go:388
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/controller.go:106
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/controller.go:126
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/metacontroller.go:171
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/metacontroller.go:156
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/metacontroller.go:124
  | /usr/local/google/home/enisoc/k8s/src/k8s.io/metacontroller/controller/decorator/metacontroller.go:94
  | /usr/local/google/home/enisoc/.gvm/gos/go1.10/src/runtime/asm_amd64.s:2361

my controller definition is the following:

kind: DecoratorController
metadata:
  name: microsegmentation
spec:
  resources:
  - apiVersion: v1
    resource: services
    annotationSelector:
      matchExpressions:
      - {key: io.raffa.microsegmentation, operator: In, values: ['true']}
  attachments:
  - apiVersion: v1beta1
    resource: networkpolicies
  hooks:
    sync:
      webhook:
        url: http://microsegmentation.metacontroller:8080/microsegmentation
enisoc commented 6 years ago

I think the trigger was that apiVersion for networkpolicies should be either extensions/v1beta1 or networking.k8s.io/v1.

I'm still looking into why this misconfiguration caused a panic.

enisoc commented 6 years ago

After the fix in #40, I now get the expected error:

failed to sync DecoratorController "microsegmentation": can't create informer for child resource: can't create client for networkpolicies.v1beta1 shared informer: discovery: can't find resource networkpolicies in apiVersion v1beta1

If I change apiVersion to extensions/v1beta1, the error goes away.