Generates YAML list of ArgoCD resources to whitelist for both Cluster and Namespace for an ArgoCD argoproj.io/v1alpha1 AppProject
This is needed if using whitelists in ArgoCD 2.2+ because they restrict showing the child objects unless they are whitelists if using whitelists
Dumps all API object resources from the current Kubernetes cluster context into YAML format to put straight into argocd-project.yaml
If an argocd-project.yaml is given, parses it for existing resource whitelist, merges the two lists in sorted order by Kind and then updates the yaml with an in-place edit
You should have revision controlled your yaml file in Git before you do this - both as a backup of the last good version as well as to see the difference of the edited file
Requires kubectl to be installed and configured, and also yq if a yaml file is given
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="[<argocd-project.yaml>]"
help_usage "$@"
max_args 1"$@"
yaml_file="${1:-}"
api_resources="$(
# there is no -o json as of Kubernetes 1.27
kubectl api-resources |
# strip header line
tail -n +2 || : # ignore this error:
# error: unable to retrieve the complete list of server APIs: external.metrics.k8s.io/v1beta1: received empty response for: external.metrics.k8s.io/v1beta1
)"
if[ -n "$yaml_file"];then
[ -f "$yaml_file"]|| die "Given YAML file does not exist: $yaml_file"