service_duplicator

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Reverse proxy based on a header's value

(This code is based on the code (and takes inspiration) from: https://github.com/acouvreur/sablier) This middleware can be used to manage the automatic deployment and scaling of services in Kubernetes, for the purpose of setting up a personal environment for the logged in user.

Compared to the original application (Sablier), this is a much more specialized, focused plugin for a very specific task.

It main purpose: based on a header field, check to see if there exists a specific service. If not, copy-n-modify a generic example service to provide the requested service.

Configuration

Static:

Production:

[pilot]
  token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

[experimental]
  [experimental.plugins]
    [experimental.plugins.my-plugin-name]
      moduleName = "github.com/dobots/service-duplicator
      version = "v0.0.2"

or if you're using devMode:

[pilot]
  token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  
[experimental.devPlugin]
  goPath = "/plugins/go"
  moduleName = "github.com/dobots/service-duplicator"
  # Plugin will be loaded from '/plugins/go/src/github.com/dobots/service-duplicator'
Dynamic:

Production:

[http]
  [http.middlewares]
    [http.middlewares.my-middleware-name.plugin.my-plugin-name]
      header  = "X-Forwarded-User"
      namespace = "myk8snamespace"

  [http.routers]
    [http.routers.my-router-name]
      entryPoints = ["websecure"]
      rule = "Host(`my-service-name.domain.tld`)"
      middlewares = ["traefik-forward-auth@docker", "my-middleware-name@file"]
      
      # if no matches are found this is the service that we forward the request to
      service = "noop@internal"
      
      [http.routers.my-router-name.tls]
        certResolver = "letsencrypt"

or if you're using devMode:

[http]
  [http.middlewares]
    [http.middlewares.my-middleware-name.plugin.dev]
      header  = "X-Forwarded-User"
      namespace = "myk8snamespace"

  [http.routers]
    [http.routers.my-router-name]
      entryPoints = ["websecure"]
      rule = "Host(`my-service-name.domain.tld`)"
      middlewares = ["traefik-forward-auth@docker", "my-middleware-name@file"]
      
      # if no matches are found this is the service that we forward the request to
      service = "noop@internal"
      
      [http.routers.my-router-name.tls]
        certResolver = "letsencrypt"

License

This software is released under the Apache 2.0 License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new ServiceDup plugin.

Types

type Config

type Config struct {
	Header    string `json:"header,omitempty" yaml:"Header" mapstructure:"Header" default:"X-Forwarded-User"`
	Namespace string `json:"namespace,omitempty" yaml:"Namespace" mapstructure:"Namespace" default:"default"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type KubernetesProvider

type KubernetesProvider struct {
	Client kubernetes.Interface
}

type ServiceDup

type ServiceDup struct {
	// contains filtered or unexported fields
}

func (*ServiceDup) ServeHTTP

func (a *ServiceDup) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL