Skip to content

Commit

Permalink
Add --namespace flag to support forwarding a single service (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
databus23 authored Dec 9, 2020
1 parent 818dff6 commit ad8c798
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cmd/localizer/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func main() { //nolint:funlen,gocyclo
Usage: "Set the IP address CIDR, must include the /",
Value: "127.0.0.1/8",
},
&cli.StringFlag{
Name: "namespace",
Usage: "Restrict forwarding to the given namespace. (default: all namespaces)",
},
},
Commands: []*cli.Command{
NewListCommand(log),
Expand Down Expand Up @@ -129,7 +133,7 @@ func main() { //nolint:funlen,gocyclo
return err
}
log.Infof("using apiserver %s", config.Host)
kevents.ConfigureGlobalCache(k)
kevents.ConfigureGlobalCache(k, c.String("namespace"))

return nil
},
Expand Down
11 changes: 6 additions & 5 deletions internal/kevents/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type EventHandler func(Event)
type Cache struct {
k kubernetes.Interface

stores map[string]cache.Store
subs map[string][]EventHandler
stores map[string]cache.Store
subs map[string][]EventHandler
namespace string
}

type Event struct {
Expand All @@ -44,8 +45,8 @@ var (
)

// ConfigureGlobalCache sets up package wide global cache
func ConfigureGlobalCache(k kubernetes.Interface) {
GlobalCache = &Cache{k, make(map[string]cache.Store), make(map[string][]EventHandler)}
func ConfigureGlobalCache(k kubernetes.Interface, namespace string) {
GlobalCache = &Cache{k, make(map[string]cache.Store), make(map[string][]EventHandler), namespace}
}

func WaitForSync(ctx context.Context, cont cache.Controller) error {
Expand Down Expand Up @@ -84,7 +85,7 @@ func (c *Cache) TrackObject(resourceName string, obj runtime.Object) cache.Contr
key := c.getObjectType(obj)

objStore, objInformer := cache.NewInformer(
cache.NewListWatchFromClient(c.k.CoreV1().RESTClient(), resourceName, corev1.NamespaceAll, fields.Everything()),
cache.NewListWatchFromClient(c.k.CoreV1().RESTClient(), resourceName, c.namespace, fields.Everything()),
&corev1.Endpoints{},
time.Second*60,
cache.ResourceEventHandlerFuncs{
Expand Down

0 comments on commit ad8c798

Please sign in to comment.