Skip to content

Commit

Permalink
Merge pull request #14 from rusenask/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rusenask authored Jul 1, 2017
2 parents d1a9752 + f7bb1f9 commit 2bb80bc
Show file tree
Hide file tree
Showing 2,371 changed files with 222,381 additions and 733,972 deletions.
213 changes: 34 additions & 179 deletions glide.lock

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

14 changes: 7 additions & 7 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import:
subpackages:
- iterator
- option
- support
- support
- transport
- package: google.golang.org/grpc
version: a94a7ac054dc76e5ab6cf170a9d82faba8aaf33f
subpackages:
- status
- package: github.com/Sirupsen/logrus
subpackages:
- formatters
- formatters/logstash
- status
- package: github.com/coreos/go-semver
subpackages:
- semver
Expand All @@ -37,7 +33,7 @@ import:
- protoc-gen-gogo/descriptor
- gogoproto
- plugin/testgen
- protoc-gen-gogo/generator
- protoc-gen-gogo/generator
- package: k8s.io/apimachinery
version: 75b8dd260ef0469d96d578705a87cffd0e09dab8
subpackages:
Expand All @@ -50,3 +46,7 @@ import:
- pkg/apis/extensions/v1beta1
- rest
- tools/clientcmd
- package: github.com/Masterminds/semver
version: ^1.3.0
- package: github.com/sirupsen/logrus
version: ^1.0.0
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {

// setupProviders - setting up available providers. New providers should be initialised here and added to
// provider map
func setupProviders(k8sImplementer kubernetes.Implementer) (providers map[string]provider.Provider, teardown func()) {
func setupProviders(k8sImplementer kubernetes.Implementer) (providers provider.Providers, teardown func()) {
k8sProvider, err := kubernetes.NewProvider(k8sImplementer)
if err != nil {
log.WithFields(log.Fields{
Expand All @@ -110,8 +110,7 @@ func setupProviders(k8sImplementer kubernetes.Implementer) (providers map[string
}
go k8sProvider.Start()

providers = make(map[string]provider.Provider)
providers[k8sProvider.GetName()] = k8sProvider
providers = provider.New([]provider.Provider{k8sProvider})

teardown = func() {
k8sProvider.Stop()
Expand All @@ -122,7 +121,7 @@ func setupProviders(k8sImplementer kubernetes.Implementer) (providers map[string

// setupTriggers - setting up triggers. New triggers should be added to this function. Each trigger
// should go through all providers (or not if there is a reason) and submit events)
func setupTriggers(ctx context.Context, k8sImplementer kubernetes.Implementer, providers map[string]provider.Provider) (teardown func()) {
func setupTriggers(ctx context.Context, k8sImplementer kubernetes.Implementer, providers provider.Providers) (teardown func()) {

// setting up generic http webhook server
whs := http.NewTriggerServer(&http.Opts{
Expand Down
49 changes: 49 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,59 @@ package provider

import (
"github.com/rusenask/keel/types"

log "github.com/Sirupsen/logrus"
)

// Provider - generic provider interface
type Provider interface {
Submit(event types.Event) error
GetName() string
}

// Providers - available providers
type Providers interface {
Submit(event types.Event) error
List() []string // list all providers
}

// New - new providers registry
func New(providers []Provider) *DefaultProviders {
pvs := make(map[string]Provider)

for _, p := range providers {
pvs[p.GetName()] = p
}

return &DefaultProviders{
providers: pvs,
}
}

type DefaultProviders struct {
providers map[string]Provider
}

func (p *DefaultProviders) Submit(event types.Event) error {
for _, provider := range p.providers {
err := provider.Submit(event)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"provider": provider.GetName(),
"event": event.Repository,
"trigger": event.TriggerName,
}).Error("provider.DefaultProviders: submit event failed")
}
}

return nil
}

func (p *DefaultProviders) List() []string {
list := []string{}
for name := range p.providers {
list = append(list, name)
}
return list
}
4 changes: 1 addition & 3 deletions trigger/http/dockerhub_webhook_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ var fakeRequest = `{
func TestDockerhubWebhookHandler(t *testing.T) {

fp := &fakeProvider{}
providers := map[string]provider.Provider{
fp.GetName(): fp,
}
providers := provider.New([]provider.Provider{fp})
srv := NewTriggerServer(&Opts{Providers: providers})
srv.registerRoutes(srv.router)

Expand Down
Loading

0 comments on commit 2bb80bc

Please sign in to comment.