Skip to content

Instantly share code, notes, and snippets.

@hatembentayeb
Created October 24, 2023 20:53
Show Gist options
  • Save hatembentayeb/9970d7f25f3f67d7c85dccc15b76b173 to your computer and use it in GitHub Desktop.
Save hatembentayeb/9970d7f25f3f67d7c85dccc15b76b173 to your computer and use it in GitHub Desktop.
generate argocd app of apps from an existing project/applications
#!/bin/bash
output_file="all_applications-$project_name.yaml"
echo "" > "$output_file"
project_yaml=$(kubectl get AppProject "$project_name" -n argocd -o yaml)
updated_project_yaml=$(echo "$project_yaml" | yq eval 'del(.metadata.creationTimestamp, .metadata.generation, .metadata.resourceVersion,.status, .metadata.uid, .metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' -)
echo "$updated_project_yaml" >> "$output_file"
echo '---' >> "$output_file"
for app_name in $(kubectl get applications -n argocd -o custom-columns=:.metadata.name --no-headers); do
app_yaml=$(kubectl get application "$app_name" -n argocd -o yaml)
is_matching=$(echo "$app_yaml" | yq e '.spec.project == env(project_name)' -)
if [ "$is_matching" = "true" ]; then
updated_yaml=$(echo "$app_yaml" | yq eval 'del(.metadata.creationTimestamp, .metadata.generation, .metadata.resourceVersion, .metadata.uid, .status, .metadata.annotations."notified.notifications.argoproj.io", .metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' -)
echo "$updated_yaml" >> "$output_file"
echo '---' >> "$output_file"
fi
done
# Run the script
# chmod +x argocd-app-of-apps-generation.sh
# project_name=<put-the-project-name-here> ./argocd-app-of-apps-generation.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment