Skip to content

Commit

Permalink
Added gateway for gitlab project hooks (argoproj#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavPage authored Nov 14, 2018
1 parent fda678d commit 7b4267c
Show file tree
Hide file tree
Showing 37 changed files with 998 additions and 115 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ storage-grid-image: storage-grid-linux
docker build -t $(IMAGE_PREFIX)storage-grid-gateway:$(IMAGE_TAG) -f ./gateways/custom/storagegrid/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)storage-grid-gateway:$(IMAGE_TAG) ; fi

gitlab:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/gitlab-gateway ./gateways/custom/gitlab/cmd

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

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


# gRPC gateway binary
grpc-gateway-images: gateway-processor-grpc-client-image calendar-grpc-image
Expand All @@ -230,7 +240,6 @@ calendar-grpc-image: calendar-grpc-linux
docker build -t $(IMAGE_PREFIX)calendar-grpc-gateway:$(IMAGE_TAG) -f ./gateways/grpc/calendar/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)calendar-grpc-gateway:$(IMAGE_TAG) ; fi


# HTTP gateway client binary
http-gateway-images: gateway-processor-http-client-image calendar-http-image

Expand Down
14 changes: 13 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ const (
// GatewayProcessorHTTPServerEventEndpoint is REST endpoint to send event to for gateway processor server
GatewayProcessorHTTPServerEventEndpoint = "/event"

// EnvVarGatewayProcessorHTTPServerConfigActivated is used to get the REST endpoint to send notifications for configuration that are successfully running
EnvVarGatewayProcessorHTTPServerConfigActivated = "GATEWAY_HTTP_CONFIG_RUNNING"

// GatewayProcessorHTTPServerConfigActivatedEndpoint is the REST endpoint on which gateway processor listens for activated notifications from configurations
GatewayProcessorHTTPServerConfigActivatedEndpoint = "/activated"

// EnvVarGatewayProcessorHTTPServerConfigError is used to get the REST endpoint on which gateway processor listens for errors from configurations
EnvVarGatewayProcessorHTTPServerConfigError = "GATEWAY_HTTP_CONFIG_ERROR"

// GatewayProcessorHTTPServerConfigErrorEndpoint is the REST endpoint on which gateway processor listens for errors from configurations
GatewayProcessorHTTPServerConfigErrorEndpoint = "/error"

// GatewayProcessorGRPCClientImage is gRPC gateway processor client image
GatewayProcessorGRPCClientImage = "argoproj/gateway-processor-grpc-client"

Expand Down Expand Up @@ -218,4 +230,4 @@ const (
// CloudEventsVersion is the version of the CloudEvents spec targeted+
// by this library.
CloudEventsVersion = "0.1"
)
)
17 changes: 12 additions & 5 deletions controllers/gateway/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,13 @@ func (goc *gwOperationCtx) operate() error {
ObjectMeta: metav1.ObjectMeta{
Labels: goc.gw.ObjectMeta.Labels,
},
Spec: corev1.PodSpec{
ServiceAccountName: goc.gw.Spec.DeploySpec.ServiceAccountName,
Containers: *goc.getContainersForGatewayPod(),
},
Spec: *goc.gw.Spec.DeploySpec,
},
},
}

gatewayDeployment.Spec.Template.Spec.Containers = *goc.getContainersForGatewayPod()

// we can now create the gateway deployment.
// depending on user configuration gateway will be exposed outside the cluster or intra-cluster.
_, err = goc.controller.kubeClientset.AppsV1().Deployments(goc.gw.Namespace).Create(gatewayDeployment)
Expand Down Expand Up @@ -421,6 +420,14 @@ func (goc *gwOperationCtx) getContainersForGatewayPod() *[]corev1.Container {
Name: common.EnvVarGatewayProcessorHTTPServerEventEndpoint,
Value: common.GatewayProcessorHTTPServerEventEndpoint,
},
{
Name: common.EnvVarGatewayProcessorHTTPServerConfigActivated,
Value: common.GatewayProcessorHTTPServerConfigActivatedEndpoint,
},
{
Name: common.EnvVarGatewayProcessorHTTPServerConfigError,
Value: common.GatewayProcessorHTTPServerConfigErrorEndpoint,
},
}

