Skip to content

Commit

Permalink
logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Nov 7, 2021
1 parent 6fddaae commit 5b20cd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 2 additions & 5 deletions cmd/varnish-cache-invalidator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"io/ioutil"
"log"
"os"
"strings"
"varnish-cache-invalidator/internal/k8s"
Expand Down Expand Up @@ -32,19 +31,17 @@ func init() {

func main() {
defer func() {
err := logger.Sync()
if err != nil {
if err := logger.Sync(); err != nil {
panic(err)
}
}()

// below check ensures that if our Varnish instances inside kubernetes or not
if opts.InCluster {
logger.Info("will use kubernetes pod instances, running pod informer to fetch pods")
k8s.InitK8sTypes()
// k8s.InitK8sTypes()
go k8s.RunPodInformer()
} else {
log.Println(opts.TargetHosts)
splitted := strings.Split(opts.TargetHosts, ",")
logger.Info("will use standalone varnish instances", zap.Any("instances", splitted))
for _, v := range splitted {
Expand Down
12 changes: 11 additions & 1 deletion internal/k8s/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ var (
)

func init() {
logger = logging.GetLogger()
opts = options.GetVarnishCacheInvalidatorOptions()
logger = logging.GetLogger()
logger.Info("initializing kube client")
if restConfig, err = getConfig(); err != nil {
logger.Fatal("fatal error occurred while initializing kube client", zap.String("error", err.Error()))
}
if clientSet, err = getClientSet(restConfig); err != nil {
logger.Fatal("fatal error occurred while getting client set", zap.String("error", err.Error()))
}

logger = logger.With(zap.Bool("inCluster", opts.InCluster), zap.String("masterIp", restConfig.Host),
zap.String("varnishLabel", opts.VarnishLabel), zap.String("varnishNamespace", opts.VarnishNamespace))
}

// InitK8sTypes initializes the required k8s types rest.Config and kubernetes.ClientSet
Expand Down

0 comments on commit 5b20cd7

Please sign in to comment.