-
Notifications
You must be signed in to change notification settings - Fork 152
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
Move The 'wait' Argument Handling Logic To Its Exec Function #1630
Conversation
This ensures that 'wait' has more control over the rendering of the conditions arguments, which are made up of a mixed of Go template actions and jsonpath variables. The handling of all other arguments remain unchanged. Signed-off-by: Ivan Sim <ivan.sim@kasten.io>
Thanks for submitting this pull request 🎉. The team will review it soon and get back to you. If you haven't already, please take a moment to review our project contributing guideline and Code of Conduct document. |
Signed-off-by: Ivan Sim <ivan.sim@kasten.io>
2d005f9
to
f0b309e
Compare
args map[string]interface{}, | ||
tp param.TemplateParams) (map[string]interface{}, error) { | ||
// let wait handle its own go template + jsonpath mixed arguments | ||
if strings.ToLower(funcName) == "wait" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the declared name from function pkg - function.WaitFuncName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it will lead to an import loop.
var conditions WaitConditions | ||
var err error | ||
if err = Arg(args, WaitTimeoutArg, &timeout); err != nil { | ||
if err := Arg(rendered, WaitTimeoutArg, &timeout); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need rendered arg to parse timeout? As per my understanding, it's always going to be const value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to retain the original behaviour where we used the rendered argument in Arg()
, in this PR. I am curious - do we support Go template everywhere in the blueprint, or only specific fields?
objRefRaw := map[string]crv1alpha1.ObjectReference{ | ||
"objRef": cond.ObjectReference, | ||
} | ||
rendered, err := param.RenderObjectRefs(objRefRaw, tp) | ||
if err != nil { | ||
return false, err | ||
} | ||
objRef := rendered["objRef"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to a separate helper function?
@ihcsim I've been testing on the couchbase cluster example this blueprint
The first func kubeExecAll work as expected but the second has this error
In your example I can see that you use
I'm not sure I understand why you are using that, is it to evaluate a jsonpath expression or the contrary avoid the evaluation as a jsonpath ? My understanding was that now we could use plain go-template in conditions but I may have misunderstood. |
@michaelcourcy thanks for trying it out. I thought the proper jsonpath syntax requires the |
Signed-off-by: Ivan Sim <ivan.sim@kasten.io>
Signed-off-by: Ivan Sim <ivan.sim@kasten.io>
I am working on switching to go-template syntax for fetching k8s object value in wait condition. Can we hold off on the PR till then? |
I really would prefer that personally, it's a bit ubiquitous to switch from jsonpath to go-template in the same expression. |
I have raised - #1635 on top of the current PR |
* Switch to go template syntax for Wait conditions Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com> * Update K8ssandra BP as per the new Wait func syntax Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com> Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
This PR is marked as stale due to inactivity. Add a new comment to reactivate it. |
Since we decided to implement a new function which supports only |
@PrasadG193 I have approved this. Do you want to merge this and refactor the required things in your PR? |
Change Overview
This PR moves the handling of the
wait
function's arguments to itsExec()
function, to give it more control over the rendering of theconditions
arguments, which are made up of a mixed of Go templates with nested jsonpath variables. This change isolates the rendering of theseconditions
to thewait
function code, allowing the removal of the jsonpath check from the generalparam.render()
function.The previous implementation of rendering Go templates with nested jsonpath variables doesn't work with templates contains control structure like conditionals and loops. These constructs may refer to root-scoped variables using the
$
reference, leading to template validation errors, when these root-scoped variables are being misinterpreted as jsonpath variables by the existing regex. Since Go regex doesn't support negative lookbehind, there isn't an easy way to update the regex to match "only one{
and}
but not before or after".The handling of all other arguments remain unchanged.
Pull request type
Please check the type of change your PR introduces:
Issues
Test Plan
Deploy this Nginx statefulset workload to your cluster:
Deploy this blueprint to test the
KubeExecAll
andWait
functions:Deploy this actionset to trigger the
execAll
action and expect the actionset to complete successfully:Deploy this actionset to trigger the
execAllErr
action and expect the actionset to fail and report the unidenfitiedFoo
field:Deploy this actionset to trigger the
wait
action and expect the actionset to complete successfully: