Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource lifecycle hooks #420

Open
lbialy opened this issue Mar 25, 2024 · 0 comments
Open

Add resource lifecycle hooks #420

lbialy opened this issue Mar 25, 2024 · 0 comments
Labels
area/api User visible API kind/enhancement New feature or request without workaround needs-design Needs from design work: architecture, API, DX/UX

Comments

@lbialy
Copy link
Collaborator

lbialy commented Mar 25, 2024

For example:

  extension [A <: besom.internal.Resource](outputOfResource: Output[A])
    def afterCreate(callback: A => Output[Unit]): Output[A] =
      for
        resource <- outputOfResource
        // make sure we run the callback after URN is resolved on a separate fork
        // CHECK THAT TASK TRACKER IS TRACKING THIS FORK
        _        <- (resource.urn *> callback(resource)).getData.fork 
      yield resource

This allows user to run code after a resource was actually created (by hijacking URN Promise resolution). Useful for execution of postconditions and unrelated tasks that have to happen ONLY for said resource, integrations for instance.

Separate fork is necessary to prevent pollution of main thread (that declares resources) with dynamic Output that will short-circuit on empty during dry-run and remove subsequent resources from the plan.

Use cases:

  • grafana instance can be configured post start with a hook (without init containers)
  • interact with a kubernetes service through a port-forward
@lbialy lbialy added kind/enhancement New feature or request without workaround area/api User visible API labels Mar 25, 2024
@pawelprazak pawelprazak added the needs-design Needs from design work: architecture, API, DX/UX label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api User visible API kind/enhancement New feature or request without workaround needs-design Needs from design work: architecture, API, DX/UX
Projects
None yet
Development

No branches or pull requests

2 participants