A NamespaceSelector is an Anthos Config Management (ACM) object that selects namespaces using Kubernetes labels. A namespace-scoped configuration can reference the selector to deploy the same object to multiple matching namespaces. section 11.2.1 section 11.3.1
NamespaceSelectors are primarily useful in unstructured repositories. In a hierarchy repository, a selector adds a restriction to inheritance: a namespace must both be below the folder containing the object and match the selector. section 11.2.1 section 11.2.2
Select production namespaces
Define a selector named production that matches the label env: production. A namespace-scoped Role can then reference that selector through the configmanagement.gke.io/namespace-selector annotation, applying one configuration to matching namespaces. In an unstructured repository, each namespace-scoped object must either specify metadata.namespace directly or use a NamespaceSelector. section 11.3.1
kind: NamespaceSelector
apiVersion: configmanagement.gke.io/v1
metadata:
name: production
spec:
selector:
matchLabels:
env: production
The production NamespaceSelector defines its label match. section 11.3.1
apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: prod-developer annotations: configmanagement.gke.io/namespace-selector: production rules: - apiGroups: [""] resources: ["pods", "configmaps"] verbs: ["get", "watch", "list"] - apiGroups: ["apps", "extensions"] resources: ["deployments", "replicasets"] verbs: ["get", "watch", "list"] - apiGroups: [""] resources: ["secrets"] verbs: ["list"]
The production Role references the selector by annotation. section 11.3.1
Selection depends on namespace labels being present and valid. Policy Controller constraints can require labels such as environment and team and restrict their allowed values. A selector can also target a namespace normally expected to be unique, avoiding massive changes to team configurations when a new project is created. section 11.3.1

