Skip to content

Commit

Permalink
Add step to patchthe ArgoCD CR
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Jun 26, 2024
1 parent 6cc397a commit 22b27ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ Options:
kubectl label namespace <MY_NAMESPACE> \
argocd.argoproj.io/managed-by=<argocd_namespace>
```
- Patch the ArgoCD CR to add your namespace using the parameter: `sourceNamespaces`
```bash
NAMESPACE="<MY-NAMESPACE>"
ARGOCD_NAME="argocd"
NAMESPACE_ARGOCD="openshift-gitops"
# Fetch the current ArgoCD resource
ARGOCD_JSON=$(kubectl get argocd $ARGOCD_NAME -n $NAMESPACE_ARGOCD -o json)
# Check if the namespace is already in the sourceNamespaces array
if echo "$ARGOCD_JSON" | jq -e --arg ns "$NAMESPACE" '.spec.sourceNamespaces | index($ns)' > /dev/null; then
echo "Namespace '$NAMESPACE' already exists in sourceNamespaces."
else
echo "Adding namespace '$NAMESPACE' to sourceNamespaces."
PATCH=$(echo "$ARGOCD_JSON" | jq --arg ns "$NAMESPACE" '.spec.sourceNamespaces += [$ns] | {spec: {sourceNamespaces: .spec.sourceNamespaces}}')
kubectl patch argocd $ARGOCD_NAME -n $NAMESPACE_ARGOCD --type merge --patch "$PATCH"
fi
```
- Patch also the default `AppProject` to support to deploy the Applications CR in different namespaces.
```bash
kubectl get AppProject/default -n openshift-gitops -o json | jq '.spec.sourceNamespaces += ["*"]' | kubectl apply -f -
```
- And finally, create the service account `my-backstage` and give it `admin` rights using the following RBAC to access the Kubernetes API resources.
```bash
kubectl create sa my-backstage
Expand Down
1 change: 1 addition & 0 deletions manifest/installation/gitops/argocd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ spec:
cpu: 250m
memory: 128Mi
provider: dex
sourceNamespaces: {}
tls:
ca: {}
15 changes: 15 additions & 0 deletions scripts/provision-namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,18 @@ fi

echo "### Apply the label: argocd.argoproj.io/managed-by=<argocd_namespace> on your namespace"
execute_kubectl "label namespace $NAMESPACE argocd.argoproj.io/managed-by=openshift-gitops"

echo "### Adding your namespace to the parameter: sourceNamespaces of the ArgoCD CR ..."
ARGOCD_NAME="argocd"
NAMESPACE_ARGOCD="openshift-gitops"

# Fetch the current ArgoCD resource
ARGOCD_JSON=$(kubectl get argocd $ARGOCD_NAME -n $NAMESPACE_ARGOCD -o json)

if echo "$ARGOCD_JSON" | jq -e --arg ns "$NAMESPACE" '.spec.sourceNamespaces | index($ns)' > /dev/null; then
echo "Namespace '$NAMESPACE' already exists in sourceNamespaces."
else
echo "Adding namespace '$NAMESPACE' to sourceNamespaces."
PATCH=$(echo "$ARGOCD_JSON" | jq --arg ns "$NAMESPACE" '.spec.sourceNamespaces += [$ns] | {spec: {sourceNamespaces: .spec.sourceNamespaces}}')
kubectl patch argocd $ARGOCD_NAME -n $NAMESPACE_ARGOCD --type merge --patch "$PATCH"
fi

0 comments on commit 22b27ea

Please sign in to comment.