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

Trello gateway #193

Merged
merged 4 commits into from
Mar 3, 2019
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
3 changes: 3 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
| cloud.google.com/go | Apache-2.0 |
| colinmarc/hdfs | MIT |
| jcmturner/gokrb5 | Apache-2.0 |
| adlio/trello | MIT |
| aws/aws-sdk-go | Apache-2.0 |

13 changes: 11 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ required = [
"gopkg.in/src-d/go-git.v4"
]

[[constraint]]
name = "github.com/adlio/trello"
branch = "master"

[[constraint]]
name = "k8s.io/code-generator"
branch = "release-1.10"
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ sqs-image: sqs-linux
docker build -t $(IMAGE_PREFIX)aws-sqs-gateway:$(IMAGE_TAG) -f ./gateways/community/aws-sqs/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)aws-sqs-gateway:$(IMAGE_TAG) ; fi

trello:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/trello-gateway ./gateways/community/trello/cmd

trello-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make trello

trello-image: trello-linux
docker build -t $(IMAGE_PREFIX)trello-gateway:$(IMAGE_TAG) -f ./gateways/community/trello/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)trello-gateway:$(IMAGE_TAG) ; fi

test:
go test $(shell go list ./... | grep -v /vendor/) -race -short -v

Expand Down
16 changes: 16 additions & 0 deletions examples/gateways/trello-gateway-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: trello-gateway-configmap
data:
notification_1: |-
endpoint: "/"
port: "9600"
apiKey:
name: trello-secret
key: apikey
token:
name trello-secret
key: tokenkey
url: "URL_TO_REGISTER"
description: "test webhook"
35 changes: 35 additions & 0 deletions examples/gateways/trello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: Gateway
metadata:
name: trello-gateway
labels:
gateways.argoproj.io/gateway-controller-instanceid: argo-events
gateway-name: "trello-gateway"
spec:
processorPort: "9330"
eventProtocol:
type: "HTTP"
http:
port: "9300"
deploySpec:
metadata:
name: "trello-gateway"
labels:
gateway-name: "trello-gateway"
spec:
containers:
- name: "gateway-client"
image: "argoproj/gateway-client"
imagePullPolicy: "Always"
command: ["/bin/gateway-client"]
- name: "trello-events"
image: "argoproj/trello-gateway"
imagePullPolicy: "Always"
command: ["/bin/trello-gateway"]
serviceAccountName: "argo-events-sa"
configMap: "trello-gateway-configmap"
type: "trello"
eventVersion: "1.0"
watchers:
sensors:
- name: "trello-sensor"
52 changes: 52 additions & 0 deletions examples/sensors/trello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: trello-sensor
labels:
sensors.argoproj.io/sensor-controller-instanceid: argo-events
spec:
deploySpec:
containers:
- name: "sensor"
image: "argoproj/sensor"
imagePullPolicy: Always
serviceAccountName: argo-events-sa
eventProtocol:
type: "HTTP"
http:
port: "9300"
dependencies:
- name: "trello-gateway:notification_1"
triggers:
- name: trello-workflow
resource:
namespace: argo-events
group: argoproj.io
version: v1alpha1
kind: Workflow
parameters:
- src:
event: "trello-gateway:notification_1"
dest: spec.arguments.parameters.0.value
source:
inline: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: trello-
spec:
entrypoint: whalesay
arguments:
parameters:
- name: message
# this is the value that should be overridden
value: hello world
templates:
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
3 changes: 3 additions & 0 deletions gateways/community/trello/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY dist/trello-gateway /bin/
ENTRYPOINT [ "/bin/trello-gateway" ]
44 changes: 44 additions & 0 deletions gateways/community/trello/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2018 BlackRock, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"os"

"github.com/argoproj/argo-events/common"
"github.com/argoproj/argo-events/gateways"
"github.com/argoproj/argo-events/gateways/community/trello"
"k8s.io/client-go/kubernetes"
)

func main() {
kubeConfig, _ := os.LookupEnv(common.EnvVarKubeConfig)
restConfig, err := common.GetClientConfig(kubeConfig)
if err != nil {
panic(err)
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
namespace, ok := os.LookupEnv(common.EnvVarGatewayNamespace)
if !ok {
panic("namespace is not provided")
}
gateways.StartGateway(&trello.TrelloEventSourceExecutor{
Log: common.GetLoggerContext(common.LoggerConf()).Logger(),
Clientset: clientset,
Namespace: namespace,
})
}
57 changes: 57 additions & 0 deletions gateways/community/trello/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2018 BlackRock, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package trello

import (
"github.com/ghodss/yaml"
"github.com/rs/zerolog"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)

type TrelloEventSourceExecutor struct {
Log zerolog.Logger
// Clientset is kubernetes client
Clientset kubernetes.Interface
// Namespace where gateway is deployed
Namespace string
}

type trello struct {
// ApiKey for client
ApiKey *corev1.SecretKeySelector `json:"apiKey"`
// Token for client
Token *corev1.SecretKeySelector `json:"token"`
// Endpoint is REST API endpoint
Endpoint string `json:"endpoint"`
// Port to run the http server on
Port string `json:"port"`
// URL to register at trello
URL string `json:"url"`
// Description for webhook
// +optional
Description string `json:"description,omitempty"`
}

func parseEventSource(es string) (interface{}, error) {
var n *trello
err := yaml.Unmarshal([]byte(es), &n)
if err != nil {
return nil, err
}
return n, nil
}
Loading