Skip to content

Commit

Permalink
improvement(openfaas): updated faas-netes and made more configurable
Browse files Browse the repository at this point in the history
See the updated docs for details.

Fixes #1306
  • Loading branch information
edvald committed Nov 8, 2019
1 parent aa82e89 commit 4b188ee
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 76 deletions.
4 changes: 2 additions & 2 deletions docs/reference/module-types/openfaas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: Openfaas

# `openfaas` reference

Deploy [OpenFaaS](https://www.openfaas.com/) functions using Garden. Requires either the `openfaas` or
`local-openfaas` provider to be configured.
Deploy [OpenFaaS](https://www.openfaas.com/) functions using Garden. Requires the `openfaas` provider
to be configured.

Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration
guide](../../guides/configuration-files.md).
Expand Down
60 changes: 58 additions & 2 deletions docs/reference/providers/local-openfaas.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,30 @@ providers:
- name: "openfaas"
```

### `providers[].gatewayUrl`

[providers](#providers) > gatewayUrl

The external URL to the function gateway, after installation. This is required if you set `faasNetes.values`
or `faastNetes.install: false`, so that Garden can know how to reach the gateway.

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

Example:

```yaml
providers:
- gatewayUrl: "https://functions.mydomain.com"
```

### `providers[].hostname`

[providers](#providers) > hostname

The hostname to configure for the function gateway.
Defaults to the default hostname of the configured Kubernetes provider.
The ingress hostname to configure for the function gateway, when `faasNetes.install: true` and not
overriding `faasNetes.values`. Defaults to the default hostname of the configured Kubernetes provider.

Important: If you have other types of services, this should be different from their ingress hostnames,
or the other services should not expose paths under /function and /system to avoid routing conflicts.
Expand All @@ -73,6 +91,40 @@ providers:
- hostname: "functions.mydomain.com"
```

### `providers[].faasNetes`

[providers](#providers) > faasNetes

| Type | Required | Default |
| -------- | -------- | ------------------ |
| `object` | No | `{"install":true}` |

### `providers[].faasNetes.install`

[providers](#providers) > [faasNetes](#providersfaasnetes) > install

Set to false if you'd like to install and configure faas-netes yourself.
See the [official instructions](https://docs.openfaas.com/deployment/kubernetes/) for details.

| Type | Required | Default |
| --------- | -------- | ------- |
| `boolean` | No | `true` |

### `providers[].faasNetes.values`

[providers](#providers) > [faasNetes](#providersfaasnetes) > values

Override the values passed to the faas-netes Helm chart. Ignored if `install: false`.
See the [chart docs](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas) for the available
options.

Note that this completely replaces the values Garden assigns by default, including `functionNamespace`,
ingress configuration etc. so you need to make sure those are correctly configured for your use case.

| Type | Required |
| -------- | -------- |
| `object` | No |


## Complete YAML schema

Expand All @@ -82,5 +134,9 @@ The values in the schema below are the default values.
providers:
- environments:
name: openfaas
gatewayUrl:
hostname:
faasNetes:
install: true
values:
```
60 changes: 58 additions & 2 deletions docs/reference/providers/openfaas.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,30 @@ providers:
- name: "openfaas"
```

### `providers[].gatewayUrl`

[providers](#providers) > gatewayUrl

The external URL to the function gateway, after installation. This is required if you set `faasNetes.values`
or `faastNetes.install: false`, so that Garden can know how to reach the gateway.

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

Example:

```yaml
providers:
- gatewayUrl: "https://functions.mydomain.com"
```

### `providers[].hostname`

[providers](#providers) > hostname

The hostname to configure for the function gateway.
Defaults to the default hostname of the configured Kubernetes provider.
The ingress hostname to configure for the function gateway, when `faasNetes.install: true` and not
overriding `faasNetes.values`. Defaults to the default hostname of the configured Kubernetes provider.

Important: If you have other types of services, this should be different from their ingress hostnames,
or the other services should not expose paths under /function and /system to avoid routing conflicts.
Expand All @@ -73,6 +91,40 @@ providers:
- hostname: "functions.mydomain.com"
```

### `providers[].faasNetes`

[providers](#providers) > faasNetes

| Type | Required | Default |
| -------- | -------- | ------------------ |
| `object` | No | `{"install":true}` |

### `providers[].faasNetes.install`

[providers](#providers) > [faasNetes](#providersfaasnetes) > install

Set to false if you'd like to install and configure faas-netes yourself.
See the [official instructions](https://docs.openfaas.com/deployment/kubernetes/) for details.

| Type | Required | Default |
| --------- | -------- | ------- |
| `boolean` | No | `true` |

### `providers[].faasNetes.values`

[providers](#providers) > [faasNetes](#providersfaasnetes) > values

Override the values passed to the faas-netes Helm chart. Ignored if `install: false`.
See the [chart docs](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas) for the available
options.

Note that this completely replaces the values Garden assigns by default, including `functionNamespace`,
ingress configuration etc. so you need to make sure those are correctly configured for your use case.

| Type | Required |
| -------- | -------- |
| `object` | No |


## Complete YAML schema

Expand All @@ -82,5 +134,9 @@ The values in the schema below are the default values.
providers:
- environments:
name: openfaas
gatewayUrl:
hostname:
faasNetes:
install: true
values:
```
47 changes: 42 additions & 5 deletions garden-service/src/plugins/openfaas/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { join } from "path"
import { resolve as urlResolve } from "url"
import { ConfigurationError } from "../../exceptions"
import { PluginContext } from "../../plugin-context"
import { joiArray, joiProviderName, joi, joiEnvVars } from "../../config/common"
import { joiArray, joiProviderName, joi, joiEnvVars, DeepPrimitiveMap } from "../../config/common"
import { Module } from "../../types/module"
import { Service } from "../../types/service"
import { ExecModuleSpecBase, ExecTestSpec, execTestSchema } from "../exec"
Expand Down Expand Up @@ -81,31 +81,64 @@ export type OpenFaasModuleConfig = OpenFaasModule["_ConfigType"]
export interface OpenFaasService extends Service<OpenFaasModule> {}

export interface OpenFaasConfig extends ProviderConfig {
gatewayUrl: string
hostname: string
faasNetes: {
install: boolean
values: DeepPrimitiveMap
}
}

export const configSchema = providerConfigBaseSchema.keys({
name: joiProviderName("openfaas"),
gatewayUrl: joi
.string()
.uri({ scheme: ["http", "https"] })
.description(
dedent`
The external URL to the function gateway, after installation. This is required if you set \`faasNetes.values\`
or \`faastNetes.install: false\`, so that Garden can know how to reach the gateway.
`
)
.example("https://functions.mydomain.com"),
hostname: joi
.string()
.hostname()
.allow(null)
.description(
dedent`
The hostname to configure for the function gateway.
Defaults to the default hostname of the configured Kubernetes provider.
The ingress hostname to configure for the function gateway, when \`faasNetes.install: true\` and not
overriding \`faasNetes.values\`. Defaults to the default hostname of the configured Kubernetes provider.
Important: If you have other types of services, this should be different from their ingress hostnames,
or the other services should not expose paths under /function and /system to avoid routing conflicts.`
or the other services should not expose paths under /function and /system to avoid routing conflicts.
`
)
.example("functions.mydomain.com"),
faasNetes: joi
.object()
.keys({
install: joi.boolean().default(true).description(dedent`
Set to false if you'd like to install and configure faas-netes yourself.
See the [official instructions](https://docs.openfaas.com/deployment/kubernetes/) for details.
`),
values: joi.object().description(dedent`
Override the values passed to the faas-netes Helm chart. Ignored if \`install: false\`.
See the [chart docs](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas) for the available
options.
Note that this completely replaces the values Garden assigns by default, including \`functionNamespace\`,
ingress configuration etc. so you need to make sure those are correctly configured for your use case.
`),
})
.default({ install: true }),
})

export type OpenFaasProvider = Provider<OpenFaasConfig>
export type OpenFaasPluginContext = PluginContext<OpenFaasConfig>

export function getK8sProvider(providers: Provider[]): KubernetesProvider {
const providerMap = keyBy(providers, "name")
// FIXME: use new plugin inheritance mechanism here, instead of explicitly checking for local-kubernetes
const provider = <KubernetesProvider>(providerMap["local-kubernetes"] || providerMap.kubernetes)

if (!provider) {
Expand Down Expand Up @@ -212,3 +245,7 @@ async function getInternalServiceUrl(ctx: PluginContext<OpenFaasConfig>, log: Lo
export function getServicePath(config: OpenFaasModuleConfig) {
return join("/", "function", config.name)
}

export function getExternalGatewayUrl(ctx: PluginContext<OpenFaasConfig>) {
return ctx.provider.config.gatewayUrl || `http://${ctx.provider.config.hostname}`
}
12 changes: 6 additions & 6 deletions garden-service/src/plugins/openfaas/faas-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export const faasCli = new BinaryCmd({
name: "faas-cli",
specs: {
darwin: {
url: "https://github.com/openfaas/faas-cli/releases/download/0.8.21/faas-cli-darwin",
sha256: "68d99f789e2e0a763b6f58f075f0118b8828fd43b3ca4eed646961eb6ac352fa",
url: "https://github.com/openfaas/faas-cli/releases/download/0.9.5/faas-cli-darwin",
sha256: "28beff63ef8234c1c937b14fd63e8c25244432897830650b8f76897fe4e22cbb",
},
linux: {
url: "https://github.com/openfaas/faas-cli/releases/download/0.8.21/faas-cli",
sha256: "b8a5b455f20b14751140cb63277ee4d435e23ed041be1898a0dc2c27ee718046",
url: "https://github.com/openfaas/faas-cli/releases/download/0.9.5/faas-cli",
sha256: "f4c8014d953f42e0c83628c089aff36aaf306f9f1aea62e5f22c84ab4269d1f7",
},
win32: {
url: "https://github.com/openfaas/faas-cli/releases/download/0.8.21/faas-cli.exe",
sha256: "366e01a364e64f90bec6b8234c2bc5bb87bbd059b187f8afe43c36d22f4d5b84",
url: "https://github.com/openfaas/faas-cli/releases/download/0.9.5/faas-cli.exe",
sha256: "45d09e4dbff679c32aff8f86cc39e12c3687b6b344a9a20510c6c61f4e141eb5",
},
},
})
Loading

0 comments on commit 4b188ee

Please sign in to comment.