From 414fb1f406951f17226fda57172c574cd55dc4e1 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 18 May 2016 15:45:48 +0200 Subject: [PATCH] add kubernetes.Namespaces parser --- provider/kubernetes.go | 24 ++++++++++++++++++++++++ traefik.go | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/provider/kubernetes.go b/provider/kubernetes.go index bdaf245ce..3dd3e9e4e 100644 --- a/provider/kubernetes.go +++ b/provider/kubernetes.go @@ -1,6 +1,7 @@ package provider import ( + "fmt" log "github.com/Sirupsen/logrus" "github.com/cenkalti/backoff" "github.com/containous/traefik/provider/k8s" @@ -23,6 +24,29 @@ const ( // Namespaces holds kubernetes namespaces type Namespaces []string +//Set adds strings elem into the the parser +//it splits str on , and ; +func (ns *Namespaces) Set(str string) error { + fargs := func(c rune) bool { + return c == ',' || c == ';' + } + // get function + slice := strings.FieldsFunc(str, fargs) + *ns = append(*ns, slice...) + return nil +} + +//Get []string +func (ns *Namespaces) Get() interface{} { return Namespaces(*ns) } + +//String return slice in a string +func (ns *Namespaces) String() string { return fmt.Sprintf("%v", *ns) } + +//SetValue sets []string into the parser +func (ns *Namespaces) SetValue(val interface{}) { + *ns = Namespaces(val.(Namespaces)) +} + // Kubernetes holds configurations of the Kubernetes provider. type Kubernetes struct { BaseProvider `mapstructure:",squash"` diff --git a/traefik.go b/traefik.go index a1c060914..b0e2cb745 100644 --- a/traefik.go +++ b/traefik.go @@ -6,6 +6,7 @@ import ( "github.com/containous/flaeg" "github.com/containous/staert" "github.com/containous/traefik/middlewares" + "github.com/containous/traefik/provider" fmtlog "log" "net/http" "os" @@ -53,7 +54,7 @@ Complete documentation is available at https://traefik.io`, //add custom parsers f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{}) f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{}) - //Wait for DefaultSliceStringParser + f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{}) //add version command f.AddCommand(versionCmd)