Skip to content

Commit

Permalink
fix(k8s): helm modules weren't identified as hot reloadable
Browse files Browse the repository at this point in the history
This adds an explicit flag to service configs to tell the framework
when they are valid for hot reloading.
  • Loading branch information
edvald authored and thsig committed May 6, 2019
1 parent 890e05d commit 0b7ce98
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion garden-service/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class DeployCommand extends Command<Args, Opts> {
async prepare({ log, logFooter, opts }: PrepareParams<Args, Opts>) {
logHeader({ log, emoji: "rocket", command: "Deploy" })

if (!!opts.watch) {
if (!!opts.watch || !!opts["hot-reload"]) {
this.server = await startServer(logFooter)
}
}
Expand Down
4 changes: 1 addition & 3 deletions garden-service/src/commands/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export async function validateHotReloadServiceNames(
}
}

// TODO: Add hotReload to baseModuleSpecSchema. It's bad form to dig into module type-specific fields
// outside the scope of its plugins.
function supportsHotReloading(service: Service) {
return !!service.module.spec.hotReload
return service.config.hotReloadable
}
5 changes: 5 additions & 0 deletions garden-service/src/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ export const baseServiceSchema = Joi.object()
.description("The required attributes of a service. This is generally further defined by plugins.")

export interface ServiceConfig<T extends ServiceSpec = ServiceSpec> extends CommonServiceSpec {
hotReloadable: boolean
sourceModuleName?: string

// Plugins can add custom fields that are kept here
spec: T
}

export const serviceConfigSchema = baseServiceSchema
.keys({
hotReloadable: Joi.boolean()
.default(false)
.description("Set this to true if the module and service configuration supports hot reloading."),
sourceModuleName: joiIdentifier()
.optional()
.description(deline`
Expand Down
4 changes: 3 additions & 1 deletion garden-service/src/plugins/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export async function configureContainerModule({ ctx, moduleConfig }: ConfigureM
}
}

const hotReloadable = !!moduleConfig.spec.hotReload

// validate services
moduleConfig.serviceConfigs = moduleConfig.spec.services.map(spec => {
// make sure ports are correctly configured
Expand Down Expand Up @@ -91,7 +93,7 @@ export async function configureContainerModule({ ctx, moduleConfig }: ConfigureM
return {
name,
dependencies: spec.dependencies,
outputs: spec.outputs,
hotReloadable,
spec,
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export async function configureGcfModule(
name,
dependencies: spec.dependencies,
outputs: spec.outputs,
hotReloadable: false,
spec,
}]

Expand Down
2 changes: 2 additions & 0 deletions garden-service/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export async function validateHelmModule({ moduleConfig }: ConfigureModuleParams
name: moduleConfig.name,
dependencies,
outputs: {},
// Note: We can't tell here if the source module supports hot-reloading, so we catch it in the handler if need be.
hotReloadable: !!sourceModuleName,
sourceModuleName,
spec: moduleConfig.spec,
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function configureKubernetesModule({ moduleConfig }: ConfigureModul
name: moduleConfig.name,
dependencies: moduleConfig.spec.dependencies,
outputs: {},
hotReloadable: false,
spec: moduleConfig.spec,
}]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const gardenPlugin = (): GardenPlugin => ({
return {
name: spec.name,
dependencies: spec.dependencies,
hotReloadable: false,
outputs: spec.outputs,
spec,
}
Expand Down
1 change: 1 addition & 0 deletions garden-service/src/plugins/openfaas/openfaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function gardenPlugin(): GardenPlugin {

moduleConfig.serviceConfigs = [{
dependencies: [],
hotReloadable: false,
name: moduleConfig.name,
outputs: {},
spec: {
Expand Down
1 change: 1 addition & 0 deletions garden-service/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ const defaultModuleConfig: ModuleConfig = {
name: "test-service",
dependencies: [],
outputs: {},
hotReloadable: false,
spec: {},
},
],
Expand Down
1 change: 1 addition & 0 deletions garden-service/test/unit/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ const testPlugin: PluginFactory = async () => ({
name: spec.name,
dependencies: spec.dependencies || [],
outputs: {},
hotReloadable: false,
spec,
}))

Expand Down
1 change: 1 addition & 0 deletions garden-service/test/unit/src/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ describe("plugins.container", () => {
name: "service-a",
dependencies: [],
outputs: {},
hotReloadable: false,
spec:
{
name: "service-a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ describe("createIngressResources", () => {
name: spec.name,
dependencies: [],
outputs: {},
hotReloadable: false,
spec,
},
module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe("validateHelmModule", () => {
name: "api",
dependencies: [],
outputs: {},
hotReloadable: true,
sourceModuleName: "api-image",
spec: {
build: {
Expand Down

0 comments on commit 0b7ce98

Please sign in to comment.