Skip to content

Commit

Permalink
fix and handle empty digest file
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps committed Aug 29, 2020
1 parent 04f7f58 commit 91cf58b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kubectl-kaniko
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ while [ $# -gt 0 ]; do
esac
done

args+="\"--image-name-with-digest-file=/dev/termination-log\""

if [ -n "$digestfile" ] || [ -n "$imagenamewithdigestfile" ]; then
args+="\"--image-name-with-digest-file=/dev/termination-log\""
else
args+="\"--image-name-with-digest-file=\""
fi

if [ -z "$context" ]; then
args+=" ]"
elif [ -d "$context" ]; then
Expand Down Expand Up @@ -148,8 +154,13 @@ else
kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator $kubecontext $kubeconfig $namespace
fi

# Retrieve digest file
if [ $? -eq 0 ] && ( [ -n "$digestfile" ] || [ -n "$imagenamewithdigestfile" ] ) then
imagenamewithdigest=$(kubectl get pod "$name" -o go-template='{{ range .status.containerStatuses }}{{ with .state.terminated.message }}{{ . }}{{ end }}{{ end }}')
if [ -z "$imagenamewithdigest" ]; then
echo "Error: termination message is missing" >&2
exit 2
fi
digest=${imagenamewithdigest##*@}
[ -z "$digestfile" ] || printf "%s" "$digest" > "$digestfile"
[ -z "$imagenamewithdigestfile" ] || printf "%s\n" "$imagenamewithdigest" > "$imagenamewithdigestfile"
Expand Down

0 comments on commit 91cf58b

Please sign in to comment.