@@ -18,14 +18,34 @@ set -o errexit
1818set -o nounset
1919set -o pipefail
2020
21- SCRIPT_ROOT=$( dirname ${BASH_SOURCE} ) /..
22-
2321function print_help {
2422 echo " ERROR! Usage: vpa-process-yaml.sh <YAML files>+"
2523 echo " Script will output content of YAML files separated with YAML document"
2624 echo " separator and substituting REGISTRY and TAG for pod images"
2725}
2826
27+ # Requires input from stdin, otherwise hangs. Checks for "admission-controller", "updater", or "recommender", and
28+ # applies the respective kubectl patch command to add the feature gates specified in the FEATURE_GATES environment variable.
29+ # e.g. cat file.yaml | apply_feature_gate
30+ function apply_feature_gate() {
31+ local input=" "
32+ while IFS= read -r line; do
33+ input+=" $line " $' \n '
34+ done
35+
36+ if [ -n " ${FEATURE_GATES} " ]; then
37+ if echo " $input " | grep -q " admission-controller" ; then
38+ echo " $input " | kubectl patch --type=json --local -p=' [{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--feature-gates=' " ${FEATURE_GATES} " ' "}]' -o yaml -f -
39+ elif echo " $input " | grep -q " updater" || echo " $input " | grep -q " recommender" ; then
40+ echo " $input " | kubectl patch --type=json --local -p=' [{"op": "add", "path": "/spec/template/spec/containers/0/args", "value": ["--feature-gates=' " ${FEATURE_GATES} " ' "]}]' -o yaml -f -
41+ else
42+ echo " $input "
43+ fi
44+ else
45+ echo " $input "
46+ fi
47+ }
48+
2949if [ $# -eq 0 ]; then
3050 print_help
3151 exit 1
@@ -36,6 +56,7 @@ DEFAULT_TAG="1.3.0"
3656
3757REGISTRY_TO_APPLY=${REGISTRY-$DEFAULT_REGISTRY }
3858TAG_TO_APPLY=${TAG-$DEFAULT_TAG }
59+ FEATURE_GATES=${FEATURE_GATES:- " " }
3960
4061if [ " ${REGISTRY_TO_APPLY} " != " ${DEFAULT_REGISTRY} " ]; then
4162 (>&2 echo " WARNING! Using image repository from REGISTRY env variable (${REGISTRY_TO_APPLY} ) instead of ${DEFAULT_REGISTRY} ." )
@@ -46,7 +67,6 @@ if [ "${TAG_TO_APPLY}" != "${DEFAULT_TAG}" ]; then
4667fi
4768
4869for i in $* ; do
49- sed -e " s,${DEFAULT_REGISTRY} /\([a-z-]*\):.*,${REGISTRY_TO_APPLY} /\1:${TAG_TO_APPLY} ," $i
50- echo " "
70+ sed -e " s,${DEFAULT_REGISTRY} /\([a-z-]*\):.*,${REGISTRY_TO_APPLY} /\1:${TAG_TO_APPLY} ," $i | apply_feature_gate
5171 echo " ---"
5272done
0 commit comments