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

Connector example #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

zeerorg
Copy link

@zeerorg zeerorg commented Jan 15, 2019

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 [email protected]

}
}

func getControllerConfig() *types.ControllerConfig {
Copy link
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)

}
fmt.Println("Gateway Url: ", gURL)
Copy link
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.


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

topics := getTopics()

// Simulate events emitting from queue/pub-sub
for {
time.Sleep(2 * time.Second)
Copy link
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
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 ?

PrintResponse: true,
}
creds := types.GetCredentials() // Get credentials for gateway login
config := getControllerConfig()

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

Choose a reason for hiding this comment

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

Remove this line.

PrintResponse: true,
}
creds := types.GetCredentials() // Get credentials for gateway login
config := getControllerConfig()

controller := types.NewController(creds, config)
fmt.Println(controller)
Copy link
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.

@@ -0,0 +1,16 @@
FROM golang:1.9.2 as builder
Copy link
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.

# 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
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.

@@ -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
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
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?


COPY main.go .

RUN go get -d -v ./...
Copy link
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.


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
Member

Choose a reason for hiding this comment

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

openfaas -> OpenFaaS


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
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

Copy link
Member

@alexellis alexellis left a comment

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
Copy link
Author

zeerorg commented Jan 15, 2019

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

}

func getControllerConfig() (*types.ControllerConfig, error) {
gURL, ok := os.LookupEnv("gateway_url")
Copy link
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
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
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

@zeerorg
Copy link
Author

zeerorg commented Jan 28, 2019

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