add kubernetes.Namespaces parser

This commit is contained in:
Martin 2016-05-18 15:45:48 +02:00
parent fe0a8f3363
commit 414fb1f406
2 changed files with 26 additions and 1 deletions

View file

@ -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"`

View file

@ -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)