Skip to content

Commit e2c8282

Browse files
LucasRoesleralexellis
authored andcommitted
Update to faas-provider 0.14.0
**What** - Update faas-provider to 0.14.0 - Refactor to remove the gateway dep - Add logs and secrets handlers so that the implementation is complete - Moved makefile targets that referenced the docker compose, because the file does not exist anymore - Add new `make start` command that builds and starts the faas-memory on port 8083 Signed-off-by: Lucas Roesler <[email protected]>
1 parent 2c2a26d commit e2c8282

32 files changed

+728
-200
lines changed

Gopkg.lock

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
[[constraint]]
3737
name = "github.com/openfaas/faas-provider"
38-
version = "0.9.0"
38+
version = "0.14.0"
3939

4040
[[constraint]]
4141
name = "github.com/sirupsen/logrus"

Makefile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ build:
1818

1919
.PHONY: build-local
2020
build-local:
21-
go build --ldflags "-s -w \
21+
GO111MODULE=off go build --ldflags "-s -w \
2222
-X github.com/openfaas-incubator/faas-memory/version.GitCommitSHA=${GIT_COMMIT_SHA} \
2323
-X \"github.com/openfaas-incubator/faas-memory/version.GitCommitMessage=${GIT_COMMIT_MESSAGE}\" \
2424
-X github.com/openfaas-incubator/faas-memory/version.Version=${VERSION}" \
2525
-o faas-memory .
2626

27-
.PHONY: up-local-deps
28-
up-local-deps:
29-
docker-compose -f./docker-compose.local.yml up -d
3027

31-
.PHONY: up-local
32-
up-local: build-local
33-
-pkill faas-memory
34-
docker-compose -f ./docker-compose.local.yml up -d
35-
env port=8081 ./faas-memory
28+
.PHONY: start
29+
start: build-local
30+
port=8083 ./faas-memory
3631

3732
.PHONY: release
3833
release:
@@ -70,4 +65,4 @@ lint:
7065
echo "Lint found errors in the source code. Please check the reported errors"; \
7166
echo "and fix them if necessary before submitting the code for review."; \
7267
exit 1; \
73-
fi
68+
fi

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ In one terminal, build and start the provider:
1414
export GOPATH=$HOME/go
1515
go get -u github.com/openfaas-incubator/faas-memory
1616
cd $GOPATH/go/src/github.com/openfaas-incubator/faas-memory
17-
18-
make build-local
19-
20-
port=8083 ./faas-provider
17+
make start
2118
```
2219

2320
In another use the CLI with it:
2421

2522
```sh
26-
$ export GOPATH=$HOME/go
27-
$ cd $GOPATH/go/src/github.com/openfaas-incubator/faas-memory
28-
2923
$ export OPENFAAS_URL=127.0.0.1:8083
3024

3125
$ faas-cli list
@@ -42,6 +36,6 @@ URL: http://127.0.0.1:8083/function/figlet
4236
$ faas-cli list
4337

4438
Function Invocations Replicas
45-
figlet 0 1
39+
figlet 0 1
4640
```
4741

handlers/delete.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
"io/ioutil"
99
"net/http"
1010

11-
"github.com/openfaas/faas/gateway/requests"
1211
log "github.com/sirupsen/logrus"
1312
)
1413

14+
type deleteFunctionRequest struct {
15+
FunctionName string `json:"functionName"`
16+
}
17+
1518
// MakeDeleteHandler delete a function
1619
func MakeDeleteHandler() http.HandlerFunc {
1720
return func(w http.ResponseWriter, r *http.Request) {
1821
log.Info("delete request")
1922
defer r.Body.Close()
2023

2124
body, _ := ioutil.ReadAll(r.Body)
22-
request := requests.DeleteFunctionRequest{}
25+
request := deleteFunctionRequest{}
2326
if err := json.Unmarshal(body, &request); err != nil {
2427
log.Errorf("error de-serializing request body:%s", body)
2528
log.Error(err)

handlers/deploy.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"io/ioutil"
99
"net/http"
1010

11-
"github.com/openfaas/faas/gateway/requests"
1211
log "github.com/sirupsen/logrus"
12+
13+
typesv1 "github.com/openfaas/faas-provider/types"
1314
)
1415

15-
var functions = map[string]*requests.Function{}
16+
var functions = map[string]*typesv1.FunctionStatus{}
1617

1718
// MakeDeployHandler creates a handler to create new functions in the cluster
1819
func MakeDeployHandler() http.HandlerFunc {
@@ -23,14 +24,14 @@ func MakeDeployHandler() http.HandlerFunc {
2324

2425
body, _ := ioutil.ReadAll(r.Body)
2526

26-
request := requests.CreateFunctionRequest{}
27+
request := typesv1.FunctionDeployment{}
2728
if err := json.Unmarshal(body, &request); err != nil {
2829
log.Errorln("error during unmarshal of create function request. ", err)
2930
w.WriteHeader(http.StatusBadRequest)
3031
return
3132
}
3233

33-
functions[request.Service] = createToRequest(request)
34+
functions[request.Service] = requestToStatus(request)
3435

3536
log.Infof("deployment request for function %s", request.Service)
3637

handlers/info.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55
"net/http"
66

7-
"github.com/openfaas/faas-provider/types"
7+
typesv1 "github.com/openfaas/faas-provider/types"
88
log "github.com/sirupsen/logrus"
99
)
1010

@@ -24,16 +24,16 @@ func MakeInfoHandler(version, sha string) http.HandlerFunc {
2424

2525
log.Info("info request")
2626

27-
infoRequest := types.InfoRequest{
27+
infoResponse := typesv1.InfoResponse{
2828
Orchestration: OrchestrationIdentifier,
2929
Provider: ProviderName,
30-
Version: types.ProviderVersion{
30+
Version: typesv1.ProviderVersion{
3131
Release: version,
3232
SHA: sha,
3333
},
3434
}
3535

36-
jsonOut, marshalErr := json.Marshal(infoRequest)
36+
jsonOut, marshalErr := json.Marshal(infoResponse)
3737
if marshalErr != nil {
3838
log.Error("Error during unmarshal of info request ", marshalErr)
3939
w.WriteHeader(http.StatusInternalServerError)

handlers/logs.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package handlers
2+
3+
import (
4+
"context"
5+
6+
"github.com/openfaas/faas-provider/logs"
7+
)
8+
9+
// LogRequester implements the Requester interface
10+
type LogRequester struct{}
11+
12+
// NewLogRequester returns a Requestor instance that can be used in the function logs endpoint
13+
func NewLogRequester() logs.Requester {
14+
return &LogRequester{}
15+
}
16+
17+
// Query implements the actual Swarm logs request logic for the Requester interface
18+
func (l LogRequester) Query(ctx context.Context, r logs.Request) (<-chan logs.Message, error) {
19+
msgStream := make(chan logs.Message, 1)
20+
msgStream <- logs.Message{
21+
Name: r.Name,
22+
Namespace: r.Namespace,
23+
Text: "memory log line",
24+
}
25+
close(msgStream)
26+
return msgStream, nil
27+
}

handlers/namespace.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"net/http"
7+
)
8+
9+
// faas-memory does not use namespaces, so we return an empty list. see https://github.com/openfaas-incubator/connector-sdk/pull/46
10+
func NamespaceLister() http.HandlerFunc {
11+
return func(w http.ResponseWriter, r *http.Request) {
12+
w.Header().Set("Content-Type", "application/json")
13+
namespaces := []string{}
14+
nsJSON, err := json.Marshal(namespaces)
15+
16+
if err != nil {
17+
log.Printf("Unable to marshal namespaces into JSON %q", err)
18+
w.WriteHeader(http.StatusInternalServerError)
19+
w.Write([]byte("\"error\": \"unable to return namespaces\""))
20+
}
21+
22+
w.WriteHeader(http.StatusOK)
23+
w.Write(nsJSON)
24+
}
25+
}

handlers/reader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"encoding/json"
88
"net/http"
99

10-
"github.com/openfaas/faas/gateway/requests"
10+
typesv1 "github.com/openfaas/faas-provider/types"
1111
log "github.com/sirupsen/logrus"
1212
)
1313

@@ -32,17 +32,17 @@ func MakeFunctionReader() http.HandlerFunc {
3232
}
3333
}
3434

35-
func readServices() ([]*requests.Function, error) {
36-
var list []*requests.Function
35+
func readServices() ([]*typesv1.FunctionStatus, error) {
36+
var list []*typesv1.FunctionStatus
3737
for _, v := range functions {
3838
list = append(list, v)
3939
}
4040

4141
return list, nil
4242
}
4343

44-
func createToRequest(request requests.CreateFunctionRequest) *requests.Function {
45-
return &requests.Function{
44+
func requestToStatus(request typesv1.FunctionDeployment) *typesv1.FunctionStatus {
45+
return &typesv1.FunctionStatus{
4646
Name: request.Service,
4747
Annotations: request.Annotations,
4848
EnvProcess: request.EnvProcess,

0 commit comments

Comments
 (0)