-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(k8s): add exec to kubernetes and helm modules
Implemented `execInService` handlers for the `kubernetes` and `helm` module types. These are very similar to the one used for `container` modules, differing mostly in the way the target workload is located.
- Loading branch information
Showing
9 changed files
with
204 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2018-2021 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { includes } from "lodash" | ||
import { DeploymentError } from "../../../exceptions" | ||
import { getAppNamespace } from "../namespace" | ||
import { KubernetesPluginContext } from "../config" | ||
import { execInWorkload, findServiceResource, getServiceResourceSpec } from "../util" | ||
import { ExecInServiceParams } from "../../../types/plugin/service/execInService" | ||
import { HelmModule } from "./config" | ||
import { getServiceStatus } from "./status" | ||
import { getBaseModule, getChartResources } from "./common" | ||
|
||
export async function execInHelmService(params: ExecInServiceParams<HelmModule>) { | ||
const { ctx, log, service, command, interactive } = params | ||
const module = service.module | ||
const k8sCtx = <KubernetesPluginContext>ctx | ||
const provider = k8sCtx.provider | ||
const status = await getServiceStatus({ | ||
...params, | ||
// The runtime context doesn't matter here. We're just checking if the service is running. | ||
runtimeContext: { | ||
envVars: {}, | ||
dependencies: [], | ||
}, | ||
devMode: false, | ||
hotReload: false, | ||
}) | ||
const namespace = await getAppNamespace(k8sCtx, log, k8sCtx.provider) | ||
|
||
const baseModule = getBaseModule(module) | ||
const serviceResourceSpec = getServiceResourceSpec(module, baseModule) | ||
const manifests = await getChartResources({ | ||
ctx: k8sCtx, | ||
module, | ||
devMode: false, | ||
hotReload: false, | ||
log, | ||
version: service.version, | ||
}) | ||
|
||
const serviceResource = await findServiceResource({ | ||
ctx, | ||
log, | ||
module, | ||
baseModule, | ||
manifests, | ||
resourceSpec: serviceResourceSpec, | ||
}) | ||
|
||
// TODO: this check should probably live outside of the plugin | ||
if (!serviceResource || !includes(["ready", "outdated"], status.state)) { | ||
throw new DeploymentError(`Service ${service.name} is not running`, { | ||
name: service.name, | ||
state: status.state, | ||
}) | ||
} | ||
|
||
return execInWorkload({ ctx, provider, log, namespace, workload: serviceResource, command, interactive }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2018-2021 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { includes } from "lodash" | ||
import { DeploymentError } from "../../../exceptions" | ||
import { KubernetesModule } from "./config" | ||
import { getAppNamespace } from "../namespace" | ||
import { KubernetesPluginContext } from "../config" | ||
import { execInWorkload, findServiceResource, getServiceResourceSpec } from "../util" | ||
import { getKubernetesServiceStatus } from "./handlers" | ||
import { ExecInServiceParams } from "../../../types/plugin/service/execInService" | ||
|
||
export async function execInKubernetesService(params: ExecInServiceParams<KubernetesModule>) { | ||
const { ctx, log, service, command, interactive } = params | ||
const module = service.module | ||
const k8sCtx = <KubernetesPluginContext>ctx | ||
const provider = k8sCtx.provider | ||
const status = await getKubernetesServiceStatus({ | ||
...params, | ||
// The runtime context doesn't matter here. We're just checking if the service is running. | ||
runtimeContext: { | ||
envVars: {}, | ||
dependencies: [], | ||
}, | ||
devMode: false, | ||
hotReload: false, | ||
}) | ||
const namespace = await getAppNamespace(k8sCtx, log, k8sCtx.provider) | ||
|
||
const serviceResourceSpec = getServiceResourceSpec(module, undefined) | ||
const serviceResource = await findServiceResource({ | ||
ctx, | ||
log, | ||
module, | ||
baseModule: undefined, | ||
manifests: status.detail.remoteResources, | ||
resourceSpec: serviceResourceSpec, | ||
}) | ||
|
||
// TODO: this check should probably live outside of the plugin | ||
if (!serviceResource || !includes(["ready", "outdated"], status.state)) { | ||
throw new DeploymentError(`Service ${service.name} is not running`, { | ||
name: service.name, | ||
state: status.state, | ||
}) | ||
} | ||
|
||
return execInWorkload({ ctx, provider, log, namespace, workload: serviceResource, command, interactive }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters