diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index 5fceb84b8a..ecc15e57b6 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -402,7 +402,7 @@ export class ActionHelper implements TypeGuard { return (handler)(handlerParams) } - private async callModuleHandler>( + private async callModuleHandler>( { params, actionType, defaultHandler }: { params: ModuleActionHelperParams, actionType: T, defaultHandler?: ModuleActions[T] }, ): Promise { diff --git a/garden-service/src/garden.ts b/garden-service/src/garden.ts index d37f46ba37..34b8424762 100644 --- a/garden-service/src/garden.ts +++ b/garden-service/src/garden.ts @@ -839,7 +839,7 @@ export class Garden { @param force - add the module again, even if it's already registered */ async addModule(config: ModuleConfig, force = false) { - const validateHandler = await this.getModuleActionHandler({ actionType: "validate", moduleType: config.type }) + const validateHandler = await this.getModuleActionHandler({ actionType: "configure", moduleType: config.type }) const ctx = this.getPluginContext(validateHandler["pluginName"]) config = await validateHandler({ ctx, moduleConfig: config }) diff --git a/garden-service/src/plugins/container/container.ts b/garden-service/src/plugins/container/container.ts index af7cb94249..d0ee34ccfb 100644 --- a/garden-service/src/plugins/container/container.ts +++ b/garden-service/src/plugins/container/container.ts @@ -15,7 +15,7 @@ import { GardenPlugin } from "../../types/plugin/plugin" import { BuildModuleParams, GetBuildStatusParams, - ValidateModuleParams, + ConfigureModuleParams, HotReloadServiceParams, PublishModuleParams, } from "../../types/plugin/params" @@ -23,7 +23,7 @@ import { keyBy } from "lodash" import { containerHelpers } from "./helpers" import { ContainerModule, containerModuleSpecSchema } from "./config" -export async function validateContainerModule({ ctx, moduleConfig }: ValidateModuleParams) { +export async function configureContainerModule({ ctx, moduleConfig }: ConfigureModuleParams) { moduleConfig.spec = validateWithPath({ config: moduleConfig.spec, schema: containerModuleSpecSchema, @@ -148,7 +148,7 @@ export async function validateContainerModule({ ctx, moduleConfig }: ValidateMod export const gardenPlugin = (): GardenPlugin => ({ moduleActions: { container: { - validate: validateContainerModule, + configure: configureContainerModule, async getBuildStatus({ module, log }: GetBuildStatusParams) { const identifier = await containerHelpers.imageExistsLocally(module) diff --git a/garden-service/src/plugins/exec.ts b/garden-service/src/plugins/exec.ts index 247ca3a279..11d9ed59d0 100644 --- a/garden-service/src/plugins/exec.ts +++ b/garden-service/src/plugins/exec.ts @@ -21,15 +21,16 @@ import { Module } from "../types/module" import { BuildResult, BuildStatus, - ValidateModuleResult, TestResult, RunTaskResult, + ConfigureModuleResult, } from "../types/plugin/outputs" import { BuildModuleParams, GetBuildStatusParams, - ValidateModuleParams, - TestModuleParams, RunTaskParams, + TestModuleParams, + RunTaskParams, + ConfigureModuleParams, } from "../types/plugin/params" import { CommonServiceSpec } from "../config/service" import { BaseTestSpec, baseTestSpecSchema } from "../config/test" @@ -84,9 +85,9 @@ export const execModuleSpecSchema = Joi.object() export interface ExecModule extends Module { } -export async function parseExecModule( - { ctx, moduleConfig }: ValidateModuleParams, -): Promise { +export async function configureExecModule( + { ctx, moduleConfig }: ConfigureModuleParams, +): Promise { moduleConfig.spec = validateWithPath({ config: moduleConfig.spec, @@ -225,7 +226,7 @@ export async function runExecTask(params: RunTaskParams): Promise export const execPlugin: GardenPlugin = { moduleActions: { exec: { - validate: parseExecModule, + configure: configureExecModule, getBuildStatus: getExecModuleBuildStatus, build: buildExecModule, runTask: runExecTask, diff --git a/garden-service/src/plugins/google/google-cloud-functions.ts b/garden-service/src/plugins/google/google-cloud-functions.ts index fe47821019..d3548fa84e 100644 --- a/garden-service/src/plugins/google/google-cloud-functions.ts +++ b/garden-service/src/plugins/google/google-cloud-functions.ts @@ -11,12 +11,12 @@ import { validateWithPath, } from "../../config/common" import { Module } from "../../types/module" -import { ValidateModuleResult } from "../../types/plugin/outputs" +import { ConfigureModuleResult } from "../../types/plugin/outputs" import { DeployServiceParams, GetServiceOutputsParams, GetServiceStatusParams, - ValidateModuleParams, + ConfigureModuleParams, } from "../../types/plugin/params" import { ServiceState, ServiceStatus, ingressHostnameSchema, Service } from "../../types/service" import { @@ -79,9 +79,9 @@ function getGcfProject(service: Service, provider: Provi return service.spec.project || provider.config["default-project"] || null } -export async function parseGcfModule( - { ctx, moduleConfig }: ValidateModuleParams, -): Promise> { +export async function configureGcfModule( + { ctx, moduleConfig }: ConfigureModuleParams, +): Promise> { // TODO: check that each function exists at the specified path moduleConfig.spec = validateWithPath({ @@ -116,7 +116,7 @@ export const gardenPlugin = (): GardenPlugin => ({ }, moduleActions: { "google-cloud-function": { - validate: parseGcfModule, + configure: configureGcfModule, async deployService(params: DeployServiceParams) { const { ctx, service } = params diff --git a/garden-service/src/plugins/kubernetes/container/handlers.ts b/garden-service/src/plugins/kubernetes/container/handlers.ts index b435e0f603..3e86d5c2de 100644 --- a/garden-service/src/plugins/kubernetes/container/handlers.ts +++ b/garden-service/src/plugins/kubernetes/container/handlers.ts @@ -12,15 +12,15 @@ import { getServiceLogs } from "./logs" import { execInService, runContainerModule, runContainerService, runContainerTask } from "./run" import { testContainerModule } from "./test" import { ConfigurationError } from "../../../exceptions" -import { validateContainerModule } from "../../container/container" +import { configureContainerModule } from "../../container/container" import { KubernetesProvider } from "../kubernetes" -import { ValidateModuleParams } from "../../../types/plugin/params" +import { ConfigureModuleParams } from "../../../types/plugin/params" import { getContainerServiceStatus, getServiceOutputs } from "./status" import { getTestResult } from "../test" import { ContainerModule } from "../../container/config" -async function validate(params: ValidateModuleParams) { - const config = await validateContainerModule(params) +async function configure(params: ConfigureModuleParams) { + const config = await configureContainerModule(params) // validate ingress specs const provider: KubernetesProvider = params.ctx.provider @@ -49,6 +49,7 @@ async function validate(params: ValidateModuleParams) { } export const containerHandlers = { + configure, deployService: deployContainerService, deleteService, execInService, @@ -62,5 +63,4 @@ export const containerHandlers = { runService: runContainerService, runTask: runContainerTask, testModule: testContainerModule, - validate, } diff --git a/garden-service/src/plugins/kubernetes/helm/config.ts b/garden-service/src/plugins/kubernetes/helm/config.ts index a44d28c178..081bfd9d0f 100644 --- a/garden-service/src/plugins/kubernetes/helm/config.ts +++ b/garden-service/src/plugins/kubernetes/helm/config.ts @@ -20,8 +20,8 @@ import { joiUserIdentifier, } from "../../../config/common" import { Module, FileCopySpec } from "../../../types/module" -import { ValidateModuleParams } from "../../../types/plugin/params" -import { ValidateModuleResult } from "../../../types/plugin/outputs" +import { ConfigureModuleParams } from "../../../types/plugin/params" +import { ConfigureModuleResult } from "../../../types/plugin/outputs" import { containsSource } from "./common" import { ConfigurationError } from "../../../exceptions" import { deline } from "../../../util/string" @@ -205,8 +205,8 @@ export const helmModuleSpecSchema = Joi.object().keys({ ), }) -export async function validateHelmModule({ ctx, moduleConfig }: ValidateModuleParams) - : Promise> { +export async function validateHelmModule({ ctx, moduleConfig }: ConfigureModuleParams) + : Promise> { moduleConfig.spec = validateWithPath({ config: moduleConfig.spec, schema: helmModuleSpecSchema, diff --git a/garden-service/src/plugins/kubernetes/helm/handlers.ts b/garden-service/src/plugins/kubernetes/helm/handlers.ts index 401de4cdff..09e43b081d 100644 --- a/garden-service/src/plugins/kubernetes/helm/handlers.ts +++ b/garden-service/src/plugins/kubernetes/helm/handlers.ts @@ -8,7 +8,7 @@ import { ModuleAndRuntimeActions } from "../../../types/plugin/plugin" import { getExecModuleBuildStatus } from "../../exec" -import { HelmModule, validateHelmModule } from "./config" +import { HelmModule, validateHelmModule as configureHelmModule } from "./config" import { buildHelmModule } from "./build" import { getServiceStatus, getServiceOutputs } from "./status" import { deployService, deleteService } from "./deployment" @@ -20,6 +20,7 @@ import { testHelmModule } from "./test" export const helmHandlers: Partial> = { build: buildHelmModule, + configure: configureHelmModule, // TODO: add execInService handler deleteService, deployService, @@ -33,5 +34,4 @@ export const helmHandlers: Partial> = { runModule: runHelmModule, runTask: runHelmTask, testModule: testHelmModule, - validate: validateHelmModule, } diff --git a/garden-service/src/plugins/local/local-google-cloud-functions.ts b/garden-service/src/plugins/local/local-google-cloud-functions.ts index e27ec44a7e..497198b244 100644 --- a/garden-service/src/plugins/local/local-google-cloud-functions.ts +++ b/garden-service/src/plugins/local/local-google-cloud-functions.ts @@ -6,11 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { ValidateModuleParams } from "../../types/plugin/params" +import { ConfigureModuleParams } from "../../types/plugin/params" import { join } from "path" import { GcfModule, - parseGcfModule, + configureGcfModule, } from "../google/google-cloud-functions" import { GardenPlugin, @@ -33,8 +33,8 @@ export const gardenPlugin = (): GardenPlugin => ({ moduleActions: { "google-cloud-function": { - async validate(params: ValidateModuleParams) { - const parsed = await parseGcfModule(params) + async configure(params: ConfigureModuleParams) { + const parsed = await configureGcfModule(params) // convert the module and services to containers to run locally const serviceConfigs: ServiceConfig[] = parsed.serviceConfigs.map((s) => { diff --git a/garden-service/src/plugins/openfaas/openfaas.ts b/garden-service/src/plugins/openfaas/openfaas.ts index 43a1f70a3d..3777d34bbb 100644 --- a/garden-service/src/plugins/openfaas/openfaas.ts +++ b/garden-service/src/plugins/openfaas/openfaas.ts @@ -15,11 +15,11 @@ import { Garden } from "../../garden" import { PluginContext } from "../../plugin-context" import { joiArray, validate, PrimitiveMap } from "../../config/common" import { Module } from "../../types/module" -import { ValidateModuleResult } from "../../types/plugin/outputs" +import { ConfigureModuleResult } from "../../types/plugin/outputs" import { PrepareEnvironmentParams, GetEnvironmentStatusParams, - ValidateModuleParams, + ConfigureModuleParams, DeleteServiceParams, GetServiceLogsParams, } from "../../types/plugin/params" @@ -162,7 +162,7 @@ export function gardenPlugin({ config }: { config: OpenFaasConfig }): GardenPlug }, moduleActions: { openfaas: { - async validate({ moduleConfig }: ValidateModuleParams): Promise { + async configure({ moduleConfig }: ConfigureModuleParams): Promise { moduleConfig.spec = validate( moduleConfig.spec, openfaasModuleSpecSchame, diff --git a/garden-service/src/types/plugin/outputs.ts b/garden-service/src/types/plugin/outputs.ts index 994ba4c3d6..24b2414bfb 100644 --- a/garden-service/src/types/plugin/outputs.ts +++ b/garden-service/src/types/plugin/outputs.ts @@ -142,7 +142,7 @@ export const moduleTypeDescriptionSchema = Joi.object() ), }) -export type ValidateModuleResult = +export type ConfigureModuleResult = ModuleConfig< T["spec"], T["serviceConfigs"][0]["spec"], @@ -150,7 +150,7 @@ export type ValidateModuleResult = T["taskConfigs"][0]["spec"] > -export const validateModuleResultSchema = moduleConfigSchema +export const configureModuleResultSchema = moduleConfigSchema export interface BuildResult { buildLog?: string @@ -335,7 +335,7 @@ export interface TaskActionOutputs { export interface ModuleActionOutputs extends ServiceActionOutputs { describeType: Promise - validate: Promise + configure: Promise getBuildStatus: Promise build: Promise pushModule: Promise diff --git a/garden-service/src/types/plugin/params.ts b/garden-service/src/types/plugin/params.ts index f3473adf05..7cddcdc68b 100644 --- a/garden-service/src/types/plugin/params.ts +++ b/garden-service/src/types/plugin/params.ts @@ -74,12 +74,12 @@ export interface DescribeModuleTypeParams { } export const describeModuleTypeParamsSchema = Joi.object() .keys({}) -export interface ValidateModuleParams { +export interface ConfigureModuleParams { ctx: PluginContext log?: LogEntry moduleConfig: T["_ConfigType"] } -export const validateModuleParamsSchema = Joi.object() +export const configureModuleParamsSchema = Joi.object() .keys({ ctx: pluginContextSchema .required(), @@ -336,7 +336,7 @@ export interface TaskActionParams { export interface ModuleActionParams { describeType: DescribeModuleTypeParams, - validate: ValidateModuleParams + configure: ConfigureModuleParams getBuildStatus: GetBuildStatusParams build: BuildModuleParams pushModule: PushModuleParams diff --git a/garden-service/src/types/plugin/plugin.ts b/garden-service/src/types/plugin/plugin.ts index 9e8cf29678..71f3fd590f 100644 --- a/garden-service/src/types/plugin/plugin.ts +++ b/garden-service/src/types/plugin/plugin.ts @@ -38,7 +38,7 @@ import { getServiceLogsParamsSchema, runServiceParamsSchema, describeModuleTypeParamsSchema, - validateModuleParamsSchema, + configureModuleParamsSchema, getBuildStatusParamsSchema, buildModuleParamsSchema, pushModuleParamsSchema, @@ -71,7 +71,7 @@ import { TaskActionOutputs, setSecretResultSchema, testResultSchema, - validateModuleResultSchema, + configureModuleResultSchema, publishModuleResultSchema, taskStatusSchema, runTaskResultSchema, @@ -291,9 +291,9 @@ export const moduleActionDescriptions: paramsSchema: describeModuleTypeParamsSchema, resultSchema: moduleTypeDescriptionSchema, }, - validate: { + configure: { description: dedent` - Validate and optionally transform the given module configuration. + Validate and transform the given module configuration. Note that this does not need to perform structural schema validation (the framework does that automatically), but should in turn perform semantic validation to make sure the configuration is sane. @@ -303,8 +303,8 @@ export const moduleActionDescriptions: framework configuration fields, this action needs to specify those via the \`serviceConfigs\` and \`testConfigs\` output keys. `, - paramsSchema: validateModuleParamsSchema, - resultSchema: validateModuleResultSchema, + paramsSchema: configureModuleParamsSchema, + resultSchema: configureModuleResultSchema, }, getBuildStatus: { diff --git a/garden-service/test/helpers.ts b/garden-service/test/helpers.ts index 0987646ef7..2d867cb62f 100644 --- a/garden-service/test/helpers.ts +++ b/garden-service/test/helpers.ts @@ -27,7 +27,7 @@ import { mapValues, fromPairs } from "lodash" import { DeleteSecretParams, GetSecretParams, - ValidateModuleParams, + ConfigureModuleParams, RunModuleParams, RunServiceParams, RunTaskParams, @@ -92,7 +92,7 @@ export const testModuleSpecSchema = containerModuleSpecSchema tasks: joiArray(testModuleTaskSchema), }) -export async function validateTestModule({ moduleConfig }: ValidateModuleParams) { +export async function configureTestModule({ moduleConfig }: ConfigureModuleParams) { moduleConfig.spec = validate( moduleConfig.spec, testModuleSpecSchema, @@ -155,7 +155,7 @@ export const testPlugin: PluginFactory = (): GardenPlugin => { moduleActions: { test: { testModule: testExecModule, - validate: validateTestModule, + configure: configureTestModule, build: buildExecModule, runModule, diff --git a/garden-service/test/src/actions.ts b/garden-service/test/src/actions.ts index bcbab6a9cd..65ef6be6c0 100644 --- a/garden-service/test/src/actions.ts +++ b/garden-service/test/src/actions.ts @@ -13,7 +13,7 @@ import { ServiceLogEntry } from "../../src/types/plugin/outputs" import { LogEntry } from "../../src/logger/log-entry" import { describeModuleTypeParamsSchema, - validateModuleParamsSchema, + configureModuleParamsSchema, getBuildStatusParamsSchema, buildModuleParamsSchema, pushModuleParamsSchema, @@ -389,8 +389,8 @@ const testPlugin: PluginFactory = async () => ({ } }, - validate: async (params) => { - validate(params, validateModuleParamsSchema) + configure: async (params) => { + validate(params, configureModuleParamsSchema) const serviceConfigs = params.moduleConfig.spec.services.map(spec => ({ name: spec.name, diff --git a/garden-service/test/src/commands/call.ts b/garden-service/test/src/commands/call.ts index 649c596681..0a5818f52d 100644 --- a/garden-service/test/src/commands/call.ts +++ b/garden-service/test/src/commands/call.ts @@ -6,7 +6,7 @@ import { PluginFactory } from "../../../src/types/plugin/plugin" import { GetServiceStatusParams } from "../../../src/types/plugin/params" import { ServiceStatus } from "../../../src/types/service" import nock = require("nock") -import { validateTestModule } from "../../helpers" +import { configureTestModule } from "../../helpers" const testProvider: PluginFactory = () => { const testStatuses: { [key: string]: ServiceStatus } = { @@ -39,7 +39,7 @@ const testProvider: PluginFactory = () => { return { moduleActions: { - test: { validate: validateTestModule, getServiceStatus }, + test: { configure: configureTestModule, getServiceStatus }, }, } } diff --git a/garden-service/test/src/commands/delete.ts b/garden-service/test/src/commands/delete.ts index 9eab970c1a..ef6224a6e2 100644 --- a/garden-service/test/src/commands/delete.ts +++ b/garden-service/test/src/commands/delete.ts @@ -6,7 +6,7 @@ import { import { Garden } from "../../../src/garden" import { EnvironmentStatus } from "../../../src/types/plugin/outputs" import { PluginFactory } from "../../../src/types/plugin/plugin" -import { expectError, makeTestGardenA, getDataDir, validateTestModule } from "../../helpers" +import { expectError, makeTestGardenA, getDataDir, configureTestModule } from "../../helpers" import { expect } from "chai" import { ServiceStatus } from "../../../src/types/service" import { DeleteServiceParams } from "../../../src/types/plugin/params" @@ -99,7 +99,7 @@ describe("DeleteServiceCommand", () => { return { moduleActions: { test: { - validate: validateTestModule, + configure: configureTestModule, deleteService, }, }, diff --git a/garden-service/test/src/commands/deploy.ts b/garden-service/test/src/commands/deploy.ts index 74303b1087..504a99a3f7 100644 --- a/garden-service/test/src/commands/deploy.ts +++ b/garden-service/test/src/commands/deploy.ts @@ -3,16 +3,14 @@ import { Garden } from "../../../src/garden" import { DeployCommand } from "../../../src/commands/deploy" import { expect } from "chai" import { buildExecModule } from "../../../src/plugins/exec" -import { - PluginFactory, -} from "../../../src/types/plugin/plugin" +import { PluginFactory } from "../../../src/types/plugin/plugin" import { DeployServiceParams, GetServiceStatusParams, RunTaskParams, } from "../../../src/types/plugin/params" import { ServiceState, ServiceStatus } from "../../../src/types/service" -import { taskResultOutputs, validateTestModule } from "../../helpers" +import { taskResultOutputs, configureTestModule } from "../../helpers" import { RunTaskResult } from "../../../src/types/plugin/outputs" const placeholderTimestamp = new Date() @@ -73,7 +71,7 @@ const testProvider: PluginFactory = () => { return { moduleActions: { test: { - validate: validateTestModule, + configure: configureTestModule, build: buildExecModule, deployService, getServiceStatus, diff --git a/garden-service/test/src/commands/publish.ts b/garden-service/test/src/commands/publish.ts index 50807f3a93..46e5de4003 100644 --- a/garden-service/test/src/commands/publish.ts +++ b/garden-service/test/src/commands/publish.ts @@ -6,7 +6,7 @@ import * as td from "testdouble" import { Garden } from "../../../src/garden" import { PluginFactory } from "../../../src/types/plugin/plugin" import { PublishCommand } from "../../../src/commands/publish" -import { makeTestGardenA, validateTestModule } from "../../helpers" +import { makeTestGardenA, configureTestModule } from "../../helpers" import { expectError, taskResultOutputs } from "../../helpers" import { ModuleVersion } from "../../../src/vcs/base" import { LogEntry } from "../../../src/logger/log-entry" @@ -29,7 +29,7 @@ const testProvider: PluginFactory = () => { return { moduleActions: { test: { - validate: validateTestModule, + configure: configureTestModule, getBuildStatus, build, publishModule, diff --git a/garden-service/test/src/plugins/container.ts b/garden-service/test/src/plugins/container.ts index 5ff7d5587f..27664f19f8 100644 --- a/garden-service/test/src/plugins/container.ts +++ b/garden-service/test/src/plugins/container.ts @@ -23,7 +23,7 @@ describe("plugins.container", () => { const relDockerfilePath = "docker-dir/Dockerfile" const handler = gardenPlugin() - const validate = handler.moduleActions!.container!.validate! + const configure = handler.moduleActions!.container!.configure! const build = handler.moduleActions!.container!.build! const publishModule = handler.moduleActions!.container!.publishModule! const getBuildStatus = handler.moduleActions!.container!.getBuildStatus! @@ -69,7 +69,7 @@ describe("plugins.container", () => { }) async function getTestModule(moduleConfig: ContainerModuleConfig) { - const parsed = await validate({ ctx, moduleConfig }) + const parsed = await configure({ ctx, moduleConfig }) return moduleFromConfig(garden, parsed) } @@ -241,7 +241,7 @@ describe("plugins.container", () => { testConfigs: [], } - const result = await validate({ ctx, moduleConfig }) + const result = await configure({ ctx, moduleConfig }) expect(result).to.eql({ allowPublish: false, @@ -349,7 +349,7 @@ describe("plugins.container", () => { moduleConfig.spec.dockerfile = "path/to/non-existing/Dockerfile" await expectError( - () => validate({ ctx, moduleConfig }), + () => configure({ ctx, moduleConfig }), "configuration", ) }) @@ -404,7 +404,7 @@ describe("plugins.container", () => { } await expectError( - () => validate({ ctx, moduleConfig }), + () => configure({ ctx, moduleConfig }), "configuration", ) }) @@ -454,7 +454,7 @@ describe("plugins.container", () => { } await expectError( - () => validate({ ctx, moduleConfig }), + () => configure({ ctx, moduleConfig }), "configuration", ) }) @@ -501,7 +501,7 @@ describe("plugins.container", () => { } await expectError( - () => validate({ ctx, moduleConfig }), + () => configure({ ctx, moduleConfig }), "configuration", ) }) diff --git a/garden-service/test/src/plugins/kubernetes/container/ingress.ts b/garden-service/test/src/plugins/kubernetes/container/ingress.ts index 546f49f317..c8e96bad64 100644 --- a/garden-service/test/src/plugins/kubernetes/container/ingress.ts +++ b/garden-service/test/src/plugins/kubernetes/container/ingress.ts @@ -290,7 +290,7 @@ const wildcardDomainCertSecret = { describe("createIngresses", () => { const projectRoot = resolve(dataDir, "test-project-container") const handler = gardenPlugin() - const validate = handler.moduleActions!.container!.validate! + const configure = handler.moduleActions!.container!.configure! let garden: Garden @@ -354,7 +354,7 @@ describe("createIngresses", () => { } const ctx = await garden.getPluginContext("container") - const parsed = await validate({ ctx, moduleConfig }) + const parsed = await configure({ ctx, moduleConfig }) const module = await moduleFromConfig(garden, parsed) return {