-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added caching for task results. Similarly to the caching for test runs that was already in place, these are stored by version as ConfigMap-s. The version used to index these results includes the task's module's current version, along with the module versions of the task's runtime dependencies (if any). This is the same formula that is used for computing test task versions. Currently, tasks always execute, regardless of whether they have cached results for the current version, since we need to finish other changes that will provide dependency results to the process methods of task classes before the caching semantics can be finalized for tasks, in relation to dependency calculations. A versioning bug was also fixed for the test result caching functionality. Here, the version used was just the test config's module's version, whereas now the corresponding test task's version is used to index it instead (the same as is now also used to cache task results).
- Loading branch information
Showing
17 changed files
with
241 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { GetTaskResultParams } from "../../types/plugin/params" | ||
import { ContainerModule } from "../container/config" | ||
import { HelmModule } from "./helm/config" | ||
import { ModuleVersion } from "../../vcs/base" | ||
import { KubernetesPluginContext, KubernetesProvider } from "./kubernetes" | ||
import { KubeApi } from "./api" | ||
import { getMetadataNamespace } from "./namespace" | ||
import { RunTaskResult } from "../../types/plugin/outputs" | ||
import { deserializeValues, serializeValues } from "../../util/util" | ||
import { PluginContext } from "../../plugin-context" | ||
|
||
export async function getTaskResult( | ||
{ ctx, task, taskVersion }: GetTaskResultParams<ContainerModule | HelmModule>, | ||
): Promise<RunTaskResult | null> { | ||
const k8sCtx = <KubernetesPluginContext>ctx | ||
const api = new KubeApi(k8sCtx.provider.config.context) | ||
const ns = await getMetadataNamespace(k8sCtx, k8sCtx.provider) | ||
const resultKey = getTaskResultKey(task.name, taskVersion) | ||
|
||
try { | ||
const res = await api.core.readNamespacedConfigMap(resultKey, ns) | ||
return <RunTaskResult>deserializeValues(res.body.data) | ||
} catch (err) { | ||
if (err.code === 404) { | ||
return null | ||
} else { | ||
throw err | ||
} | ||
} | ||
} | ||
|
||
export function getTaskResultKey(taskName: string, version: ModuleVersion) { | ||
return `task-result--${taskName}--${version.versionString}` | ||
} | ||
|
||
/** | ||
* Store a task run result as a ConfigMap in the cluster. | ||
* | ||
* TODO: Implement a CRD for this. | ||
*/ | ||
export async function storeTaskResult( | ||
{ ctx, taskName, taskVersion, result }: | ||
{ ctx: PluginContext, taskName: string, taskVersion: ModuleVersion, result: RunTaskResult }, | ||
): Promise<RunTaskResult> { | ||
const provider = <KubernetesProvider>ctx.provider | ||
const api = new KubeApi(provider.config.context) | ||
const ns = await getMetadataNamespace(ctx, provider) | ||
const resultKey = getTaskResultKey(taskName, taskVersion) | ||
|
||
const body = { | ||
apiVersion: "v1", | ||
kind: "ConfigMap", | ||
metadata: { | ||
name: resultKey, | ||
annotations: { | ||
"garden.io/generated": "true", | ||
}, | ||
}, | ||
data: serializeValues(result), | ||
} | ||
|
||
try { | ||
await api.core.createNamespacedConfigMap(ns, <any>body) | ||
} catch (err) { | ||
if (err.code === 409) { | ||
await api.core.patchNamespacedConfigMap(resultKey, ns, body) | ||
} else { | ||
throw err | ||
} | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.