Skip to content

Connector example#3

Open
zeerorg wants to merge 5 commits into
openfaas:masterfrom
zeerorg:connector-example
Open

Connector example#3
zeerorg wants to merge 5 commits into
openfaas:masterfrom
zeerorg:connector-example

Conversation

@zeerorg

@zeerorg zeerorg commented Jan 15, 2019

Copy link
Copy Markdown

This PR updates the connector example with swarm and kubernetes deployment files.

How it is tested:

  1. Clone this Pull request locally.
  2. Go into the directory: cd ./connector-sdk/cmd/tester/yaml
  3. For openfaas deployed on docker swarm do: docker stack deploy func -c ./docker-compose.yml
  4. For openfaas deployed on kubernetes do: kubectl create -f ./kubernetes --namespace openfaas

Run this command to deploy a sample function and see trigger-func invocation count growing in ui.

faas-cli deploy --image=functions/nodeinfo --name=trigger-func --annotation topic=faas-request

Signed-off-by: Rishabh Gupta r.g.gupta@outlook.com

Comment thread cmd/tester/main.go Outdated
}
}

func getControllerConfig() *types.ControllerConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If running in a the default is gateway.openfaas:8080 / gateway:8080 on Swarm. We should just not default at all if not passed and return an error (types.ControllerConfig, error)

Comment thread cmd/tester/main.go Outdated
if !ok {
gURL = "http://127.0.0.1:8080/"
}
fmt.Println("Gateway Url: ", gURL)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not print this here.

Comment thread cmd/tester/main.go

// Simulate events emitting from queue/pub-sub
for {
time.Sleep(2 * time.Second)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this configurable to please.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add an env-var to make this configurable ? Or a simple variable is enough ?

Comment thread cmd/tester/main.go Outdated
config := getControllerConfig()

controller := types.NewController(creds, config)
fmt.Println(controller)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

Comment thread cmd/tester/main.go Outdated
config := getControllerConfig()

controller := types.NewController(creds, config)
fmt.Println(controller)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace fmt with log for use in the container.

Comment thread cmd/tester/Dockerfile Outdated
@@ -0,0 +1,16 @@
FROM golang:1.9.2 as builder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy the example from the vcenter connector please it has an updated Golang version.

Comment thread cmd/tester/Dockerfile Outdated
# Stripping via -ldflags "-s -w"
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o ./connector

FROM alpine

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy the example from the vcenter connector please it has an updated alpine version, we must always pin to 3.8 or whatever version we are targeting.

Comment thread cmd/tester/Dockerfile Outdated
@@ -0,0 +1,16 @@
FROM golang:1.9.2 as builder
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector
WORKDIR /go/src/github.com/openfaas-incubator/connector

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path I guess is connector-sdk right? To match the repo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it's:

/go/src/github.com/openfaas-incubator/connector-sdk/cmd/tester/ correct?

Comment thread cmd/tester/Dockerfile Outdated

COPY main.go .

RUN go get -d -v ./...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove go get

It should use vendoring via dep or the correct path.

Comment thread cmd/tester/README.md Outdated

1. Clone this repository: `git clone https://github.com/openfaas-incubator/connector-sdk.git`
2. Go into the directory: `cd ./connector-sdk/cmd/tester/yaml`
3. For openfaas deployed on docker swarm do: `docker stack deploy func -c ./docker-compose.yml`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openfaas -> OpenFaaS

Comment thread cmd/tester/README.md Outdated

1. Clone this repository: `git clone https://github.com/openfaas-incubator/connector-sdk.git`
2. Go into the directory: `cd ./connector-sdk/cmd/tester/yaml`
3. For openfaas deployed on docker swarm do: `docker stack deploy func -c ./docker-compose.yml`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker swarm -> Docker Swarm

@alexellis alexellis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, thanks for working on this PR. I had some mixed feelings on creating and maintaining a separate set of Dockerfiles and Kubernetes YAML files, but since you've done it I'd like to give you some feedback so that we can merge it.

The items are very minor and once done can be merged. Just ping me again when you've worked through the suggestions.

@zeerorg

zeerorg commented Jan 15, 2019

Copy link
Copy Markdown
Author

I've worked through all the suggestions. This should be good to go.

Some major changes:

  1. I removed fetching topics from environment variable (made the example hard to follow). now a single topic is defined.
  2. Also removed print_response environment variable was not doing anything

Comment thread cmd/tester/main.go Outdated
}

func getControllerConfig() (*types.ControllerConfig, error) {
gURL, ok := os.LookupEnv("gateway_url")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to gatewayURL

containers:
- name: sample-connector
image: zeerorg/connector-sample:1.0
env:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add topics as an env-var, this is how connectors are intended to work.

@alexellis

Copy link
Copy Markdown
Member

The scope of this PR was simply to provide a Dockerfile and Kubernetes YAML, not to change the example behaviour or functionality. Please can you revert the below?

Some major changes:
I removed fetching topics from environment variable (made the example hard to follow). now a single topic is defined.
Also removed print_response environment variable was not doing anything

I think the extracting the configuration loading is fine to keep in the changes, but in a separate PR.

Alex

Signed-off-by: Rishabh Gupta <r.g.gupta@outlook.com>
Signed-off-by: Rishabh Gupta<r.g.gupta@outlook.com>
Signed-off-by: Rishabh Gupta<r.g.gupta@outlook.com>
Signed-off-by: Rishabh Gupta<r.g.gupta@outlook.com>
Signed-off-by: Rishabh Gupta<r.g.gupta@outlook.com>
@zeerorg

zeerorg commented Jan 28, 2019

Copy link
Copy Markdown
Author

The previous example had fixed gateway url, I changed it to rely on environment variable and same is done for topic which rely on environment variable.

This pretty much resembles a very trimmed down version of kafka connector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants