Skip to content

Commit

Permalink
Use k8s.io/klog instead of glog
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-0 committed Feb 27, 2019
1 parent 8944afd commit e0110b8
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 136 deletions.
11 changes: 5 additions & 6 deletions vertical-pod-autoscaler/e2e/v1beta1/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"testing"
"time"

"github.com/golang/glog"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/gomega"
Expand All @@ -38,6 +36,7 @@ import (

// needed to authorize to GKE cluster
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/version"
commontest "k8s.io/kubernetes/test/e2e/common"
"k8s.io/kubernetes/test/e2e/framework"
Expand All @@ -57,7 +56,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {

c, err := framework.LoadClientset()
if err != nil {
glog.Fatal("Error loading client: ", err)
klog.Fatal("Error loading client: ", err)
}

// Delete any namespaces except those created by the system. This ensures no
Expand All @@ -72,7 +71,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
if err != nil {
framework.Failf("Error deleting orphaned namespaces: %v", err)
}
glog.Infof("Waiting for deletion of the following namespaces: %v", deleted)
klog.Infof("Waiting for deletion of the following namespaces: %v", deleted)
if err := framework.WaitForNamespacesDeleted(c, deleted, framework.NamespaceCleanupTimeout); err != nil {
framework.Failf("Failed to delete orphaned namespaces %v: %v", deleted, err)
}
Expand Down Expand Up @@ -225,12 +224,12 @@ func RunE2ETests(t *testing.T) {
// TODO: we should probably only be trying to create this directory once
// rather than once-per-Ginkgo-node.
if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil {
glog.Errorf("Failed creating report directory: %v", err)
klog.Errorf("Failed creating report directory: %v", err)
} else {
r = append(r, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, "junit_02.xml")))
}
}
glog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunId, config.GinkgoConfig.ParallelNode)
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunId, config.GinkgoConfig.ParallelNode)

ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
}
6 changes: 3 additions & 3 deletions vertical-pod-autoscaler/e2e/v1beta1/recommender.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"k8s.io/kubernetes/test/e2e/framework"

"github.com/golang/glog"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)
Expand Down Expand Up @@ -108,9 +108,9 @@ func getVpaObserver(vpaClientSet *vpa_clientset.Clientset) *observer {
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
go controller.Run(make(chan struct{}))
if !cache.WaitForCacheSync(make(chan struct{}), controller.HasSynced) {
glog.Fatalf("Failed to sync VPA cache during initialization")
klog.Fatalf("Failed to sync VPA cache during initialization")
} else {
glog.Info("Initial VPA synced successfully")
klog.Info("Initial VPA synced successfully")
}
return &vpaObserver
}
Expand Down
10 changes: 5 additions & 5 deletions vertical-pod-autoscaler/e2e/v1beta2/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"testing"
"time"

"github.com/golang/glog"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
Expand All @@ -38,6 +37,7 @@ import (

// needed to authorize to GKE cluster
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/version"
commontest "k8s.io/kubernetes/test/e2e/common"
"k8s.io/kubernetes/test/e2e/framework"
Expand All @@ -57,7 +57,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {

c, err := framework.LoadClientset()
if err != nil {
glog.Fatal("Error loading client: ", err)
klog.Fatal("Error loading client: ", err)
}

// Delete any namespaces except those created by the system. This ensures no
Expand All @@ -72,7 +72,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
if err != nil {
framework.Failf("Error deleting orphaned namespaces: %v", err)
}
glog.Infof("Waiting for deletion of the following namespaces: %v", deleted)
klog.Infof("Waiting for deletion of the following namespaces: %v", deleted)
if err := framework.WaitForNamespacesDeleted(c, deleted, framework.NamespaceCleanupTimeout); err != nil {
framework.Failf("Failed to delete orphaned namespaces %v: %v", deleted, err)
}
Expand Down Expand Up @@ -225,12 +225,12 @@ func RunE2ETests(t *testing.T) {
// TODO: we should probably only be trying to create this directory once
// rather than once-per-Ginkgo-node.
if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil {
glog.Errorf("Failed creating report directory: %v", err)
klog.Errorf("Failed creating report directory: %v", err)
} else {
r = append(r, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, "junit_01.xml")))
}
}
glog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunId, config.GinkgoConfig.ParallelNode)
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunId, config.GinkgoConfig.ParallelNode)

ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
}
6 changes: 3 additions & 3 deletions vertical-pod-autoscaler/e2e/v1beta2/recommender.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"k8s.io/kubernetes/test/e2e/framework"

"github.com/golang/glog"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)
Expand Down Expand Up @@ -108,9 +108,9 @@ func getVpaObserver(vpaClientSet *vpa_clientset.Clientset) *observer {
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
go controller.Run(make(chan struct{}))
if !cache.WaitForCacheSync(make(chan struct{}), controller.HasSynced) {
glog.Fatalf("Failed to sync VPA cache during initialization")
klog.Fatalf("Failed to sync VPA cache during initialization")
} else {
glog.Info("Initial VPA synced successfully")
klog.Info("Initial VPA synced successfully")
}
return &vpaObserver
}
Expand Down
8 changes: 4 additions & 4 deletions vertical-pod-autoscaler/pkg/admission-controller/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package main
import (
"os"

"github.com/golang/glog"
"k8s.io/klog"
)

type certsContainer struct {
Expand All @@ -33,16 +33,16 @@ type certsConfig struct {
func readFile(filePath string) []byte {
file, err := os.Open(filePath)
if err != nil {
glog.Error(err)
klog.Error(err)
return nil
}
res := make([]byte, 5000)
count, err := file.Read(res)
if err != nil {
glog.Error(err)
klog.Error(err)
return nil
}
glog.Infof("Successfully read %d bytes from %v", count, filePath)
klog.Infof("Successfully read %d bytes from %v", count, filePath)
return res
}

Expand Down
15 changes: 7 additions & 8 deletions vertical-pod-autoscaler/pkg/admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/golang/glog"
"k8s.io/klog"
)

const (
Expand All @@ -36,19 +35,19 @@ const (
func getClient() *kubernetes.Clientset {
config, err := rest.InClusterConfig()
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return clientset
}

func configTLS(clientset *kubernetes.Clientset, serverCert, serverKey []byte) *tls.Config {
sCert, err := tls.X509KeyPair(serverCert, serverKey)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return &tls.Config{
Certificates: []tls.Certificate{sCert},
Expand All @@ -63,7 +62,7 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace
_, err := client.Get(webhookConfigName, metav1.GetOptions{})
if err == nil {
if err2 := client.Delete(webhookConfigName, nil); err2 != nil {
glog.Fatal(err2)
klog.Fatal(err2)
}
}
webhookConfig := &v1beta1.MutatingWebhookConfiguration{
Expand Down Expand Up @@ -101,8 +100,8 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace
},
}
if _, err := client.Create(webhookConfig); err != nil {
glog.Fatal(err)
klog.Fatal(err)
} else {
glog.V(3).Info("Self registration as MutatingWebhook succeeded.")
klog.V(3).Info("Self registration as MutatingWebhook succeeded.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ limitations under the License.
package logic

import (
"github.com/golang/glog"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"

vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
vpa_lister "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/listers/autoscaling.k8s.io/v1beta2"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target"
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"
"k8s.io/klog"
)

// ContainerResources holds resources request for container
Expand Down Expand Up @@ -65,7 +64,7 @@ func getContainersResources(pod *v1.Pod, podRecommendation vpa_types.Recommended

recommendation := vpa_api_util.GetRecommendationForContainer(container.Name, &podRecommendation)
if recommendation == nil {
glog.V(2).Infof("no matching recommendation found for container %s", container.Name)
klog.V(2).Infof("no matching recommendation found for container %s", container.Name)
continue
}
resources[i].Requests = recommendation.Target
Expand All @@ -76,7 +75,7 @@ func getContainersResources(pod *v1.Pod, podRecommendation vpa_types.Recommended
func (p *recommendationProvider) getMatchingVPA(pod *v1.Pod) *vpa_types.VerticalPodAutoscaler {
configs, err := p.vpaLister.VerticalPodAutoscalers(pod.Namespace).List(labels.Everything())
if err != nil {
glog.Errorf("failed to get vpa configs: %v", err)
klog.Errorf("failed to get vpa configs: %v", err)
return nil
}
onConfigs := make([]*vpa_api_util.VpaWithSelector, 0)
Expand All @@ -86,15 +85,15 @@ func (p *recommendationProvider) getMatchingVPA(pod *v1.Pod) *vpa_types.Vertical
}
selector, err := p.selectorFetcher.Fetch(vpaConfig)
if err != nil {
glog.V(3).Infof("skipping VPA object %v because we cannot fetch selector", vpaConfig.Name)
klog.V(3).Infof("skipping VPA object %v because we cannot fetch selector", vpaConfig.Name)
continue
}
onConfigs = append(onConfigs, &vpa_api_util.VpaWithSelector{
Vpa: vpaConfig,
Selector: selector,
})
}
glog.V(2).Infof("Let's choose from %d configs for pod %s/%s", len(onConfigs), pod.Namespace, pod.Name)
klog.V(2).Infof("Let's choose from %d configs for pod %s/%s", len(onConfigs), pod.Namespace, pod.Name)
result := vpa_api_util.GetControllingVPAForPod(pod, onConfigs)
if result != nil {
return result.Vpa
Expand All @@ -105,10 +104,10 @@ func (p *recommendationProvider) getMatchingVPA(pod *v1.Pod) *vpa_types.Vertical
// GetContainersResourcesForPod returns recommended request for a given pod, annotations and name of controlling VPA.
// The returned slice corresponds 1-1 to containers in the Pod.
func (p *recommendationProvider) GetContainersResourcesForPod(pod *v1.Pod) ([]ContainerResources, vpa_api_util.ContainerToAnnotationsMap, string, error) {
glog.V(2).Infof("updating requirements for pod %s.", pod.Name)
klog.V(2).Infof("updating requirements for pod %s.", pod.Name)
vpaConfig := p.getMatchingVPA(pod)
if vpaConfig == nil {
glog.V(2).Infof("no matching VPA found for pod %s", pod.Name)
klog.V(2).Infof("no matching VPA found for pod %s", pod.Name)
return nil, nil, "", nil
}

Expand All @@ -119,7 +118,7 @@ func (p *recommendationProvider) GetContainersResourcesForPod(pod *v1.Pod) ([]Co
var err error
recommendedPodResources, annotations, err = p.recommendationProcessor.Apply(vpaConfig.Status.Recommendation, vpaConfig.Spec.ResourcePolicy, vpaConfig.Status.Conditions, pod)
if err != nil {
glog.V(2).Infof("cannot process recommendation for pod %s", pod.Name)
klog.V(2).Infof("cannot process recommendation for pod %s", pod.Name)
return nil, annotations, vpaConfig.Name, err
}
}
Expand Down
20 changes: 10 additions & 10 deletions vertical-pod-autoscaler/pkg/admission-controller/logic/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (

"strings"

"github.com/golang/glog"
"k8s.io/api/admission/v1beta1"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
metrics_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/metrics/admission"
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"
"k8s.io/klog"
)

// AdmissionServer is an admission webhook server that modifies pod resources request based on VPA recommendation
Expand Down Expand Up @@ -59,7 +59,7 @@ func (s *AdmissionServer) getPatchesForPodResourceRequest(raw []byte, namespace
pod.Name = pod.GenerateName + "%"
pod.Namespace = namespace
}
glog.V(4).Infof("Admitting pod %v", pod.ObjectMeta)
klog.V(4).Infof("Admitting pod %v", pod.ObjectMeta)
containersResources, annotationsPerContainer, vpaName, err := s.recommendationProvider.GetContainersResourcesForPod(&pod)
if err != nil {
return nil, err
Expand Down Expand Up @@ -192,7 +192,7 @@ func getPatchesForVPADefaults(raw []byte) ([]patchRecord, error) {
return nil, err
}

glog.V(4).Infof("Processing vpa: %v", vpa)
klog.V(4).Infof("Processing vpa: %v", vpa)
patches := []patchRecord{}
if vpa.Spec.UpdatePolicy == nil {
// Sets the default updatePolicy.
Expand All @@ -212,7 +212,7 @@ func (s *AdmissionServer) admit(data []byte) (*v1beta1.AdmissionResponse, metric

ar := v1beta1.AdmissionReview{}
if err := json.Unmarshal(data, &ar); err != nil {
glog.Error(err)
klog.Error(err)
return &response, metrics_admission.Error, metrics_admission.Unknown
}
// The externalAdmissionHookConfiguration registered via selfRegistration
Expand Down Expand Up @@ -243,20 +243,20 @@ func (s *AdmissionServer) admit(data []byte) (*v1beta1.AdmissionResponse, metric
}

if err != nil {
glog.Error(err)
klog.Error(err)
return &response, metrics_admission.Error, resource
}

if len(patches) > 0 {
patch, err := json.Marshal(patches)
if err != nil {
glog.Errorf("Cannot marshal the patch %v: %v", patches, err)
klog.Errorf("Cannot marshal the patch %v: %v", patches, err)
return &response, metrics_admission.Error, resource
}
patchType := v1beta1.PatchTypeJSONPatch
response.PatchType = &patchType
response.Patch = patch
glog.V(4).Infof("Sending patches: %v", patches)
klog.V(4).Infof("Sending patches: %v", patches)
}

var status metrics_admission.AdmissionStatus
Expand Down Expand Up @@ -286,7 +286,7 @@ func (s *AdmissionServer) Serve(w http.ResponseWriter, r *http.Request) {
// verify the content type is accurate
contentType := r.Header.Get("Content-Type")
if contentType != "application/json" {
glog.Errorf("contentType=%s, expect application/json", contentType)
klog.Errorf("contentType=%s, expect application/json", contentType)
timer.Observe(metrics_admission.Error, metrics_admission.Unknown)
return
}
Expand All @@ -298,13 +298,13 @@ func (s *AdmissionServer) Serve(w http.ResponseWriter, r *http.Request) {

resp, err := json.Marshal(ar)
if err != nil {
glog.Error(err)
klog.Error(err)
timer.Observe(metrics_admission.Error, resource)
return
}

if _, err := w.Write(resp); err != nil {
glog.Error(err)
klog.Error(err)
timer.Observe(metrics_admission.Error, resource)
return
}
Expand Down
Loading

0 comments on commit e0110b8

Please sign in to comment.