Skip to content

Commit

Permalink
Allow controller to watch specified namespace only
Browse files Browse the repository at this point in the history
Add a command line option to the controller for specifying a single
namespace to watch, rather than watching all namespaces. Still
defaults to watching all namespaces, but this should be an improvement
for multitenant usage.
  • Loading branch information
abayer authored and tekton-robot committed Apr 24, 2019
1 parent 86b41f1 commit 11d1ca8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"time"

corev1 "k8s.io/api/core/v1"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -49,6 +50,7 @@ const (
var (
masterURL string
kubeconfig string
namespace string
)

func main() {
Expand Down Expand Up @@ -100,8 +102,8 @@ func main() {
Logger: logger,
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, opt.ResyncPeriod)
pipelineInformerFactory := pipelineinformers.NewSharedInformerFactory(pipelineClient, opt.ResyncPeriod)
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, opt.ResyncPeriod, kubeinformers.WithNamespace(namespace))
pipelineInformerFactory := pipelineinformers.NewSharedInformerFactoryWithOptions(pipelineClient, opt.ResyncPeriod, pipelineinformers.WithNamespace(namespace))

taskInformer := pipelineInformerFactory.Tekton().V1alpha1().Tasks()
clusterTaskInformer := pipelineInformerFactory.Tekton().V1alpha1().ClusterTasks()
Expand Down Expand Up @@ -182,4 +184,5 @@ func main() {
func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&namespace, "namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
}

0 comments on commit 11d1ca8

Please sign in to comment.