Skip to content

Commit

Permalink
Merge pull request #471 from garden-io/ingress-config
Browse files Browse the repository at this point in the history
feat(k8s): allow disabling nginx setup in local-kubernetes provider
  • Loading branch information
edvald authored Jan 25, 2019
2 parents df64d95 + 33511bc commit 4363fc5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
6 changes: 0 additions & 6 deletions docs/basics/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ is set as the current context, Docker for Mac is preferred by default.

(If you're not yet familiar with Garden configuration files, see: [Configuration files](../using-garden/configuration-files.md))

### Hostname

Garden needs the Kubernetes instance to have a hostname. By default Garden will use `<minikube-ip>.nip.io`. If you'd
like to use a custom hostname, you can specify it via the `ingressHostname` in the `local-kubernetes` provider config
(see above).

### Anything else?

Once the above is set up, the `local-kubernetes` plugin will automatically configure everything else Garden needs to
Expand Down
5 changes: 4 additions & 1 deletion garden-service/src/plugins/kubernetes/container/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export async function createIngresses(api: KubeApi, namespace: string, service:
const cert = certIngresses[0].certificate

const annotations = {
"kubernetes.io/ingress.class": api.provider.config.ingressClass,
"ingress.kubernetes.io/force-ssl-redirect": !!cert + "",
}

if (api.provider.config.ingressClass) {
annotations["kubernetes.io/ingress.class"] = api.provider.config.ingressClass
}

const spec: any = { rules }

if (!!cert) {
Expand Down
25 changes: 17 additions & 8 deletions garden-service/src/plugins/kubernetes/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
getAllNamespaces,
} from "./namespace"
import { KUBECTL_DEFAULT_TIMEOUT, kubectl } from "./kubectl"
import { name as providerName } from "./kubernetes"
import { name as providerName, KubernetesProvider } from "./kubernetes"
import { isSystemGarden, getSystemGarden } from "./system"
import { PluginContext } from "../../plugin-context"
import { LogEntry } from "../../logger/log-entry"
Expand Down Expand Up @@ -99,12 +99,9 @@ export async function getLocalEnvironmentStatus({ ctx, log }: GetEnvironmentStat
const sysCtx = await sysGarden.getPluginContext(ctx.provider.name)
const sysStatus = await sysGarden.actions.getStatus({ log })

const serviceStatuses = ctx.provider.config._systemServices
? pick(sysStatus.services, ctx.provider.config._systemServices)
: sysStatus.services
const serviceStatuses = pick(sysStatus.services, getSystemServices(ctx.provider))

const servicesReady = every(values(serviceStatuses).map(s => s.state === "ready"))

const systemReady = sysStatus.providers[ctx.provider.config.name].ready && servicesReady

if (!systemReady) {
Expand Down Expand Up @@ -329,11 +326,13 @@ async function configureSystemServices(
log,
})

// only deploy services if configured to do so (minikube bundles the required services as addons)
if (!provider.config._systemServices || provider.config._systemServices.length > 0) {
// only deploy services if configured to do so (e.g. minikube bundles some required services as addons)
const systemServices = getSystemServices(ctx.provider)

if (systemServices.length > 0) {
const results = await sysGarden.actions.deployServices({
log,
serviceNames: provider.config._systemServices,
serviceNames: systemServices,
force,
})

Expand All @@ -346,3 +345,13 @@ async function configureSystemServices(
}
}
}

function getSystemServices(provider: KubernetesProvider) {
const names = ["kubernetes-dashboard"]

if (provider.config.setupIngressController === "nginx") {
names.push("ingress-controller", "default-backend")
}

return names
}
7 changes: 3 additions & 4 deletions garden-service/src/plugins/kubernetes/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface KubernetesBaseConfig extends ProviderConfig {
imagePullSecrets: SecretRef[]
ingressHttpPort: number
ingressHttpsPort: number
ingressClass: string
ingressClass?: string
namespace?: string
tlsCertificates: IngressTlsCertificate[]
}
Expand Down Expand Up @@ -120,10 +120,9 @@ const configSchema = kubernetesConfigBase
.required(),
deploymentRegistry: containerRegistryConfigSchema,
ingressClass: Joi.string()
.default("nginx")
.description(dedent`
The ingress class to use on configured Ingresses when deploying services. **Note that Garden
currently only supports the nginx ingress controller.**
The ingress class to use on configured Ingresses (via the \`kubernetes.io/ingress.class\` annotation)
when deploying \`container\` services. Use this if you have multiple ingress controllers in your cluster.
`),
ingressHttpPort: Joi.number()
.default(80)
Expand Down
16 changes: 5 additions & 11 deletions garden-service/src/plugins/kubernetes/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async function setMinikubeDockerEnv() {

export interface LocalKubernetesConfig extends KubernetesBaseConfig {
_system?: Symbol
_systemServices?: string[]
}

const configSchema = kubernetesConfigBase
Expand All @@ -64,12 +63,11 @@ const configSchema = kubernetesConfigBase
"Specify which namespace to deploy services to (defaults to the project name). " +
"Note that the framework generates other namespaces as well with this name as a prefix.",
),
ingressHostname: Joi.string()
.description("The hostname of the cluster's ingress controller."),
setupIngressController: Joi.string()
.allow("nginx", false, null)
.default("nginx")
.description("Set this to null or false to skip installing/enabling the `nginx` ingress controller."),
_system: Joi.any().meta({ internal: true }),
_systemServices: Joi.array().items(Joi.string())
.meta({ internal: true })
.description("The system services which should be automatically deployed to the cluster."),
})
.description("The provider configuration for the local-kubernetes plugin.")

Expand All @@ -80,7 +78,6 @@ export async function gardenPlugin({ projectName, config, log }): Promise<Garden

let context = config.context
let defaultHostname = config.defaultHostname
let systemServices

if (!context) {
// automatically detect supported kubectl context if not explicitly configured
Expand Down Expand Up @@ -123,8 +120,6 @@ export async function gardenPlugin({ projectName, config, log }): Promise<Garden
execa("minikube", ["addons", "enable", "ingress"]),
setMinikubeDockerEnv(),
])

systemServices = ["kubernetes-dashboard"]
} else {
if (!defaultHostname) {
defaultHostname = `${projectName}.local.app.garden`
Expand All @@ -143,11 +138,10 @@ export async function gardenPlugin({ projectName, config, log }): Promise<Garden
imagePullSecrets: config.imagePullSecrets,
ingressHttpPort: 80,
ingressHttpsPort: 443,
ingressClass: "nginx",
ingressClass: config.ingressClass,
namespace: config.namespace || projectName,
tlsCertificates: config.tlsCertificates,
_system: config._system,
_systemServices: systemServices,
}

const plugin = k8sPlugin({ config: k8sConfig })
Expand Down

0 comments on commit 4363fc5

Please sign in to comment.