@@ -66,8 +66,8 @@ func (i *arrayFlags) Set(value string) error {
6666}
6767
6868var (
69- namespace = flag . String ( "namespace" , os . Getenv ( "NAMESPACE" ), "kubernetes namespace" )
70- timeout = flag . Duration ( "timeout" , time .Second * 30 , "execution timeout" )
69+ namespace string
70+ timeout time.Duration
7171 pfconfig = portForwardConf {services : make (map [string ][]uint16 )}
7272 kubeconfig string
7373 waitForApps arrayFlags
7676)
7777
7878func init () {
79+ flag .StringVar (& namespace , "namespace" , os .Getenv ("NAMESPACE" ), "kubernetes namespace" )
80+ flag .DurationVar (& timeout , "timeout" , time .Second * 30 , "execution timeout" )
7981 flag .Var (& pfconfig , "portforward" , "set a port forward item in form of servicename:port" )
8082 flag .StringVar (& kubeconfig , "kubeconfig" , os .Getenv ("KUBECONFIG" ), "path to kubernetes config file" )
8183 flag .Var (& waitForApps , "waitforapp" , "wait for pods with label app=<this parameter>" )
@@ -130,7 +132,7 @@ func listReadyApps(list []interface{}) (readypods, notReady []string) {
130132// listenForEvents listens for events and prints them to stdout. if event reason is "Failed" it will call the failure callback
131133func listenForEvents (ctx context.Context , clientset * kubernetes.Clientset , onFailure func (* v1.Event )) {
132134
133- kubeInformerFactory := informers .NewFilteredSharedInformerFactory (clientset , time . Second * 30 , * namespace , nil )
135+ kubeInformerFactory := informers .NewSharedInformerFactoryWithOptions (clientset , 0 , informers . WithNamespace ( namespace ) )
134136 eventsInformer := kubeInformerFactory .Core ().V1 ().Events ().Informer ()
135137
136138 fn := func (obj interface {}) {
@@ -146,8 +148,7 @@ func listenForEvents(ctx context.Context, clientset *kubernetes.Clientset, onFai
146148 }
147149
148150 handler := & cache.ResourceEventHandlerFuncs {
149- AddFunc : fn ,
150- DeleteFunc : fn ,
151+ AddFunc : fn ,
151152 UpdateFunc : func (old interface {}, new interface {}) {
152153 fn (new )
153154 },
@@ -172,7 +173,7 @@ func waitForPods(ctx context.Context, clientset *kubernetes.Clientset) error {
172173 },
173174 }
174175
175- kubeInformerFactory := informers .NewFilteredSharedInformerFactory (clientset , time .Second * 30 , * namespace , nil )
176+ kubeInformerFactory := informers .NewFilteredSharedInformerFactory (clientset , time .Second * 30 , namespace , nil )
176177 podsInformer := kubeInformerFactory .Core ().V1 ().Pods ().Informer ()
177178 podsInformer .AddEventHandler (handler )
178179 go kubeInformerFactory .Start (ctx .Done ())
@@ -233,7 +234,7 @@ func waitForEndpoints(ctx context.Context, clientset *kubernetes.Clientset, conf
233234 },
234235 }
235236
236- kubeInformerFactory := informers .NewFilteredSharedInformerFactory (clientset , time .Second * 30 , * namespace , nil )
237+ kubeInformerFactory := informers .NewFilteredSharedInformerFactory (clientset , time .Second * 30 , namespace , nil )
237238 endpointsInformer := kubeInformerFactory .Core ().V1 ().Endpoints ().Informer ()
238239 endpointsInformer .AddEventHandler (handler )
239240 go kubeInformerFactory .Start (ctx .Done ())
@@ -276,7 +277,7 @@ func portForward(ctx context.Context, clientset *kubernetes.Clientset, config *r
276277 var wg sync.WaitGroup
277278 wg .Add (len (ports ))
278279 for _ , port := range ports {
279- ep , err := clientset .CoreV1 ().Endpoints (* namespace ).Get (ctx , serviceName , meta_v1.GetOptions {})
280+ ep , err := clientset .CoreV1 ().Endpoints (namespace ).Get (ctx , serviceName , meta_v1.GetOptions {})
280281 if err != nil {
281282 return fmt .Errorf ("error listing endpoints for service %s: %v" , serviceName , err )
282283 }
@@ -335,7 +336,7 @@ var ErrTermSignalReceived = errors.New("TERM signal received")
335336func main () {
336337 flag .Parse ()
337338 log .SetOutput (os .Stdout )
338- ctx , timeoutCancel := context .WithTimeoutCause (context .Background (), * timeout , ErrTimedOut )
339+ ctx , timeoutCancel := context .WithTimeoutCause (context .Background (), timeout , ErrTimedOut )
339340 defer timeoutCancel ()
340341 ctx , cancel := context .WithCancelCause (ctx )
341342 c := make (chan os.Signal , 1 )
@@ -372,7 +373,7 @@ func main() {
372373 clientset = kubernetes .NewForConfigOrDie (config )
373374
374375 go func () {
375- err := stern .Run (ctx , * namespace , clientset , allowErrors , disablePodLogs )
376+ err := stern .Run (ctx , namespace , clientset , allowErrors , disablePodLogs )
376377 if err != nil {
377378 log .Print (err )
378379 }
0 commit comments