Browse Source

fix: [compose-core] repair indirect action

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
cache-relation
Valentin Lab 2 years ago
parent
commit
084f9a0c0a
  1. 25
      bin/compose-core

25
bin/compose-core

@ -2771,11 +2771,8 @@ _run_service_action_relation() {
return 1 return 1
fi fi
export RELATION_DATA_FILE=$(get_relation_data_file "$service" "$target_service" "$relation_name" "$relation_config")
export action_errlvl_file="$state_tmpdir/action-$service-$charm-$action-errlvl" export action_errlvl_file="$state_tmpdir/action-$service-$charm-$action-errlvl"
export state_tmpdir export state_tmpdir
{
( (
set +e ## Prevents unwanted leaks from parent shell set +e ## Prevents unwanted leaks from parent shell
export METADATA_CONFIG=$(charm.metadata "$charm") export METADATA_CONFIG=$(charm.metadata "$charm")
@ -2791,15 +2788,7 @@ _run_service_action_relation() {
export SERVICE_CONFIGSTORE="$CONFIGSTORE/$service" export SERVICE_CONFIGSTORE="$CONFIGSTORE/$service"
exname="$exname $ACTION_NAME $SERVICE_NAME" \ exname="$exname $ACTION_NAME $SERVICE_NAME" \
stdbuf -oL -eL bash -c 'charm.run_relation_action "$@"' -- "$target_charm" "$relation_name" "$action" "$@" stdbuf -oL -eL bash -c 'charm.run_relation_action "$@"' -- "$target_charm" "$relation_name" "$action" "$@"
echo "$?" > "$action_errlvl_file"
) | logstdout "$DARKYELLOW$service$NORMAL/${DARKCYAN}$action${NORMAL} ${GREEN}@${NORMAL}"
} 3>&1 1>&2 2>&3 | logstderr "$DARKYELLOW$service$NORMAL/${DARKCYAN}$action${NORMAL} ${RED}@$NORMAL" 3>&1 1>&2 2>&3
if ! [ -e "$action_errlvl_file" ]; then
err "Action $DARKYELLOW$service$NORMAL:$DARKCYAN$action$NORMAL has failed without having time" \
"to output an errlvl"
return 1
fi
return "$(cat "$action_errlvl_file")"
) 0<&6 ## inject general stdin
} }
export -f _run_service_action_relation export -f _run_service_action_relation
@ -3733,6 +3722,7 @@ get_docker_charm_action_help() {
local services service charm relation_name target_service relation_config \ local services service charm relation_name target_service relation_config \
target_charm target_charm
services=($(get_compose_yml_content | shyaml keys 2>/dev/null)) services=($(get_compose_yml_content | shyaml keys 2>/dev/null))
get_all_relations "${services[@]}" >/dev/null 2>&1 || exit 1
for service in "${services[@]}"; do for service in "${services[@]}"; do
out=$( out=$(
charm=$(get_service_charm "$service") || return 1 charm=$(get_service_charm "$service") || return 1
@ -3744,7 +3734,7 @@ get_docker_charm_action_help() {
for action in $(charm.ls_relation_actions "$target_charm" "$relation_name"); do for action in $(charm.ls_relation_actions "$target_charm" "$relation_name"); do
printf " %-28s %s\n" "$action $service" "Indirect action from ${DARKPINK}$target_charm${NORMAL}" printf " %-28s %s\n" "$action $service" "Indirect action from ${DARKPINK}$target_charm${NORMAL}"
done done
done < <(get_compose_relations "$service")
done < <(get_service_relations "$service")
) )
if [ "$out" ]; then if [ "$out" ]; then
echo " for ${DARKYELLOW}$service${NORMAL}:" echo " for ${DARKYELLOW}$service${NORMAL}:"
@ -4226,6 +4216,12 @@ if [ -z "$is_docker_compose_action" -a "$action" ]; then
display_commands_help display_commands_help
exit 1 exit 1
fi fi
## Required by has_service_action
array_read-0 services_args < <(printf "%s" "$COMPOSE_YML_CONTENT" | shyaml keys-0 2>/dev/null)
get_all_relations "${services_args[@]}" >/dev/null 2>&1 || return 1
remainder_args=("${remainder_args[@]:1}") remainder_args=("${remainder_args[@]:1}")
if has_service_action "$action_service" "$action" >/dev/null; then if has_service_action "$action_service" "$action" >/dev/null; then
is_service_action=true is_service_action=true
@ -4242,6 +4238,7 @@ if [ -z "$is_docker_compose_action" -a "$action" ]; then
esac esac
} < <(has_service_action "$action_service" "$action") } < <(has_service_action "$action_service" "$action")
services_args=("$action_service") services_args=("$action_service")
get_all_relations "${services_args[@]}" >/dev/null 2>&1 || return 1
## Divert logging to stdout to stderr ## Divert logging to stdout to stderr
log () { cat >&2; } log () { cat >&2; }
@ -4420,7 +4417,7 @@ case "$action" in
;; ;;
*) *)
if [ "$is_service_action" ]; then if [ "$is_service_action" ]; then
run_service_action "$SERVICE_PACK" "$action" "${remainder_args[@]}"
run_service_action "$action_service" "$action" "${remainder_args[@]}"
errlvl="$?" errlvl="$?"
errlvl "$errlvl" errlvl "$errlvl"
else else

Loading…
Cancel
Save