Skip to content

Commit

Permalink
feat(k8s): enable hot reloading for kubernetes modules
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Oct 14, 2020
1 parent 2ae7684 commit 878b50e
Show file tree
Hide file tree
Showing 35 changed files with 1,430 additions and 291 deletions.
22 changes: 21 additions & 1 deletion core/src/plugins/kubernetes/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { PluginContext } from "../../plugin-context"
import { deline } from "../../util/string"
import { defaultSystemNamespace } from "./system"
import { hotReloadableKinds, HotReloadableKind } from "./hot-reload"
import { hotReloadableKinds, HotReloadableKind } from "./hot-reload/hot-reload"
import { baseTaskSpecSchema, BaseTaskSpec, cacheResultSchema } from "../../config/task"
import { baseTestSpecSchema, BaseTestSpec } from "../../config/test"
import { ArtifactSpec } from "../../config/validation"
Expand Down Expand Up @@ -620,6 +620,26 @@ export const serviceResourceSchema = () =>
),
})

export const containerModuleSchema = () =>
joiIdentifier()
.description(
deline`The Garden module that contains the sources for the container. This needs to be specified under
\`serviceResource\` in order to enable hot-reloading, but is not necessary for tasks and tests.
Must be a \`container\` module, and for hot-reloading to work you must specify the \`hotReload\` field
on the container module.
Note: If you specify a module here, you don't need to specify it additionally under \`build.dependencies\``
)
.example("my-container-module")

export const hotReloadArgsSchema = () =>
joi
.array()
.items(joi.string())
.description("If specified, overrides the arguments for the main container when running in hot-reload mode.")
.example(["nodemon", "my-server.js"])

export const kubernetesTaskSchema = () =>
baseTaskSpecSchema()
.keys({
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/kubernetes/container/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { getAppNamespace } from "../namespace"
import { PluginContext } from "../../../plugin-context"
import { KubeApi } from "../api"
import { KubernetesProvider, KubernetesPluginContext } from "../config"
import { configureHotReload } from "../hot-reload"
import { KubernetesWorkload, KubernetesResource } from "../types"
import { ConfigurationError } from "../../../exceptions"
import { getContainerServiceStatus, ContainerServiceStatus } from "./status"
Expand All @@ -33,6 +32,7 @@ import { RuntimeContext } from "../../../runtime-context"
import { resolve } from "path"
import { killPortForwards } from "../port-forward"
import { prepareImagePullSecrets } from "../secrets"
import { configureHotReload } from "../hot-reload/helpers"

export const DEFAULT_CPU_REQUEST = "10m"
export const DEFAULT_MEMORY_REQUEST = "64Mi"
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/kubernetes/container/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { deployContainerService, deleteService } from "./deployment"
import { hotReloadContainer } from "../hot-reload"
import { hotReloadContainer } from "../hot-reload/hot-reload"
import { getServiceLogs } from "./logs"
import { runContainerModule, runContainerService, runContainerTask } from "./run"
import { execInService } from "./exec"
Expand Down
20 changes: 4 additions & 16 deletions core/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
KubernetesTestSpec,
KubernetesTaskSpec,
namespaceSchema,
containerModuleSchema,
hotReloadArgsSchema,
} from "../config"
import { posix } from "path"

Expand Down Expand Up @@ -88,22 +90,8 @@ const helmServiceResourceSchema = () =>
directly from the template in question in order to match it. Note that you may need to add single quotes around
the string for the YAML to be parsed correctly.`
),
containerModule: joiIdentifier()
.description(
deline`The Garden module that contains the sources for the container. This needs to be specified under
\`serviceResource\` in order to enable hot-reloading for the chart, but is not necessary for tasks and tests.
Must be a \`container\` module, and for hot-reloading to work you must specify the \`hotReload\` field
on the container module.
Note: If you specify a module here, you don't need to specify it additionally under \`build.dependencies\``
)
.example("my-container-module"),
hotReloadArgs: joi
.array()
.items(joi.string())
.description("If specified, overrides the arguments for the main container when running in hot-reload mode.")
.example(["nodemon", "my-server.js"]),
containerModule: containerModuleSchema(),
hotReloadArgs: hotReloadArgsSchema(),
})

const helmTaskSchema = () =>
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/helm/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import { helm } from "./helm-cli"
import { HelmModule } from "./config"
import { getChartPath, getReleaseName, getChartResources, getValueArgs, getBaseModule } from "./common"
import { getReleaseStatus, HelmServiceStatus, getDeployedResources } from "./status"
import { configureHotReload, HotReloadableResource } from "../hot-reload"
import { HotReloadableResource } from "../hot-reload/hot-reload"
import { apply, deleteResources } from "../kubectl"
import { KubernetesPluginContext } from "../config"
import { ContainerHotReloadSpec } from "../../container/config"
import { getHotReloadSpec, getHotReloadContainerName } from "./hot-reload"
import { DeployServiceParams } from "../../../types/plugin/service/deployService"
import { DeleteServiceParams } from "../../../types/plugin/service/deleteService"
import { getForwardablePorts, killPortForwards } from "../port-forward"
import { findServiceResource, getServiceResourceSpec } from "../util"
import { getModuleNamespace } from "../namespace"
import { getHotReloadSpec, configureHotReload, getHotReloadContainerName } from "../hot-reload/helpers"

export async function deployHelmService({
ctx,
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/helm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getServiceStatus } from "./status"
import { deployHelmService, deleteService } from "./deployment"
import { getTestResult } from "../test-results"
import { runHelmTask, runHelmModule } from "./run"
import { hotReloadHelmChart } from "./hot-reload"
import { getServiceLogs } from "./logs"
import { testHelmModule } from "./test"
import { getPortForwardHandler } from "../port-forward"
Expand All @@ -26,6 +25,7 @@ import { pathExists } from "fs-extra"
import chalk = require("chalk")
import { SuggestModulesParams, SuggestModulesResult } from "../../../types/plugin/module/suggestModules"
import { getReleaseName } from "./common"
import { hotReloadK8s } from "../hot-reload/hot-reload"

export const helmHandlers: Partial<ModuleAndRuntimeActionHandlers<HelmModule>> = {
build: buildHelmModule,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const helmHandlers: Partial<ModuleAndRuntimeActionHandlers<HelmModule>> =
getServiceStatus,
getTaskResult,
getTestResult,
hotReloadService: hotReloadHelmChart,
hotReloadService: hotReloadK8s,
// TODO: add publishModule handler
runModule: runHelmModule,
runTask: runHelmTask,
Expand Down
109 changes: 0 additions & 109 deletions core/src/plugins/kubernetes/helm/hot-reload.ts

This file was deleted.

0 comments on commit 878b50e

Please sign in to comment.