Merge pull request #708 from zalando-incubator/fix-apiserver-setup

Fix custom apiserver setup
This commit is contained in:
Katyanna Moura 2024-05-13 15:51:02 +02:00 committed by GitHub
commit f55afc0905
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,21 +151,8 @@ func (o AdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct
klog.Fatal(http.ListenAndServe(o.MetricsAddress, nil)) klog.Fatal(http.ListenAndServe(o.MetricsAddress, nil))
}() }()
serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs)
err := o.CustomMetricsAdapterServerOptions.ApplyTo(serverConfig)
if err != nil {
return err
}
config := &apiserver.Config{
GenericConfig: &serverConfig.Config,
}
config.GenericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(apiserver.Scheme))
config.GenericConfig.OpenAPIConfig.Info.Title = "kube-metrics-adapter"
config.GenericConfig.OpenAPIConfig.Info.Version = "1.0.0"
var clientConfig *rest.Config var clientConfig *rest.Config
var err error
if len(o.RemoteKubeConfigFile) > 0 { if len(o.RemoteKubeConfigFile) > 0 {
loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile} loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{}) loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
@ -178,6 +165,21 @@ func (o AdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct
return fmt.Errorf("unable to construct lister client config to initialize provider: %v", err) return fmt.Errorf("unable to construct lister client config to initialize provider: %v", err)
} }
serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs)
serverConfig.ClientConfig = clientConfig
err = o.CustomMetricsAdapterServerOptions.ApplyTo(serverConfig)
if err != nil {
return err
}
config := &apiserver.Config{
GenericConfig: &serverConfig.Config,
}
config.GenericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(apiserver.Scheme))
config.GenericConfig.OpenAPIConfig.Info.Title = "kube-metrics-adapter"
config.GenericConfig.OpenAPIConfig.Info.Version = "1.0.0"
// convert stop channel to a context // convert stop channel to a context
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
go func() { go func() {