From 9a19eb51dd651b54e2c741702c2622d940c521ff Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Mon, 21 Jun 2021 15:56:36 +0200 Subject: [PATCH 1/4] Fix issue with unbound variable --- dump-objects | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dump-objects b/dump-objects index b8de614..dedae02 100755 --- a/dump-objects +++ b/dump-objects @@ -32,13 +32,15 @@ usage() { echo ' -v Verbose output' echo " -d Destination directory (default: ${default_output_dir})" echo ' -s Short delays in case of failures' + echo ' -D enable Debug log' } output_dir="$default_output_dir" opt_verbose= +opt_debug=false opt_fastretries= -while getopts 'hvd:s' opt; do +while getopts 'hvd:Ds' opt; do case "$opt" in h) usage @@ -47,6 +49,7 @@ while getopts 'hvd:s' opt; do v) opt_verbose=yes ;; d) output_dir="$OPTARG" ;; s) opt_fastretries=yes ;; + D) opt_debug=true ;; *) usage >&2 exit 1 @@ -65,7 +68,9 @@ fi find "$output_dir" -mindepth 1 -maxdepth 1 -type f -delete log() { - test -n "$DEBUG" && echo "$@" >&2 + if [ "$opt_debug" = true ]; then + echo "$@" >&2 + fi } delay_attempt() { From 9188aef8b2ccc8b4f023f3f901ad87de0d914f02 Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Mon, 21 Jun 2021 16:16:58 +0200 Subject: [PATCH 2/4] Spellchecker fixes --- dump-objects | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dump-objects b/dump-objects index dedae02..bc55380 100755 --- a/dump-objects +++ b/dump-objects @@ -139,7 +139,7 @@ extract_versioned_apis() { } validate_kinds() { - local -a expected=( $(< /usr/local/share/k8s-object-dumper/must-exist) ) + local -a mapfile -t expected < /usr/local/share/k8s-object-dumper/must-exist local missing=() for j in "${expected[@]}"; do local found= @@ -194,7 +194,8 @@ object_kinds() { # Get all object types for each group for url in "${groups[@]}"; do - local san_name=$(sanitize_name <<< "${url##/}") + local san_name + san_name = $(sanitize_name <<< "${url##/}") local name="api-${san_name}.json" local fname="${output_dir}/${name}" @@ -213,7 +214,7 @@ object_kinds() { # # retrievable_kind() { - local -a known_to_fail=( $(< /usr/local/share/k8s-object-dumper/known-to-fail) ) + local -a mapfile -t known_to_fail < /usr/local/share/k8s-object-dumper/known-to-fail for kind in "${known_to_fail[@]}" do @@ -255,7 +256,7 @@ fetch_objects() { errprefix+='(|Error from server( \([a-zA-Z]+\)|): *|error: *)' - if egrep -iq \ + if grep -Eiq \ -e "^${errprefix}the server does not allow this method on the requested resource\$" \ -e "^${errprefix}Unable to list \"${kind}\": the server could not find the requested resource\$" \ -e "^${errprefix}Unable to list {\".*\" \"v1\" \"${kind}\"}: the server could not find the requested resource\$" \ @@ -368,11 +369,11 @@ declare -i errors=0 if (( "${#kinds[@]}" < min_expected_kinds )); then echo "Expected at least ${min_expected_kinds} resource kinds" >&2 - let ++errors + (( ++errors )) || true fi if ! validate_kinds "${kinds[@]}"; then - let ++errors + (( ++errors )) || true fi log "Fetching resources for ${#kinds[@]} distinct kinds: ${kinds[*]}" @@ -422,21 +423,21 @@ for i in "${kinds[@]}"; do fi if (( status != 0 )); then - let ++errors + (( ++errors )) || true fi echo >&2 done if ! split_objects ${object_files+"${object_files[@]}"}; then - let ++errors + (( ++errors )) || true fi date > "${output_dir}/timestamp-end.txt" # Output for K8up -( cd "${output_dir}" && tar czf ${output_dir}/k8s-objects.tar.gz timestamp-*.txt version.* objects-*.json split/ ) +( cd "${output_dir}" && tar czf "${output_dir}/k8s-objects.tar.gz" timestamp-*.txt version.* objects-*.json split/ ) # dump tar to original stdout cat "${output_dir}/k8s-objects.tar.gz" >&1 From f9b14a3c31ad182e635d1cdf0a35c2ad0724e029 Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Mon, 21 Jun 2021 16:32:22 +0200 Subject: [PATCH 3/4] Set kubectl to specific version --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a6a07d0..124b166 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,9 @@ RUN apt-get update \ curl \ && rm -rf /var/lib/apt/lists/* -RUN curl -sLo /tmp/kubectl "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" \ +ARG K8S_VERSION=v1.18.20 + +RUN curl -sLo /tmp/kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl" \ && chmod +x /tmp/kubectl RUN curl -sLo /tmp/krossa.tar.gz https://github.com/appuio/krossa/releases/download/v0.0.4/krossa_0.0.4_linux_amd64.tar.gz \ From d66f1a8e5b8a9f9bade19a24b625a1206b56b3c1 Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Tue, 22 Jun 2021 09:46:11 +0200 Subject: [PATCH 4/4] Update Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6943768..abfa355 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ useridentitymappings validations ``` -To enable informative logging output for non-error cases, set `$DEBUG` to a non-empty value. +To enable informative logging output for non-error cases, set the `-D` argument. ## Contributing and license