-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat(core): expose service and task dependency outputs at runtime #1123
Conversation
1282fe3
to
86e1a01
Compare
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.
Had a few comments and questions.
Also, would we also want to include test outputs?
Another thing I noticed is that garden init
starts checking the status for kubernetes-dashboard
et al but then just stops, like so:
➜ demo-project (runtime-outputs) g init
Initializing local environment ⚙️
✔ providers → Getting status... → Done
✔ garden-system → Initializing...
✔ providers → Getting status... → Done
kubernetes-dashboard → Checking status...
default-backend → Checking status...
ingress-controller → Checking status...
Done! ✔️
@@ -457,6 +457,36 @@ services: | |||
For a full reference of the keys available in template strings, please look at the | |||
[Template Strings Reference](../reference/template-strings.md). | |||
|
|||
#### Runtime outputs |
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.
We can do it in a separate PR but we really need to split this doc up.
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.
True. But in a separate PR for sure. Maybe an Advanced configuration
guide would be good.
@@ -457,6 +457,36 @@ services: | |||
For a full reference of the keys available in template strings, please look at the | |||
[Template Strings Reference](../reference/template-strings.md). | |||
|
|||
#### Runtime outputs | |||
|
|||
Template keys prefixed with `runtime.` have some special semantics. They are used to expose runtime outputs from services and tasks, and therefore are resolved later than other template strings. _This means that you cannot use them for some fields, such as most identifiers, because those need to be resolved before validating the configuration._ |
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.
How does the user know what fields exactly can use runtime.
template strings?
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.
That's tricky, because it's going to be quite dependent on individual module type schemas. So we can't describe it here, nor can we easily flag this in schemas.
@@ -1132,3 +1133,18 @@ outputs: | |||
... | |||
deployment-image-name: "my-deployment-registry.io/my-org/my-module" | |||
``` | |||
|
|||
|
|||
### Task outputs |
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.
Shouldn't we also add service outputs here?
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.
We do in the generator, there just aren't any in this case.
The following keys are available via the `${runtime.tasks.<task-name>}` template string key for `exec` module tasks. | ||
Note that these are only resolved when deploying/running dependants of the task, so they are not usable for every field. | ||
|
||
### `runtime.tasks.<task-name>.outputs.log` |
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.
Are we foreseeing any other output types than log? Also log feels a little off to me, would stdout
be clearer?
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.
Feels like this could just be runtime.tasks<task-name>.stdout
(or runtime.tasks<task-name>.output)
, but maybe I'm missing something.
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.
Not for this module type in particular, but tasks could feasibly have any number of outputs. Say if a provider outputs file paths for artifacts, particular metadata etc.
export async function prepareRuntimeContext( | ||
{ garden, module, dependencies, serviceStatuses, taskResults }: PrepareRuntimeContextParams, | ||
): Promise<RuntimeContext> { | ||
// const buildDepKeys = module.build.dependencies.map(dep => getModuleKey(dep.name, dep.plugin)) |
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.
Remove this?
taskResults: { [name: string]: RunTaskResult } | ||
} | ||
|
||
export async function prepareRuntimeContext( |
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.
It would be nice to better document the runtimeContext
and how we use it.
@@ -550,9 +572,28 @@ export class ActionHelper implements TypeGuard { | |||
defaultHandler, | |||
}) | |||
|
|||
// Resolve ${runtime.*} template strings if needed. | |||
if (runtimeContext && (await getRuntimeTemplateReferences(module)).length > 0) { |
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.
Feels like this and the code above could be de-duplicated.
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.
Feels like, yes, but I felt the code is subtly different enough for an abstraction to be unnecessary.
export function getRunTaskResults(dependencyResults: TaskResults): { [name: string]: RunTaskResult } { | ||
const storedResults = pickBy(dependencyResults, r => r.type === "get-task-result") | ||
const runResults = pickBy(dependencyResults, r => r.type === "task") | ||
// TaskTask results take precedence over GetTaskResultTask results |
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.
That's a mouthful :)
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.
Yeah, once we rename the TaskGraph to ActionGraph and *Tasks to *Actions this will be more digestable :P
I'll take a look at the Re: Test outputs, we could add them as well, but there was no immediately obvious use case—you could only pass test outputs to other tests, and I'm not sure if/how that's useful—so I figured we could fairly easily add those later. |
252c79b
to
10e37fe
Compare
This is a fairly substantial addition, which allows users to reference runtime outputs from services and tasks in dependant services and tasks. It involves adding a couple of new TaskGraph tasks, so that we can resolve service statuses and task results in dependency order. We also substantially overhaul the usage and testing of runtime contexts across the board, since it is now a more fundamental feature. The usage is documented in a new section in the Configuration Files guide, please start with that when reviewing.
fe91d94
to
7f830dd
Compare
What this PR does / why we need it:
This is a fairly substantial addition, which allows users to reference
runtime outputs from services and tasks in dependant services and tasks.
It involves adding a couple of new TaskGraph tasks, so that we can
resolve service statuses and task results in dependency order. We also
substantially overhaul the usage and testing of runtime contexts across
the board, since it is now a more fundamental feature.
The usage is documented in a new section in the Configuration Files
guide, please start with that when reviewing.
Which issue(s) this PR fixes:
Closes #1095