Skip to content

Commit

Permalink
*: replace glog with klog
Browse files Browse the repository at this point in the history
  • Loading branch information
s-urbaniak committed Apr 18, 2019
1 parent 34298a0 commit 4a014e6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
14 changes: 7 additions & 7 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import (
"fmt"
"time"

"github.com/golang/glog"
"k8s.io/klog"
apierr "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -317,7 +317,7 @@ import (
"flag"
"os"

"github.com/golang/glog"
"github.com/golang/klog"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/logs"

Expand Down Expand Up @@ -349,7 +349,7 @@ func main() {
// initialize the flags, with one custom flag for the message
cmd := &YourAdapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure you get the glog flags
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure you get the klog flags
cmd.Flags().Parse(os.Args)

provider := cmd.makeProviderOrDie()
Expand All @@ -358,9 +358,9 @@ func main() {
// if your provider supported it:
// cmd.WithExternalMetrics(provider)

glog.Infof(cmd.Message)
klog.Infof(cmd.Message)
if err := cmd.Run(wait.NeverStop); err != nil {
glog.Fatalf("unable to run custom metrics adapter: %v", err)
klog.Fatalf("unable to run custom metrics adapter: %v", err)
}
}
```
Expand All @@ -375,12 +375,12 @@ you wrote above, the setup code looks something like this:
func (a *SampleAdapter) makeProviderOrDie() provider.CustomMetricsProvider {
client, err := a.DynamicClient()
if err != nil {
glog.Fatalf("unable to construct dynamic client: %v", err)
klog.Fatalf("unable to construct dynamic client: %v", err)
}

mapper, err := a.RESTMapper()
if err != nil {
glog.Fatalf("unable to construct discovery REST mapper: %v", err)
klog.Fatalf("unable to construct discovery REST mapper: %v", err)
}

return yourprov.NewProvider(client, mapper)
Expand Down
3 changes: 0 additions & 3 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import:
- package: github.com/go-openapi/spec
version: 1de3e0542de65ad8d75452a595886fdd0befb363 # from kubernetes Godeps.json

- package: github.com/golang/glog
version: 44145f04b68cf362d9c4df2182967c2275eaefed # from kubernetes Godep.json

- package: github.com/spf13/cobra
version: c439c4fa093711d42e1b01acb1235b52004753c1 # from kubernetes Godeps.json

Expand Down
24 changes: 21 additions & 3 deletions pkg/dynamicmapper/fake_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package dynamicmapper
import (
"fmt"

"github.com/emicklei/go-restful-swagger12"
"github.com/googleapis/gnostic/OpenAPIv2"
swagger "github.com/emicklei/go-restful-swagger12"
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/version"
Expand Down Expand Up @@ -61,6 +61,24 @@ func (c *FakeDiscovery) ServerResources() ([]*metav1.APIResourceList, error) {
return c.Resources, nil
}

func (c *FakeDiscovery) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
sgs, err := c.ServerGroups()
if err != nil {
return nil, nil, err
}
resultGroups := []*metav1.APIGroup{}
for i := range sgs.Groups {
resultGroups = append(resultGroups, &sgs.Groups[i])
}

action := testing.ActionImpl{
Verb: "get",
Resource: schema.GroupVersionResource{Resource: "resource"},
}
c.Invokes(action, nil)
return resultGroups, c.Resources, nil
}

func (c *FakeDiscovery) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
return nil, nil
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/dynamicmapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"sync"
"time"

"github.com/golang/glog"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"k8s.io/client-go/restmapper"
"k8s.io/klog"
)

// RengeneratingDiscoveryRESTMapper is a RESTMapper which Regenerates its cache of mappings periodically.
Expand Down Expand Up @@ -44,7 +43,7 @@ func NewRESTMapper(discoveryClient discovery.DiscoveryInterface, refreshInterval
func (m *RegeneratingDiscoveryRESTMapper) RunUntil(stop <-chan struct{}) {
go wait.Until(func() {
if err := m.RegenerateMappings(); err != nil {
glog.Errorf("error regenerating REST mappings from discovery: %v", err)
klog.Errorf("error regenerating REST mappings from discovery: %v", err)
}
}, m.refreshInterval, stop)
}
Expand Down
14 changes: 7 additions & 7 deletions test-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"os"

"github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/logs"
"k8s.io/klog"

basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
Expand All @@ -41,12 +41,12 @@ type SampleAdapter struct {
func (a *SampleAdapter) makeProviderOrDie() (provider.MetricsProvider, *restful.WebService) {
client, err := a.DynamicClient()
if err != nil {
glog.Fatalf("unable to construct dynamic client: %v", err)
klog.Fatalf("unable to construct dynamic client: %v", err)
}

mapper, err := a.RESTMapper()
if err != nil {
glog.Fatalf("unable to construct discovery REST mapper: %v", err)
klog.Fatalf("unable to construct discovery REST mapper: %v", err)
}

return fakeprov.NewFakeProvider(client, mapper)
Expand All @@ -58,21 +58,21 @@ func main() {

cmd := &SampleAdapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the glog flags
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
cmd.Flags().Parse(os.Args)

testProvider, webService := cmd.makeProviderOrDie()
cmd.WithCustomMetrics(testProvider)
cmd.WithExternalMetrics(testProvider)

glog.Infof(cmd.Message)
klog.Infof(cmd.Message)
// Set up POST endpoint for writing fake metric values
restful.DefaultContainer.Add(webService)
go func() {
// Open port for POSTing fake metrics
glog.Fatal(http.ListenAndServe(":8080", nil))
klog.Fatal(http.ListenAndServe(":8080", nil))
}()
if err := cmd.Run(wait.NeverStop); err != nil {
glog.Fatalf("unable to run custom metrics adapter: %v", err)
klog.Fatalf("unable to run custom metrics adapter: %v", err)
}
}
4 changes: 2 additions & 2 deletions test-adapter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/klog"

apierr "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -171,7 +171,7 @@ func (p *testingProvider) updateMetric(request *restful.Request, response *restf

info, _, err = info.Normalized(p.mapper)
if err != nil {
glog.Errorf("Error normalizing info: %s", err)
klog.Errorf("Error normalizing info: %s", err)
}
namespacedName := types.NamespacedName{
Name: name,
Expand Down

0 comments on commit 4a014e6

Please sign in to comment.