Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Use a forked version of glog in kubernetes #268

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions examples/slackcontroller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"syscall"
"time"

"github.com/golang/glog"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

clientset "k8s.io/cluster-registry/pkg/client/clientset/versioned"
informers "k8s.io/cluster-registry/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -62,16 +62,16 @@ func main() {

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

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

clusterInformerFactory := informers.NewSharedInformerFactory(clusterClient, time.Second*30)
Expand All @@ -81,7 +81,7 @@ func main() {
go clusterInformerFactory.Start(stopCh)

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

Expand Down
24 changes: 12 additions & 12 deletions examples/slackcontroller/slackcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"
"time"

"github.com/golang/glog"
"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
Expand All @@ -35,6 +34,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"

clientset "k8s.io/cluster-registry/pkg/client/clientset/versioned"
clusterregistryscheme "k8s.io/cluster-registry/pkg/client/clientset/versioned/scheme"
Expand Down Expand Up @@ -93,9 +93,9 @@ func NewSlackController(
// Add clusterregistry-controller types to the default Kubernetes Scheme so Events can be
// logged for clusterregistry-controller types.
clusterregistryscheme.AddToScheme(scheme.Scheme)
glog.V(4).Info("Creating event broadcaster")
klog.V(4).Info("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})

Expand All @@ -109,7 +109,7 @@ func NewSlackController(
slackURL: slackURL,
}

glog.Info("Setting up event handlers")
klog.Info("Setting up event handlers")
clusterInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueCluster,
DeleteFunc: controller.enqueueCluster,
Expand All @@ -127,23 +127,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 Cluster controller")
klog.Info("Starting Cluster controller")

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

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

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

return nil
}
Expand Down Expand Up @@ -197,7 +197,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)
klog.Infof("Successfully synced '%s'", key)
return nil
}(obj)

Expand All @@ -211,7 +211,7 @@ func (c *Controller) processNextWorkItem() bool {

// syncHandler sends Slack notifications when the cluster is updated.
func (c *Controller) syncHandler(key string) error {
glog.Infof(key)
klog.Infof(key)
// Convert the namespace/name string into a distinct namespace and name
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
Expand All @@ -238,7 +238,7 @@ func (c *Controller) syncHandler(key string) error {
if err != nil {
return err
}
glog.V(4).Infof("%#v", resp)
klog.V(4).Infof("%#v", resp)

if cluster != nil {
c.recorder.Event(cluster, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced)
Expand Down