|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2025 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -o errexit |
| 18 | +set -o nounset |
| 19 | +set -o pipefail |
| 20 | + |
| 21 | +SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}"))/.. |
| 22 | +TARGET_FILE="${SCRIPT_ROOT}/docs/flags.md" |
| 23 | +COMPONENTS=("admission-controller" "recommender" "updater") |
| 24 | + |
| 25 | +# Function to extract flags from a binary |
| 26 | +extract_flags() { |
| 27 | + local binary=$1 |
| 28 | + local component=$2 |
| 29 | + |
| 30 | + if [ ! -f "$binary" ]; then |
| 31 | + echo "Error: Binary not found for ${component} at ${binary}" |
| 32 | + return 1 |
| 33 | + fi |
| 34 | + |
| 35 | + echo "# What are the parameters to VPA ${component}?" |
| 36 | + echo "This document is auto-generated from the flag definitions in the VPA ${component} code." |
| 37 | + echo |
| 38 | + echo "| Flag | Default | Description |" |
| 39 | + echo "|---------|---------|-------------|" |
| 40 | + |
| 41 | + $binary --help 2>&1 | grep -E '^\s*-' | while read -r line; do |
| 42 | + if [[ $line == *"-v, --v Level"* ]]; then |
| 43 | + # Special handling for the -v, --v Level flag |
| 44 | + flag="v" |
| 45 | + default=$(echo "$line" | sed -n 's/.*default: \([0-9]\+\).*/\1/p') |
| 46 | + description="Set the log level verbosity" |
| 47 | + else |
| 48 | + flag=$(echo "$line" | awk '{print $1}' | sed 's/^-*//;s/=.*$//') |
| 49 | + default=$(echo "$line" | sed -n 's/.*default \([^)]*\).*/\1/p') |
| 50 | + description=$(echo "$line" | sed -E 's/^\s*-[^[:space:]]+ [^[:space:]]+ //;s/ \(default.*\)//') |
| 51 | + description=$(echo "$description" | sed -E "s/^--?${flag}[[:space:]]?//") |
| 52 | + fi |
| 53 | + |
| 54 | + echo "| \`--${flag}\` | ${default:-} | ${description} |" |
| 55 | + done |
| 56 | + echo |
| 57 | +} |
| 58 | +# Build components |
| 59 | +pushd "${SCRIPT_ROOT}" >/dev/null |
| 60 | +for component in "${COMPONENTS[@]}"; do |
| 61 | + echo "Building ${component}..." |
| 62 | + pushd "pkg/${component}" >/dev/null |
| 63 | + if ! go build -o ${component} ; then |
| 64 | + echo "Error: Failed to build ${component}" |
| 65 | + popd >/dev/null |
| 66 | + continue |
| 67 | + fi |
| 68 | + popd >/dev/null |
| 69 | +done |
| 70 | +popd >/dev/null |
| 71 | + |
| 72 | +# Generate combined flags documentation |
| 73 | +echo "Generating flags documentation..." |
| 74 | +{ |
| 75 | + echo "# Vertical Pod Autoscaler Flags" |
| 76 | + echo "This document contains the flags for all VPA components." |
| 77 | + echo |
| 78 | + echo "> **Note:** This document is auto-generated from the default branch (master) of the VPA repository." |
| 79 | + echo |
| 80 | + |
| 81 | + for component in "${COMPONENTS[@]}"; do |
| 82 | + binary="${SCRIPT_ROOT}/pkg/${component}/${component}" |
| 83 | + if ! extract_flags "$binary" "$component" ; then |
| 84 | + echo "Error: Failed to extract flags for ${component}" |
| 85 | + fi |
| 86 | + done |
| 87 | +} > "${TARGET_FILE}" |
| 88 | + |
| 89 | +echo "VPA flags documentation has been generated in ${TARGET_FILE}" |
0 commit comments