From 3c41c8e1fb2ed6536cf81d0d96a076049286f456 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Mon, 18 Mar 2019 18:02:20 +0100 Subject: [PATCH] fix(k8s): validation error on maven-container modules This fix is quite ugly, but will be handled better after pending framework changes that better accommodate module-type customizations. --- .../src/plugins/container/config.ts | 2 +- .../plugins/kubernetes/container/handlers.ts | 52 ++++++++++++------- .../src/plugins/kubernetes/kubernetes.ts | 4 +- .../maven-container/maven-container.ts | 6 +-- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/garden-service/src/plugins/container/config.ts b/garden-service/src/plugins/container/config.ts index 3c5f87ed7d..a5d9c2c642 100644 --- a/garden-service/src/plugins/container/config.ts +++ b/garden-service/src/plugins/container/config.ts @@ -282,7 +282,7 @@ export const containerTaskSchema = baseTaskSpecSchema }) .description("A task that can be run in the container.") -interface ContainerBuildSpec extends BaseBuildSpec { +export interface ContainerBuildSpec extends BaseBuildSpec { targetImage?: string } diff --git a/garden-service/src/plugins/kubernetes/container/handlers.ts b/garden-service/src/plugins/kubernetes/container/handlers.ts index e0eb5654c7..c39b671659 100644 --- a/garden-service/src/plugins/kubernetes/container/handlers.ts +++ b/garden-service/src/plugins/kubernetes/container/handlers.ts @@ -18,11 +18,45 @@ import { ConfigureModuleParams } from "../../../types/plugin/params" import { getContainerServiceStatus } from "./status" import { getTestResult } from "../test" import { ContainerModule } from "../../container/config" +import { configureMavenContainerModule, MavenContainerModule } from "../../maven-container/maven-container" async function configure(params: ConfigureModuleParams) { const config = await configureContainerModule(params) + await validateConfig(params) + return config +} + +// TODO: avoid having to special-case this (needs framework improvements) +async function configureMaven(params: ConfigureModuleParams) { + const config = await configureMavenContainerModule(params) + await validateConfig(params) + return config +} + +export const containerHandlers = { + configure, + deployService: deployContainerService, + deleteService, + execInService, + getServiceLogs, + getServiceStatus: getContainerServiceStatus, + getTestResult, + hotReloadService: hotReloadContainer, + pushModule, + runModule: runContainerModule, + runService: runContainerService, + runTask: runContainerTask, + testModule: testContainerModule, +} +export const mavenContainerHandlers = { + ...containerHandlers, + configure: configureMaven, +} + +async function validateConfig(params: ConfigureModuleParams) { // validate ingress specs + const config = params.moduleConfig const provider = params.ctx.provider for (const serviceConfig of config.serviceConfigs) { @@ -44,22 +78,4 @@ async function configure(params: ConfigureModuleParams) { ingressSpec.hostname = hostname } } - - return config -} - -export const containerHandlers = { - configure, - deployService: deployContainerService, - deleteService, - execInService, - getServiceLogs, - getServiceStatus: getContainerServiceStatus, - getTestResult, - hotReloadService: hotReloadContainer, - pushModule, - runModule: runContainerModule, - runService: runContainerService, - runTask: runContainerTask, - testModule: testContainerModule, } diff --git a/garden-service/src/plugins/kubernetes/kubernetes.ts b/garden-service/src/plugins/kubernetes/kubernetes.ts index 8ffa239e93..081f88134a 100644 --- a/garden-service/src/plugins/kubernetes/kubernetes.ts +++ b/garden-service/src/plugins/kubernetes/kubernetes.ts @@ -16,7 +16,7 @@ import { helmHandlers } from "./helm/handlers" import { getSecret, setSecret, deleteSecret } from "./secrets" import { containerRegistryConfigSchema, ContainerRegistryConfig } from "../container/config" import { getRemoteEnvironmentStatus, prepareRemoteEnvironment, cleanupEnvironment } from "./init" -import { containerHandlers } from "./container/handlers" +import { containerHandlers, mavenContainerHandlers } from "./container/handlers" import { PluginContext } from "../../plugin-context" export const name = "kubernetes" @@ -156,7 +156,7 @@ export function gardenPlugin(): GardenPlugin { moduleActions: { "container": containerHandlers, // TODO: we should find a way to avoid having to explicitly specify the key here - "maven-container": containerHandlers, + "maven-container": mavenContainerHandlers, "helm": helmHandlers, }, } diff --git a/garden-service/src/plugins/maven-container/maven-container.ts b/garden-service/src/plugins/maven-container/maven-container.ts index da4d6e756f..c44ac715a7 100644 --- a/garden-service/src/plugins/maven-container/maven-container.ts +++ b/garden-service/src/plugins/maven-container/maven-container.ts @@ -43,7 +43,7 @@ interface MavenContainerModuleSpec extends ContainerModuleSpec { // type MavenContainerModuleConfig = ModuleConfig -interface MavenContainerModule< +export interface MavenContainerModule< M extends MavenContainerModuleSpec = MavenContainerModuleSpec, S extends ContainerServiceSpec = ContainerServiceSpec, T extends ContainerTestSpec = ContainerTestSpec, @@ -78,7 +78,7 @@ export const gardenPlugin = (): GardenPlugin => { moduleActions: { "maven-container": { ...basePlugin.moduleActions!.container, - configure, + configure: configureMavenContainerModule, getBuildStatus, build, }, @@ -86,7 +86,7 @@ export const gardenPlugin = (): GardenPlugin => { } } -async function configure(params: ConfigureModuleParams) { +export async function configureMavenContainerModule(params: ConfigureModuleParams) { const { ctx, moduleConfig } = params const mavenFields = validateWithPath({