Skip to content

Instantly share code, notes, and snippets.

@niqdev
Last active October 2, 2019 11:09
Show Gist options
  • Save niqdev/fffc1b27f50cbc6436e264b8d48a1b62 to your computer and use it in GitHub Desktop.
Save niqdev/fffc1b27f50cbc6436e264b8d48a1b62 to your computer and use it in GitHub Desktop.
Generate ArgoCD helm chart
#!/bin/bash
PREFIX="argo-cd-"
INSTALL_FILE="install.yaml"
TEMPLATES_PATH="templates/"
# reset templates
rm -fr ${TEMPLATES_PATH}
mkdir -p ${TEMPLATES_PATH}
cd ${TEMPLATES_PATH}
# https://argoproj.github.io/argo-cd/getting_started/#1-install-argo-cd
curl -s -o ${INSTALL_FILE} https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# split by resource type
split -p "---" -a 3 ${INSTALL_FILE} ${PREFIX}
function extract_file_name {
local FILE=$1
# extract second column from lines starting with "kind"
# prefix upper case with dash
# convert upper to lower case
# add file extension
awk '/^kind/ { print $2 }' $FILE |
sed 's/\(.\)\([A-Z]\)/\1-\2/g' |
tr '[:upper:]' '[:lower:]' |
awk '{ print $1".yaml" }'
}
# append content to file of the same resource type
for FILE in ${PREFIX}*; do
FILE_NAME=$(extract_file_name $FILE)
cat $FILE >> $FILE_NAME
done
# remove comment
find . -type f -name '*.yaml' -exec sed -i '.orig' 's/^.*DO NOT EDIT$/---/' {} \;
# cleanup
rm ${INSTALL_FILE}
rm ${PREFIX}*
rm *".orig"
@niqdev
Copy link
Author

niqdev commented May 18, 2019

charts/
└── argocd
    ├── Chart.yaml
    ├── split-templates-macos.sh
    ├── templates # <<<<<<<<<<<<<<<<<<<< generated
    │   ├── cluster-role-binding.yaml
    │   ├── cluster-role.yaml
    │   ├── config-map.yaml
    │   ├── custom-resource-definition.yaml
    │   ├── deployment.yaml
    │   ├── role-binding.yaml
    │   ├── role.yaml
    │   ├── secret.yaml
    │   ├── service-account.yaml
    │   └── service.yaml
    └── values.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment