-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivaylo Korakov
committed
Apr 8, 2021
1 parent
2063e56
commit 307b201
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Goland | ||
.idea | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# The name of your plugin as displayed in the Traefik Pilot web UI. | ||
displayName: Traefik routing plugin | ||
|
||
# For now, `middleware` is the only type available. | ||
type: middleware | ||
|
||
# The import path of your plugin. | ||
import: github.com/kumina/traefik-routing-plugin | ||
|
||
# A brief description of what your plugin is doing. | ||
summary: Proof of concept! See if we can bait Traefik so that we decide from a custom configuration where each request should go! | ||
|
||
# Test data the plugin will use to test itself on startup | ||
testData: | ||
routes: | ||
http.test.com: asd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.PHONY: test vendor clean | ||
|
||
export GO111MODULE=on | ||
|
||
default: test | ||
|
||
test: | ||
go test -v -cover ./... | ||
|
||
yaegi_test: | ||
yaegi test -v . | ||
|
||
vendor: | ||
go mod vendor | ||
|
||
clean: | ||
rm -rf ./vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# traefik-routing-plugin | ||
Proof of concept. Is it possible to bait Traefik so that we can have a custom solution for figuring out which request needs to go to which k8s service? | ||
# Traefik Routing Plugin | ||
|
||
**Proof of concept.** | ||
|
||
Is it possible to bait Traefik so that we can have a custom solution for figuring out which request needs to go to which k8s service? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package traefik_routing_plugin | ||
|
||
// Config the plugin configuration. | ||
type Config struct { | ||
Routes map[string]string `json:"routes,omitempty"` | ||
} | ||
|
||
// CreateConfig creates the default plugin configuration. | ||
func CreateConfig() *Config { | ||
return &Config{ | ||
Routes: make(map[string]string), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/kumina/traefik-routing-plugin | ||
|
||
go 1.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package traefik_routing_plugin | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type Router struct { | ||
// Required by Traefik | ||
next http.Handler | ||
name string | ||
|
||
// Our custom configuration | ||
routes map[string]string | ||
} | ||
|
||
// Function needed for Traefik to recognize this module as a plugin | ||
// Uses a generic http.Handler type from golang that we can use to work with the request | ||
// by overriding different functions of the interface | ||
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { | ||
if len(config.Routes) == 0 { | ||
return nil, fmt.Errorf("routes cannot be empty") | ||
} | ||
|
||
return &Router{ | ||
routes: config.Routes, | ||
next: next, | ||
name: name, | ||
}, nil | ||
} | ||
|
||
func (a *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) { | ||
for key, value := range a.routes { | ||
req.Header.Set(key, value) | ||
} | ||
|
||
a.next.ServeHTTP(rw, req) | ||
} |