mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-08-19 04:06:27 +00:00
Add env handler
This commit is contained in:
@@ -29,6 +29,7 @@ Web API:
|
||||
* `GET /status/{code}` returns the status code
|
||||
* `GET /panic` crashes the process with exit code 255
|
||||
* `POST /echo` forwards the call to the backend service and echos the posted content
|
||||
* `GET /env` returns the environment variables as a JSON array
|
||||
* `GET /headers` returns a JSON with the request HTTP headers
|
||||
* `GET /delay/{seconds}` waits for the specified period
|
||||
* `GET /configs` returns a JSON with configmaps and/or secrets mounted in the `config` volume
|
||||
|
||||
@@ -171,7 +171,7 @@ spec:
|
||||
- "istio.example.com"
|
||||
```
|
||||
|
||||
### Configure OpenFaaS
|
||||
### Configure OpenFaaS mTLS and access policies
|
||||
|
||||
Create the OpenFaaS namespaces:
|
||||
|
||||
@@ -386,13 +386,14 @@ echo $password | faas-cli login -g https://openfaas.istio.example.com -u admin -
|
||||
|
||||
### Canary deployments for OpenFaaS functions
|
||||
|
||||
General available release v1.0.0:
|
||||
Create a general available release for the `env` function version 1.0.0:
|
||||
|
||||
```yaml
|
||||
apiVersion: openfaas.com/v1alpha2
|
||||
kind: Function
|
||||
metadata:
|
||||
name: env
|
||||
namespace: openfaas-fn
|
||||
spec:
|
||||
name: env
|
||||
image: stefanprodan/of-env:1.0.0
|
||||
@@ -405,13 +406,14 @@ spec:
|
||||
cpu: "100m"
|
||||
```
|
||||
|
||||
Canary release v1.1.0:
|
||||
Create a canary release for version 1.1.0:
|
||||
|
||||
```yaml
|
||||
apiVersion: openfaas.com/v1alpha2
|
||||
kind: Function
|
||||
metadata:
|
||||
name: env-canaray
|
||||
namespace: openfaas-fn
|
||||
spec:
|
||||
name: env-canaray
|
||||
image: stefanprodan/of-env:1.1.0
|
||||
@@ -424,7 +426,7 @@ spec:
|
||||
cpu: "100m"
|
||||
```
|
||||
|
||||
Istio virtual service with 10% traffic going to canary:
|
||||
Create an Istio virtual service with 10% traffic going to canary:
|
||||
|
||||
```yaml
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"os"
|
||||
)
|
||||
|
||||
func (s *Server) envHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.JSONResponse(w, r, os.Environ())
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnvHandler(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "/api/env", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
srv := NewMockServer()
|
||||
handler := http.HandlerFunc(srv.infoHandler)
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
|
||||
// Check the status code is what we expect.
|
||||
if status := rr.Code; status != http.StatusOK {
|
||||
t.Errorf("handler returned wrong status code: got %v want %v",
|
||||
status, http.StatusOK)
|
||||
}
|
||||
|
||||
// Check the response body is what we expect.
|
||||
expected := ".*hostname.*"
|
||||
r := regexp.MustCompile(expected)
|
||||
if !r.MatchString(rr.Body.String()) {
|
||||
t.Fatalf("handler returned unexpected body:\ngot \n%v \nwant \n%s",
|
||||
rr.Body.String(), expected)
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ func (s *Server) registerHandlers() {
|
||||
s.router.HandleFunc("/", s.infoHandler).Methods("GET")
|
||||
s.router.HandleFunc("/version", s.versionHandler).Methods("GET")
|
||||
s.router.HandleFunc("/echo", s.echoHandler).Methods("POST")
|
||||
s.router.HandleFunc("/env", s.envHandler).Methods("GET", "POST")
|
||||
s.router.HandleFunc("/headers", s.echoHeadersHandler).Methods("GET", "POST")
|
||||
s.router.HandleFunc("/delay/{wait:[0-9]+}", s.delayHandler).Methods("GET").Name("delay")
|
||||
s.router.HandleFunc("/healthz", s.healthzHandler).Methods("GET")
|
||||
|
||||
Reference in New Issue
Block a user