Created
October 24, 2023 20:53
-
-
Save hatembentayeb/9970d7f25f3f67d7c85dccc15b76b173 to your computer and use it in GitHub Desktop.
generate argocd app of apps from an existing project/applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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