code: func New(l log.Logger, conf *SDConfig) (*Discovery, error) {
  	if l == nil {
  		l = log.NewNopLogger()
  	}
  	var (
  		kcfg *rest.Config
  		err  error
  	)
  	if conf.APIServer.URL == nil {
  		// Use the Kubernetes provided pod service account
  		// as described in https://kubernetes.io/docs/admin/service-accounts-admin/
  		kcfg, err = rest.InClusterConfig()
  		if err != nil {
  			return nil, err
  		}
  		level.Info(l).Log("msg", "Using pod service account via in-cluster config")
  	} else {
  		rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "kubernetes_sd")
  		if err != nil {
  			return nil, err
  		}
  		kcfg = &rest.Config{
  			Host:      conf.APIServer.String(),
  			Transport: rt,
  		}
  	}
  
  	kcfg.UserAgent = "Prometheus/discovery"
  
  	c, err := kubernetes.NewForConfig(kcfg)
  	if err != nil {
  		return nil, err
  	}
  	return &Discovery{
  		client:             c,
  		logger:             l,
  		role:               conf.Role,
  		namespaceDiscovery: &conf.NamespaceDiscovery,
  		discoverers:        make([]discoverer, 0),
  	}, nil
  }
docs: // New creates a new Kubernetes discovery for the given role.