Skip to content

Commit

Permalink
refactor(k8s): move some things around + remove need for login
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and thsig committed Apr 29, 2019
1 parent 6d8fdf1 commit e0543ad
Show file tree
Hide file tree
Showing 22 changed files with 641 additions and 544 deletions.
4 changes: 2 additions & 2 deletions docs/reference/providers/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ The registry where built containers should be pushed to, and then pulled to the

| Type | Required |
| ---- | -------- |
| `object` | Yes
| `object` | No
### `environments[].providers[].deploymentRegistry.hostname`
[environments](#environments) > [providers](#environments[].providers[]) > [deploymentRegistry](#environments[].providers[].deploymentregistry) > hostname

Expand Down Expand Up @@ -391,7 +391,7 @@ The external HTTPS port of the cluster's ingress controller.
### `environments[].providers[].namespace`
[environments](#environments) > [providers](#environments[].providers[]) > namespace

Specify which namespace to deploy services to (defaults to <username>--<project name>). Note that the framework generates other namespaces as well with this name as a prefix.
Specify which namespace to deploy services to (defaults to <project name>). Note that the framework generates other namespaces as well with this name as a prefix.

| Type | Required |
| ---- | -------- |
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/providers/local-kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ environments:
- providers:
- name: "local-kubernetes"
```
### `environments[].providers[].context`
[environments](#environments) > [providers](#environments[].providers[]) > context

The kubectl context to use to connect to the Kubernetes cluster.

| Type | Required |
| ---- | -------- |
| `string` | No

Example:
```yaml
environments:
- providers:
- context: "my-dev-context"
```
### `environments[].providers[].namespace`
[environments](#environments) > [providers](#environments[].providers[]) > namespace

Expand Down Expand Up @@ -344,6 +359,7 @@ environments:
name:
namespace: default
name: local-kubernetes
context:
namespace:
setupIngressController: nginx
```
14 changes: 14 additions & 0 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"mocha-logger": "^1.0.6",
"moment": "^2.23.0",
"node-emoji": "^1.8.1",
"node-forge": "^0.8.2",
"normalize-url": "^4.1.0",
"p-queue": "^3.0.0",
"path-is-inside": "^1.0.2",
Expand Down Expand Up @@ -132,6 +133,7 @@
"@types/nock": "^9.3.0",
"@types/node": "^10.12.15",
"@types/node-emoji": "^1.8.0",
"@types/node-forge": "^0.8.1",
"@types/normalize-url": "^3.3.0",
"@types/p-event": "^1.3.0",
"@types/p-queue": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ export class ActionHelper implements TypeGuard {
//region Helper Methods
//===========================================================================

async getStatus({ log }: { log: LogEntry }): Promise<EnvironmentStatus> {
async getStatus({ log, serviceNames }: { log: LogEntry, serviceNames?: string[] }): Promise<EnvironmentStatus> {
const envStatus: EnvironmentStatusMap = await this.getEnvironmentStatus({ log })
const graph = await this.garden.getConfigGraph()
const services = keyBy(await graph.getServices(), "name")
const services = keyBy(await graph.getServices(serviceNames), "name")

const serviceStatus = await Bluebird.props(mapValues(services, async (service: Service) => {
const runtimeContext = await getServiceRuntimeContext(this.garden, graph, service)
Expand Down
1 change: 0 additions & 1 deletion garden-service/src/plugins/container/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ export const containerRegistryConfigSchema = Joi.object()
.description("The namespace in the registry where images should be pushed.")
.example("my-project"),
})
.required()
.description(deline`
The registry where built containers should be pushed to, and then pulled to the cluster when deploying
services.
Expand Down
9 changes: 9 additions & 0 deletions garden-service/src/plugins/kubernetes/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (C) 2018 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/.
*/

export const RSYNC_PORT = 873
21 changes: 12 additions & 9 deletions garden-service/src/plugins/kubernetes/container/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { deployContainerService, pushModule, deleteService } from "./deployment"
import { deployContainerService, deleteService, pushModule } from "./deployment"
import { hotReloadContainer } from "../hot-reload"
import { getServiceLogs } from "./logs"
import { execInService, runContainerModule, runContainerService, runContainerTask } from "./run"
Expand All @@ -20,25 +20,26 @@ import { getTestResult } from "../test"
import { ContainerModule } from "../../container/config"
import { configureMavenContainerModule, MavenContainerModule } from "../../maven-container/maven-container"
import { getTaskResult } from "../task-results"
import { buildContainerModule, getContainerBuildStatus } from "../../container/build"

async function configure(params: ConfigureModuleParams<ContainerModule>) {
const config = await configureContainerModule(params)
await validateConfig(params)
return config
params.moduleConfig = await configureContainerModule(params)
return validateConfig(params)
}

// TODO: avoid having to special-case this (needs framework improvements)
async function configureMaven(params: ConfigureModuleParams<MavenContainerModule>) {
const config = await configureMavenContainerModule(params)
await validateConfig(params)
return config
export async function configureMaven(params: ConfigureModuleParams<MavenContainerModule>) {
params.moduleConfig = await configureMavenContainerModule(params)
return validateConfig(params)
}

export const containerHandlers = {
configure,
build: buildContainerModule,
deployService: deployContainerService,
deleteService,
execInService,
getBuildStatus: getContainerBuildStatus,
getServiceLogs,
getServiceStatus: getContainerServiceStatus,
getTestResult,
Expand All @@ -56,7 +57,7 @@ export const mavenContainerHandlers = {
configure: configureMaven,
}

async function validateConfig(params: ConfigureModuleParams<ContainerModule>) {
async function validateConfig<T extends ContainerModule>(params: ConfigureModuleParams<T>) {
// validate ingress specs
const config = params.moduleConfig
const provider = <KubernetesProvider>params.ctx.provider
Expand All @@ -80,4 +81,6 @@ async function validateConfig(params: ConfigureModuleParams<ContainerModule>) {
ingressSpec.hostname = hostname
}
}

return config
}
27 changes: 3 additions & 24 deletions garden-service/src/plugins/kubernetes/container/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/

import * as Bluebird from "bluebird"
import { certpem } from "certpem"
import { find, extend } from "lodash"
import { extend } from "lodash"
import { findByName } from "../../../util/util"
import { ContainerService, ContainerIngressSpec } from "../../container/config"
import { IngressTlsCertificate, KubernetesProvider } from "../kubernetes"
import { ServiceIngress, ServiceProtocol } from "../../../types/service"
import { KubeApi } from "../api"
import { ConfigurationError, PluginError } from "../../../exceptions"
import { ensureSecret } from "../secrets"
import { getHostnamesFromPem } from "../../../util/tls"

interface ServiceIngressWithCert extends ServiceIngress {
spec: ContainerIngressSpec
Expand Down Expand Up @@ -162,28 +162,7 @@ async function getCertificateHostnames(api: KubeApi, cert: IngressTlsCertificate
const crtData = Buffer.from(secret.data["tls.crt"], "base64").toString()

try {
// Note: Can't use the certpem.info() method here because of multiple bugs.
// And yes, this API is insane. Crypto people are bonkers. Seriously. - JE
const certInfo = certpem.debug(crtData)

const hostnames: string[] = []

const commonNameField = find(certInfo.subject.types_and_values, ["type", "2.5.4.3"])
if (commonNameField) {
hostnames.push(commonNameField.value.value_block.value)
}

for (const ext of certInfo.extensions || []) {
if (ext.parsedValue && ext.parsedValue.altNames) {
for (const alt of ext.parsedValue.altNames) {
hostnames.push(alt.Name)
}
}
}

certificateHostnames[cert.name] = hostnames

return hostnames
return getHostnamesFromPem(crtData)
} catch (error) {
throw new ConfigurationError(
`Unable to parse Secret '${cert.secretRef.name}' as a valid TLS certificate`,
Expand Down
10 changes: 9 additions & 1 deletion garden-service/src/plugins/kubernetes/helm/hot-reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ContainerModule } from "../../container/config"
import { HotReloadServiceResult } from "../../../types/plugin/outputs"
import { getChartResources, findServiceResource, getServiceResourceSpec } from "./common"
import { syncToService, HotReloadableKind } from "../hot-reload"
import { KubernetesPluginContext } from "../kubernetes"

/**
* The hot reload action handler for Helm charts.
Expand All @@ -34,7 +35,14 @@ export async function hotReloadHelmChart(
resourceSpec,
})

await syncToService(ctx, service, hotReloadSpec, <HotReloadableKind>target.kind, target.metadata.name!, log)
await syncToService(
<KubernetesPluginContext>ctx,
service,
hotReloadSpec,
<HotReloadableKind>target.kind,
target.metadata.name!,
log,
)

return {}
}
Expand Down
Loading

0 comments on commit e0543ad

Please sign in to comment.