// NewNamespaces reads from /proc/[pid/ns/* to get the namespaces of which the
// process is a member.
432997
func (p Proc) NewNamespaces() (Namespaces, error) {
	d, err := os.Open(p.path("ns"))
	if err != nil {
		return nil, err
	}
	defer d.Close()

	names, err := d.Readdirnames(-1)
	if err != nil {
		return nil, fmt.Errorf("failed to read contents of ns dir: %v", err)
	}

	ns := make(Namespaces, len(names))
	for _, name := range names {
		target, err := os.Readlink(p.path("ns", name))
		if err != nil {
			return nil, err
		}

		fields := strings.SplitN(target, ":", 2)
		if len(fields) != 2 {
			return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", target)
		}

		typ := fields[0]
		inode, err := strconv.ParseUint(strings.Trim(fields[1], "[]"), 10, 32)
		if err != nil {
			return nil, fmt.Errorf("failed to parse inode from '%v': %v", fields[1], err)
		}

		ns[name] = Namespace{typ, uint32(inode)}
	}

	return ns, nil
}
428642
func (s *OptionSpecification) SetNamespace(v string) *OptionSpecification {
	s.Namespace = &v
	return s
}
160894
func New(deps *deps.Deps) *Namespace {
	cache := namedmemcache.New()
	deps.BuildStartListeners.Add(
		func() {
			cache.Clear()
		})

	return &Namespace{
		cache: cache,
		deps:  deps,
	}
}
44810
func (r *RoleV3) GetNamespaces(rct RoleConditionType) []string {
	if rct == Allow {
		return r.Spec.Allow.Namespaces
	}
	return r.Spec.Deny.Namespaces
}
95816
func (s *SystemControl) SetNamespace(v string) *SystemControl {
	s.Namespace = &v
	return s
}
316794
func New(deps *deps.Deps) *Namespace {

	return &Namespace{
		deps:         deps,
		cacheGetCSV:  deps.FileCaches.GetCSVCache(),
		cacheGetJSON: deps.FileCaches.GetJSONCache(),
		client:       http.DefaultClient,
	}
}
330559
func (s *MetricAlarm) SetNamespace(v string) *MetricAlarm {
	s.Namespace = &v
	return s
}
243187
func (k *kubernetesClient) getNamespaceByName(name string) (*core.Namespace, error) {
	ns, err := k.client().CoreV1().Namespaces().Get(name, v1.GetOptions{IncludeUninitialized: true})
	if k8serrors.IsNotFound(err) {
		return nil, errors.NotFoundf("namespace %q", name)
	}
	if err != nil {
		return nil, errors.Annotatef(err, "getting namespace %q", name)
	}
	return ns, nil
}
150141
func NameSystems() namer.NameSystems {
	return namer.NameSystems{
		"public":          namer.NewPublicNamer(1),
		"raw":             namer.NewRawNamer("", nil),
		"defaultfn":       defaultFnNamer(),
		"objectdefaultfn": objectDefaultFnNamer(),
	}
}
663022
func (k *kubernetesClient) Namespaces() ([]string, error) {
	namespaces := k.client().CoreV1().Namespaces()
	ns, err := namespaces.List(v1.ListOptions{IncludeUninitialized: true})
	if err != nil {
		return nil, errors.Annotate(err, "listing namespaces")
	}
	result := make([]string, len(ns.Items))
	for i, n := range ns.Items {
		if err := checkNamespaceOwnedByJuju(&n, k.annotations); err != nil {
			continue
		}
		result[i] = n.Name
	}
	return result, nil
}
26782
func (c *Config) WriteNamespaces(w quad.Writer, n *voc.Namespaces) error {
	rules, err := c.rulesFor(reflect.TypeOf(namespace{}))
	if err != nil {
		return fmt.Errorf("can't load rules: %v", err)
	}
	wr := c.newWriter(w)
	for _, ns := range n.List() {
		obj := namespace{
			Full:   quad.IRI(ns.Full),
			Prefix: quad.IRI(ns.Prefix),
		}
		rv := reflect.ValueOf(obj)
		if err = wr.writeValueAs(obj.Full, rv, "", rules); err != nil {
			return err
		}
	}
	return nil
}
1096367
func (a *AuthWithRoles) GetNamespace(name string) (*services.Namespace, error) {
	if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbRead); err != nil {
		return nil, trace.Wrap(err)
	}
	return a.authServer.GetNamespace(name)
}
275339
func deleteNamespaces(namespaces k8s.NamespaceListerDeleter, skip map[string]struct{}) error {
	namespacesList, err := namespaces.List(v1.ListOptions{})
	if err != nil {
		return errListNamespaces{origErr: err}
	}
	// TODO: delete concurrently https://github.com/deis/k8s-claimer/issues/49
	var errs []error
	for _, namespace := range namespacesList.Items {
		_, inSkip := skip[namespace.Name]
		_, isDefault := skipDeleteNamespaces[namespace.Name]
		if !isDefault && !inSkip {
			if err := namespaces.Delete(namespace.Name, &v1.DeleteOptions{}); err != nil {
				errs = append(errs, err)
			}
		}
	}
	if len(errs) > 0 {
		return errDeleteNamespaces{origErrs: errs}
	}
	return nil
}
532833
func (v *version) Namespaces() NamespaceInformer {
	return &namespaceInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
138159
func NewNamespace() Namespace {
	return &namespace{
		taken: make(map[string]struct{}),
		gave:  make(map[string][]string),
	}
}
599655
func (f *Factory) Namespace(scope metrics.NSOptions) metrics.Factory {
	newFactory := &Factory{
		factories: make([]metrics.Factory, len(f.factories)),
	}
	for i, factory := range f.factories {
		newFactory.factories[i] = factory.Namespace(scope)
	}
	return newFactory
}
452580
func Namespace(c context.Context, namespace string) (context.Context, error) {
	if !validNamespace.MatchString(namespace) {
		return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace)
	}
	n := &namespacedContext{
		ctx:       c,
		namespace: namespace,
	}
	return internal.WithNamespace(internal.WithCallOverride(c, n.call), namespace), nil
}