GoogleCloudPlatform / metacontroller

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

CompositeController without children #156

Closed trondhindenes closed 5 years ago

trondhindenes commented 5 years ago

We're looking to use Metacontroller in order to offload the "CRUD Loop" work, but the objects we're looking at are "flat", e.g. there's no need for a parent/child relationship.

For example we're looking at using kind: foo where webhooks will ensure that instances of foo are provisioned in a 3rd party system. When each instance of foo is deleted, we want to run a deprovisioning process.

It's unclear to me if metacontroller is a good choice for this, given the documentation's focus on interacting with "known" Kubernetes constructs (Ingresses, Jobs, etc) using the CompositeController type.

luisdavim commented 5 years ago

I use the composite controller without children in a similar situation to the one you're describing, no problems so far.

enisoc commented 5 years ago

As @luisdavim mentioned, CompositeController has been enhanced since the docs were originally written to better support managing "children" that are actually in a third-party system.

For example, in addition to the controller-wide resync period for checking external state (since Metacontroller doesn't know when things change there), you can now use resyncAfterSeconds to request faster resync for specific objects when your hook knows to expect changes soon (e.g. when waiting for an async process to complete). Note resyncAfterSeconds is an experimental new feature in the latest alpha (metacontroller/metacontroller:v0.4.0).

To make sure you get a chance to clean up third-party instances, I recommend using the finalize hook.

trondhindenes commented 5 years ago

Thanks for the feedback both, I was able to do a bit of work on this yesterday, and it seems to be working perfectly. Our use case is to use CRDs to generate AWS Cloudformation stacks based on abstractions (which is why we won't use the regular Service Broker for AWS etc), to make it super-easy for devs to (for example) auto-provision the required Kube2IAM role with correct trust settings etc.

I copied the "noop" example so I built this on a DecoratorController, and using both finalize and resyncAfterSeconds to make the cloudformation provisioning tasks complete. It all works beautifully so thanks for this project, it looks like it's gonna save us a bunch of time!

enisoc commented 5 years ago

Glad it worked out!