How do I use the result of a plan
function in my Starlark?
#699
-
I'm doing a recipe = ExecRecipe(command=["/bin/sh", "-c", "curl -XGET %s" % my_service.url])
result = plan.exec(service_name=service_name, recipe=recipe)
stripped_result = result["output"].strip()
if stripped_result == "":
plan.print("Result is empty") How can I do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This isn't possible in current Kurtosis. Kurtosis uses a multi-phase approach when running, which means that all Starlark will be completely interpreted and done before any execution happens. This has the benefit that Kurtosis can validate the complete plan of what the user is trying to do before anything runs, but has the downside that execution-time values (such as the result of Instead, the same thing can be accomplished by pushing the dynamic logic down to execution-time computation. For example: recipe = ExecRecipe(command=["/bin/sh", "-c", "curl -XGET %s" % my_service.url])
result = plan.exec(service_name=service_name, recipe=recipe)
evalute_is_empty_result = plan.run_sh("""
stripped_result="$(echo "%s" | xargs)"
if [ "${stripped_result}" = "" ]; then
echo "Result is empty"
fi
""" % result["output"])
plan.print(evalute_is_empty_result["output"]) Note that this is not exactly the same as the original code, because the To see why, consider the following code that gets the image of the service from an execution-time value: # Gets which Docker image we want to use, dynamically at execution time
latest_alpine_image = plan.run_sh("echo 'alpne:latest'")
plan.add_service(
name = "my-alpine-service",
config = ServiceConfig(
image = latest_alpine_image["output"],
cmd = ["echo", "Hello, world!"],
)
) At Starlark interpretation time (the time that In this case, there's a typo - |
Beta Was this translation helpful? Give feedback.
This isn't possible in current Kurtosis. Kurtosis uses a multi-phase approach when running, which means that all Starlark will be completely interpreted and done before any execution happens.
This has the benefit that Kurtosis can validate the complete plan of what the user is trying to do before anything runs, but has the downside that execution-time values (such as the result of
curl
) are not available in Starlark because thecurl
hasn't run yet.Instead, the same thing can be accomplished by pushing the dynamic logic down to execution-time computation. For example: