diff --git a/docs/getting-started.md b/docs/getting-started.md index 51d0a1a7f..f83a53aed 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -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" @@ -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" @@ -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() @@ -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) } } ``` @@ -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) diff --git a/glide.yaml b/glide.yaml index f03eacfb5..e076d023e 100644 --- a/glide.yaml +++ b/glide.yaml @@ -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 diff --git a/pkg/dynamicmapper/fake_discovery.go b/pkg/dynamicmapper/fake_discovery.go index 785ce305e..4e1b4c54d 100644 --- a/pkg/dynamicmapper/fake_discovery.go +++ b/pkg/dynamicmapper/fake_discovery.go @@ -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" @@ -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 } diff --git a/pkg/dynamicmapper/mapper.go b/pkg/dynamicmapper/mapper.go index 4a87f29fc..f9f5d4173 100644 --- a/pkg/dynamicmapper/mapper.go +++ b/pkg/dynamicmapper/mapper.go @@ -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. @@ -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) } diff --git a/test-adapter/main.go b/test-adapter/main.go index bd357685f..d0988c863 100644 --- a/test-adapter/main.go +++ b/test-adapter/main.go @@ -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" @@ -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) @@ -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) } } diff --git a/test-adapter/provider/provider.go b/test-adapter/provider/provider.go index b0b5e579f..26c6f8479 100644 --- a/test-adapter/provider/provider.go +++ b/test-adapter/provider/provider.go @@ -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" @@ -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,