// getMatchingClusters examines the kubeconfig for all clusters that point to the same server
327059
func getMatchingClusters(clientConfig restclient.Config, kubeconfig clientcmdapi.Config) sets.String {
	ret := sets.String{}

	for key, cluster := range kubeconfig.Clusters {
		if (cluster.Server == clientConfig.Host) && (cluster.InsecureSkipTLSVerify == clientConfig.Insecure) && (cluster.CertificateAuthority == clientConfig.CAFile) && (bytes.Compare(cluster.CertificateAuthorityData, clientConfig.CAData) == 0) {
			ret.Insert(key)
		}
	}

	return ret
}
699227
func GetClusterConfigSchema(extensionSchema string) string {
	var clusterConfigSchema string
	if clusterConfigSchema == "" {
		clusterConfigSchema = fmt.Sprintf(ClusterConfigSpecSchemaTemplate, "")
	} else {
		clusterConfigSchema = fmt.Sprintf(ClusterConfigSpecSchemaTemplate, ","+extensionSchema)
	}
	return fmt.Sprintf(V2SchemaTemplate, MetadataSchema, clusterConfigSchema, DefaultDefinitions)
}
953604
func GetSupportedClusterVersions(host string) ([]string, error) {
	if host == "" {
		host = client.GetUnixServerPath(OsdSocket, cluster.APIBase)
	}
	client, err := client.NewClient(host, "", "")
	if err != nil {
		return []string{}, err
	}
	versions, err := client.Versions("cluster")
	if err != nil {
		return []string{}, err
	}
	return versions, nil
}
704944
func (manager *configManager) GetClusterConf() (*ClusterConfig, error) {
	// get json from kvdb and unmarshal into config
	kvPair, err := manager.kv.Get(filepath.Join(baseKey, clusterKey))
	if err != nil {
		return nil, err
	}

	config := new(ClusterConfig)
	if err := json.Unmarshal(kvPair.Value, config); err != nil {
		return nil, err
	}

	return config, nil
}
947569
func NewClusterConfig(spec ClusterConfigSpecV3) (ClusterConfig, error) {
	cc := ClusterConfigV3{
		Kind:    KindClusterConfig,
		Version: V3,
		Metadata: Metadata{
			Name:      MetaNameClusterConfig,
			Namespace: defaults.Namespace,
		},
		Spec: spec,
	}
	if err := cc.CheckAndSetDefaults(); err != nil {
		return nil, trace.Wrap(err)
	}

	return &cc, nil
}
1010491
func (c *Conn) GetClusterStats() (stat ClusterStat, err error) {
	if err := c.ensure_connected(); err != nil {
		return ClusterStat{}, err
	}
	c_stat := C.struct_rados_cluster_stat_t{}
	ret := C.rados_cluster_stat(c.cluster, &c_stat)
	if ret < 0 {
		return ClusterStat{}, RadosError(int(ret))
	} else {
		return ClusterStat{
			Kb:          uint64(c_stat.kb),
			Kb_used:     uint64(c_stat.kb_used),
			Kb_avail:    uint64(c_stat.kb_avail),
			Num_objects: uint64(c_stat.num_objects),
		}, nil
	}
}
397950
func (s *APIServer) getRemoteClusters(auth ClientI, w http.ResponseWriter, r *http.Request, p httprouter.Params, version string) (interface{}, error) {
	clusters, err := auth.GetRemoteClusters()
	if err != nil {
		return nil, trace.Wrap(err)
	}
	items := make([]json.RawMessage, len(clusters))
	for i, cluster := range clusters {
		data, err := services.MarshalRemoteCluster(cluster, services.WithVersion(version), services.PreserveResourceID())
		if err != nil {
			return nil, trace.Wrap(err)
		}
		items[i] = data
	}
	return items, nil
}
1040363
func (f *ToolsFinder) findMatchingTools(args params.FindToolsParams) (coretools.List, error) {
	exactMatch := args.Number != version.Zero && args.Series != "" && args.Arch != ""
	storageList, err := f.matchingStorageTools(args)
	if err == nil && exactMatch {
		return storageList, nil
	} else if err != nil && err != coretools.ErrNoMatches {
		return nil, err
	}

	// Look for tools in simplestreams too, but don't replace
	// any versions found in storage.
	env, err := environs.GetEnviron(f.configGetter, environs.New)
	if err != nil {
		return nil, err
	}
	filter := toolsFilter(args)
	cfg := env.Config()
	requestedStream := cfg.AgentStream()
	if args.AgentStream != "" {
		requestedStream = args.AgentStream
	}
	streams := envtools.PreferredStreams(&args.Number, cfg.Development(), requestedStream)
	simplestreamsList, err := envtoolsFindTools(
		env, args.MajorVersion, args.MinorVersion, streams, filter,
	)
	if len(storageList) == 0 && err != nil {
		return nil, err
	}

	list := storageList
	found := make(map[version.Binary]bool)
	for _, tools := range storageList {
		found[tools.Version] = true
	}
	for _, tools := range simplestreamsList {
		if !found[tools.Version] {
			list = append(list, tools)
		}
	}
	sort.Sort(list)
	return list, nil
}
1003704
func (_class ClusterClass) GetAll(sessionID SessionRef) (_retval []ClusterRef, _err error) {
	_method := "Cluster.get_all"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertClusterRefSetToGo(_method + " -> ", _result.Value)
	return
}
984178
func (o *objectCountEvaluator) MatchingResources(input []corev1.ResourceName) []corev1.ResourceName {
	return quota.Intersection(input, o.resourceNames)
}
194761
func findRandomUnusuedGKECluster(clusterMap *Map, leaseMap *leases.Map) (*container.Cluster, error) {
	clusterNames := clusterMap.Names()
	if len(clusterNames) > 0 {
		for tries := 0; tries < 10; tries++ {
			clusterName := clusterNames[rand.Intn(len(clusterNames))]
			cluster, err := checkLease(clusterMap, leaseMap, clusterName)
			if err == nil {
				return cluster, nil
			}
		}
	}
	return nil, errUnusedGKEClusterNotFound
}
840340
func (c *Cache) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error) {
	config, err := c.clusterConfigCache.GetClusterConfig(services.AddOptions(opts, services.SkipValidation())...)
	if trace.IsNotFound(err) {
		return c.ClusterConfig.GetClusterConfig(opts...)
	}
	return config, err
}
248891
func findUnusedClusterByVersion(clusterMap *Map, leaseMap *leases.Map, clusterVersion string) (*containerservice.ContainerService, error) {
	clusterNames := clusterMap.ClusterNamesByVersion(clusterVersion)
	if len(clusterNames) > 0 {
		for tries := 0; tries < 10; tries++ {
			clusterName := clusterNames[rand.Intn(len(clusterNames))]
			cluster, err := checkLease(clusterMap, leaseMap, clusterName)
			if err == nil {
				return cluster, nil
			}
		}
	}
	return nil, errUnusedAzureClusterNotFound
}
447532
func (c *cache) fetchClusters(ctx context.Context) (map[string]cluster.Cluster, error) {
	signer := newJWTSASigner(ctx, c.config, c.options...)
	cln, err := signer.createSignedClient()
	if err != nil {
		return nil, err
	}

	res, err := cln.ShowAuthClientClusters(goasupport.ForwardContextRequestID(ctx), clusterclient.ShowAuthClientClustersPath())
	if err != nil {
		return nil, err
	}
	defer rest.CloseResponse(res)

	if res.StatusCode != http.StatusOK {
		bodyString := rest.ReadBody(res.Body)
		log.Error(ctx, map[string]interface{}{
			"response_status": res.Status,
			"response_body":   bodyString,
		}, "unable to get clusters from Cluster Management Service")
		return nil, errors.Errorf("unable to get clusters from Cluster Management Service. Response status: %s. Response body: %s", res.Status, bodyString)
	}

	clusters, err := cln.DecodeFullClusterList(res)
	if err != nil {
		return nil, err
	}

	clusterMap := map[string]cluster.Cluster{}
	if clusters.Data != nil {
		for _, d := range clusters.Data {
			cls := cluster.Cluster{
				Name:                   d.Name,
				APIURL:                 d.APIURL,
				AppDNS:                 d.AppDNS,
				ConsoleURL:             d.ConsoleURL,
				LoggingURL:             d.LoggingURL,
				MetricsURL:             d.MetricsURL,
				TokenProviderID:        d.TokenProviderID,
				AuthClientDefaultScope: d.AuthClientDefaultScope,
				AuthClientID:           d.AuthClientID,
				AuthClientSecret:       d.AuthClientSecret,
				ServiceAccountUsername: d.ServiceAccountUsername,
				ServiceAccountToken:    d.ServiceAccountToken,
				CapacityExhausted:      d.CapacityExhausted,
			}
			clusterMap[rest.AddTrailingSlashToURL(cls.APIURL)] = cls
		}
	}
	return clusterMap, nil
}
847673
func (_class ClusterHostClass) GetCluster(sessionID SessionRef, self ClusterHostRef) (_retval ClusterRef, _err error) {
	_method := "Cluster_host.get_cluster"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertClusterHostRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertClusterRefToGo(_method + " -> ", _result.Value)
	return
}
569221
func (s *ClusterConfigurationService) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error) {
	item, err := s.Get(context.TODO(), backend.Key(clusterConfigPrefix, generalPrefix))
	if err != nil {
		if trace.IsNotFound(err) {
			return nil, trace.NotFound("cluster configuration not found")
		}
		return nil, trace.Wrap(err)
	}
	return services.GetClusterConfigMarshaler().Unmarshal(item.Value,
		services.AddOptions(opts, services.WithResourceID(item.ID),
			services.WithExpires(item.Expires))...)
}
768216
func (s *NoopStatusStore) FindClusterStatus(cluster *Cluster) (*ClusterStatus, error) {
	glog.Warningf("FindClusterStatus called on NoopStore")
	return nil, nil
}