Skip to content

Commit

Permalink
Merge pull request #18 from projectsyn/various_fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
mhutter authored Jun 23, 2021
2 parents f7803a7 + d66f1a8 commit 3ca077a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 17 additions & 11 deletions dump-objects
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -134,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=
Expand Down Expand Up @@ -189,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}"

Expand All @@ -208,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
Expand Down Expand Up @@ -250,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\$" \
Expand Down Expand Up @@ -363,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[*]}"
Expand Down Expand Up @@ -417,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
Expand Down

0 comments on commit 3ca077a

Please sign in to comment.