github.com/argoproj-labs/argocd-operator@v0.10.0/docs/usage/deploy-to-different-namespaces.md (about)

     1  # Deploy resources to a different namespace
     2  
     3  To grant Argo CD the permissions to manage resources in multiple namespaces, we need to configure the namespace with a label `argocd.argoproj.io/managed-by` and the value being the namespace of the managing Argo CD instance.
     4  
     5  For example, If Argo CD instance deployed in the namespace `foo` wants to manage resources in namespace `bar`. Update the namespace `bar` as shown below.
     6  
     7  ```yml
     8  apiVersion: v1
     9  kind: Namespace
    10  metadata:
    11    name: bar
    12    labels:
    13      argocd.argoproj.io/managed-by: foo // namespace of managing Argo CD instance
    14  ```
    15  !!! note
    16      The above described method assumes that the user has admin privileges on their cluster, which would allow them to apply labels to namespaces. 
    17  
    18  
    19  Alternatively, users can achieve the same behavior by leveraging the `.spec.syncPolicy` field of an application. SyncPolicy allows users to have a namespace created  with certain labels pre-configured at the time of application sync. Consider the following example Application:
    20  
    21  ```yaml
    22  apiVersion: argoproj.io/v1alpha1
    23  kind: Application
    24  metadata:
    25    name: guestbook
    26    namespace: argocd
    27  spec:
    28    syncPolicy:
    29      managedNamespaceMetadata:
    30        labels:
    31          argocd.argoproj.io/managed-by: foo // namespace of managing Argo CD instance 
    32      syncOptions:
    33      - CreateNamespace=true
    34    destination:
    35      server: https://kubernetes.default.svc
    36      namespace: bar 
    37  ```
    38  
    39  The above described application will create a new namespace `bar` carrying a label `argocd.arogproj.io/managed-by: foo` at the time of application sync, and then deploy application resources in it, without requiring the user to be able to label namespace `bar` manually.
    40  
    41  Users creating applications using the Argo CD UI instead of CLI must check the "auto-create namespace" box, and then switch to the yaml editor to add the label into `.spec.syncPolicy.managedNamespaceMetadata.labels` as described above.
    42  
    43  A few points to keep in mind:
    44  
    45  - This method requires that the user create the namespace at app sync time using `createNamespace=true` or checking the `auto-create namespace` box in the UI, and not include their own namespace manifest in their git repository. 
    46  - A destination namespace must be set in `.spec.destination.namespace` 
    47  - Users should have admin privileges and/or access to a cluster scoped Argo CD instance  
    48  
    49  See https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/#namespace-metadata for more information 
    50  
    51  !!! note
    52      There is a possibility that sync might fail at first try when using the above method. In such cases a follow up sync should be successful