httpGatewayEnvVars := append(envVars, httpEnvVars...)
Expand Down Expand Up @@ -478,4 +485,4 @@ func (goc *gwOperationCtx) getContainersForGatewayPod() *[]corev1.Container {
containers = append(containers, gatewayTransformerContainer)

return &containers
}
}
14 changes: 6 additions & 8 deletions examples/gateways/amqp-gateway-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ metadata:
data:
amqp.fooConfig: |-
url: amqp://amqp.argo-events:5672
attributes:
exchangeName: fooExchangeName
exchangeType: fanout
routingKey: fooRoutingKey
exchangeName: fooExchangeName
exchangeType: fanout
routingKey: fooRoutingKey
amqp.barConfig: |-
url: amqp://amqp.argo-events:5672
attributes:
exchangeName: barExchangeName
exchangeType: fanout
routingKey: barRoutingKey
exchangeName: barExchangeName
exchangeType: fanout
routingKey: barRoutingKey
14 changes: 14 additions & 0 deletions examples/gateways/gitlab-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: gitlab-gateway-configmap
data:
gitlab.defaultConfig: |-
projectId: "1"
url: "YOUR_WEBHOOK_GATEWAY_EXTERNAL_URL"
event: "PushEvents"
accessToken:
key: accesskey
name: gitlab-access
enableSSLVerification: false
gitlabBaseUrl: "YOUR_GITLAB_URL"
22 changes: 22 additions & 0 deletions examples/gateways/gitlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Gateway
metadata:
name: gitlab-gateway
labels:
gateways.argoproj.io/gateway-controller-instanceid: argo-events
gateway-name: "gitlab-gateway"
spec:
deploySpec:
containers:
- name: "gitlab-events"
image: "argoproj/gitlab-gateway:test"
imagePullPolicy: "Always"
command: ["/bin/gitlab-gateway"]
serviceAccountName: "argo-events-sa"
configMap: "gitlab-gateway-configmap"
type: "gitlab"
dispatchMechanism: "HTTP"
version: "1.0"
watchers:
sensors:
- name: "gitlab-sensor"
34 changes: 34 additions & 0 deletions examples/sensors/gitlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: gitlab-sensor
labels:
sensors.argoproj.io/sensor-controller-instanceid: argo-events
spec:
repeat: true
serviceAccountName: argo-events-sa
signals:
- name: webhook-gateway/webhook.pushConfig
triggers:
- name: gitlab-workflow-trigger
resource:
namespace: argo-events
group: argoproj.io
version: v1alpha1
kind: Workflow
source:
inline: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
args:
- "hello world"
command:
- cowsay
image: "docker/whalesay:latest"
112 changes: 67 additions & 45 deletions gateways/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
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 gateways

import (
Expand Down Expand Up @@ -89,17 +105,21 @@ type GatewayEvent struct {
}

// HTTPGatewayServerConfig contains information regarding http ports, endpoints
type HTTPGatewayServerConfig struct {
type HttpGatewayServerConfig struct {
// HTTPServerPort is the port on which gateway processor server is running
HTTPServerPort string
HttpServerPort string
// HTTPClientPort is the port on which gateway processor client is running
HTTPClientPort string
// ConfigActivateEndpoint is REST endpoint listening for new configurations to run.
ConfigActivateEndpoint string
// ConfigurationDeactivateEndpoint is REST endpoint listening to deactivate active configuration
ConfigurationDeactivateEndpoint string
HttpClientPort string
// StartConfigEndpoint is REST endpoint listening for new configurations to run.
StartConfigEndpoint string
// StopConfigEndpoint is REST endpoint listening to stop active configuration
StopConfigEndpoint string
// EventEndpoint is REST endpoint on which gateway processor server sends events to gateway processor client
EventEndpoint string
// ConfigActivatedEndpoint is the REST endpoint on which gateway processor listens for activated notifications from configurations
ConfigActivatedEndpoint string
// ConfigErrorEndpoint is the REST endpoint on which gateway processor listens for errors from configurations
ConfigErrorEndpoint string
// GwConfig holds generic gateway configuration
GwConfig *GatewayConfig
// Data holds the actual configuration
Expand Down Expand Up @@ -163,44 +183,46 @@ func NewGatewayConfiguration() *GatewayConfig {
}
}

// NewHTTPGatewayServerConfig returns a new HTTPGatewayServerConfig
func NewHTTPGatewayServerConfig() *HTTPGatewayServerConfig {
httpGatewayServerConfig := &HTTPGatewayServerConfig{}
httpGatewayServerConfig.HTTPServerPort = func() string {
httpServerPort, ok := os.LookupEnv(common.EnvVarGatewayProcessorServerHTTPPort)
if !ok {
panic("gateway server http port is not provided")
}
return httpServerPort
}()
httpGatewayServerConfig.HTTPClientPort = func() string {
httpClientPort, ok := os.LookupEnv(common.EnvVarGatewayProcessorClientHTTPPort)
if !ok {
panic("gateway client http port is not provided")
}
return httpClientPort
}()
httpGatewayServerConfig.ConfigActivateEndpoint = func() string {
configActivateEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigStartEndpoint)
if !ok {
panic("gateway config activation endpoint is not provided")
}
return configActivateEndpoint
}()
httpGatewayServerConfig.ConfigurationDeactivateEndpoint = func() string {
configDeactivateEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigStopEndpoint)
if !ok {
panic("gateway config deactivation endpoint is not provided")
}
return configDeactivateEndpoint
}()
httpGatewayServerConfig.EventEndpoint = func() string {
eventEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerEventEndpoint)
if !ok {
panic("gateway event endpoint is not provided")
}
return eventEndpoint
}()
// NewHttpGatewayServerConfig returns a new HTTPGatewayServerConfig
func NewHttpGatewayServerConfig() *HttpGatewayServerConfig {
httpServerPort, ok := os.LookupEnv(common.EnvVarGatewayProcessorServerHTTPPort)
if !ok {
panic("server port is not provided")
}
clientPort, ok := os.LookupEnv(common.EnvVarGatewayProcessorClientHTTPPort)
if !ok {
panic("client port is not provided")
}
startConfigEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigStartEndpoint)
if !ok {
panic("start config endpoint is not provided")
}
stopConfigEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigStopEndpoint)
if !ok {
panic("stop config endpoint is not provided")
}
eventEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerEventEndpoint)
if !ok {
panic("event endpoint is not provided")
}
configActivatedEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigActivated)
if !ok {
panic("activated config endpoint is not provided")
}
configErrorEndpoint, ok := os.LookupEnv(common.EnvVarGatewayProcessorHTTPServerConfigError)
if !ok {
panic("config error endpoint is not provided")
}

httpGatewayServerConfig := &HttpGatewayServerConfig{
HttpServerPort: httpServerPort,
HttpClientPort: clientPort,
StartConfigEndpoint: startConfigEndpoint,
StopConfigEndpoint: stopConfigEndpoint,
EventEndpoint: eventEndpoint,
ConfigActivatedEndpoint: configActivatedEndpoint,
ConfigErrorEndpoint: configErrorEndpoint,
}
httpGatewayServerConfig.GwConfig = NewGatewayConfiguration()
return httpGatewayServerConfig
}
Expand Down
16 changes: 16 additions & 0 deletions gateways/config_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
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 gateways

import (
Expand Down
3 changes: 3 additions & 0 deletions gateways/custom/gitlab/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY dist/gitlab-gateway /bin/
ENTRYPOINT [ "/bin/gitlab-gateway" ]
29 changes: 29 additions & 0 deletions gateways/custom/gitlab/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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 (
"github.com/argoproj/argo-events/gateways"
"github.com/argoproj/argo-events/gateways/custom/gitlab"
)

func main() {
gc := gateways.NewGatewayConfiguration()
ce := &gitlab.GitlabExecutor{}
ce.GatewayConfig = gc
gc.StartGateway(ce)
}
Loading

0 comments on commit 7b4267c

Please sign in to comment.