Skip to content

Commit

Permalink
cleanup output and verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Nov 22, 2019
1 parent 36096e5 commit 3ba0564
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 17 additions & 19 deletions cmd/kubefwd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ var Cmd = &cobra.Command{

func runCmd(cmd *cobra.Command, args []string) {

if verbose {
log.SetLevel(log.DebugLevel)
}

hasRoot, err := utils.CheckRoot()

if !hasRoot {
fmt.Printf(`
log.Errorf(`
This program requires superuser privileges to run. These
privileges are required to add IP address aliases to your
loopback interface. Superuser privileges are also needed
Expand Down Expand Up @@ -284,9 +288,7 @@ func (opts *FwdServiceOpts) AddServiceHandler(obj interface{}) {
return
}

if verbose {
fmt.Printf("Add service %s namespace %s !\r\n", svcName, svcNamespace)
}
log.Debugf("Add service %s namespace %s.", svcName, svcNamespace)

opts.ForwardService(svcName, svcNamespace)
}
Expand All @@ -301,17 +303,15 @@ func (opts *FwdServiceOpts) DeleteServiceHandler(obj interface{}) {
return
}

if verbose {
fmt.Printf("Delete service %s namespace %s !\r\n", svcName, svcNamespace)
}
log.Debugf("Delete service %s namespace %s.", svcName, svcNamespace)

opts.UnForwardService(svcName, svcNamespace)
}

func (opts *FwdServiceOpts) UpdateServiceHandler(old interface{}, new interface{}) {
key, err := cache.MetaNamespaceKeyFunc(new)
if err == nil {
fmt.Printf("update service %s !\r\n", key)
log.Printf("update service %s.", key)
}
}

Expand Down Expand Up @@ -412,23 +412,21 @@ func (opts *FwdServiceOpts) LoopPodToForward(pods []v1.Pod, podName bool, svc *v
}

if opts.Domain != "" {
if verbose {
log.Printf("Using domain %s in generated hostnames", opts.Domain)
}

log.Debugf("Using domain %s in generated hostnames", opts.Domain)

serviceHostName = serviceHostName + "." + opts.Domain
}

if opts.Remote {
serviceHostName = fmt.Sprintf("%s.svc.cluster.%s", serviceHostName, opts.Context)
}

if verbose {
log.Printf("Resolving: %s%s to %s\n",
svc.Name,
serviceHostName,
localIp.String(),
)
}
log.Debugf("Resolving: %s%s to %s\n",
svc.Name,
serviceHostName,
localIp.String(),
)

log.Printf("Forwarding: %s:%d to pod %s:%s\n",
serviceHostName,
Expand Down Expand Up @@ -466,7 +464,7 @@ func (opts *FwdServiceOpts) LoopPodToForward(pods []v1.Pod, podName bool, svc *v
log.Printf("ERROR: %s", err.Error())
}

log.Printf("Stopped forwarding %s in %s.", pfo.Service, pfo.Namespace)
log.Warnf("Stopped forwarding %s in %s.", pfo.Service, pfo.Namespace)

opts.Wg.Done()
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/fwdport/fwdport.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (pfo *PortForwardOpts) ListenUntilPodDeleted(signalsChan chan struct{}, pod
}
switch event.Type {
case watch.Deleted:
fmt.Printf("%s Pod deleted, restart the %s service portforward.", pod.ObjectMeta.Name, pfo.NativeServiceName)
log.Warnf("%s Pod deleted, restart the %s service portforward.", pod.ObjectMeta.Name, pfo.NativeServiceName)
pfo.ServiceOperator.UnForwardService(pfo.NativeServiceName, pfo.Namespace)
pfo.ServiceOperator.ForwardService(pfo.NativeServiceName, pfo.Namespace)
return
Expand Down

0 comments on commit 3ba0564

Please sign in to comment.