add kubernetes.Namespaces parser
This commit is contained in:
parent
fe0a8f3363
commit
414fb1f406
2 changed files with 26 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/cenkalti/backoff"
|
"github.com/cenkalti/backoff"
|
||||||
"github.com/containous/traefik/provider/k8s"
|
"github.com/containous/traefik/provider/k8s"
|
||||||
|
@ -23,6 +24,29 @@ const (
|
||||||
// Namespaces holds kubernetes namespaces
|
// Namespaces holds kubernetes namespaces
|
||||||
type Namespaces []string
|
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.
|
// Kubernetes holds configurations of the Kubernetes provider.
|
||||||
type Kubernetes struct {
|
type Kubernetes struct {
|
||||||
BaseProvider `mapstructure:",squash"`
|
BaseProvider `mapstructure:",squash"`
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/containous/flaeg"
|
"github.com/containous/flaeg"
|
||||||
"github.com/containous/staert"
|
"github.com/containous/staert"
|
||||||
"github.com/containous/traefik/middlewares"
|
"github.com/containous/traefik/middlewares"
|
||||||
|
"github.com/containous/traefik/provider"
|
||||||
fmtlog "log"
|
fmtlog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -53,7 +54,7 @@ Complete documentation is available at https://traefik.io`,
|
||||||
//add custom parsers
|
//add custom parsers
|
||||||
f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{})
|
f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{})
|
||||||
f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{})
|
f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{})
|
||||||
//Wait for DefaultSliceStringParser
|
f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{})
|
||||||
//add version command
|
//add version command
|
||||||
f.AddCommand(versionCmd)
|
f.AddCommand(versionCmd)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue