func (o sampleAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct{}) error {
	config, err := o.Config()
	if err != nil {
		return err
	}

	var clientConfig *rest.Config
	if len(o.RemoteKubeConfigFile) > 0 {
		loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
		loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})

		clientConfig, err = loader.ClientConfig()
	} else {
		clientConfig, err = rest.InClusterConfig()
	}
	if err != nil {
		return fmt.Errorf("unable to construct lister client config to initialize provider: %v", err)
	}

	client, err := coreclient.NewForConfig(clientConfig)
	if err != nil {
		return fmt.Errorf("unable to construct lister client to initialize provider: %v", err)
	}

	discoveryClient, err := discovery.NewDiscoveryClientForConfig(clientConfig)
	if err != nil {
		return fmt.Errorf("unable to construct discovery client for dynamic client: %v", err)
	}
	dynamicMapper, err := dynamicmapper.NewRESTMapper(discoveryClient, meta.InterfacesForUnstructured, time.Minute)
	if err != nil {
		return fmt.Errorf("unable to construct dynamic mapper: %v", err)
	}

	tokenSource, err := google.DefaultTokenSource(oauth2.NoContext, "")
	if err != nil {
		return fmt.Errorf("unable to use default token source: %v", err)
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	stackdriverService, err := stackdriver.New(oauthClient)
	if err != nil {
		return fmt.Errorf("Failed to create Stackdriver client: %v", err)
	}
	provider := provider.NewStackdriverProvider(coreclient.New(client.RESTClient()), dynamicMapper, stackdriverService, 5*time.Minute, time.Minute, o.UseNewResourceModel)
	customMetricsProvider, externalMetricsProvider := provider, provider
	if !o.EnableCustomMetricsAPI {
		customMetricsProvider = nil
	}
	if !o.EnableExternalMetricsAPI {
		externalMetricsProvider = nil
	}

	server, err := config.Complete().New("custom-metrics-stackdriver-adapter", customMetricsProvider, externalMetricsProvider)
	if err != nil {
		return err
	}
	return server.GenericAPIServer.PrepareRun().Run(stopCh)
}
// RunCustomMetricsAdapterServer runs Custom Metrics Adapter API server.
RunCustomMetricsAdapterServer runs Custom Metrics Adapter API server.
// RunCustomMetricsAdapterServer runs Custom Metrics Adapter API server .
func (o sampleAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct{}) error {
	config, err := o.Config()
	if err != nil {
		return err
	}
	var clientConfig *rest.Config
	if len(o.RemoteKubeConfigFile) > 0 {
		loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
		loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
		clientConfig, err = loader.ClientConfig()
	} else {
		clientConfig, err = rest.InClusterConfig()
	}
	if err != nil {
		return fmt.Errorf("unable to construct lister client config to initialize provider: %v", err)
	}
	client, err := coreclient.NewForConfig(clientConfig)
	if err != nil {
		return fmt.Errorf("unable to construct lister client to initialize provider: %v", err)
	}
	discoveryClient, err := discovery.NewDiscoveryClientForConfig(clientConfig)
	if err != nil {
		return fmt.Errorf("unable to construct discovery client for dynamic client: %v", err)
	}
	dynamicMapper, err := dynamicmapper.NewRESTMapper(discoveryClient, meta.InterfacesForUnstructured, time.Minute)
	if err != nil {
		return fmt.Errorf("unable to construct dynamic mapper: %v", err)
	}
	tokenSource, err := google.DefaultTokenSource(oauth2.NoContext, "")
	if err != nil {
		return fmt.Errorf("unable to use default token source: %v", err)
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	stackdriverService, err := stackdriver.New(oauthClient)
	if err != nil {
		return fmt.Errorf("Failed to create Stackdriver client: %v", err)
	}
	provider := provider.NewStackdriverProvider(coreclient.New(client.RESTClient()), dynamicMapper, stackdriverService, 5*time.Minute, time.Minute, o.UseNewResourceModel)
	customMetricsProvider, externalMetricsProvider := provider, provider
	if !o.EnableCustomMetricsAPI {
		customMetricsProvider = nil
	}
	if !o.EnableExternalMetricsAPI {
		externalMetricsProvider = nil
	}
	server, err := config.Complete().New("custom-metrics-stackdriver-adapter", customMetricsProvider, externalMetricsProvider)
	if err != nil {
		return err
	}
	return server.GenericAPIServer.PrepareRun().Run(stopCh)
}
func ( o sampleAdapterServerOptions ) RunCustomMetricsAdapterServer ( stopCh <- chan struct { } ) error { config , err := o . Config ( ) if err != nil { return err } var clientConfig * rest . Config if len ( o . RemoteKubeConfigFile ) > 0 { loadingRules := & clientcmd . ClientConfigLoadingRules { ExplicitPath : o . RemoteKubeConfigFile } loader := clientcmd . NewNonInteractiveDeferredLoadingClientConfig ( loadingRules , & clientcmd . ConfigOverrides { } ) clientConfig , err = loader . ClientConfig ( ) } else { clientConfig , err = rest . InClusterConfig ( ) } if err != nil { return fmt . Errorf ( " " , err ) } client , err := coreclient . NewForConfig ( clientConfig ) if err != nil { return fmt . Errorf ( " " , err ) } discoveryClient , err := discovery . NewDiscoveryClientForConfig ( clientConfig ) if err != nil { return fmt . Errorf ( " " , err ) } dynamicMapper , err := dynamicmapper . NewRESTMapper ( discoveryClient , meta . InterfacesForUnstructured , time . Minute ) if err != nil { return fmt . Errorf ( " " , err ) } tokenSource , err := google . DefaultTokenSource ( oauth2 . NoContext , " " ) if err != nil { return fmt . Errorf ( " " , err ) } oauthClient := oauth2 . NewClient ( oauth2 . NoContext , tokenSource ) stackdriverService , err := stackdriver . New ( oauthClient ) if err != nil { return fmt . Errorf ( " " , err ) } provider := provider . NewStackdriverProvider ( coreclient . New ( client . RESTClient ( ) ) , dynamicMapper , stackdriverService , 5 * time . Minute , time . Minute , o . UseNewResourceModel ) customMetricsProvider , externalMetricsProvider := provider , provider if ! o . EnableCustomMetricsAPI { customMetricsProvider = nil } if ! o . EnableExternalMetricsAPI { externalMetricsProvider = nil } server , err := config . Complete ( ) . New ( " " , customMetricsProvider , externalMetricsProvider ) if err != nil { return err } return server . GenericAPIServer . PrepareRun ( ) . Run ( stopCh ) }
RunCustomMetricsAdapterServer runs Custom Metrics Adapter API server.
RunCustomMetricsAdapterServer runs Custom Metrics Adapter API server .