Skip to content

Commit

Permalink
fix(local-k8s): don't install nginx when running with Minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Feb 22, 2019
1 parent 02cd157 commit 056924b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion garden-service/src/docs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { execModuleSpecSchema } from "../plugins/exec"
import { projectSchema } from "../config/project"
import { baseModuleSpecSchema } from "../config/module"
import handlebars = require("handlebars")
import { configSchema as localK8sConfigSchema } from "../plugins/kubernetes/local"
import { configSchema as localK8sConfigSchema } from "../plugins/kubernetes/local/local"
import { configSchema as k8sConfigSchema } from "../plugins/kubernetes/kubernetes"
import { configSchema as openfaasConfigSchema } from "../plugins/openfaas/openfaas"
import { openfaasModuleSpecSchema } from "../plugins/openfaas/openfaas"
Expand Down
9 changes: 5 additions & 4 deletions garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,16 @@ export class Garden {

// call configureProvider action if provided
const configureHandler = actions.configureProvider
if (configureHandler) {
const configureOutput = await configureHandler({ config: providerConfig })
providerConfig = configureOutput.config
}

if (plugin.configSchema) {
providerConfig = validate(providerConfig, plugin.configSchema, { context: `${pluginName} configuration` })
}

if (configureHandler) {
const configureOutput = await configureHandler({ config: providerConfig })
providerConfig = configureOutput.config
}

if (providerIndex === -1) {
this.environment.providers.push({ name: pluginName, config: providerConfig })
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import * as execa from "execa"
import { safeLoad } from "js-yaml"
import * as Joi from "joi"
import { join } from "path"
import { GardenPlugin, PluginFactoryParams } from "../../types/plugin/plugin"
import { GardenPlugin, PluginFactoryParams } from "../../../types/plugin/plugin"
import {
gardenPlugin as k8sPlugin,
KubernetesBaseConfig,
kubernetesConfigBase,
} from "./kubernetes"
} from "../kubernetes"
import { readFile } from "fs-extra"
import { homedir } from "os"
import { getLocalEnvironmentStatus, prepareLocalEnvironment } from "./init"
import { ConfigureProviderParams } from "../../types/plugin/params"
import { getLocalEnvironmentStatus, prepareLocalEnvironment } from "../init"
import { ConfigureProviderParams } from "../../../types/plugin/params"

// TODO: split this into separate plugins to handle Docker for Mac and Minikube

Expand Down Expand Up @@ -52,6 +52,7 @@ async function setMinikubeDockerEnv() {

export interface LocalKubernetesConfig extends KubernetesBaseConfig {
_system?: Symbol
setupIngressController: string | boolean | null
}

export const configSchema = kubernetesConfigBase
Expand Down Expand Up @@ -80,6 +81,7 @@ export function gardenPlugin({ projectName, log }: PluginFactoryParams): GardenP
plugin.actions!.configureProvider = async ({ config }: ConfigureProviderParams<LocalKubernetesConfig>) => {
let context = config.context
let defaultHostname = config.defaultHostname
let setupIngressController = config.setupIngressController

if (!context) {
// automatically detect supported kubectl context if not explicitly configured
Expand Down Expand Up @@ -117,11 +119,15 @@ export function gardenPlugin({ projectName, log }: PluginFactoryParams): GardenP
defaultHostname = `${projectName}.${minikubeIp}.nip.io`
}

await Promise.all([
// TODO: wait for ingress addon to be ready, if it was previously disabled
execa("minikube", ["addons", "enable", "ingress"]),
setMinikubeDockerEnv(),
])
if (config.setupIngressController === "nginx") {
log.silly("Using minikube's ingress addon")
await execa("minikube", ["addons", "enable", "ingress"])
// make sure the prepare handler doesn't also set up the ingress controller
setupIngressController = false
}

await setMinikubeDockerEnv()

} else {
if (!defaultHostname) {
defaultHostname = `${projectName}.local.app.garden`
Expand All @@ -142,6 +148,7 @@ export function gardenPlugin({ projectName, log }: PluginFactoryParams): GardenP
ingressHttpsPort: 443,
ingressClass: "nginx",
namespace: config.namespace || projectName,
setupIngressController,
tlsCertificates: config.tlsCertificates,
_system: config._system,
}
Expand Down
22 changes: 12 additions & 10 deletions garden-service/src/plugins/kubernetes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,24 @@ export async function checkDeploymentStatus(
if (event.involvedObject.kind === "Pod") {
const logs = await getPodLogs(api, namespace, [event.involvedObject.name])

out.logs = dedent`
<Showing last ${podLogLines} lines for the pod. Run the following command for complete logs:>
kubectl -n ${namespace} --context=${api.context} logs ${event.involvedObject.name}
if (logs) {
out.logs = dedent`
<Showing last ${podLogLines} lines for the pod. Run the following command for complete logs>
kubectl -n ${namespace} --context=${api.context} logs ${event.involvedObject.name}
${logs}
`
` + logs
}
} else {
const pods = await getPods(api, namespace, statusRes.spec.selector.matchLabels)
const logs = await getPodLogs(api, namespace, pods.map(pod => pod.metadata.name))

out.logs = dedent`
<Showing last ${podLogLines} lines per pod in this ${obj.kind}. Run the following command for complete logs:>
kubectl -n ${namespace} --context=${api.context} logs ${obj.kind.toLowerCase()}/${obj.metadata.name}
if (logs) {
out.logs = dedent`
<Showing last ${podLogLines} lines per pod in this ${obj.kind}. Run the following command for complete logs>
kubectl -n ${namespace} --context=${api.context} logs ${obj.kind.toLowerCase()}/${obj.metadata.name}
${logs}
`
` + logs
}
}

return out
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/plugins/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const container = require("./container/container")
const gcf = require("./google/google-cloud-functions")
const localGcf = require("./local/local-google-cloud-functions")
const kubernetes = require("./kubernetes/kubernetes")
const localKubernetes = require("./kubernetes/local")
const localKubernetes = require("./kubernetes/local/local")
const npmPackage = require("./npm-package")
const gae = require("./google/google-app-engine")
const openfaas = require("./openfaas/openfaas")
Expand Down

0 comments on commit 056924b

Please sign in to comment.