Skip to content

Commit

Permalink
fix pub scale scheme (#988)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg authored Jun 7, 2022
1 parent 245298c commit 0529790
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/util/controllerfinder/controller_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
scaleclient "k8s.io/client-go/scale"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -43,16 +45,23 @@ func InitControllerFinder(mgr manager.Manager) error {
Client: mgr.GetClient(),
mapper: mgr.GetRESTMapper(),
}
k8sClient, err := clientset.NewForConfig(mgr.GetConfig())
cfg := mgr.GetConfig()
if cfg.GroupVersion == nil {
cfg.GroupVersion = &schema.GroupVersion{}
}
codecs := serializer.NewCodecFactory(mgr.GetScheme())
cfg.NegotiatedSerializer = codecs.WithoutConversion()
restClient, err := rest.RESTClientFor(cfg)
if err != nil {
return err
}
Finder.discoveryClient = k8sClient.Discovery()
scaleKindResolver := scaleclient.NewDiscoveryScaleKindResolver(Finder.discoveryClient)
Finder.scaleNamespacer, err = scaleclient.NewForConfig(mgr.GetConfig(), Finder.mapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver)
k8sClient, err := clientset.NewForConfig(mgr.GetConfig())
if err != nil {
return err
}
Finder.discoveryClient = k8sClient.Discovery()
scaleKindResolver := scaleclient.NewDiscoveryScaleKindResolver(Finder.discoveryClient)
Finder.scaleNamespacer = scaleclient.New(restClient, Finder.mapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver)
return nil
}

Expand Down

0 comments on commit 0529790

Please sign in to comment.