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

feat(core): expose service and task dependency outputs at runtime #1123

Merged
merged 3 commits into from
Aug 28, 2019

Conversation

edvald
Copy link
Collaborator

@edvald edvald commented Aug 23, 2019

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

@thsig thsig self-assigned this Aug 23, 2019
@edvald edvald mentioned this pull request Aug 23, 2019
Copy link
Collaborator

@eysi09 eysi09 left a 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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._
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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`
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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))
Copy link
Collaborator

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(
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a mouthful :)

Copy link
Collaborator Author

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

@edvald
Copy link
Collaborator Author

edvald commented Aug 27, 2019

I'll take a look at the Getting status... issue, hadn't noticed that when testing.

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.

@edvald edvald force-pushed the runtime-outputs branch 2 times, most recently from 252c79b to 10e37fe Compare August 27, 2019 15:39
edvald added 3 commits August 28, 2019 14:50
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.
@edvald edvald merged commit fca6a72 into master Aug 28, 2019
@edvald edvald deleted the runtime-outputs branch August 28, 2019 15:00
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

Successfully merging this pull request may close these issues.

Allow exposing runtime outputs across services and tasks
3 participants