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

Combining Helm and Go to monitor the same CR #206

Open
nuwang opened this issue Dec 15, 2022 · 2 comments
Open

Combining Helm and Go to monitor the same CR #206

nuwang opened this issue Dec 15, 2022 · 2 comments

Comments

@nuwang
Copy link

nuwang commented Dec 15, 2022

I'm evaluating the use of the hybrid-helm operator (this is my first attempt at writing an operator) and it appears to have enormous potential to cut down on boilerplate while exerting advanced control when necessary.

I'm specifically interested in the following scenario. I'm hoping to use Helm to quickly deploy the basic scaffolding, and then use some Go code for additional operations, such as communicating with an external API (Keycloak) to perform additional reconciliation tasks.

Most of the examples I've seen are centered around using Helm to manage a specific CR (e.g. Memcached) with Go code to manage a secondary CR (MemCachedBackup). What I'm hoping to do is to use Helm to manage a primary CR, but perform additional actions on the same CR using Go.

My questions are:
a. Is this a supported scenario?
b. The Pre and PostHooks could conceivably be used to perform additional tasks, like calling an external API, but how can I indicate a failure and request a requeue if the external call fails? Currently, the hook error appears to be logged and ignored:

log.Error(err, "pre-release hook failed")

c. How can I add additional status fields using hooks?

@joelanford
Copy link
Member

a. Is this a supported scenario?

Absolutely. That's one of the main goals for the hybrid helm/go implementation.

b. The Pre and PostHooks could conceivably be used to perform additional tasks, like calling an external API, but how can I indicate a failure and request a requeue if the external call fails?

Yes, this is exactly the idea.

Currently, the hook error appears to be logged and ignored

You are right about that! I'm not sure anyone has ever needed to return that error/requeue but it makes total sense. The Pre/Post Hook APIs are probably the least used and most in need of some real world usage and feedback. So thanks for asking about this, and sorry it doesn't work the way you expect! It seems like a good idea.

Any suggestions for changing/augmenting the Pre/PostHook interface or usage in the reconciler?

c. How can I add additional status fields using hooks?

Your hook can use the same client that the reconciler uses (it's up to you to set the hook implementation up with what you need), but that should give you the ability to use the cl.Status.Update() method in your hook logic.

@nuwang
Copy link
Author

nuwang commented Mar 15, 2023

Absolutely. That's one of the main goals for the hybrid helm/go implementation.

That's good news! Thanks for confirming.

Any suggestions for changing/augmenting the Pre/PostHook interface or usage in the reconciler?

I've forgotten some of the details from the time I originally looked into this, and was planning to revisit it at a later date when this issue was resolved. So my recollection of the exact issues I ran into are a bit hazy, however, what I was hoping to accomplish was something like this (in pseudocode):

func postHook()
   # 1. Call keycloak API
   # 2. If API calls fails:
             2a. update status field indicating error
             2b. request re-queue so API call can be retried later
   # 3. If API calls succeed:
             3a. update status field with success status
             3b. return

Therefore, I think there needs to be some way for the hook function to return a request for a re-queue if needed, or Nil otherwise. Sorry, that's not particularly helpful, but I'm new to both Go and operators, so I'm not sure how this would be handled idiomatically.

that should give you the ability to use the cl.Status.Update() method in your hook logic.

Looks like that could work nicely, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants