// Returns a ConfigPolicyNode that is a merged version of the namespace provided.
166970
func (c *ConfigPolicy) Get(ns []string) *ConfigPolicyNode {

	n := c.config.Get(ns)
	if n == nil {
		return NewPolicyNode()
	}
	switch t := n.(type) {
	case ConfigPolicyNode:
		return &t
	default:
		return t.(*ConfigPolicyNode)
	}
}
940225
func Namespace(ctx context.Context) (string, bool) {
	namespace, ok := ctx.Value(namespaceKey{}).(string)
	if !ok {
		return fromGRPCHeader(ctx)
	}

	return namespace, ok
}
952236
func WithNamespace(namespace string) SharedInformerOption {
	return func(factory *sharedInformerFactory) *sharedInformerFactory {
		factory.namespace = namespace
		return factory
	}
}
1167442
func MergeConfig(startingConfig, addition clientcmdapi.Config) (*clientcmdapi.Config, error) {
	ret := startingConfig

	for requestedKey, value := range addition.Clusters {
		ret.Clusters[requestedKey] = value
	}

	for requestedKey, value := range addition.AuthInfos {
		ret.AuthInfos[requestedKey] = value
	}

	requestedContextNamesToActualContextNames := map[string]string{}
	for requestedKey, newContext := range addition.Contexts {
		actualContext := clientcmdapi.NewContext()
		actualContext.AuthInfo = newContext.AuthInfo
		actualContext.Cluster = newContext.Cluster
		actualContext.Namespace = newContext.Namespace
		actualContext.Extensions = newContext.Extensions

		if existingName := findExistingContextName(startingConfig, *actualContext); len(existingName) > 0 {
			// if this already exists, just move to the next, our job is done
			requestedContextNamesToActualContextNames[requestedKey] = existingName
			continue
		}

		requestedContextNamesToActualContextNames[requestedKey] = requestedKey
		ret.Contexts[requestedKey] = actualContext
	}

	if len(addition.CurrentContext) > 0 {
		if newCurrentContext, exists := requestedContextNamesToActualContextNames[addition.CurrentContext]; exists {
			ret.CurrentContext = newCurrentContext
		} else {
			ret.CurrentContext = addition.CurrentContext
		}
	}

	return &ret, nil
}
165170
func EnableDynamicConfigForNode(client clientset.Interface, nodeName string, kubeletVersion *version.Version) error {

	configMapName := kubeadmconstants.GetKubeletConfigMapName(kubeletVersion)
	fmt.Printf("[kubelet] Enabling Dynamic Kubelet Config for Node %q; config sourced from ConfigMap %q in namespace %s\n",
		nodeName, configMapName, metav1.NamespaceSystem)
	fmt.Println("[kubelet] WARNING: The Dynamic Kubelet Config feature is beta, but off by default. It hasn't been well-tested yet at this stage, use with caution.")

	_, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(configMapName, metav1.GetOptions{})
	if err != nil {
		return errors.Wrap(err, "couldn't get the kubelet configuration ConfigMap")
	}

	// Loop on every falsy return. Return with an error if raised. Exit successfully if true is returned.
	return apiclient.PatchNode(client, nodeName, func(n *v1.Node) {
		patchNodeForDynamicConfig(n, configMapName)
	})
}
615038
func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfig) ([]swarm.ConfigSpec, error) {
	result := []swarm.ConfigSpec{}
	for name, config := range configs {
		if config.External.External {
			continue
		}

		data, err := ioutil.ReadFile(config.File)
		if err != nil {
			return nil, err
		}

		result = append(result, swarm.ConfigSpec{
			Annotations: swarm.Annotations{
				Name:   namespace.Scope(name),
				Labels: AddStackLabel(namespace, config.Labels),
			},
			Data: data,
		})
	}
	return result, nil
}
225196
func (bc *BuildController) findOwnedConfigMap(owner *corev1.Pod, namespace string, name string) (bool, error) {
	cm, err := bc.configMapClient.ConfigMaps(namespace).Get(name, metav1.GetOptions{})
	if err != nil && errors.IsNotFound(err) {
		return false, nil
	} else if err != nil {
		return false, err
	}
	if hasRef := hasBuildPodOwnerRef(owner, cm); !hasRef {
		return true, fmt.Errorf("configMap %s/%s is not owned by build pod %s/%s", cm.Namespace, cm.Name, owner.Namespace, owner.Name)
	}
	return true, nil
}
1262758
func MergeEnvironment(current, newValues map[string]string) map[string]string {
	if current == nil {
		current = make(map[string]string)
	}
	if runtime.GOOS == "windows" {
		return mergeEnvWin(current, newValues)
	}
	return mergeEnvUnix(current, newValues)
}
1049444
func (r *Repo) namespace(ctx context.Context) namespace {
	ns := namespace(eh.NamespaceFromContext(ctx))

	r.cacheMu.Lock()
	defer r.cacheMu.Unlock()
	if _, ok := r.cache[ns]; !ok {
		r.cache[ns] = map[uuid.UUID]eh.Entity{}
	}

	return ns
}
1109392
func (c *configMaps) Get(name string) (result *api.ConfigMap, err error) {
	result = &api.ConfigMap{}
	err = c.client.Get().
		Namespace(c.ns).
		Resource("configmaps").
		Name(name).
		Do().
		Into(result)
	return
}
1003064
func (config *DirectClientConfig) Namespace() (string, bool, error) {
	if config.overrides != nil && config.overrides.Context.Namespace != "" {
		// In the event we have an empty config but we do have a namespace override, we should return
		// the namespace override instead of having config.ConfirmUsable() return an error. This allows
		// things like in-cluster clients to execute `kubectl get pods --namespace=foo` and have the
		// --namespace flag honored instead of being ignored.
		return config.overrides.Context.Namespace, true, nil
	}

	if err := config.ConfirmUsable(); err != nil {
		return "", false, err
	}

	configContext, err := config.getContext()
	if err != nil {
		return "", false, err
	}

	if len(configContext.Namespace) == 0 {
		return "default", false, nil
	}

	return configContext.Namespace, false, nil
}
73262
func ConfigGlobalScopeDefaultNetworks(defaultAddressPool []*NetworkToSplit) error {
	if defaultAddressPool == nil {
		defaultAddressPool = globalScopeDefaultNetworks
	}
	return configDefaultNetworks(defaultAddressPool, &PredefinedGlobalScopeDefaultNetworks)
}
788185
func Merge(c1, c2 *Config) (*Config, error) {
	c := new(Config)

	// Merge unknown keys
	unknowns := make(map[string]struct{})
	for _, k := range c1.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}
	for _, k := range c2.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}

	// Merge Atlas configuration. This is a dumb one overrides the other
	// sort of merge.
	c.Atlas = c1.Atlas
	if c2.Atlas != nil {
		c.Atlas = c2.Atlas
	}

	// Merge the Terraform configuration
	if c1.Terraform != nil {
		c.Terraform = c1.Terraform
		if c2.Terraform != nil {
			c.Terraform.Merge(c2.Terraform)
		}
	} else {
		c.Terraform = c2.Terraform
	}

	// NOTE: Everything below is pretty gross. Due to the lack of generics
	// in Go, there is some hoop-jumping involved to make this merging a
	// little more test-friendly and less repetitive. Ironically, making it
	// less repetitive involves being a little repetitive, but I prefer to
	// be repetitive with things that are less error prone than things that
	// are more error prone (more logic). Type conversions to an interface
	// are pretty low-error.

	var m1, m2, mresult []merger

	// Modules
	m1 = make([]merger, 0, len(c1.Modules))
	m2 = make([]merger, 0, len(c2.Modules))
	for _, v := range c1.Modules {
		m1 = append(m1, v)
	}
	for _, v := range c2.Modules {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Modules = make([]*Module, len(mresult))
		for i, v := range mresult {
			c.Modules[i] = v.(*Module)
		}
	}

	// Outputs
	m1 = make([]merger, 0, len(c1.Outputs))
	m2 = make([]merger, 0, len(c2.Outputs))
	for _, v := range c1.Outputs {
		m1 = append(m1, v)
	}
	for _, v := range c2.Outputs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Outputs = make([]*Output, len(mresult))
		for i, v := range mresult {
			c.Outputs[i] = v.(*Output)
		}
	}

	// Provider Configs
	m1 = make([]merger, 0, len(c1.ProviderConfigs))
	m2 = make([]merger, 0, len(c2.ProviderConfigs))
	for _, v := range c1.ProviderConfigs {
		m1 = append(m1, v)
	}
	for _, v := range c2.ProviderConfigs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.ProviderConfigs = make([]*ProviderConfig, len(mresult))
		for i, v := range mresult {
			c.ProviderConfigs[i] = v.(*ProviderConfig)
		}
	}

	// Resources
	m1 = make([]merger, 0, len(c1.Resources))
	m2 = make([]merger, 0, len(c2.Resources))
	for _, v := range c1.Resources {
		m1 = append(m1, v)
	}
	for _, v := range c2.Resources {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Resources = make([]*Resource, len(mresult))
		for i, v := range mresult {
			c.Resources[i] = v.(*Resource)
		}
	}

	// Variables
	m1 = make([]merger, 0, len(c1.Variables))
	m2 = make([]merger, 0, len(c2.Variables))
	for _, v := range c1.Variables {
		m1 = append(m1, v)
	}
	for _, v := range c2.Variables {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Variables = make([]*Variable, len(mresult))
		for i, v := range mresult {
			c.Variables[i] = v.(*Variable)
		}
	}

	// Local Values
	// These are simpler than the other config elements because they are just
	// flat values and so no deep merging is required.
	if localsCount := len(c1.Locals) + len(c2.Locals); localsCount != 0 {
		// Explicit length check above because we want c.Locals to remain
		// nil if the result would be empty.
		c.Locals = make([]*Local, 0, len(c1.Locals)+len(c2.Locals))
		c.Locals = append(c.Locals, c1.Locals...)
		c.Locals = append(c.Locals, c2.Locals...)
	}

	return c, nil
}
1256572
func (config *DirectClientConfig) Namespace() (string, bool, error) {
	if err := config.ConfirmUsable(); err != nil {
		return "", false, err
	}

	configContext := config.getContext()

	if len(configContext.Namespace) == 0 {
		return api.NamespaceDefault, false, nil
	}

	overridden := false
	if config.overrides != nil && config.overrides.Context.Namespace != "" {
		overridden = true
	}
	return configContext.Namespace, overridden, nil
}
832464
func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfig) ([]swarm.ConfigSpec, error) {
	result := []swarm.ConfigSpec{}
	for name, config := range configs {
		if config.External.External {
			continue
		}

		obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(config))
		if err != nil {
			return nil, err
		}
		spec := swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data}
		if config.TemplateDriver != "" {
			spec.Templating = &swarm.Driver{
				Name: config.TemplateDriver,
			}
		}
		result = append(result, spec)
	}
	return result, nil
}
43538
func getSupportedComponentConfigAPIObjects() []string {
	objects := []string{}
	for componentType := range componentconfigs.Known {
		objects = append(objects, string(componentType))
	}
	return objects
}
1253376
func (c1 *Config) Merge(c2 *Config) *Config {
	var result Config
	result.Providers = make(map[string]string)
	result.Provisioners = make(map[string]string)
	for k, v := range c1.Providers {
		result.Providers[k] = v
	}
	for k, v := range c2.Providers {
		if v1, ok := c1.Providers[k]; ok {
			log.Printf("[INFO] Local %s provider configuration '%s' overrides '%s'", k, v, v1)
		}
		result.Providers[k] = v
	}
	for k, v := range c1.Provisioners {
		result.Provisioners[k] = v
	}
	for k, v := range c2.Provisioners {
		if v1, ok := c1.Provisioners[k]; ok {
			log.Printf("[INFO] Local %s provisioner configuration '%s' overrides '%s'", k, v, v1)
		}
		result.Provisioners[k] = v
	}
	result.DisableCheckpoint = c1.DisableCheckpoint || c2.DisableCheckpoint
	result.DisableCheckpointSignature = c1.DisableCheckpointSignature || c2.DisableCheckpointSignature

	result.PluginCacheDir = c1.PluginCacheDir
	if result.PluginCacheDir == "" {
		result.PluginCacheDir = c2.PluginCacheDir
	}

	if (len(c1.Hosts) + len(c2.Hosts)) > 0 {
		result.Hosts = make(map[string]*ConfigHost)
		for name, host := range c1.Hosts {
			result.Hosts[name] = host
		}
		for name, host := range c2.Hosts {
			result.Hosts[name] = host
		}
	}

	if (len(c1.Credentials) + len(c2.Credentials)) > 0 {
		result.Credentials = make(map[string]map[string]interface{})
		for host, creds := range c1.Credentials {
			result.Credentials[host] = creds
		}
		for host, creds := range c2.Credentials {
			// We just clobber an entry from the other file right now. Will
			// improve on this later using the more-robust merging behavior
			// built in to HCL2.
			result.Credentials[host] = creds
		}
	}

	if (len(c1.CredentialsHelpers) + len(c2.CredentialsHelpers)) > 0 {
		result.CredentialsHelpers = make(map[string]*ConfigCredentialsHelper)
		for name, helper := range c1.CredentialsHelpers {
			result.CredentialsHelpers[name] = helper
		}
		for name, helper := range c2.CredentialsHelpers {
			result.CredentialsHelpers[name] = helper
		}
	}

	return &result
}