// buildGenericConfig takes the server options and produces the genericapiserver.RecommendedConfig associated with it
buildGenericConfig takes the server options and produces the genericapiserver.RecommendedConfig associated with it
// buildGenericConfig takes the server options and produces the genericapiserver . RecommendedConfig associated with it
func buildGenericConfig(s *ServiceCatalogServerOptions) (*genericapiserver.RecommendedConfig, *serviceCatalogConfig, error) {
	if s.StandaloneMode {
		glog.Infof("service catalog is in standalone mode")
	}
	if err := s.SecureServingOptions.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), nil , []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
		return nil, nil, err
	}
	genericConfig := genericapiserver.NewRecommendedConfig(api.Codecs)
	if err := s.GenericServerRunOptions.ApplyTo(&genericConfig.Config); err != nil {
		return nil, nil, err
	}
	if err := s.SecureServingOptions.ApplyTo(&genericConfig.Config); err != nil {
		return nil, nil, err
	}
	if !s.DisableAuth && !s.StandaloneMode {
		if err := s.AuthenticationOptions.ApplyTo(&genericConfig.Config.Authentication, genericConfig.Config.SecureServing, genericConfig.Config.OpenAPIConfig); err != nil {
			return nil, nil, err
		}
		if err := s.AuthorizationOptions.ApplyTo(&genericConfig.Config.Authorization); err != nil {
			return nil, nil, err
		}
	} else {
		glog.Warning("Authentication and authorization disabled for testing purposes")
		genericConfig.Authentication.Authenticator = &authenticator.AnyUserAuthenticator{}
		genericConfig.Authorization.Authorizer = authorizerfactory.NewAlwaysAllowAuthorizer()
	}
	if err := s.AuditOptions.ApplyTo(&genericConfig.Config); err != nil {
		return nil, nil, err
	}
	if s.ServeOpenAPISpec {
		genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(
			openapi.GetOpenAPIDefinitions, apiopenapi.NewDefinitionNamer(api.Scheme))
		if genericConfig.OpenAPIConfig.Info == nil {
			genericConfig.OpenAPIConfig.Info = &spec.Info{}
		}
		if genericConfig.OpenAPIConfig.Info.Version == "" {
			if genericConfig.Version != nil {
				genericConfig.OpenAPIConfig.Info.Version = strings.Split(genericConfig.Version.String(), "-")[0]
			} else {
				genericConfig.OpenAPIConfig.Info.Version = "unversioned"
			}
		}
	} else {
		glog.Warning("OpenAPI spec will not be served")
	}
	genericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
	genericConfig.EnableMetrics = true
	serviceCatalogVersion := version.Get()
	genericConfig.Version = &serviceCatalogVersion
	client, err := internalclientset.NewForConfig(genericConfig.LoopbackClientConfig)
	if err != nil {
		glog.Errorf("Failed to create clientset for service catalog self-communication: %v", err)
		return nil, nil, err
	}
	sharedInformers := informers.NewSharedInformerFactory(client, 10*time.Minute)
	scConfig := &serviceCatalogConfig{
		client:          client,
		sharedInformers: sharedInformers,
	}
	if !s.StandaloneMode {
		clusterConfig, err := kube.LoadConfig(s.KubeconfigPath, "")
		if err != nil {
			glog.Errorf("Failed to parse kube client config: %v", err)
			return nil, nil, err
		}
		if clusterConfig == nil {
			clusterConfig, err = restclient.InClusterConfig()
			if err != nil {
				glog.Errorf("Failed to get kube client config: %v", err)
				return nil, nil, err
			}
		}
		clusterConfig.GroupVersion = &schema.GroupVersion{}
		kubeClient, err := kubeclientset.NewForConfig(clusterConfig)
		if err != nil {
			glog.Errorf("Failed to create clientset interface: %v", err)
			return nil, nil, err
		}
		kubeSharedInformers := kubeinformers.NewSharedInformerFactory(kubeClient, 10*time.Minute)
		genericConfig.SharedInformerFactory = kubeSharedInformers
		genericConfig.AdmissionControl, err = buildAdmission(genericConfig, s, client, sharedInformers, kubeClient, kubeSharedInformers)
		if err != nil {
			return nil, nil, fmt.Errorf("failed to initialize admission: %v", err)
		}
		scConfig.kubeClient = kubeClient
		scConfig.kubeSharedInformers = kubeSharedInformers
	}
	return genericConfig, scConfig, nil
}
func buildGenericConfig ( s * ServiceCatalogServerOptions ) ( * genericapiserver . RecommendedConfig , * serviceCatalogConfig , error ) { if s . StandaloneMode { glog . Infof ( " " ) } if err := s . SecureServingOptions . MaybeDefaultWithSelfSignedCerts ( s . GenericServerRunOptions . AdvertiseAddress . String ( ) , nil , [ ] net . IP { net . ParseIP ( " " ) } ) ; err != nil { return nil , nil , err } genericConfig := genericapiserver . NewRecommendedConfig ( api . Codecs ) if err := s . GenericServerRunOptions . ApplyTo ( & genericConfig . Config ) ; err != nil { return nil , nil , err } if err := s . SecureServingOptions . ApplyTo ( & genericConfig . Config ) ; err != nil { return nil , nil , err } if ! s . DisableAuth && ! s . StandaloneMode { if err := s . AuthenticationOptions . ApplyTo ( & genericConfig . Config . Authentication , genericConfig . Config . SecureServing , genericConfig . Config . OpenAPIConfig ) ; err != nil { return nil , nil , err } if err := s . AuthorizationOptions . ApplyTo ( & genericConfig . Config . Authorization ) ; err != nil { return nil , nil , err } } else { glog . Warning ( " " ) genericConfig . Authentication . Authenticator = & authenticator . AnyUserAuthenticator { } genericConfig . Authorization . Authorizer = authorizerfactory . NewAlwaysAllowAuthorizer ( ) } if err := s . AuditOptions . ApplyTo ( & genericConfig . Config ) ; err != nil { return nil , nil , err } if s . ServeOpenAPISpec { genericConfig . OpenAPIConfig = genericapiserver . DefaultOpenAPIConfig ( openapi . GetOpenAPIDefinitions , apiopenapi . NewDefinitionNamer ( api . Scheme ) ) if genericConfig . OpenAPIConfig . Info == nil { genericConfig . OpenAPIConfig . Info = & spec . Info { } } if genericConfig . OpenAPIConfig . Info . Version == " " { if genericConfig . Version != nil { genericConfig . OpenAPIConfig . Info . Version = strings . Split ( genericConfig . Version . String ( ) , " " ) [ 0 ] } else { genericConfig . OpenAPIConfig . Info . Version = " " } } } else { glog . Warning ( " " ) } genericConfig . SwaggerConfig = genericapiserver . DefaultSwaggerConfig ( ) genericConfig . EnableMetrics = true serviceCatalogVersion := version . Get ( ) genericConfig . Version = & serviceCatalogVersion client , err := internalclientset . NewForConfig ( genericConfig . LoopbackClientConfig ) if err != nil { glog . Errorf ( " " , err ) return nil , nil , err } sharedInformers := informers . NewSharedInformerFactory ( client , 10 * time . Minute ) scConfig := & serviceCatalogConfig { client : client , sharedInformers : sharedInformers , } if ! s . StandaloneMode { clusterConfig , err := kube . LoadConfig ( s . KubeconfigPath , " " ) if err != nil { glog . Errorf ( " " , err ) return nil , nil , err } if clusterConfig == nil { clusterConfig , err = restclient . InClusterConfig ( ) if err != nil { glog . Errorf ( " " , err ) return nil , nil , err } } clusterConfig . GroupVersion = & schema . GroupVersion { } kubeClient , err := kubeclientset . NewForConfig ( clusterConfig ) if err != nil { glog . Errorf ( " " , err ) return nil , nil , err } kubeSharedInformers := kubeinformers . NewSharedInformerFactory ( kubeClient , 10 * time . Minute ) genericConfig . SharedInformerFactory = kubeSharedInformers genericConfig . AdmissionControl , err = buildAdmission ( genericConfig , s , client , sharedInformers , kubeClient , kubeSharedInformers ) if err != nil { return nil , nil , fmt . Errorf ( " " , err ) } scConfig . kubeClient = kubeClient scConfig . kubeSharedInformers = kubeSharedInformers } return genericConfig , scConfig , nil }
buildGenericConfig takes the server options and produces the genericapiserver.RecommendedConfig associated with it
buildGenericConfig takes the server options and produces the genericapiserver . RecommendedConfig associated with it
// check if we are running in standalone mode (for test scenarios) // server configuration options /*alternateDNS*/ // always warn when auth is disabled, since this should only be used for testing // TODO: investigate if we need metrics unique to service catalog, but take defaults for now // see https://github.com/kubernetes-incubator/service-catalog/issues/677 // TODO: add support to default these values in build // see https://github.com/kubernetes-incubator/service-catalog/issues/722 // FUTURE: use protobuf for communication back to itself? // If clusterConfig is nil, look at the default in-cluster config. // TODO: we need upstream to package AlwaysAdmit, or stop defaulting to it! // NOTE: right now, we only run admission controllers when on kube cluster.