Skip to content

Instantly share code, notes, and snippets.

@isutton
Last active August 29, 2019 13:44
Show Gist options
  • Save isutton/8e3eeb0f08d42bd5ba65a4132bf01f5d to your computer and use it in GitHub Desktop.
Save isutton/8e3eeb0f08d42bd5ba65a4132bf01f5d to your computer and use it in GitHub Desktop.
Watch from Mapper example
type CRDToWatchMapper {
c *Controller
}
func (m *CRDToWatchMapper) Map(obj handler.MapObject) []reconcile.Request {
crdGvk := extractGVKFromCRD(obj.Object)
m.c.Watch(
createSourceForGVK(crdGvk),
&handler.EnqueueRequestsFromMapFunc{ToRequests: &SBRRequestMapper{}},
)
return []reconcile.Request{}
}
func add() {
// ...
err := c.Watch(
createSourceForGVK(v1.SchemeGroupVersion.WithKind("CustomResourceDefinition")),
&handler.EnqueueRequestsFromMapFunc{ToRequests: &CRDToWatchMapper{c: c}},
)
if err != nil {
return err
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment