migrate util package to klog from glog.

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2019-02-04 18:35:43 +05:30 committed by mergify[bot]
parent cb77ff5d87
commit c0712db08a
3 changed files with 17 additions and 17 deletions

View File

@ -19,7 +19,7 @@ package util
import ( import (
"errors" "errors"
"github.com/golang/glog" "k8s.io/klog"
) )
const ( const (
@ -41,13 +41,13 @@ type CachePersister interface {
// NewCachePersister returns CachePersister based on store // NewCachePersister returns CachePersister based on store
func NewCachePersister(metadataStore, driverName string) (CachePersister, error) { func NewCachePersister(metadataStore, driverName string) (CachePersister, error) {
if metadataStore == "k8s_configmap" { if metadataStore == "k8s_configmap" {
glog.Infof("cache-perister: using kubernetes configmap as metadata cache persister") klog.Infof("cache-perister: using kubernetes configmap as metadata cache persister")
k8scm := &K8sCMCache{} k8scm := &K8sCMCache{}
k8scm.Client = NewK8sClient() k8scm.Client = NewK8sClient()
k8scm.Namespace = GetK8sNamespace() k8scm.Namespace = GetK8sNamespace()
return k8scm, nil return k8scm, nil
} else if metadataStore == "node" { } else if metadataStore == "node" {
glog.Infof("cache-persister: using node as metadata cache persister") klog.Infof("cache-persister: using node as metadata cache persister")
nc := &NodeCache{} nc := &NodeCache{}
nc.BasePath = PluginFolder + "/" + driverName nc.BasePath = PluginFolder + "/" + driverName
return nc, nil return nc, nil

View File

@ -22,8 +22,8 @@ import (
"os" "os"
"regexp" "regexp"
"github.com/golang/glog"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/klog"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors" apierrs "k8s.io/apimachinery/pkg/api/errors"
@ -66,19 +66,19 @@ func NewK8sClient() *k8s.Clientset {
if cPath != "" { if cPath != "" {
cfg, err = clientcmd.BuildConfigFromFlags("", cPath) cfg, err = clientcmd.BuildConfigFromFlags("", cPath)
if err != nil { if err != nil {
glog.Errorf("Failed to get cluster config with error: %v\n", err) klog.Errorf("Failed to get cluster config with error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} else { } else {
cfg, err = rest.InClusterConfig() cfg, err = rest.InClusterConfig()
if err != nil { if err != nil {
glog.Errorf("Failed to get cluster config with error: %v\n", err) klog.Errorf("Failed to get cluster config with error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }
client, err := k8s.NewForConfig(cfg) client, err := k8s.NewForConfig(cfg)
if err != nil { if err != nil {
glog.Errorf("Failed to create client with error: %v\n", err) klog.Errorf("Failed to create client with error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
return client return client
@ -123,7 +123,7 @@ func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFun
func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error { func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error {
cm, err := k8scm.getMetadataCM(identifier) cm, err := k8scm.getMetadataCM(identifier)
if cm != nil && err == nil { if cm != nil && err == nil {
glog.V(4).Infof("k8s-cm-cache: configmap already exists, skipping configmap creation") klog.V(4).Infof("k8s-cm-cache: configmap already exists, skipping configmap creation")
return nil return nil
} }
dataJSON, err := json.Marshal(data) dataJSON, err := json.Marshal(data)
@ -145,13 +145,13 @@ func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error {
_, err = k8scm.Client.CoreV1().ConfigMaps(k8scm.Namespace).Create(cm) _, err = k8scm.Client.CoreV1().ConfigMaps(k8scm.Namespace).Create(cm)
if err != nil { if err != nil {
if apierrs.IsAlreadyExists(err) { if apierrs.IsAlreadyExists(err) {
glog.V(4).Infof("k8s-cm-cache: configmap already exists") klog.V(4).Infof("k8s-cm-cache: configmap already exists")
return nil return nil
} }
return errors.Wrapf(err, "k8s-cm-cache: couldn't persist %s metadata as configmap", identifier) return errors.Wrapf(err, "k8s-cm-cache: couldn't persist %s metadata as configmap", identifier)
} }
glog.V(4).Infof("k8s-cm-cache: configmap %s successfully created\n", identifier) klog.V(4).Infof("k8s-cm-cache: configmap %s successfully created\n", identifier)
return nil return nil
} }
@ -174,6 +174,6 @@ func (k8scm *K8sCMCache) Delete(identifier string) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "k8s-cm-cache: couldn't delete metadata configmap %s", identifier) return errors.Wrapf(err, "k8s-cm-cache: couldn't delete metadata configmap %s", identifier)
} }
glog.V(4).Infof("k8s-cm-cache: successfully deleted metadata configmap %s", identifier) klog.V(4).Infof("k8s-cm-cache: successfully deleted metadata configmap %s", identifier)
return nil return nil
} }

View File

@ -25,8 +25,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/golang/glog"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/klog"
) )
// NodeCache to store metadata // NodeCache to store metadata
@ -87,7 +87,7 @@ func decodeObj(filepath, pattern string, file os.FileInfo, destObj interface{})
// #nosec // #nosec
fp, err := os.Open(path.Join(filepath, file.Name())) fp, err := os.Open(path.Join(filepath, file.Name()))
if err != nil { if err != nil {
glog.Infof("node-cache: open file: %s err %v", file.Name(), err) klog.Infof("node-cache: open file: %s err %v", file.Name(), err)
return errDec return errDec
} }
decoder := json.NewDecoder(fp) decoder := json.NewDecoder(fp)
@ -112,7 +112,7 @@ func (nc *NodeCache) Create(identifier string, data interface{}) error {
defer func() { defer func() {
if err = fp.Close(); err != nil { if err = fp.Close(); err != nil {
glog.Warningf("failed to close file:%s %v", fp.Name(), err) klog.Warningf("failed to close file:%s %v", fp.Name(), err)
} }
}() }()
@ -120,7 +120,7 @@ func (nc *NodeCache) Create(identifier string, data interface{}) error {
if err = encoder.Encode(data); err != nil { if err = encoder.Encode(data); err != nil {
return errors.Wrapf(err, "node-cache: failed to encode metadata for file: %s\n", file) return errors.Wrapf(err, "node-cache: failed to encode metadata for file: %s\n", file)
} }
glog.V(4).Infof("node-cache: successfully saved metadata into file: %s\n", file) klog.V(4).Infof("node-cache: successfully saved metadata into file: %s\n", file)
return nil return nil
} }
@ -135,7 +135,7 @@ func (nc *NodeCache) Get(identifier string, data interface{}) error {
defer func() { defer func() {
if err = fp.Close(); err != nil { if err = fp.Close(); err != nil {
glog.Warningf("failed to close file:%s %v", fp.Name(), err) klog.Warningf("failed to close file:%s %v", fp.Name(), err)
} }
}() }()
@ -156,6 +156,6 @@ func (nc *NodeCache) Delete(identifier string) error {
return errors.Wrapf(err, "node-cache: error removing file %s", file) return errors.Wrapf(err, "node-cache: error removing file %s", file)
} }
} }
glog.V(4).Infof("node-cache: successfully deleted metadata storage file at: %+v\n", file) klog.V(4).Infof("node-cache: successfully deleted metadata storage file at: %+v\n", file)
return nil return nil
} }