Skip to content

Commit 238fdb0

Browse files
committed
VPA: fixup vpa-process-yaml.sh script
The script needs to also check if the yaml input is a Deployment, and no longer needs to check for vpa-component names. Signed-off-by: Max Cao <[email protected]>
1 parent cf14055 commit 238fdb0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

vertical-pod-autoscaler/hack/vpa-process-yaml.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ function print_help {
2424
echo "separator and substituting REGISTRY and TAG for pod images"
2525
}
2626

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.
27+
# Requires input from stdin, otherwise hangs. If the input is a Deployment manifest,
28+
# apply kubectl patch to add feature gates specified in the FEATURE_GATES environment variable.
2929
# e.g. cat file.yaml | apply_feature_gate
3030
function apply_feature_gate() {
3131
local input=""
3232
while IFS= read -r line; do
3333
input+="$line"$'\n'
3434
done
3535

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 -
36+
# matching precisely "kind: Deployment" to avoid matching "kind: DeploymentConfig" or a line with extra whitespace
37+
if echo "$input" | grep -qE '^kind: Deployment$'; then
38+
if [ -n "${FEATURE_GATES}" ]; then
39+
if ! 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 - 2>/dev/null; then
40+
# If it fails, there was no args field, so we need to add it
41+
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 -
42+
fi
4143
else
4244
echo "$input"
4345
fi

0 commit comments

Comments
 (0)