Skip to content

Commit

Permalink
fix(k8s): don't store full version object with test+task results
Browse files Browse the repository at this point in the history
This addresses issues where the list of files, contained in the module
version object, would push the size of the result ConfigMap over 1MB.
  • Loading branch information
edvald committed Jun 26, 2019
1 parent 773365c commit c4e4059
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 41 deletions.
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GetTaskResultCommand extends Command<Args> {
const output: TaskResultOutput = {
name: taskResult.taskName,
module: taskResult.moduleName,
version: taskResult.version.versionString,
version: taskResult.version,
output: taskResult.output,
startedAt: taskResult.startedAt,
completedAt: taskResult.completedAt,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-test-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class GetTestResultCommand extends Command<Args> {
module: testResult.moduleName,
startedAt: testResult.startedAt,
completedAt: testResult.completedAt,
version: testResult.version.versionString,
version: testResult.version,
output: testResult.output,
}

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export async function testExecModule({ module, testConfig }: TestModuleParams<Ex
moduleName: module.name,
command,
testName: testConfig.name,
version: module.version,
version: module.version.versionString,
success: result.code === 0,
startedAt,
completedAt: new Date(),
Expand Down Expand Up @@ -215,7 +215,7 @@ export async function runExecTask(params: RunTaskParams): Promise<RunTaskResult>
moduleName: module.name,
taskName: task.name,
command,
version: module.version,
version: module.version.versionString,
success: true,
output,
startedAt,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/plugins/kubernetes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function runPod(
return {
moduleName: module.name,
command: [...cmd, ...args],
version: module.version,
version: module.version.versionString,
startedAt,
completedAt: new Date(),
output: res.output,
Expand Down
18 changes: 13 additions & 5 deletions garden-service/src/plugins/kubernetes/task-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ export async function getTaskResult(

try {
const res = await api.core.readNamespacedConfigMap(resultKey, ns)
return <RunTaskResult>deserializeValues(res.data!)
const result: any = deserializeValues(res.data!)

// Backwards compatibility for modified result schema
if (result.version.versionString) {
result.version = result.version.versionString
}

return <RunTaskResult>result
} catch (err) {
if (err.code === 404) {
return null
Expand Down Expand Up @@ -70,9 +77,6 @@ export async function storeTaskResult(
const api = await KubeApi.factory(log, provider.config.context)
const namespace = await getMetadataNamespace(ctx, log, provider)

// Make sure the output isn't too large for a ConfigMap
result.output = tailString(result.output, MAX_RUN_RESULT_OUTPUT_LENGTH, true)

await upsertConfigMap({
api,
namespace,
Expand All @@ -83,6 +87,10 @@ export async function storeTaskResult(
[gardenAnnotationKey("moduleVersion")]: module.version.versionString,
[gardenAnnotationKey("version")]: taskVersion.versionString,
},
data: result,
data: {
...result,
// Make sure the output isn't too large for a ConfigMap
output: tailString(result.output, MAX_RUN_RESULT_OUTPUT_LENGTH, true),
},
})
}
9 changes: 8 additions & 1 deletion garden-service/src/plugins/kubernetes/test-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ export async function getTestResult(

try {
const res = await api.core.readNamespacedConfigMap(resultKey, testResultNamespace)
return <TestResult>deserializeValues(res.data!)
const result: any = deserializeValues(res.data!)

// Backwards compatibility for modified result schema
if (result.version.versionString) {
result.version = result.version.versionString
}

return <TestResult>result
} catch (err) {
if (err.code === 404) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*/

import { join } from "path"
import { ConfigureProviderParams } from "../../types/plugin/provider/configureProvider"
import { GcfModule, configureGcfModule } from "../google/google-cloud-functions"
import { GardenPlugin } from "../../types/plugin/plugin"
import { STATIC_DIR, DEFAULT_API_VERSION } from "../../constants"
import { ServiceConfig } from "../../config/service"
import { ContainerModuleConfig } from "../container/config"
import { ConfigureModuleParams } from "../../types/plugin/module/configure"
import { ContainerServiceSpec, ServicePortProtocol } from "../container/config"
import { ConfigureProviderParams } from "../../types/plugin/provider/configureProvider"
import { ConfigureModuleParams } from "../../types/plugin/module/configure"

const pluginName = "local-google-cloud-functions"
const emulatorModuleName = "local-gcf-container"
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/types/plugin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Module, moduleSchema } from "../module"
import { RuntimeContext, Service, serviceSchema, runtimeContextSchema } from "../service"
import { Task } from "../task"
import { taskSchema } from "../../config/task"
import { ModuleVersion, moduleVersionSchema } from "../../vcs/vcs"
import { joi } from "../../config/common"

export interface PluginActionContextParams {
Expand Down Expand Up @@ -77,7 +76,7 @@ export const runBaseParams = {
export interface RunResult {
moduleName: string
command: string[]
version: ModuleVersion
version: string
success: boolean
startedAt: Date
completedAt: Date
Expand All @@ -91,7 +90,8 @@ export const runResultSchema = joi.object()
command: joi.array().items(joi.string())
.required()
.description("The command that was run in the module."),
version: moduleVersionSchema,
version: joi.string()
.description("The string version of the module."),
success: joi.boolean()
.required()
.description("Whether the module was successfully run."),
Expand Down
4 changes: 4 additions & 0 deletions garden-service/src/types/plugin/module/getTestResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const testResultSchema = runResultSchema
testName: joi.string()
.required()
.description("The name of the test that was run."),
version: joi.string()
.description(deline`
The test run's version, as a string. In addition to the parent module's version, this also
factors in the module versions of the test's runtime dependencies (if any).`),
})

export const testVersionSchema = moduleVersionSchema
Expand Down
3 changes: 2 additions & 1 deletion garden-service/src/types/plugin/task/getTaskResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const taskResultSchema = joi.object()
command: joi.array().items(joi.string())
.required()
.description("The command that the task ran in the module."),
version: moduleVersionSchema,
version: joi.string()
.description("The string version of the task."),
success: joi.boolean()
.required()
.description("Whether the task was successfully run."),
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/types/plugin/task/runTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface RunTaskResult extends RunResult {
moduleName: string
taskName: string
command: string[]
version: ModuleVersion
version: string
success: boolean
startedAt: Date
completedAt: Date
Expand Down
4 changes: 1 addition & 3 deletions garden-service/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ export async function profileBlock(description: string, block: () => Promise<any
}

async function runModule(params: RunModuleParams): Promise<RunResult> {
const version = await params.module.version

return {
moduleName: params.module.name,
command: [...(params.command || []), ...params.args],
completedAt: testNow,
output: "OK",
version,
version: params.module.version.versionString,
startedAt: testNow,
success: true,
}
Expand Down
22 changes: 11 additions & 11 deletions garden-service/test/unit/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("ActionHelper", () => {
output: "bla bla",
success: true,
startedAt: now,
version: module.version,
version: module.version.versionString,
})
})
})
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("ActionHelper", () => {
success: true,
startedAt: now,
testName: "test",
version: module.version,
version: module.version.versionString,
})
})
})
Expand All @@ -222,7 +222,7 @@ describe("ActionHelper", () => {
success: true,
startedAt: now,
testName: "test",
version: module.version,
version: module.version.versionString,
})
})
})
Expand Down Expand Up @@ -289,7 +289,7 @@ describe("ActionHelper", () => {
output: "bla bla",
success: true,
startedAt: now,
version: service.module.version,
version: service.module.version.versionString,
})
})
})
Expand All @@ -315,7 +315,7 @@ describe("ActionHelper", () => {
output: "bla bla",
success: true,
startedAt: now,
version: task.module.version,
version: task.module.version.versionString,
})
})
})
Expand Down Expand Up @@ -486,7 +486,7 @@ const testPlugin: PluginFactory = async () => ({
output: "bla bla",
success: true,
startedAt: now,
version: params.module.version,
version: params.module.version.versionString,
}
},

Expand All @@ -500,7 +500,7 @@ const testPlugin: PluginFactory = async () => ({
success: true,
startedAt: now,
testName: params.testConfig.name,
version: params.module.version,
version: params.module.version.versionString,
}
},

Expand All @@ -514,7 +514,7 @@ const testPlugin: PluginFactory = async () => ({
success: true,
startedAt: now,
testName: params.testName,
version: params.module.version,
version: params.module.version.versionString,
}
},

Expand Down Expand Up @@ -555,7 +555,7 @@ const testPlugin: PluginFactory = async () => ({
output: "bla bla",
success: true,
startedAt: now,
version: params.module.version,
version: params.module.version.versionString,
}
},

Expand All @@ -570,7 +570,7 @@ const testPlugin: PluginFactory = async () => ({
output: "bla bla",
success: true,
startedAt: now,
version: params.module.version,
version: params.module.version.versionString,
}
},

Expand All @@ -585,7 +585,7 @@ const testPlugin: PluginFactory = async () => ({
output: "bla bla",
success: true,
startedAt: now,
version: params.module.version,
version: params.module.version.versionString,
}
},
},
Expand Down
6 changes: 1 addition & 5 deletions garden-service/test/unit/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const placeholderTaskResult = (moduleName, taskName, command) => ({
moduleName,
taskName,
command,
version: {
versionString: "v-1",
files: [],
dependencyVersions: {},
},
version: "v-1",
success: true,
startedAt: placeholderTimestamp,
completedAt: placeholderTimestamp,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/unit/src/commands/run/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("RunModuleCommand", () => {
command: [],
completedAt: testNow,
output: "OK",
version: testModuleVersion,
version: testModuleVersion.versionString,
startedAt: testNow,
success: true,
}
Expand All @@ -61,7 +61,7 @@ describe("RunModuleCommand", () => {
command: ["my", "command"],
completedAt: testNow,
output: "OK",
version: testModuleVersion,
version: testModuleVersion.versionString,
startedAt: testNow,
success: true,
}
Expand All @@ -85,7 +85,7 @@ describe("RunModuleCommand", () => {
command: ["/bin/sh", "-c", "my", "command"],
completedAt: testNow,
output: "OK",
version: testModuleVersion,
version: testModuleVersion.versionString,
startedAt: testNow,
success: true,
}
Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/unit/src/commands/run/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("RunServiceCommand", () => {
command: ["service-a"],
completedAt: testNow,
output: "OK",
version: testModuleVersion,
version: testModuleVersion.versionString,
startedAt: testNow,
success: true,
}
Expand Down

0 comments on commit c4e4059

Please sign in to comment.