Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use logrus consistently for logging #1414

Merged
merged 3 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions cmd/apprepository-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"fmt"
"time"

"github.com/golang/glog"
apprepov1alpha1 "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/apis/apprepository/v1alpha1"
clientset "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/clientset/versioned"
appreposcheme "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/clientset/versioned/scheme"
informers "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/informers/externalversions"
listers "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/listers/apprepository/v1alpha1"
log "github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -102,9 +102,9 @@ func NewController(
// Add apprepository-controller types to the default Kubernetes Scheme so
// Events can be logged for apprepository-controller types.
appreposcheme.AddToScheme(scheme.Scheme)
glog.V(4).Info("Creating event broadcaster")
log.Info("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventBroadcaster.StartLogging(log.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})

Expand All @@ -119,7 +119,7 @@ func NewController(
recorder: recorder,
}

glog.Info("Setting up event handlers")
log.Info("Setting up event handlers")
// Set up an event handler for when AppRepository resources change
apprepoInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueAppRepo,
Expand Down Expand Up @@ -161,23 +161,23 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error {
defer c.workqueue.ShutDown()

// Start the informer factories to begin populating the informer caches
glog.Info("Starting AppRepository controller")
log.Info("Starting AppRepository controller")

// Wait for the caches to be synced before starting workers
glog.Info("Waiting for informer caches to sync")
log.Info("Waiting for informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, c.cronjobsSynced, c.appreposSynced); !ok {
return fmt.Errorf("failed to wait for caches to sync")
}

glog.Info("Starting workers")
log.Info("Starting workers")
// Launch two workers to process AppRepository resources
for i := 0; i < threadiness; i++ {
go wait.Until(c.runWorker, time.Second, stopCh)
}

glog.Info("Started workers")
log.Info("Started workers")
<-stopCh
glog.Info("Shutting down workers")
log.Info("Shutting down workers")

return nil
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (c *Controller) processNextWorkItem() bool {
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
c.workqueue.Forget(obj)
glog.Infof("Successfully synced '%s'", key)
log.Infof("Successfully synced '%s'", key)
return nil
}(obj)

Expand Down Expand Up @@ -260,7 +260,7 @@ func (c *Controller) syncHandler(key string) error {
// The AppRepository resource may no longer exist, in which case we stop
// processing.
if errors.IsNotFound(err) {
glog.Infof("AppRepository '%s' no longer exists so performing cleanup of charts from the DB", key)
log.Infof("AppRepository '%s' no longer exists so performing cleanup of charts from the DB", key)
// Trigger a Job to perfrom the cleanup of the charts in the DB corresponding to deleted AppRepository
_, err = c.kubeclientset.BatchV1().Jobs(namespace).Create(newCleanupJob(name, namespace))
return nil
Expand All @@ -273,7 +273,7 @@ func (c *Controller) syncHandler(key string) error {
cronjob, err := c.cronjobsLister.CronJobs(apprepo.Namespace).Get(cronjobName)
// If the resource doesn't exist, we'll create it
if errors.IsNotFound(err) {
glog.V(4).Infof("Creating CronJob %q for AppRepository %q", cronjobName, apprepo.GetName())
log.Infof("Creating CronJob %q for AppRepository %q", cronjobName, apprepo.GetName())
cronjob, err = c.kubeclientset.BatchV1beta1().CronJobs(apprepo.Namespace).Create(newCronJob(apprepo))
if err != nil {
return err
Expand All @@ -283,7 +283,7 @@ func (c *Controller) syncHandler(key string) error {
_, err = c.kubeclientset.BatchV1().Jobs(apprepo.Namespace).Create(newSyncJob(apprepo))
} else if err == nil {
// If the resource already exists, we'll update it
glog.V(4).Infof("Updating CronJob %q for AppRepository %q", cronjobName, apprepo.GetName())
log.Infof("Updating CronJob %q for AppRepository %q", cronjobName, apprepo.GetName())
cronjob, err = c.kubeclientset.BatchV1beta1().CronJobs(apprepo.Namespace).Update(newCronJob(apprepo))
if err != nil {
return err
Expand Down Expand Up @@ -351,9 +351,9 @@ func (c *Controller) handleObject(obj interface{}) {
runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type"))
return
}
glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName())
log.Infof("Recovered deleted object '%s' from tombstone", object.GetName())
}
glog.V(4).Infof("Processing object: %s", object.GetName())
log.Infof("Processing object: %s", object.GetName())
if ownerRef := metav1.GetControllerOf(object); ownerRef != nil {
// If this object is not owned by an AppRepository, we should not do
// anything more with it.
Expand All @@ -363,7 +363,7 @@ func (c *Controller) handleObject(obj interface{}) {

apprepo, err := c.appreposLister.AppRepositories(object.GetNamespace()).Get(ownerRef.Name)
if err != nil {
glog.V(4).Infof("ignoring orphaned object '%s' of AppRepository '%s'", object.GetSelfLink(), ownerRef.Name)
log.Infof("ignoring orphaned object '%s' of AppRepository '%s'", object.GetSelfLink(), ownerRef.Name)
return
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/apprepository-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package main
import (
"flag"

"github.com/golang/glog"
clientset "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/clientset/versioned"
informers "github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/client/informers/externalversions"
"github.com/kubeapps/kubeapps/cmd/apprepository-controller/pkg/signals"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd" // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
log "github.com/sirupsen/logrus"
)

var (
Expand All @@ -49,17 +49,17 @@ func main() {

cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
glog.Fatalf("Error building kubeconfig: %s", err.Error())
log.Fatalf("Error building kubeconfig: %s", err.Error())
}

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
log.Fatalf("Error building kubernetes clientset: %s", err.Error())
}

apprepoClient, err := clientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building apprepo clientset: %s", err.Error())
log.Fatalf("Error building apprepo clientset: %s", err.Error())
}

kubeInformerFactory := kubeinformers.NewFilteredSharedInformerFactory(kubeClient, 0, namespace, nil)
Expand All @@ -71,7 +71,7 @@ func main() {
go apprepoInformerFactory.Start(stopCh)

if err = controller.Run(2, stopCh); err != nil {
glog.Fatalf("Error running controller: %s", err.Error())
log.Fatalf("Error running controller: %s", err.Error())
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/arschles/assert v1.0.0
github.com/ghodss/yaml v1.0.0
github.com/go-test/deep v1.0.4
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.3.1
github.com/gorilla/mux v1.7.3
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40
Expand All @@ -28,6 +27,5 @@ require (
k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5
k8s.io/client-go v0.0.0-20191016111102-bec269661e48
k8s.io/helm v2.16.0+incompatible
k8s.io/klog v1.0.0
sigs.k8s.io/yaml v1.1.0
)
8 changes: 4 additions & 4 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

chartUtils "github.com/kubeapps/kubeapps/pkg/chart"
"github.com/kubeapps/kubeapps/pkg/proxy"
log "github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/kube"
Expand All @@ -15,7 +16,6 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog"
"sigs.k8s.io/yaml"
)

Expand All @@ -25,14 +25,14 @@ type StorageForDriver func(namespace string, clientset *kubernetes.Clientset) *s
// StorageForSecrets returns a storage using the Secret driver.
func StorageForSecrets(namespace string, clientset *kubernetes.Clientset) *storage.Storage {
d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace))
d.Log = klog.Infof
d.Log = log.Infof
return storage.Init(d)
}

// StorageForConfigMaps returns a storage using the ConfigMap driver.
func StorageForConfigMaps(namespace string, clientset *kubernetes.Clientset) *storage.Storage {
d := driver.NewConfigMaps(clientset.CoreV1().ConfigMaps(namespace))
d.Log = klog.Infof
d.Log = log.Infof
return storage.Init(d)
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func NewActionConfig(storageForDriver StorageForDriver, config *rest.Config, cli
actionConfig.RESTClientGetter = restClientGetter
actionConfig.KubeClient = kube.New(restClientGetter)
actionConfig.Releases = store
actionConfig.Log = klog.Infof
actionConfig.Log = log.Infof
return actionConfig, nil
}

Expand Down