Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenFaaS support #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ terraform.tfvars
.terraform*
*.swp
password_file*
.vscode
.vscode
template
build
.secrets
3 changes: 3 additions & 0 deletions openfaas/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
template
build
.secrets
43 changes: 43 additions & 0 deletions openfaas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# What is OpenFaaS/ faas-netes?

A way to deploy FaaS objects into Kubernetes that follows open standards.

## How to get started

Install the CLI

```bash
brew install faas-cli
```

Then to download templates use

```bash
faas-cli template pull
```

Then to create a sample one in Python, use

```bash
faas-cli new hello-world --lang python3
```

Edit the `hello-world.yml` file to have the right image tag/location,
and update `requirements.txt` as necessary.

Then get the secret to log in, and port-forward the gateway

```bash
kubectl port-forward -n openfaas svc/gateway 8080:8080
PASSWORD=$(kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode)
faas-cli login --password $PASSWORD
```

Lastly, build, push and deploy your function with the following
(assuming you have dockerhub push access set up)

```bash
faas-cli build --yaml hello-world.yml
faas-cli publish --yaml hello-world.yml --reset-qemu=false # For ARM -> AMD64
faas-cli deploy --yaml hello-world.yml
```
17 changes: 17 additions & 0 deletions openfaas/dev/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-dev-terraform"
key = "terraform-openfaas.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions openfaas/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "openfaas" {
source = "../faas-netes-chart"
cluster_name = "dev-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions openfaas/dev/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
61 changes: 61 additions & 0 deletions openfaas/faas-netes-chart/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
data "digitalocean_kubernetes_cluster" "dev" {
name = var.cluster_name
}


provider "kubernetes" {
host = data.digitalocean_kubernetes_cluster.dev.endpoint
token = data.digitalocean_kubernetes_cluster.dev.kube_config[0].token
cluster_ca_certificate = base64decode(
data.digitalocean_kubernetes_cluster.dev.kube_config[0].cluster_ca_certificate
)
}

provider "helm" {
kubernetes {
host = data.digitalocean_kubernetes_cluster.dev.endpoint
token = data.digitalocean_kubernetes_cluster.dev.kube_config[0].token
cluster_ca_certificate = base64decode(
data.digitalocean_kubernetes_cluster.dev.kube_config[0].cluster_ca_certificate
)
}
}

resource "kubernetes_namespace" "openfaas-fn-ns" {
metadata {
name = "openfaas-fn"
annotations = {
"linkerd.io/inject" = "enabled"
"config.linkerd.io/skip-inbound-ports" = "4222"
"config.linkerd.io/skip-outbound-ports" = "4222"
}

labels = {
istio-injection = "enabled"
role = "openfaas-fn"
}

}
}

locals {
chart_version = "13.0.0"
}


resource "helm_release" "openfaas_chart" {
name = "openfaas"
repository = "https://openfaas.github.io/faas-netes/"
chart = "openfaas"
version = local.chart_version
namespace = "openfaas"
create_namespace = true


values = [
"${file("${path.module}/values.yaml")}",
var.values_file
]

}

10 changes: 10 additions & 0 deletions openfaas/faas-netes-chart/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
8 changes: 8 additions & 0 deletions openfaas/faas-netes-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
functionNamespace: openfaas-fn
operator:
create: false
clusterRole: true
prometheus:
create: false
alertmanager:
create: false
8 changes: 8 additions & 0 deletions openfaas/faas-netes-chart/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "cluster_name" {
type = string
}

variable "values_file" {
type = string
default = ""
}
9 changes: 9 additions & 0 deletions openfaas/hello-world.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
hello-world:
lang: python3
handler: ./hello-world
image: mckornfield/openfaas-hello-world:latest
Empty file.
7 changes: 7 additions & 0 deletions openfaas/hello-world/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def handle(req):
"""handle a request to the function
Args:
req (str): request body
"""
print("testing 123!")
return req
Empty file.
17 changes: 17 additions & 0 deletions openfaas/prod/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-production-terraform"
key = "terraform-openfaas.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions openfaas/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "openfaas" {
source = "../faas-netes-chart"
cluster_name = "prod-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions openfaas/prod/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
17 changes: 17 additions & 0 deletions openfaas/test/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-test-terraform"
key = "terraform-openfaas.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions openfaas/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "openfaas" {
source = "../faas-netes-chart"
cluster_name = "test-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions openfaas/test/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
2 changes: 1 addition & 1 deletion solr/prod/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-test-terraform"
bucket = "treetracker-production-terraform"
key = "terraform-solr.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
Expand Down