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

Refer feedback from #673 and augment documentation #684

Merged
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
2 changes: 2 additions & 0 deletions README-OPERATOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ helm upgrade openfaas --install openfaas/openfaas \

> Note: If you are switching from the OpenFaaS `faas-netes` controller, then you will need to remove all functions and redeploy them after switching to the operator.

If you want to enable multiple namespaces feature which enables you to create functions across namespaces in the cluster, set `clusterRole=true`.

#### Deploy a function with kubectl:

```bash
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The rest of this document is dedicated to technical and operational information
There are two modes available for faas-netes, the classic mode is the default.

* Classic mode (aka faas-netes) - includes a REST API, multiple-namespace support but no Function CRD
* Operator mode (aka "The OpenFaaS Operator") - includes a REST API, with a "Function" CRD, but you must use a single namespace per installation
* Operator mode (aka "The OpenFaaS Operator") - includes a REST API, with a "Function" CRD and multiple-namespace support

See also: [README for "The OpenFaaS Operator"](README-OPERATOR.md)

Expand All @@ -59,21 +59,21 @@ The single faas-netes image and binary contains both modes, switch between one o

faas-netes can be configured with environment variables, but for a full set of options see the [helm chart](./chart/openfaas/).

| Option | Usage |
|---------------------|-------------------------------------------------------------------------------------------------|
| `httpProbe` | Boolean - use http probe type for function readiness and liveness. Default: `false` |
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds). Default: `60s` |
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds). Default: `60s` |
| `image_pull_policy` | Image pull policy for deployed functions (`Always`, `IfNotPresent`, `Never`). Default: `Always` |
| `gateway.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `faasnetes.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `operator.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `queueWorker.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `prometheus.resources` | CPU/Memory resources requests/limits (memory: `512Mi`) |
| `alertmanager.resources` | CPU/Memory resources requests/limits (memory: `25Mi`) |
| `nats.resources` | CPU/Memory resources requests/limits (memory: `120Mi`) |
| `faasIdler.resources` | CPU/Memory resources requests/limits (memory: `64Mi`) |
| `basicAuthPlugin.resources`| CPU/Memory resources requests/limits (memory: `50Mi`, cpu: `20m`) |
| Option | Usage |
| --------------------------- | ------------------------------------------------------------------------------------------------ |
| `httpProbe` | Boolean - use http probe type for function readiness and liveness. Default: `false` |
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds). Default: `60s` |
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds). Default: `60s` |
| `image_pull_policy` | Image pull policy for deployed functions (`Always`, `IfNotPresent`, `Never`). Default: `Always` |
| `gateway.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `faasnetes.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `operator.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `queueWorker.resources` | CPU/Memory resources requests/limits (memory: `120Mi`, cpu: `50m`) |
| `prometheus.resources` | CPU/Memory resources requests/limits (memory: `512Mi`) |
| `alertmanager.resources` | CPU/Memory resources requests/limits (memory: `25Mi`) |
| `nats.resources` | CPU/Memory resources requests/limits (memory: `120Mi`) |
| `faasIdler.resources` | CPU/Memory resources requests/limits (memory: `64Mi`) |
| `basicAuthPlugin.resources` | CPU/Memory resources requests/limits (memory: `50Mi`, cpu: `20m`) |

### Readiness checking

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func main() {
defaultResync := time.Minute * 5

namespaceScope := config.DefaultFunctionNamespace
if operator && config.ClusterRole {
if config.ClusterRole {
namespaceScope = ""
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/handlers/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func MakeNamespacesLister(defaultNamespace string, clientset kubernetes.Interfac
return func(w http.ResponseWriter, r *http.Request) {
log.Println("Query namespaces")

if r.Body != nil {
defer r.Body.Close()
}

res := ListNamespaces(defaultNamespace, clientset)

out, err := json.Marshal(res)
Expand Down
7 changes: 3 additions & 4 deletions pkg/server/apply.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -39,7 +38,7 @@ func makeApplyHandler(defaultNamespace string, client clientset.Interface) http.
}

opts := metav1.GetOptions{}
got, err := client.OpenfaasV1().Functions(namespace).Get(context.TODO(), req.Service, opts)
got, err := client.OpenfaasV1().Functions(namespace).Get(r.Context(), req.Service, opts)
miss := false
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -60,7 +59,7 @@ func makeApplyHandler(defaultNamespace string, client clientset.Interface) http.
updated.Spec = toFunctionSpec(req)

if _, err = client.OpenfaasV1().Functions(namespace).
Update(context.TODO(), updated, metav1.UpdateOptions{}); err != nil {
Update(r.Context(), updated, metav1.UpdateOptions{}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error updating function: %s", err.Error())))
return
Expand All @@ -76,7 +75,7 @@ func makeApplyHandler(defaultNamespace string, client clientset.Interface) http.
}

if _, err = client.OpenfaasV1().Functions(namespace).
Create(context.TODO(), newFunc, metav1.CreateOptions{}); err != nil {
Create(r.Context(), newFunc, metav1.CreateOptions{}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error creating function: %s", err.Error())))
return
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/delete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"context"
"encoding/json"
"io"
"io/ioutil"
Expand Down Expand Up @@ -49,7 +48,7 @@ func makeDeleteHandler(defaultNamespace string, client clientset.Interface) http
}

err = client.OpenfaasV1().Functions(lookupNamespace).
Delete(context.TODO(), request.FunctionName, metav1.DeleteOptions{})
Delete(r.Context(), request.FunctionName, metav1.DeleteOptions{})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"context"
"encoding/json"
"net/http"

Expand Down Expand Up @@ -39,7 +38,7 @@ func makeListHandler(defaultNamespace string,
functions := []types.FunctionStatus{}

opts := metav1.ListOptions{}
res, err := client.OpenfaasV1().Functions(lookupNamespace).List(context.TODO(), opts)
res, err := client.OpenfaasV1().Functions(lookupNamespace).List(r.Context(), opts)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
Expand Down
29 changes: 0 additions & 29 deletions pkg/server/namespace.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/server/replicas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -31,7 +30,7 @@ func makeReplicaReader(defaultNamespace string, client clientset.Interface, list

opts := metav1.GetOptions{}
k8sfunc, err := client.OpenfaasV1().Functions(lookupNamespace).
Get(context.TODO(), functionName, opts)
Get(r.Context(), functionName, opts)
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -110,7 +109,7 @@ func makeReplicaHandler(defaultNamespace string, kube kubernetes.Interface) http
}

opts := metav1.GetOptions{}
dep, err := kube.AppsV1().Deployments(lookupNamespace).Get(context.TODO(), functionName, opts)
dep, err := kube.AppsV1().Deployments(lookupNamespace).Get(r.Context(), functionName, opts)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand All @@ -119,7 +118,7 @@ func makeReplicaHandler(defaultNamespace string, kube kubernetes.Interface) http
}

dep.Spec.Replicas = int32p(int32(req.Replicas))
_, err = kube.AppsV1().Deployments(lookupNamespace).Update(context.TODO(), dep, metav1.UpdateOptions{})
_, err = kube.AppsV1().Deployments(lookupNamespace).Update(r.Context(), dep, metav1.UpdateOptions{})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down
24 changes: 0 additions & 24 deletions pkg/server/secret.go

This file was deleted.

160 changes: 0 additions & 160 deletions pkg/server/secret_test.go

This file was deleted.

Loading